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.util.CsvContext;
24  
25  /**
26   * Tests the SuperCsvException class.
27   * 
28   * @author James Bassett
29   */
30  public class SuperCsvExceptionTest {
31  	
32  	private static final String MSG = "Something terrible happened!";
33  	private static final Throwable THROWABLE = new RuntimeException("I'm the cause of the problem");
34  	
35  	/**
36  	 * Tests the first constructor.
37  	 */
38  	@Test
39  	public void testConstuctor1() {
40  		SuperCsvException e = new SuperCsvException(MSG);
41  		assertEquals(MSG, e.getMessage());
42  		
43  		// test with null msg
44  		e = new SuperCsvException(null);
45  		assertNull(e.getMessage());
46  	}
47  	
48  	/**
49  	 * Tests the second constructor.
50  	 */
51  	@Test
52  	public void testConstuctor2() {
53  		SuperCsvException e = new SuperCsvException(MSG, ANONYMOUS_CSVCONTEXT);
54  		assertEquals(MSG, e.getMessage());
55  		assertEquals(ANONYMOUS_CSVCONTEXT, e.getCsvContext());
56  		
57  		// test with null msg and context
58  		e = new SuperCsvException(null, (CsvContext) null);
59  		assertNull(e.getMessage());
60  		assertNull(e.getCsvContext());
61  	}
62  	
63  	/**
64  	 * Tests the third constructor.
65  	 */
66  	@Test
67  	public void testConstuctor3() {
68  		SuperCsvException e = new SuperCsvException(MSG, ANONYMOUS_CSVCONTEXT, THROWABLE);
69  		assertEquals(MSG, e.getMessage());
70  		assertEquals(ANONYMOUS_CSVCONTEXT, e.getCsvContext());
71  		assertEquals(THROWABLE, e.getCause());
72  		
73  		// test with null msg, context and throwable
74  		e = new SuperCsvException(null, (CsvContext) null, (Throwable) null);
75  		assertNull(e.getMessage());
76  		assertNull(e.getCsvContext());
77  		assertNull(e.getCause());
78  	}
79  	
80  }