I am testing WeekConverter to use Xalan and wondering what exactly my test is doing .: D
Having the following testing method:
@Test(expected = IllegalArgumentException.class) public void testConvertTwoDigitYearWithWrongInput() { WeekConverter weekConverter = new WeekConverter(WeekConverter.Strategy.TWO_DIGIT_YEAR); //wrong or empty inputs assertEquals("0", weekConverter.convert("")); assertEquals("0", weekConverter.convert("abcdefgh")); }
Will this test expect an exception for all statements, or only for the first statement? If only the first, which would mean that I have to create a test method for each statement, although I expect the same exception in both cases. Can someone confirm my example here, please?
I also have a test for null that throws a NullPointerException. A soft check is as follows:
if (inputDate == null) { do something and throw NullPointerexception } else if (inputDate.isEmpty()) { do something and throw IllegalArgumentException, since inputDate is not really null } else if (inputDate.matches(regex)) { go futher and convert } else { do something and throw IllegalArgumentException, since inputDate does not match regex }
Therefore, one test method expects an IllegalArgumentException with two statements. But obviously, I need two different testing methods, not just to respect the functionality of JUnit, but also that I expect a throw from two different states.
source share