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 RequireSubStrTest {
39  	
40  	private static final String REQUIRED1 = "in";
41  	private static final String REQUIRED2 = "to";
42  	
43  	private CellProcessor processor;
44  	private CellProcessor processorChain;
45  	private CellProcessor processorChain2;
46  	private CellProcessor processorChain3;
47  	
48  	
49  
50  
51  	@Before
52  	public void setUp() {
53  		processor = new RequireSubStr(REQUIRED1, REQUIRED2);
54  		processorChain = new RequireSubStr(Arrays.asList(REQUIRED1, REQUIRED2), new IdentityTransform());
55  		processorChain2 = new RequireSubStr(REQUIRED1, new IdentityTransform()); 
56  		processorChain3 = new RequireSubStr(new String[] { REQUIRED1, REQUIRED2 }, new IdentityTransform());
57  	}
58  	
59  	
60  
61  
62  	@Test
63  	public void testValidInput() {
64  		String input = "to infinity and beyond!";
65  		assertEquals(input, processor.execute(input, ANONYMOUS_CSVCONTEXT));
66  		assertEquals(input, processorChain.execute(input, ANONYMOUS_CSVCONTEXT));
67  		assertEquals(input, processorChain2.execute(input, ANONYMOUS_CSVCONTEXT)); 
68  		assertEquals(input, processorChain3.execute(input, ANONYMOUS_CSVCONTEXT));
69  		
70  	}
71  	
72  	
73  
74  
75  	@Test(expected = SuperCsvConstraintViolationException.class)
76  	public void testInvalidInput() {
77  		String input = "no matches here";
78  		processor.execute(input, ANONYMOUS_CSVCONTEXT);
79  	}
80  	
81  	
82  
83  
84  	@Test(expected = SuperCsvCellProcessorException.class)
85  	public void testWithNull() {
86  		processor.execute(null, ANONYMOUS_CSVCONTEXT);
87  	}
88  	
89  	
90  
91  
92  	@Test(expected = NullPointerException.class)
93  	public void testConstructionWithNullArray() {
94  		new RequireSubStr((String[]) null);
95  	}
96  	
97  	
98  
99  
100 	@Test(expected = IllegalArgumentException.class)
101 	public void testConstructionWithEmptyArray() {
102 		new RequireSubStr(new String[] {});
103 	}
104 	
105 	
106 
107 
108 	@Test(expected = NullPointerException.class)
109 	public void testConstructionWithNullList() {
110 		new RequireSubStr((List<String>) null, new IdentityTransform());
111 	}
112 	
113 	
114 
115 
116 	@Test(expected = IllegalArgumentException.class)
117 	public void testConstructionWithEmptyList() {
118 		new RequireSubStr(new ArrayList<String>(), new IdentityTransform());
119 	}
120 	
121 	
122 
123 
124 	@Test(expected = NullPointerException.class)
125 	public void testConstructionWithNullSubstring() {
126 		new RequireSubStr(new String[] { null });
127 	}
128 }