1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2008 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17 package ch.elca.el4j.tests.util.codingsupport;
18
19 import static org.junit.Assert.assertEquals;
20
21 import org.joda.time.DateTime;
22 import org.junit.Test;
23
24 import ch.elca.el4j.util.codingsupport.JodaTimeUtils;
25
26 /**
27 *
28 * This class tests the JodaTimeUtils class.
29 *
30 * @svnLink $Revision: 3966 $;$Date: 2009-10-22 09:07:47 +0200 (Do, 22. Okt 2009) $;$Author: dajamesthomas $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/test/java/ch/elca/el4j/tests/util/codingsupport/JodaTimeTest.java $
31 *
32 * @author Daniel Thomas (DTH)
33 */
34 public class JodaTimeTest {
35
36 /**
37 * Tests the conversion from a DateTime object to a string.
38 */
39
40 @Test
41 public void testDateTimeToString() {
42 DateTime dt = new DateTime (2009, 10, 16, 10, 28, 20, 0);
43
44 assertEquals(JodaTimeUtils.getDateTimeString(dt, JodaTimeUtils.DEFAULT_DATE_WITH_PERIOD),"16.10.2009");
45 assertEquals(JodaTimeUtils.getDateTimeString(dt, JodaTimeUtils.DEFAULT_DATE_WITH_WHITESPACE),"16 10 2009");
46 assertEquals(JodaTimeUtils.getDateTimeString(dt, JodaTimeUtils.DEFAULT_DATETIME),"16.10.2009 10:28:20");
47
48
49 }
50
51 /**
52 * Tests the conversion from a string object to a DateTime object.
53 *
54 */
55
56 @Test
57 public void testStringToDateTime() {
58 DateTime dt = JodaTimeUtils.parseDateTime("09.10.16", "yy.MM.dd");
59
60 assertEquals(dt.getYear(), 2009);
61 assertEquals(dt.getMonthOfYear(), 10);
62 assertEquals(dt.getDayOfMonth(), 16);
63
64 }
65
66 }