1212import java .util .HashMap ;
1313import java .util .List ;
1414import java .util .Map ;
15- import java .util .stream .Collectors ;
1615
1716import org .junit .Assert ;
1817import org .junit .Test ;
3736 */
3837public class CommaSeparatedLayoutTest {
3938
40- /**
41- * Created on Jun 25, 2012 by depryf
42- */
4339 @ Test
4440 public void testLayout () throws Exception {
4541
@@ -221,7 +217,7 @@ public void testPartialNaaccrLayout() throws Exception {
221217 // regular CSV fields don't have subfields; only fixed-column fields have those, so we have to tweak the design a bit...
222218 final Map <Integer , List <FixedColumnsField >> subFields = new HashMap <>();
223219 int idx = 1 ;
224- for (String header : CsvReader .builder ().ofCsvRecord (firstLine ).stream ().flatMap (f -> f .getFields ().stream ()).collect ( Collectors . toList () )) {
220+ for (String header : CsvReader .builder ().ofCsvRecord (firstLine ).stream ().flatMap (f -> f .getFields ().stream ()).toList ()) {
225221 FixedColumnsField field = null ;
226222 if (header .matches ("#\\ d+" ))
227223 field = naaccrLayout .getFieldByNaaccrItemNumber (Integer .valueOf (header .substring (1 )));
@@ -251,8 +247,8 @@ public void testPartialNaaccrLayout() throws Exception {
251247 newSubField .setDefaultValue (ff .getDefaultValue ());
252248 newSubField .setAlign (ff .getAlign ());
253249 newSubField .setPadChar (ff .getPadChar ());
254- newSubField .setStart (ff .getStart () - field .getSubFields ().get ( 0 ).getStart () + 1 );
255- newSubField .setEnd (ff .getEnd () - field .getSubFields ().get ( 0 ).getStart () + 1 );
250+ newSubField .setStart (ff .getStart () - field .getSubFields ().getFirst ( ).getStart () + 1 );
251+ newSubField .setEnd (ff .getEnd () - field .getSubFields ().getFirst ( ).getStart () + 1 );
256252 newSubFields .add (newSubField );
257253 }
258254 }
@@ -271,7 +267,7 @@ public Map<String, String> createRecordFromLine(String line, Integer lineNumber,
271267 List <FixedColumnsField > fields = subFields .get (field .getIndex ());
272268 if (fields != null ) {
273269 String originalValue = result .get (field .getName ());
274- if (originalValue != null && originalValue .length () >= fields .get ( fields . size () - 1 ).getEnd ()) {
270+ if (originalValue != null && originalValue .length () >= fields .getLast ( ).getEnd ()) {
275271 for (FixedColumnsField child : fields ) {
276272 String value = originalValue .substring (child .getStart () - 1 , child .getEnd ());
277273 if (trimValues (options ))
@@ -332,7 +328,7 @@ public String createLineFromRecord(Map<String, String> rec, RecordLayoutOptions
332328 LayoutFactory .registerLayout (layout );
333329
334330 // make sure we can now recognize the file
335- LayoutInfo info = LayoutFactory .discoverFormat (file ).get ( 0 );
331+ LayoutInfo info = LayoutFactory .discoverFormat (file ).getFirst ( );
336332 Assert .assertNotNull (info );
337333
338334 // read the data file using the new layout
@@ -343,8 +339,8 @@ public String createLineFromRecord(Map<String, String> rec, RecordLayoutOptions
343339 Assert .assertNotNull (rec .get ("patientIdNumber" ));
344340 Assert .assertNotNull (rec .get ("race1" ));
345341 }
346- Assert .assertEquals ("20100615" , records .get ( 0 ).get ("dateOfBirth" ));
347- Assert .assertEquals ("2010" , records .get ( 0 ).get ("dateOfBirthYear" ));
342+ Assert .assertEquals ("20100615" , records .getFirst ( ).get ("dateOfBirth" ));
343+ Assert .assertEquals ("2010" , records .getFirst ( ).get ("dateOfBirthYear" ));
348344 Assert .assertEquals ("06" , records .get (0 ).get ("dateOfBirthMonth" ));
349345 Assert .assertEquals ("15" , records .get (0 ).get ("dateOfBirthDay" ));
350346 Assert .assertEquals ("2010" , records .get (1 ).get ("dateOfBirth" ));
@@ -357,8 +353,8 @@ public String createLineFromRecord(Map<String, String> rec, RecordLayoutOptions
357353 RecordLayoutOptions options = new RecordLayoutOptions ();
358354 options .setTrimValues (false );
359355 records = layout .readAllRecords (file , options );
360- Assert .assertEquals ("20100615" , records .get ( 0 ).get ("dateOfBirth" ));
361- Assert .assertEquals ("2010" , records .get ( 0 ).get ("dateOfBirthYear" ));
356+ Assert .assertEquals ("20100615" , records .getFirst ( ).get ("dateOfBirth" ));
357+ Assert .assertEquals ("2010" , records .getFirst ( ).get ("dateOfBirthYear" ));
362358 Assert .assertEquals ("06" , records .get (0 ).get ("dateOfBirthMonth" ));
363359 Assert .assertEquals ("15" , records .get (0 ).get ("dateOfBirthDay" ));
364360 Assert .assertEquals ("2010 " , records .get (1 ).get ("dateOfBirth" ));
@@ -508,5 +504,18 @@ public void testBuildFileInfo() throws IOException {
508504
509505 options .setCommaSeparatedAllowDiscoveryFromNumFields (false );
510506 Assert .assertNull (layout .buildFileInfo (file , null , options ));
507+ options .setCommaSeparatedAllowDiscoveryFromNumFields (true );
508+
509+ SeerUtils .writeFile ("\" A\" ,\" B\" ,\" C\" " , file );
510+ Assert .assertNotNull (layout .buildFileInfo (file , null , options ));
511+
512+ SeerUtils .writeFile ("A|B|C" , file );
513+ Assert .assertNull (layout .buildFileInfo (file , null , options ));
514+
515+ SeerUtils .writeFile ("\" A\" |\" B\" |\" C\" " , file );
516+ Assert .assertNull (layout .buildFileInfo (file , null , options ));
517+
518+ SeerUtils .writeFile (" " , file );
519+ Assert .assertNull (layout .buildFileInfo (file , null , options ));
511520 }
512521}
0 commit comments