Add some more tests

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1390815 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2012-09-27 02:46:55 +00:00
parent 9dabaeeb96
commit 67914b1475
1 changed files with 18 additions and 2 deletions

View File

@ -333,6 +333,14 @@ public class FastDateParserTest {
assertEquals(cal.getTime(), fdf.parse("'20030210A'B153320989'"));
}
@Test
public void testSpecialCharacters() throws Exception {
testSdfAndFdp("q" ,"", true); // bad pattern character (at present)
testSdfAndFdp("Q" ,"", true); // bad pattern character
testSdfAndFdp("$" ,"$", false); // OK
testSdfAndFdp("?.d" ,"?.12", false); // OK
}
@Test
public void testLANG_832() throws Exception {
testSdfAndFdp("'d'd" ,"d3", false); // OK
@ -346,6 +354,7 @@ public class FastDateParserTest {
private void testSdfAndFdp(String format, String date, boolean shouldFail)
throws Exception {
final boolean debug = false;
Date dfdp = null;
Date dsdf = null;
Throwable f = null;
@ -363,7 +372,9 @@ public class FastDateParserTest {
if (!shouldFail) {
throw e;
}
// System.out.println("sdf:"+format+"/"+date+"=>"+e);
if (debug) {
System.out.println("sdf:"+format+"/"+date+"=>"+e);
}
}
try {
@ -377,11 +388,16 @@ public class FastDateParserTest {
if (!shouldFail) {
throw e;
}
// System.out.println("fdf:"+format+"/"+date+"=>"+e);
if (debug) {
System.out.println("fdf:"+format+"/"+date+"=>"+e);
}
}
// SDF and FDF should produce equivalent results
assertTrue("Should both or neither throw Exceptions", (f==null)==(s==null));
assertEquals("Parsed dates should be equal", dsdf, dfdp);
if (debug) {
System.out.println(format + "," + date + " => " + dsdf);
}
}
@Test