⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcurrencyconvertertests.java

📁 一些很有用的spring的书籍
💻 JAVA
字号:
package com.apress.springbook.chapter10;

import junit.framework.TestCase;

import org.easymock.EasyMock;

public class DefaultCurrencyConverterTests extends TestCase {
   private DefaultCurrencyConverter converter;

   private ExchangeRateService exchangeRateService;

   public DefaultCurrencyConverterTests(String name) {
      super(name);
   }

   protected void setUp() throws Exception {
      converter = new DefaultCurrencyConverter();

      exchangeRateService = EasyMock.createMock(ExchangeRateService.class);
      converter.setExchangeRateService(exchangeRateService);
   }

   // tests go here ...
public void testConvertWithValidInput() throws UnknownCurrencyException {
  EasyMock.expect(exchangeRateService.getExchangeRate("EUR", "USD"))
         .andReturn(1.2).times(2);

  EasyMock.replay(exchangeRateService);

  assertEquals(12.0, converter.convert(10.0, "EUR", "USD"));
  assertEquals(24.0, converter.convert(20.0, "EUR", "USD"));

  EasyMock.verify(exchangeRateService);
}

public void testConvertWithUnknownCurrency() throws UnknownCurrencyException {
  EasyMock.expect(exchangeRateService.getExchangeRate(
         (String)EasyMock.isA(String.class), (String)EasyMock.isA(String.class)))
         .andThrow(new UnknownCurrencyException()).times(2);

  EasyMock.replay(exchangeRateService);

  try {
    converter.convert(10.0, "EUR", "-UNKNOWN-");
    fail("an unknown currency exception was expected");
  } catch (UnknownCurrencyException e) {
    // do nothing, was expected
  }

  try {
    converter.convert(10.0, "-UNKNOWN-", "EUR");
    fail("an unknown currency exception was expected");
  } catch (UnknownCurrencyException e) {
    // do nothing, was expected
  }

  EasyMock.verify(exchangeRateService);
}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -