public class Iso8601DateParserTest extends TestCase {
@Test
public void testWeekFormatParse() {
Iso8601DateParser parser = new Iso8601DateParser();
String s1 = "2010-W01-1";
try {
Iso8601Date d1 = parser.parse(s1);
assertNotNull(d1);
assertTrue(d1.isDay());
assertEquals(d1.getYear(), 2010);
assertEquals(d1.getWeekOfYear(), 1);
assertEquals(d1.getDayOfWeek(), 1);
} catch (Iso8601DateParseException e) {
fail();
e.printStackTrace();
}
String s2 = "2010-W01";
try {
Iso8601Date d2 = parser.parse(s2);
assertNotNull(d2);
assertFalse(d2.isDay());
assertTrue(d2.isWeek());
assertEquals(d2.getYear(), 2010);
assertEquals(d2.getWeekOfYear(), 1);
} catch (Iso8601DateParseException e) {
e.printStackTrace();
fail();
}
String s3 = "2010W01";
try {
Iso8601Date d3 = parser.parse(s3);
assertNotNull(d3);
assertFalse(d3.isDay());
assertTrue(d3.isWeek());
assertEquals(d3.getYear(), 2010);
assertEquals(d3.getWeekOfYear(), 1);
} catch (Iso8601DateParseException e) {
e.printStackTrace();
fail();
}
String s4 = "2010W011";
try {
Iso8601Date d4 = parser.parse(s4);
assertNotNull(d4);
assertTrue(d4.isDay());
assertEquals(d4.getYear(), 2010);
assertEquals(d4.getWeekOfYear(), 1);
assertEquals(d4.getDayOfWeek(), 1);
} catch (Iso8601DateParseException e) {
e.printStackTrace();
fail();
}
String s5 = "2010011";
try {
Iso8601Date d5 = parser.parse(s5);
assertNotNull(d5);
assertTrue(d5.isDay());
assertEquals(d5.getYear(), 2010);
assertEquals(d5.getDayOfYear(), 11);
} catch (Iso8601DateParseException e) {
e.printStackTrace();
fail();
}
String s6 = "2010W1";
boolean correctError = false;
try {
parser.parse(s6);
} catch (Iso8601DateParseException e) {
System.err.println(e.getMessage());
correctError = true;
} catch (NumberFormatException e1) {
e1.printStackTrace();
fail();
}
assertTrue(correctError);
String s7 = "201001";
try {
Iso8601Date d7 = parser.parse(s7);
assertNotNull(d7);
assertTrue(d7.isMonth());
assertEquals(d7.getYear(), 2010);
assertEquals(d7.getMonth(), 1);
} catch (Iso8601DateParseException e) {
e.printStackTrace();
fail();
}
String s8 = "2010-W011";
boolean correctError2 = false;
try {
parser.parse(s8);
} catch (Iso8601DateParseException e) {
correctError2 = true;
System.err.println(e.getMessage());
} catch (NumberFormatException nfe) {
nfe.printStackTrace();