Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright Openmind http://www.openmindonline.it
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package it.openutils.testing;
 
 import java.util.Date;


Utility methods for checking dates in unit tests.

Author(s):
fgiust
Version:
$Id: DateAssert.java 619 2008-02-17 09:11:48Z fgiust $
 
 public final class DateAssert
 {
 
     private static DateFormat df = new SimpleDateFormat("yyyyMMdd");
 
     private static DateFormat dtf = new SimpleDateFormat("yyyyMMdd HH:mm");

    
Don't instantiate.
 
     private DateAssert()
     {
         // unused
     }

    

Parameters:
expectedDateAsString
date
format
Throws:
java.lang.AssertionError
 
     private static void performComparison(String expectedDateAsStringDate dateDateFormat format)
         throws AssertionError
     {
         Date expected;
 
         try
         {
             synchronized (format)
             {
                 expected = format.parse(expectedDateAsString);
             }
         }
         catch (ParseException e)
         {
             throw new IllegalArgumentException("Unparseable date String: [" + expectedDateAsString + "]");
         }
 
         if (date == null)
         {
             throw new AssertionError("Date is null");
         }
 
         String expDate;
         String actDate;
 
         synchronized (format)
         {
             expDate = format.format(expected);
             actDate = format.format(date);
         }
 
         if (!expDate.equals(actDate))
         {
             throw new AssertionError("Expected <" + expDate + ">, actual <" + actDate + ">");
         }
     }

    
Asserts that two dates are equal.

Parameters:
expectedDateAsString date formatted as "YYYYMMDD"
date actual date
Throws:
java.lang.IllegalArgumentException if expectedDateAsString is not a valid date format
 
     public static void dateEqual(String expectedDateAsStringCalendar datethrows IllegalArgumentException
     {
         performComparison(expectedDateAsStringdate.getTime(), );
     }

    
Asserts that two dates are equal.

Parameters:
expectedDateAsString date formatted as "YYYYMMDD"
date actual date
Throws:
java.lang.IllegalArgumentException if expectedDateAsString is not a valid date format
    public static void dateEqual(String expectedDateAsStringDate datethrows IllegalArgumentException
    {
        performComparison(expectedDateAsStringdate);
    }

    
Asserts that two dates are equal.

Parameters:
expectedDateAsString date formatted as "yyyyMMdd HH:mm"
date actual date
Throws:
java.lang.IllegalArgumentException if expectedDateAsString is not a valid date format
    public static void dateTimeEqual(String expectedDateAsStringDate datethrows IllegalArgumentException
    {
        performComparison(expectedDateAsStringdate);
    }

    
Asserts that two dates are equal.

Parameters:
expectedDateAsString date formatted as "yyyyMMdd HH:mm"
date actual date
Throws:
java.lang.IllegalArgumentException if expectedDateAsString is not a valid date format
    public static void dateTimeEqual(String expectedDateAsStringCalendar datethrows IllegalArgumentException
    {
        performComparison(expectedDateAsStringdate.getTime(), );
    }
New to GrepCode? Check out our FAQ X