1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.supercsv.cellprocessor.time;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.time.Period;
21
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.experimental.theories.DataPoints;
25 import org.junit.experimental.theories.Theories;
26 import org.junit.experimental.theories.Theory;
27 import org.junit.rules.ExpectedException;
28 import org.junit.runner.RunWith;
29 import org.supercsv.cellprocessor.time.mock.IdentityTransform;
30 import org.supercsv.exception.SuperCsvCellProcessorException;
31
32
33
34
35 @RunWith(Theories.class)
36 public class FmtPeriodTest {
37
38 @DataPoints public static final FmtPeriod[] processors = { new FmtPeriod(),
39 new FmtPeriod(new IdentityTransform()) };
40 @DataPoints public static final Period[] periods = { Period.of(1, 2, 3), Period.of(0, 0, 0), Period.of(4, 0, 8) };
41
42 @Rule public ExpectedException exception = ExpectedException.none();
43
44 @Theory
45 public void testValidPeriodString(final Period period, final FmtPeriod processor) {
46 assertEquals(period.toString(), processor.execute(period, SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT));
47 }
48
49 @Theory
50 public void testNullInput(final FmtPeriod p) {
51 exception.expect(SuperCsvCellProcessorException.class);
52 exception.expectMessage("this processor does not accept null input - "
53 + "if the column is optional then chain an Optional() processor before this one");
54 p.execute(null, SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT);
55 }
56
57 @Theory
58 public void testNonPeriodInput(final FmtPeriod p) {
59 exception.expect(SuperCsvCellProcessorException.class);
60 exception.expectMessage("the input value should be of type java.time.Period but is java.lang.Integer");
61 p.execute(123, SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT);
62 }
63
64 @Test
65 public void testConstructor2WithNullNext() {
66 exception.expect(NullPointerException.class);
67 new FmtPeriod(null);
68 }
69 }