Posted by Anonymous Fri 2nd Mar 2007 23:03 - Syntax is Java 5 - 134 views
Download | New Post | Modify | Hide line numbers
Description:
Second test fails... WHY!?

  1. public void testExactlyOnEndDate() throws ParseException{
  2.         String someDate = "Fri Feb 10 01:59:59 CST 2007";
  3.         SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd kk:mm:ss zzz yyyy");
  4.         date = formatter.parse(someDate);
  5.        
  6.         DateRange range = new DateRange("02/05/2007", "02/10/2007");
  7.         assertTrue("Date should be within range", range.includes(date));
  8.     }
  9.    
  10.     public void testExactlyOnEndDate2() throws ParseException{ // Fails
  11.         String someDate = "Fri Feb 10 02:00:00 CST 2007";
  12.         SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd kk:mm:ss zzz yyyy");
  13.         date = formatter.parse(someDate);
  14.        
  15.         DateRange range = new DateRange("02/05/2007", "02/10/2007");
  16.         assertTrue("Date should be within range", range.includes(date));
  17.     }
  18.  
  19.  
  20.  
  21. ---- The DateRange class
  22.  
  23. import java.text.ParseException;
  24. import java.text.SimpleDateFormat;
  25. import java.util.;
  26.  
  27. public class DateRange {
  28.     private _start;
  29.     private _end;
  30.     private static final SimpleDateFormat DEFAULT_FORMAT = new SimpleDateFormat("MM/dd/yyyy");
  31.    
  32.     public DateRange(String start, String end) throws ParseException {
  33.         _start = DEFAULT_FORMAT.parse(start);
  34.         _end = DEFAULT_FORMAT.parse(end);
  35.     }
  36.  
  37.     public boolean includes( date) {   
  38.         return _start.before(date) && _end.after(date);
  39.     }
  40.  
  41. }

PermaLink to this entry https://pastebin.co.uk/11316
Posted by Anonymous Fri 2nd Mar 2007 23:03 - Syntax is Java 5 - 134 views
Download | New Post | Modify | Hide line numbers

 

Comments: 0