@@ -80,13 +80,26 @@ record = parser.iterator().next();
8080 }
8181 }
8282
83+ @ Test
84+ public void testCSVRecordNULLValues () throws IOException {
85+ final CSVParser parser = CSVParser .parse ("A,B\r \n ONE,TWO" , CSVFormat .DEFAULT .withHeader ());
86+ final CSVRecord csvRecord = new CSVRecord (parser , null , null , 0L , 0L );
87+ assertEquals (0 , csvRecord .size ());
88+ assertThrows (IllegalArgumentException .class , () -> csvRecord .get ("B" ));
89+ }
90+
8391 @ Test
8492 public void testGetInt () {
8593 assertEquals (values [0 ], record .get (0 ));
8694 assertEquals (values [1 ], record .get (1 ));
8795 assertEquals (values [2 ], record .get (2 ));
8896 }
8997
98+ @ Test
99+ public void testGetNullEnum () {
100+ assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get ((Enum <?>) null ));
101+ }
102+
90103 @ Test
91104 public void testGetString () {
92105 assertEquals (values [0 ], recordWithHeader .get ("first" ));
@@ -110,11 +123,6 @@ public void testGetUnmappedEnum() {
110123 assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get (EnumFixture .UNKNOWN_COLUMN ));
111124 }
112125
113- @ Test
114- public void testGetNullEnum () {
115- assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get ((Enum <?>) null ));
116- }
117-
118126 @ Test
119127 public void testGetUnmappedName () {
120128 assertThrows (IllegalArgumentException .class , () -> assertNull (recordWithHeader .get ("fourth" )));
@@ -130,6 +138,13 @@ public void testGetUnmappedPositiveInt() {
130138 assertThrows (ArrayIndexOutOfBoundsException .class , () -> recordWithHeader .get (Integer .MAX_VALUE ));
131139 }
132140
141+ @ Test
142+ public void testGetWithEnum () {
143+ assertEquals (recordWithHeader .get ("first" ), recordWithHeader .get (EnumHeader .FIRST ));
144+ assertEquals (recordWithHeader .get ("second" ), recordWithHeader .get (EnumHeader .SECOND ));
145+ assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get (EnumFixture .UNKNOWN_COLUMN ));
146+ }
147+
133148 @ Test
134149 public void testIsConsistent () {
135150 assertTrue (record .isConsistent ());
@@ -281,6 +296,14 @@ public void testToMapWithShortRecord() throws Exception {
281296 }
282297 }
283298
299+ @ Test
300+ public void testToString () {
301+ assertNotNull (recordWithHeader .toString ());
302+ assertTrue (recordWithHeader .toString ().contains ("comment=" ));
303+ assertTrue (recordWithHeader .toString ().contains ("recordNumber=" ));
304+ assertTrue (recordWithHeader .toString ().contains ("values=" ));
305+ }
306+
284307 private void validateMap (final Map <String , String > map , final boolean allowsNulls ) {
285308 assertTrue (map .containsKey ("first" ));
286309 assertTrue (map .containsKey ("second" ));
@@ -294,27 +317,4 @@ private void validateMap(final Map<String, String> map, final boolean allowsNull
294317 assertEquals ("C" , map .get ("third" ));
295318 assertEquals (null , map .get ("fourth" ));
296319 }
297-
298- @ Test
299- public void testToString () {
300- assertNotNull (recordWithHeader .toString ());
301- assertTrue (recordWithHeader .toString ().contains ("comment=" ));
302- assertTrue (recordWithHeader .toString ().contains ("recordNumber=" ));
303- assertTrue (recordWithHeader .toString ().contains ("values=" ));
304- }
305-
306- @ Test
307- public void testGetWithEnum () {
308- assertEquals (recordWithHeader .get ("first" ), recordWithHeader .get (EnumHeader .FIRST ));
309- assertEquals (recordWithHeader .get ("second" ), recordWithHeader .get (EnumHeader .SECOND ));
310- assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get (EnumFixture .UNKNOWN_COLUMN ));
311- }
312-
313- @ Test
314- public void testCSVRecordNULLValues () throws IOException {
315- final CSVParser parser = CSVParser .parse ("A,B\r \n ONE,TWO" , CSVFormat .DEFAULT .withHeader ());
316- final CSVRecord csvRecord = new CSVRecord (parser , null , null , 0L , 0L );
317- assertEquals (0 , csvRecord .size ());
318- assertThrows (IllegalArgumentException .class , () -> csvRecord .get ("B" ));
319- }
320320}
0 commit comments