View Javadoc
1   /*
2    * Copyright 2007 Kasper B. Graversen
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.cellprocessor.ift.CellProcessor;
24  import org.supercsv.exception.SuperCsvConstraintViolationException;
25  import org.supercsv.mock.IdentityTransform;
26  
27  /**
28   * Tests the NotNull constraint.
29   * 
30   * @author Dominique De Vito
31   * @author James Bassett
32   */
33  public class NotNullTest {
34  	
35  	private CellProcessor processor;
36  	private CellProcessor processorChain;
37  	
38  	/**
39  	 * Sets up the processors for the test using all constructor combinations.
40  	 */
41  	@Before
42  	public void setUp() {
43  		processor = new NotNull();
44  		processorChain = new NotNull(new IdentityTransform());
45  	}
46  	
47  	/**
48  	 * Tests unchained/chained execution with a non-null value.
49  	 */
50  	@Test
51  	public void testValidInput() {
52  		String input = "not null!";
53  		assertEquals(input, processor.execute(input, ANONYMOUS_CSVCONTEXT));
54  		assertEquals(input, processorChain.execute(input, ANONYMOUS_CSVCONTEXT));
55  	}
56  	
57  	/**
58  	 * Tests unchained/chained execution with a empty String.
59  	 */
60  	@Test
61  	public void testEmptyString() {
62  		String input = "";
63  		assertEquals(input, processor.execute(input, ANONYMOUS_CSVCONTEXT));
64  		assertEquals(input, processorChain.execute(input, ANONYMOUS_CSVCONTEXT));
65  	}
66  	
67  	/**
68  	 * Tests execution with a null input (should throw an Exception).
69  	 */
70  	@Test(expected = SuperCsvConstraintViolationException.class)
71  	public void testWithNull() {
72  		processor.execute(null, ANONYMOUS_CSVCONTEXT);
73  	}
74  	
75  }