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