gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / test / java / org / gvsig / tools / datatypes / impl / coercion / CoerceToDateTimeTest.java @ 2080
History | View | Annotate | Download (2.66 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.tools.datatypes.impl.coercion; |
25 |
|
26 |
import java.text.DateFormat; |
27 |
import java.util.Calendar; |
28 |
import java.util.Date; |
29 |
|
30 |
import org.gvsig.tools.dataTypes.CoercionException; |
31 |
import org.gvsig.tools.dataTypes.Coercion; |
32 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDate; |
33 |
import org.gvsig.tools.dataTypes.impl.coercion.CoerceToDateTime; |
34 |
|
35 |
/**
|
36 |
* Unit tests for the {@link CoerceToDate} class.
|
37 |
*
|
38 |
* @author gvSIG Team
|
39 |
* @version $Id$
|
40 |
*/
|
41 |
public class CoerceToDateTimeTest extends CoercionTestAbstract { |
42 |
|
43 |
public void testCoerce() throws Exception { |
44 |
CoerceToDateTime coerce = new CoerceToDateTime();
|
45 |
|
46 |
Calendar calendar = Calendar.getInstance(); |
47 |
// Remember the month value is in format 0 to 11, instead of 1 to 12,
|
48 |
// so september is the 8th month
|
49 |
calendar.set(2011, 8, 5, 10, 5, 30); |
50 |
Date date = calendar.getTime();
|
51 |
|
52 |
assertCoercion(coerce, date, date); |
53 |
DateFormat format =
|
54 |
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); |
55 |
assertCoercion(coerce, format.format(date), date); |
56 |
} |
57 |
|
58 |
private void assertCoercion(Coercion coerce, Object value, Date expected) |
59 |
throws CoercionException {
|
60 |
Object result = coerce.coerce(value);
|
61 |
assertEquals(Date.class, result.getClass());
|
62 |
Date resultDate = (Date) result; |
63 |
assertEquals(expected.getYear(), resultDate.getYear()); |
64 |
assertEquals(expected.getMonth(), resultDate.getMonth()); |
65 |
assertEquals(expected.getDay(), resultDate.getDay()); |
66 |
assertEquals(expected.getHours(), resultDate.getHours()); |
67 |
assertEquals(expected.getMinutes(), resultDate.getMinutes()); |
68 |
assertEquals(expected.getSeconds(), resultDate.getSeconds()); |
69 |
} |
70 |
|
71 |
} |