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 java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.supercsv.cellprocessor.ift.CellProcessor;
28 import org.supercsv.exception.SuperCsvCellProcessorException;
29 import org.supercsv.exception.SuperCsvConstraintViolationException;
30 import org.supercsv.mock.IdentityTransform;
31
32
33
34
35
36
37
38 public class ForbidSubStrTest {
39
40 private static final String FORBIDDEN = "C++";
41 private static final String FORBIDDEN2 = "Microsoft";
42
43 private CellProcessor processor;
44 private CellProcessor processor2;
45 private CellProcessor processorChain;
46 private CellProcessor processorChain2;
47 private CellProcessor processorChain3;
48
49
50
51
52 @Before
53 public void setUp() {
54 processor = new ForbidSubStr(Arrays.asList(FORBIDDEN, FORBIDDEN2));
55 processor2 = new ForbidSubStr(FORBIDDEN, FORBIDDEN2);
56 processorChain = new ForbidSubStr(Arrays.asList(FORBIDDEN, FORBIDDEN2), new IdentityTransform());
57 processorChain2 = new ForbidSubStr(FORBIDDEN, new IdentityTransform());
58 processorChain3 = new ForbidSubStr(new String[] { FORBIDDEN, FORBIDDEN2 }, new IdentityTransform());
59 }
60
61
62
63
64 @Test
65 public void testValidInput() {
66 String input = "I think Java is an awesome language";
67 assertEquals(input, processor.execute(input, ANONYMOUS_CSVCONTEXT));
68 assertEquals(input, processor2.execute(input, ANONYMOUS_CSVCONTEXT));
69 assertEquals(input, processorChain.execute(input, ANONYMOUS_CSVCONTEXT));
70 assertEquals(input, processorChain2.execute(input, ANONYMOUS_CSVCONTEXT));
71 assertEquals(input, processorChain3.execute(input, ANONYMOUS_CSVCONTEXT));
72
73 }
74
75
76
77
78 @Test(expected = SuperCsvConstraintViolationException.class)
79 public void testForbidden() {
80 String input = "I think C++ is an awesome language";
81 processor.execute(input, ANONYMOUS_CSVCONTEXT);
82 }
83
84
85
86
87 @Test(expected = SuperCsvConstraintViolationException.class)
88 public void testForbidden2() {
89 String input = "I love Microsoft";
90 processor.execute(input, ANONYMOUS_CSVCONTEXT);
91 }
92
93
94
95
96 @Test(expected = SuperCsvCellProcessorException.class)
97 public void testWithNull() {
98 processor.execute(null, ANONYMOUS_CSVCONTEXT);
99 }
100
101
102
103
104 @Test(expected = NullPointerException.class)
105 public void testConstructionWithNullArray() {
106 new ForbidSubStr((String[]) null);
107 }
108
109
110
111
112 @Test(expected = IllegalArgumentException.class)
113 public void testConstructionWithEmptyArray() {
114 new ForbidSubStr(new String[] {});
115 }
116
117
118
119
120 @Test(expected = NullPointerException.class)
121 public void testConstructionWithNullList() {
122 new ForbidSubStr((List<String>) null, new IdentityTransform());
123 }
124
125
126
127
128 @Test(expected = IllegalArgumentException.class)
129 public void testConstructionWithEmptyList() {
130 new ForbidSubStr(new ArrayList<String>(), new IdentityTransform());
131 }
132
133
134
135
136 @Test(expected = NullPointerException.class)
137 public void testConstructionWithNullSubstring() {
138 new ForbidSubStr(new String[] { null });
139 }
140 }