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.fail;
19 import static org.supercsv.SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT;
20
21 import java.util.Arrays;
22 import java.util.List;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.supercsv.exception.SuperCsvConstraintViolationException;
27 import org.supercsv.mock.IdentityTransform;
28
29
30
31
32
33
34 public class IsElementOfTest {
35
36 private IsElementOf processor;
37 private IsElementOf chainedProcessor;
38 private List<Object> input = Arrays.asList(new Object[] { "one", 2, 3.0, true, null });
39
40
41
42
43 @Before
44 public void setUp() {
45 processor = new IsElementOf(input);
46 chainedProcessor = new IsElementOf(input, new IdentityTransform());
47 }
48
49
50
51
52 @Test
53 public void testIsElementOf() {
54
55 for( Object o : input ) {
56 processor.execute(o, ANONYMOUS_CSVCONTEXT);
57 }
58
59 try {
60 processor.execute("not an element", ANONYMOUS_CSVCONTEXT);
61 fail("should have thrown SuperCsvConstraintViolationException");
62 }
63 catch(final SuperCsvConstraintViolationException e) {}
64
65 }
66
67
68
69
70 @Test
71 public void testChainedIsElementOf() {
72
73 for( Object o : input ) {
74 chainedProcessor.execute(o, ANONYMOUS_CSVCONTEXT);
75 }
76
77 try {
78 chainedProcessor.execute("not an element", ANONYMOUS_CSVCONTEXT);
79 fail("should have thrown SuperCsvConstraintViolationException");
80 }
81 catch(final SuperCsvConstraintViolationException e) {}
82
83 }
84
85
86
87
88 @Test(expected = NullPointerException.class)
89 public void testConstructorWithNullCollection() {
90 new IsElementOf(null);
91 }
92
93
94
95
96 @Test(expected = NullPointerException.class)
97 public void testChainedConstructorWithNullCollection() {
98 new IsElementOf(null, new IdentityTransform());
99 }
100
101 }