3434import java .util .Map ;
3535import java .util .TreeMap ;
3636import java .util .concurrent .ConcurrentHashMap ;
37+ import java .util .concurrent .atomic .AtomicInteger ;
3738
3839import org .apache .commons .lang3 .StringUtils ;
3940import org .junit .jupiter .api .BeforeEach ;
@@ -80,13 +81,26 @@ record = parser.iterator().next();
8081 }
8182 }
8283
84+ @ Test
85+ public void testCSVRecordNULLValues () throws IOException {
86+ final CSVParser parser = CSVParser .parse ("A,B\r \n ONE,TWO" , CSVFormat .DEFAULT .withHeader ());
87+ final CSVRecord csvRecord = new CSVRecord (parser , null , null , 0L , 0L );
88+ assertEquals (0 , csvRecord .size ());
89+ assertThrows (IllegalArgumentException .class , () -> csvRecord .get ("B" ));
90+ }
91+
8392 @ Test
8493 public void testGetInt () {
8594 assertEquals (values [0 ], record .get (0 ));
8695 assertEquals (values [1 ], record .get (1 ));
8796 assertEquals (values [2 ], record .get (2 ));
8897 }
8998
99+ @ Test
100+ public void testGetNullEnum () {
101+ assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get ((Enum <?>) null ));
102+ }
103+
90104 @ Test
91105 public void testGetString () {
92106 assertEquals (values [0 ], recordWithHeader .get ("first" ));
@@ -110,11 +124,6 @@ public void testGetUnmappedEnum() {
110124 assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get (EnumFixture .UNKNOWN_COLUMN ));
111125 }
112126
113- @ Test
114- public void testGetNullEnum () {
115- assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get ((Enum <?>) null ));
116- }
117-
118127 @ Test
119128 public void testGetUnmappedName () {
120129 assertThrows (IllegalArgumentException .class , () -> assertNull (recordWithHeader .get ("fourth" )));
@@ -130,6 +139,13 @@ public void testGetUnmappedPositiveInt() {
130139 assertThrows (ArrayIndexOutOfBoundsException .class , () -> recordWithHeader .get (Integer .MAX_VALUE ));
131140 }
132141
142+ @ Test
143+ public void testGetWithEnum () {
144+ assertEquals (recordWithHeader .get ("first" ), recordWithHeader .get (EnumHeader .FIRST ));
145+ assertEquals (recordWithHeader .get ("second" ), recordWithHeader .get (EnumHeader .SECOND ));
146+ assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get (EnumFixture .UNKNOWN_COLUMN ));
147+ }
148+
133149 @ Test
134150 public void testIsConsistent () {
135151 assertTrue (record .isConsistent ());
@@ -248,6 +264,15 @@ public void testSerialization() throws IOException, ClassNotFoundException {
248264 }
249265 }
250266
267+ @ Test
268+ public void testToList () {
269+ int i = 0 ;
270+ for (final String value : record .toList ()) {
271+ assertEquals (values [i ], value );
272+ i ++;
273+ }
274+ }
275+
251276 @ Test
252277 public void testToMap () {
253278 final Map <String , String > map = this .recordWithHeader .toMap ();
@@ -272,6 +297,23 @@ public void testToMapWithShortRecord() throws Exception {
272297 }
273298 }
274299
300+ @ Test
301+ public void testToStream () {
302+ final AtomicInteger i = new AtomicInteger ();
303+ record .toStream ().forEach (value -> {
304+ assertEquals (values [i .get ()], value );
305+ i .incrementAndGet ();
306+ });
307+ }
308+
309+ @ Test
310+ public void testToString () {
311+ assertNotNull (recordWithHeader .toString ());
312+ assertTrue (recordWithHeader .toString ().contains ("comment=" ));
313+ assertTrue (recordWithHeader .toString ().contains ("recordNumber=" ));
314+ assertTrue (recordWithHeader .toString ().contains ("values=" ));
315+ }
316+
275317 private void validateMap (final Map <String , String > map , final boolean allowsNulls ) {
276318 assertTrue (map .containsKey ("first" ));
277319 assertTrue (map .containsKey ("second" ));
@@ -285,27 +327,4 @@ private void validateMap(final Map<String, String> map, final boolean allowsNull
285327 assertEquals ("C" , map .get ("third" ));
286328 assertEquals (null , map .get ("fourth" ));
287329 }
288-
289- @ Test
290- public void testToString () {
291- assertNotNull (recordWithHeader .toString ());
292- assertTrue (recordWithHeader .toString ().contains ("comment=" ));
293- assertTrue (recordWithHeader .toString ().contains ("recordNumber=" ));
294- assertTrue (recordWithHeader .toString ().contains ("values=" ));
295- }
296-
297- @ Test
298- public void testGetWithEnum () {
299- assertEquals (recordWithHeader .get ("first" ), recordWithHeader .get (EnumHeader .FIRST ));
300- assertEquals (recordWithHeader .get ("second" ), recordWithHeader .get (EnumHeader .SECOND ));
301- assertThrows (IllegalArgumentException .class , () -> recordWithHeader .get (EnumFixture .UNKNOWN_COLUMN ));
302- }
303-
304- @ Test
305- public void testCSVRecordNULLValues () throws IOException {
306- final CSVParser parser = CSVParser .parse ("A,B\r \n ONE,TWO" , CSVFormat .DEFAULT .withHeader ());
307- final CSVRecord csvRecord = new CSVRecord (parser , null , null , 0L , 0L );
308- assertEquals (0 , csvRecord .size ());
309- assertThrows (IllegalArgumentException .class , () -> csvRecord .get ("B" ));
310- }
311330}
0 commit comments