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.exception;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNull;
20  import static org.supercsv.SuperCsvTestUtils.ANONYMOUS_CSVCONTEXT;
21  
22  import org.junit.Test;
23  import org.supercsv.cellprocessor.ift.CellProcessor;
24  import org.supercsv.mock.IdentityTransform;
25  import org.supercsv.util.CsvContext;
26  
27  /**
28   * Tests the SuperCsvConstraintViolationException class.
29   * 
30   * @author James Bassett
31   */
32  public class SuperCsvConstraintViolationExceptionTest {
33  	
34  	private static final String MSG = "You violated the rules!";
35  	private static final Throwable THROWABLE = new RuntimeException("I'm the cause of the problem");
36  	private static final CellProcessor PROCESSOR = new IdentityTransform();
37  	
38  	/**
39  	 * Tests the first constructor.
40  	 */
41  	@Test
42  	public void testConstuctor1() {
43  		SuperCsvConstraintViolationException e = new SuperCsvConstraintViolationException(MSG, ANONYMOUS_CSVCONTEXT, PROCESSOR);
44  		assertEquals(MSG, e.getMessage());
45  		assertEquals(ANONYMOUS_CSVCONTEXT, e.getCsvContext());
46  		assertEquals(PROCESSOR, e.getProcessor());
47  		
48  		// test with null values
49  		e = new SuperCsvConstraintViolationException(null, (CsvContext) null, (CellProcessor) null);
50  		assertNull(e.getMessage());
51  		assertNull(e.getCsvContext());
52  		assertNull(e.getProcessor());
53  	}
54  	
55  	/**
56  	 * Tests the second constructor.
57  	 */
58  	@Test
59  	public void testConstuctor2() {
60  		SuperCsvConstraintViolationException e = new SuperCsvConstraintViolationException(MSG, ANONYMOUS_CSVCONTEXT, PROCESSOR, THROWABLE);
61  		assertEquals(MSG, e.getMessage());
62  		assertEquals(ANONYMOUS_CSVCONTEXT, e.getCsvContext());
63  		assertEquals(PROCESSOR, e.getProcessor());
64  		assertEquals(THROWABLE, e.getCause());
65  		
66  		// test with null values
67  		e = new SuperCsvConstraintViolationException(null, null, null, (Throwable) null);
68  		assertNull(e.getMessage());
69  		assertNull(e.getCsvContext());
70  		assertNull(e.getProcessor());
71  		assertNull(e.getCause());
72  	}
73  	
74  }