You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/05/04 00:06:51 UTC
svn commit: r1099280 -
/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
Author: sebb
Date: Tue May 3 22:06:51 2011
New Revision: 1099280
URL: http://svn.apache.org/viewvc?rev=1099280&view=rev
Log:
Enable some future date checking
Modified:
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java?rev=1099280&r1=1099279&r2=1099280&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java Tue May 3 22:06:51 2011
@@ -27,6 +27,7 @@ import java.util.TimeZone;
import org.apache.commons.net.ftp.FTPClientConfig;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
/**
@@ -289,31 +290,51 @@ public class FTPTimestampParserImplTest
checkShortParse("2004-8-1 -26 weeks",now,target);
}
-// It has not yet been decided how to handle future dates, so skip these tests for now
+// Lenient mode allows for dates up to 1 day in the future
-// public void testParseShortFutureDates1() throws Exception {
-// GregorianCalendar now = new GregorianCalendar(2001, Calendar.MAY, 30, 12, 0);
-// checkShortParse("2001-5-30",now,now); // should always work
-// GregorianCalendar target = (GregorianCalendar) now.clone();
-// target.add(Calendar.WEEK_OF_YEAR, 1);
+ public void testParseShortFutureDates1() throws Exception {
+ GregorianCalendar now = new GregorianCalendar(2001, Calendar.MAY, 30, 12, 0);
+ checkShortParse("2001-5-30",now,now); // should always work
+ GregorianCalendar target = (GregorianCalendar) now.clone();
+ target.add(Calendar.DAY_OF_MONTH, 1);
+ checkShortParse("2001-5-30 +1 day",now,target,true);
+ try {
+ checkShortParse("2001-5-30 +1 day",now,target,false);
+ fail("Expected AssertionFailedError");
+ } catch (AssertionFailedError pe) {
+ if (pe.getMessage().startsWith("Expected AssertionFailedError")) { // don't swallow our failure
+ throw pe;
+ }
+ }
+ target.add(Calendar.WEEK_OF_YEAR, 1);
// checkShortParse("2001-5-30 +1 week",now,target);
// target.add(Calendar.WEEK_OF_YEAR, 12);
// checkShortParse("2001-5-30 +13 weeks",now,target);
// target.add(Calendar.WEEK_OF_YEAR, 13);
// checkShortParse("2001-5-30 +26 weeks",now,target);
-// }
+ }
-// public void testParseShortFutureDates2() throws Exception {
-// GregorianCalendar now = new GregorianCalendar(2004, Calendar.AUGUST, 1, 12, 0);
-// checkShortParse("2004-8-1",now,now); // should always work
-// GregorianCalendar target = (GregorianCalendar) now.clone();
+ public void testParseShortFutureDates2() throws Exception {
+ GregorianCalendar now = new GregorianCalendar(2004, Calendar.AUGUST, 1, 12, 0);
+ checkShortParse("2004-8-1",now,now); // should always work
+ GregorianCalendar target = (GregorianCalendar) now.clone();
+ target.add(Calendar.DAY_OF_MONTH, 1);
+ checkShortParse("2004-8-1 +1 day",now,target,true);
+ try {
+ checkShortParse("2004-8-1 +1 day",now,target,false);
+ fail("Expected AssertionFailedError");
+ } catch (AssertionFailedError pe) {
+ if (pe.getMessage().startsWith("Expected AssertionFailedError")) { // don't swallow our failure
+ throw pe;
+ }
+ }
// target.add(Calendar.WEEK_OF_YEAR, 1);
// checkShortParse("2004-8-1 +1 week",now,target);
// target.add(Calendar.WEEK_OF_YEAR, 12);
// checkShortParse("2004-8-1 +13 weeks",now,target);
// target.add(Calendar.WEEK_OF_YEAR, 13);
// checkShortParse("2004-8-1 +26 weeks",now,target);
-// }
+ }
// Test leap year if current year is a leap year
public void testFeb29IfLeapYear() throws Exception{