1919import  static  org .mockito .Mockito .when ;
2020
2121import  java .io .ByteArrayInputStream ;
22- import  java .io .IOException ;
2322import  java .io .InputStream ;
2423import  java .nio .file .Files ;
2524import  java .nio .file .Path ;
3029import  org .junit .jupiter .api .Test ;
3130import  org .junit .jupiter .api .extension .ExtensionContext ;
3231import  org .junit .jupiter .api .io .TempDir ;
32+ import  org .junit .jupiter .params .ParameterizedTest ;
3333import  org .junit .jupiter .params .provider .CsvFileArgumentsProvider .InputStreamProvider ;
3434import  org .junit .platform .commons .JUnitException ;
3535import  org .junit .platform .commons .PreconditionViolationException ;
@@ -410,7 +410,7 @@ void readsLineFromDefaultMaxCharsFileWithDefaultConfig(@TempDir Path tempDir) th
410410	}
411411
412412	@ Test 
413- 	void  readsLineFromExceedsMaxCharsFileWithCustomConfig (@ TempDir  Path  tempDir ) throws  java . io . IOException  {
413+ 	void  readsLineFromExceedsMaxCharsFileWithCustomExplicitConfig (@ TempDir  Path  tempDir ) throws  Exception  {
414414		var  csvFile  = writeClasspathResourceToFile ("exceeds-default-max-chars.csv" ,
415415			tempDir .resolve ("exceeds-default-max-chars.csv" ));
416416		var  annotation  = csvFileSource ()// 
@@ -426,24 +426,49 @@ void readsLineFromExceedsMaxCharsFileWithCustomConfig(@TempDir Path tempDir) thr
426426	}
427427
428428	@ Test 
429- 	void  throwsExceptionWhenMaxCharsPerColumnIsNotPositiveNumber (@ TempDir  Path  tempDir ) throws  java .io .IOException  {
429+ 	void  readsLineFromExceedsMaxCharsFileWithCustomUnlimitedConfig (@ TempDir  Path  tempDir ) throws  Exception  {
430+ 		var  csvFile  = tempDir .resolve ("test.csv" );
431+ 		try  (var  out  = Files .newBufferedWriter (csvFile )) {
432+ 			var  chunks  = 10 ;
433+ 			var  chunk  = "a" .repeat (8192 );
434+ 			for  (long  i  = 0 ; i  < chunks ; i ++) {
435+ 				out .write (chunk );
436+ 			}
437+ 		}
438+ 
439+ 		var  annotation  = csvFileSource ()// 
440+ 				.encoding ("ISO-8859-1" )// 
441+ 				.maxCharsPerColumn (-1 )// 
442+ 				.files (csvFile .toAbsolutePath ().toString ())// 
443+ 				.build ();
444+ 
445+ 		var  arguments  = provideArguments (new  CsvFileArgumentsProvider (), annotation );
446+ 
447+ 		assertThat (arguments ).hasSize (1 );
448+ 	}
449+ 
450+ 	@ ParameterizedTest 
451+ 	@ ValueSource (ints  = { Integer .MIN_VALUE , -2 , 0  })
452+ 	void  throwsExceptionWhenMaxCharsPerColumnIsNotPositiveNumberOrMinusOne (int  maxCharsPerColumn , @ TempDir  Path  tempDir )
453+ 			throws  Exception  {
430454		var  csvFile  = writeClasspathResourceToFile ("exceeds-default-max-chars.csv" ,
431455			tempDir .resolve ("exceeds-default-max-chars.csv" ));
432456		var  annotation  = csvFileSource ()// 
433457				.encoding ("ISO-8859-1" )// 
434458				.resources ("exceeds-default-max-chars.csv" )// 
435- 				.maxCharsPerColumn (-1 ).files (csvFile .toAbsolutePath ().toString ())// 
459+ 				.maxCharsPerColumn (maxCharsPerColumn )// 
460+ 				.files (csvFile .toAbsolutePath ().toString ())// 
436461				.build ();
437462
438463		var  exception  = assertThrows (PreconditionViolationException .class , // 
439464			() -> provideArguments (new  CsvFileArgumentsProvider (), annotation ).findAny ());
440465
441466		assertThat (exception )// 
442- 				.hasMessageStartingWith ("maxCharsPerColumn must be a positive number: -1"  );
467+ 				.hasMessageStartingWith ("maxCharsPerColumn must be a positive number or -1: "   +  maxCharsPerColumn );
443468	}
444469
445470	@ Test 
446- 	void  throwsExceptionForExceedsMaxCharsFileWithDefaultConfig (@ TempDir  Path  tempDir ) throws  java . io . IOException  {
471+ 	void  throwsExceptionForExceedsMaxCharsFileWithDefaultConfig (@ TempDir  Path  tempDir ) throws  Exception  {
447472		var  csvFile  = writeClasspathResourceToFile ("exceeds-default-max-chars.csv" ,
448473			tempDir .resolve ("exceeds-default-max-chars.csv" ));
449474		var  annotation  = csvFileSource ()// 
@@ -461,7 +486,7 @@ void throwsExceptionForExceedsMaxCharsFileWithDefaultConfig(@TempDir Path tempDi
461486	}
462487
463488	@ Test 
464- 	void  ignoresLeadingAndTrailingSpaces (@ TempDir  Path  tempDir ) throws  IOException  {
489+ 	void  ignoresLeadingAndTrailingSpaces (@ TempDir  Path  tempDir ) throws  Exception  {
465490		var  csvFile  = writeClasspathResourceToFile ("leading-trailing-spaces.csv" ,
466491			tempDir .resolve ("leading-trailing-spaces.csv" ));
467492		var  annotation  = csvFileSource ()// 
@@ -477,7 +502,7 @@ void ignoresLeadingAndTrailingSpaces(@TempDir Path tempDir) throws IOException {
477502	}
478503
479504	@ Test 
480- 	void  trimsLeadingAndTrailingSpaces (@ TempDir  Path  tempDir ) throws  IOException  {
505+ 	void  trimsLeadingAndTrailingSpaces (@ TempDir  Path  tempDir ) throws  Exception  {
481506		var  csvFile  = writeClasspathResourceToFile ("leading-trailing-spaces.csv" ,
482507			tempDir .resolve ("leading-trailing-spaces.csv" ));
483508		var  annotation  = csvFileSource ()// 
@@ -527,7 +552,7 @@ private static <T> T[] array(T... elements) {
527552		return  elements ;
528553	}
529554
530- 	private  static  Path  writeClasspathResourceToFile (String  name , Path  target ) throws  IOException  {
555+ 	private  static  Path  writeClasspathResourceToFile (String  name , Path  target ) throws  Exception  {
531556		try  (var  in  = CsvFileArgumentsProviderTests .class .getResourceAsStream (name )) {
532557			Files .copy (in , target );
533558		}
0 commit comments