
If you are care about my RSS Reader, it's FeedDemon.
Just a poor developer




public void testConvertWithUnknownCurrency()
throws UnknownCurrencyException {
EasyMock.expect(
exchangeRateService.getExchangeRate(
EasyMock.isA(String.class),
EasyMock.isA(String.class)
)
).andThrow(new UnknownCurrencyException());
EasyMock.replay(exchangeRateService);
try {
converter.convert(10.0, "EUR", "-UNKNOWN-");
fail("an unknown currency exception was expected");
} catch (UnknownCurrencyException e) {
// do nothing, was expected
}
EasyMock.verify(exchangeRateService);
}
@Test(expectedExceptions = {UnknownCurrencyException.class})
public void testConvertWithUnknownCurrency() {
EasyMock.expect(
exchangeRateService.getExchangeRate(
EasyMock.isA(String.class),
EasyMock.isA(String.class)
)
).andThrow(new UnknownCurrencyException());
EasyMock.replay(exchangeRateService);
converter.convert(10.0, "EUR", "-UNKNOWN-");
EasyMock.verify(exchangeRateService);
}EasyMock.verify(exchangeRateService) will never be called 'cause converter.convert(10.0, "EUR", "-UNKNOWN-") throws UnknownCurrencyException. So how to make the test works as same as JUnit version?@Test's dependsOnMethods attribute. But note that TestNG supports 2 kinds of dependencies: hard and soft. And here is explaination from TestNG document:
* Hard dependencies. All the methods you depend on must have run and succeeded for you to run. If at least one failure occurred in your dependencies, you will not be invoked and marked as a SKIP in the report.
* Soft dependencies. You will always be run after the methods you depend on, even if some of them have failed. This is useful when you just want to make sure that your test methods are run in a certain order but their success doesn't really depend on the success of others. A soft dependency is obtained by adding "alwaysRun=true" in your @Test annotation.
dependsOnMethods, what I need is a soft dependency. And here is TestNG version of above test.@Test(expectedExceptions = {UnknownCurrencyException.class})
public void testConvertWithUnknownCurrency() {
EasyMock.expect(
exchangeRateService.getExchangeRate(
EasyMock.isA(String.class),
EasyMock.isA(String.class)
)
).andThrow(new UnknownCurrencyException());
EasyMock.replay(exchangeRateService);
converter.convert(10.0, "EUR", "-UNKNOWN-");
}
@Test(alwaysRun = true,
dependsOnMethods = "testConvertWithUnknownCurrency")
public void verifyAfterTestConvertWithUnknownCurrency() {
EasyMock.verify(exchangeRateService);
}alwaysRun = true from verifyAfterTestConvertWithUnknownCurrency(). Why? 'Cause if testConvertWithUnknownCurrency() fails, it means the test fail, don't need to waste my time to verify something it was failed.List<Member> or create my own MemberList to store all members. If I want to have more features than the standard List<Member> provides, of course, I need to create my own MemberList, which bases on List<Member>. But what will I do if I only need a read-only list? A List<Member> cannot do it. To have a read-only list, I need to use Collections.unmodifiableList(myMemberList) or create MemberList which supports read-only only.List<Member> and forget about its "edit" methods.MemberList will be the best solution but it needs time to implement. To be lazy, using Collections.unmodifiableList(myMemberList) or List<Member> without using its "edit" methods is an acceptable answer.