View Javadoc

1   /*
2    * $Id: DateUtilsTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.junit4.AbstractMuleTestCase;
14  
15  import java.util.Date;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  
22  public class DateUtilsTestCase extends AbstractMuleTestCase
23  {
24      private final String TEST_DATE_FORMAT = "dd/MM/yyyy hh:mm:ss";
25      private final String TEST_DATE_FORMAT_2 = "dd-MM-yy, hh:mm";
26  
27      @Test
28      public void testDateUtils() throws Exception
29      {
30          String date = "12/11/2002 12:06:47";
31  
32          Date result = DateUtils.getDateFromString(date, TEST_DATE_FORMAT);
33          assertTrue(result.before(new Date(System.currentTimeMillis())));
34  
35          String newDate = DateUtils.getStringFromDate(result, TEST_DATE_FORMAT);
36          assertEquals(date, newDate);
37  
38          String timestamp = DateUtils.formatTimeStamp(result, TEST_DATE_FORMAT_2);
39          assertEquals("12-11-02, 12:06", timestamp);
40  
41          String newTimestamp = DateUtils.getTimeStamp(TEST_DATE_FORMAT_2);
42          assertEquals(DateUtils.getStringFromDate(new Date(), TEST_DATE_FORMAT_2), newTimestamp);
43      }
44  
45  }