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.exception.SuperCsvCellProcessorException;
25  import org.supercsv.mock.IdentityTransform;
26  
27  /**
28   * Tests the FmtBool processor.
29   * 
30   * @author Dominique De Vito
31   * @author James Bassett
32   */
33  public class FmtBoolTest {
34  	
35  	private static final String TRUE_VALUE = "y";
36  	private static final String FALSE_VALUE = "n";
37  	
38  	private CellProcessor processor;
39  	private CellProcessor processorChain;
40  	
41  	/**
42  	 * Sets up the processors for the test using all constructor combinations.
43  	 */
44  	@Before
45  	public void setUp() {
46  		processor = new FmtBool(TRUE_VALUE, FALSE_VALUE);
47  		processorChain = new FmtBool(TRUE_VALUE, FALSE_VALUE, new IdentityTransform());
48  	}
49  	
50  	/**
51  	 * Tests unchained/chained execution with true.
52  	 */
53  	@Test
54  	public void testWithTrue() {
55  		assertEquals(TRUE_VALUE, processor.execute(true, ANONYMOUS_CSVCONTEXT));
56  		assertEquals(TRUE_VALUE, processorChain.execute(true, ANONYMOUS_CSVCONTEXT));
57  	}
58  	
59  	/**
60  	 * Tests unchained/chained execution with false.
61  	 */
62  	@Test
63  	public void testWithFalse() {
64  		assertEquals(FALSE_VALUE, processor.execute(false, ANONYMOUS_CSVCONTEXT));
65  		assertEquals(FALSE_VALUE, processorChain.execute(false, ANONYMOUS_CSVCONTEXT));
66  	}
67  	
68  	/**
69  	 * Tests execution with a null input (should throw an Exception).
70  	 */
71  	@Test(expected = SuperCsvCellProcessorException.class)
72  	public void testWithNull() {
73  		processor.execute(null, ANONYMOUS_CSVCONTEXT);
74  	}
75  	
76  	/**
77  	 * Tests execution with a non-Boolean input (should throw an Exception).
78  	 */
79  	@Test(expected = SuperCsvCellProcessorException.class)
80  	public void testWithNonBoolean() {
81  		processor.execute(123, ANONYMOUS_CSVCONTEXT);
82  	}
83  	
84  }