1   /*
2    * $Id: DateUtilsTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.util;
12  
13  import org.mule.tck.AbstractMuleTestCase;
14  
15  import java.util.Date;
16  
17  public class DateUtilsTestCase extends AbstractMuleTestCase
18  {
19      private final String TEST_DATE_FORMAT = "dd/MM/yyyy hh:mm:ss";
20      private final String TEST_DATE_FORMAT_2 = "dd-MM-yy, hh:mm";
21  
22      public void testDateUtils() throws Exception
23      {
24          String date = "12/11/2002 12:06:47";
25  
26          Date result = DateUtils.getDateFromString(date, TEST_DATE_FORMAT);
27          assertTrue(result.before(new Date(System.currentTimeMillis())));
28  
29          String newDate = DateUtils.getStringFromDate(result, TEST_DATE_FORMAT);
30          assertEquals(date, newDate);
31  
32          String timestamp = DateUtils.formatTimeStamp(result, TEST_DATE_FORMAT_2);
33          assertEquals("12-11-02, 12:06", timestamp);
34  
35          String newTimestamp = DateUtils.getTimeStamp(TEST_DATE_FORMAT_2);
36          assertEquals(DateUtils.getStringFromDate(new Date(), TEST_DATE_FORMAT_2), newTimestamp);
37      }
38  
39  }