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;
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.mock.IdentityTransform;
25  
26  /**
27   * Tests the ConvertNull processor.
28   * 
29   * @author James Bassett
30   */
31  public class ConvertNullToTest {
32  	
33  	private static final String CONVERTED_VALUE = "previously null!";
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 ConvertNullTo(CONVERTED_VALUE);
44  		processorChain = new ConvertNullTo(CONVERTED_VALUE, new IdentityTransform());
45  	}
46  	
47  	/**
48  	 * Tests unchained/chained execution with a null value (should return converted value).
49  	 */
50  	@Test
51  	public void testWithNullValue() {
52  		assertEquals(CONVERTED_VALUE, processor.execute(null, ANONYMOUS_CSVCONTEXT));
53  		assertEquals(CONVERTED_VALUE, processorChain.execute(null, ANONYMOUS_CSVCONTEXT));
54  	}
55  	
56  	/**
57  	 * Tests unchained/chained execution with a non-null value (should return input unchanged).
58  	 */
59  	@Test
60  	public void testWithNonNullValue() {
61  		String notNull = "not null!";
62  		assertEquals(notNull, processor.execute(notNull, ANONYMOUS_CSVCONTEXT));
63  		assertEquals(notNull, processorChain.execute(notNull, ANONYMOUS_CSVCONTEXT));
64  	}
65  	
66  }