1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.supercsv.cellprocessor.joda;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.fail;
20 import static org.supercsv.cellprocessor.joda.SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT;
21
22 import java.util.Arrays;
23 import java.util.List;
24
25 import org.joda.time.DateTimeZone;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.supercsv.cellprocessor.ift.CellProcessor;
29 import org.supercsv.cellprocessor.joda.mock.IdentityTransform;
30 import org.supercsv.exception.SuperCsvCellProcessorException;
31
32
33
34
35 public class FmtDateTimeZoneTest {
36
37 private static final String DATE_TIME_ZONE_STRING = "Australia/Brisbane";
38 private static final DateTimeZone DATE_TIME_ZONE = DateTimeZone.forID("Australia/Brisbane");
39
40 private FmtDateTimeZone processor1;
41 private FmtDateTimeZone processorChain1;
42 private List<FmtDateTimeZone> processors;
43
44 @Before
45 public void setUp() {
46 processor1 = new FmtDateTimeZone();
47 processorChain1 = new FmtDateTimeZone(new IdentityTransform());
48 processors = Arrays.asList(processor1, processorChain1);
49 }
50
51 @Test
52 public void testValidDateTimeZoneString() {
53 for (CellProcessor p : processors) {
54 assertEquals(DATE_TIME_ZONE_STRING,
55 p.execute(DATE_TIME_ZONE, ANONYMOUS_CSVCONTEXT));
56 }
57 }
58
59 @Test
60 public void testNullInput() {
61 for (CellProcessor p : processors) {
62 try {
63 p.execute(null, ANONYMOUS_CSVCONTEXT);
64 fail("expecting SuperCsvCellProcessorException");
65 } catch (SuperCsvCellProcessorException e) {
66 assertEquals(
67 "this processor does not accept null input - "
68 + "if the column is optional then chain an Optional() processor before this one",
69 e.getMessage());
70 }
71 }
72 }
73
74 @Test
75 public void testNonDateTimeZoneInput() {
76 for (CellProcessor p : processors) {
77 try {
78 p.execute(123, ANONYMOUS_CSVCONTEXT);
79 fail("expecting SuperCsvCellProcessorException");
80 } catch (SuperCsvCellProcessorException e) {
81 assertEquals(
82 "the input value should be of type org.joda.time.DateTimeZone but is java.lang.Integer",
83 e.getMessage());
84 }
85 }
86 }
87
88 @Test(expected = NullPointerException.class)
89 public void testConstructor2WithNullNext() {
90 new FmtDateTimeZone((CellProcessor) null);
91 }
92
93 }