1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.util;
|
10
|
|
11
|
import org.joda.time.DateTimeFieldType;
|
12
|
import org.joda.time.Partial;
|
13
|
import org.junit.Assert;
|
14
|
import org.junit.Test;
|
15
|
|
16
|
import eu.etaxonomy.cdm.vaadin.util.converter.JodaTimePartialConverter;
|
17
|
|
18
|
/**
|
19
|
* @author a.kohlbecker
|
20
|
* @since Apr 10, 2017
|
21
|
*
|
22
|
*/
|
23
|
public class JodaTimePartialConverterTest extends Assert {
|
24
|
|
25
|
Partial y = new Partial(
|
26
|
new DateTimeFieldType[]{
|
27
|
DateTimeFieldType.year()
|
28
|
},
|
29
|
new int[]{
|
30
|
2012
|
31
|
}
|
32
|
);
|
33
|
Partial ym = new Partial(
|
34
|
new DateTimeFieldType[]{
|
35
|
DateTimeFieldType.year(),
|
36
|
DateTimeFieldType.monthOfYear()
|
37
|
},
|
38
|
new int[]{
|
39
|
2013,
|
40
|
04
|
41
|
}
|
42
|
);
|
43
|
Partial ymd = new Partial(
|
44
|
new DateTimeFieldType[]{
|
45
|
DateTimeFieldType.year(),
|
46
|
DateTimeFieldType.monthOfYear(),
|
47
|
DateTimeFieldType.dayOfMonth()
|
48
|
},
|
49
|
new int[]{
|
50
|
2014,
|
51
|
04,
|
52
|
12
|
53
|
}
|
54
|
);
|
55
|
|
56
|
|
57
|
@Test
|
58
|
public void toISO8601() {
|
59
|
JodaTimePartialConverter conv = new JodaTimePartialConverter(JodaTimePartialConverter.DateFormat.ISO8601);
|
60
|
assertEquals("2012", conv.convertToPresentation(y, String.class, null));
|
61
|
assertEquals("2013-04", conv.convertToPresentation(ym, String.class, null));
|
62
|
assertEquals("2014-04-12", conv.convertToPresentation(ymd, String.class, null));
|
63
|
}
|
64
|
|
65
|
|
66
|
@Test
|
67
|
public void toDAY_MONTH_YEAR_DOT() {
|
68
|
JodaTimePartialConverter conv = new JodaTimePartialConverter(JodaTimePartialConverter.DateFormat.DAY_MONTH_YEAR_DOT);
|
69
|
assertEquals("2012", conv.convertToPresentation(y, String.class, null));
|
70
|
assertEquals("04.2013", conv.convertToPresentation(ym, String.class, null));
|
71
|
assertEquals("12.04.2014", conv.convertToPresentation(ymd, String.class, null));
|
72
|
}
|
73
|
|
74
|
@Test
|
75
|
public void fromDAY_MONTH_YEAR_DOT() {
|
76
|
// using null as format since the conversion should work for all formats
|
77
|
JodaTimePartialConverter conv = new JodaTimePartialConverter(null);
|
78
|
assertEquals(y, conv.convertToModel("2012", Partial.class, null));
|
79
|
assertEquals(ym, conv.convertToModel("2013-04", Partial.class, null));
|
80
|
assertEquals(ym, conv.convertToModel("04.2013", Partial.class, null));
|
81
|
assertEquals(ymd, conv.convertToModel("2014-04-12", Partial.class, null));
|
82
|
assertEquals(ymd, conv.convertToModel("12.04.2014", Partial.class, null));
|
83
|
assertEquals(ymd, conv.convertToModel("12.4.2014", Partial.class, null));
|
84
|
}
|
85
|
|
86
|
}
|