1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.supercsv.cellprocessor.constraint;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.supercsv.SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT;
20
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.supercsv.SuperCsvTestUtils;
24 import org.supercsv.cellprocessor.ift.CellProcessor;
25 import org.supercsv.exception.SuperCsvCellProcessorException;
26 import org.supercsv.exception.SuperCsvConstraintViolationException;
27 import org.supercsv.mock.IdentityTransform;
28
29
30
31
32
33
34
35 public class StrlenTest {
36
37 private static final int LENGTH1 = 2;
38 private static final int LENGTH2 = 3;
39
40 private CellProcessor processor;
41 private CellProcessor processorChain;
42 private CellProcessor processorChain2;
43
44
45
46
47 @Before
48 public void setUp() {
49 processor = new Strlen(LENGTH1, LENGTH2);
50 processorChain = new Strlen(LENGTH1, new IdentityTransform());
51 processorChain2 = new Strlen(new int[] { LENGTH1, LENGTH2 }, new IdentityTransform());
52 }
53
54
55
56
57 @Test
58 public void testValidInput() {
59 String input = "OK";
60 assertEquals(input, processor.execute(input, ANONYMOUS_CSVCONTEXT));
61 assertEquals(input, processorChain.execute(input, ANONYMOUS_CSVCONTEXT));
62 assertEquals(input, processorChain2.execute(input, ANONYMOUS_CSVCONTEXT));
63
64 input = "yep";
65 assertEquals(input, processor.execute(input, ANONYMOUS_CSVCONTEXT));
66
67 assertEquals(input, processorChain2.execute(input, ANONYMOUS_CSVCONTEXT));
68
69 }
70
71
72
73
74 @Test(expected = SuperCsvConstraintViolationException.class)
75 public void testInvalidInput() {
76 processor.execute("four", SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT);
77 }
78
79
80
81
82 @Test(expected = IllegalArgumentException.class)
83 public void testNegativeLength() {
84 new Strlen(-1);
85 }
86
87
88
89
90 @Test(expected = SuperCsvCellProcessorException.class)
91 public void testWithNull() {
92 processor.execute(null, ANONYMOUS_CSVCONTEXT);
93 }
94
95
96
97
98 @Test(expected = NullPointerException.class)
99 public void testConstructionWithNullArray() {
100 new Strlen((int[]) null);
101 }
102
103
104
105
106 @Test(expected = IllegalArgumentException.class)
107 public void testConstructionWithEmptyArray() {
108 new Strlen(new int[] {});
109 }
110 }