19
19
import static org .mockito .Mockito .when ;
20
20
21
21
import java .io .ByteArrayInputStream ;
22
- import java .io .IOException ;
23
22
import java .io .InputStream ;
24
23
import java .nio .file .Files ;
25
24
import java .nio .file .Path ;
30
29
import org .junit .jupiter .api .Test ;
31
30
import org .junit .jupiter .api .extension .ExtensionContext ;
32
31
import org .junit .jupiter .api .io .TempDir ;
32
+ import org .junit .jupiter .params .ParameterizedTest ;
33
33
import org .junit .jupiter .params .provider .CsvFileArgumentsProvider .InputStreamProvider ;
34
34
import org .junit .platform .commons .JUnitException ;
35
35
import org .junit .platform .commons .PreconditionViolationException ;
@@ -410,7 +410,7 @@ void readsLineFromDefaultMaxCharsFileWithDefaultConfig(@TempDir Path tempDir) th
410
410
}
411
411
412
412
@ Test
413
- void readsLineFromExceedsMaxCharsFileWithCustomConfig (@ TempDir Path tempDir ) throws java . io . IOException {
413
+ void readsLineFromExceedsMaxCharsFileWithCustomExplicitConfig (@ TempDir Path tempDir ) throws Exception {
414
414
var csvFile = writeClasspathResourceToFile ("exceeds-default-max-chars.csv" ,
415
415
tempDir .resolve ("exceeds-default-max-chars.csv" ));
416
416
var annotation = csvFileSource ()//
@@ -426,24 +426,49 @@ void readsLineFromExceedsMaxCharsFileWithCustomConfig(@TempDir Path tempDir) thr
426
426
}
427
427
428
428
@ 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 {
430
454
var csvFile = writeClasspathResourceToFile ("exceeds-default-max-chars.csv" ,
431
455
tempDir .resolve ("exceeds-default-max-chars.csv" ));
432
456
var annotation = csvFileSource ()//
433
457
.encoding ("ISO-8859-1" )//
434
458
.resources ("exceeds-default-max-chars.csv" )//
435
- .maxCharsPerColumn (-1 ).files (csvFile .toAbsolutePath ().toString ())//
459
+ .maxCharsPerColumn (maxCharsPerColumn )//
460
+ .files (csvFile .toAbsolutePath ().toString ())//
436
461
.build ();
437
462
438
463
var exception = assertThrows (PreconditionViolationException .class , //
439
464
() -> provideArguments (new CsvFileArgumentsProvider (), annotation ).findAny ());
440
465
441
466
assertThat (exception )//
442
- .hasMessageStartingWith ("maxCharsPerColumn must be a positive number: -1" );
467
+ .hasMessageStartingWith ("maxCharsPerColumn must be a positive number or -1: " + maxCharsPerColumn );
443
468
}
444
469
445
470
@ Test
446
- void throwsExceptionForExceedsMaxCharsFileWithDefaultConfig (@ TempDir Path tempDir ) throws java . io . IOException {
471
+ void throwsExceptionForExceedsMaxCharsFileWithDefaultConfig (@ TempDir Path tempDir ) throws Exception {
447
472
var csvFile = writeClasspathResourceToFile ("exceeds-default-max-chars.csv" ,
448
473
tempDir .resolve ("exceeds-default-max-chars.csv" ));
449
474
var annotation = csvFileSource ()//
@@ -461,7 +486,7 @@ void throwsExceptionForExceedsMaxCharsFileWithDefaultConfig(@TempDir Path tempDi
461
486
}
462
487
463
488
@ Test
464
- void ignoresLeadingAndTrailingSpaces (@ TempDir Path tempDir ) throws IOException {
489
+ void ignoresLeadingAndTrailingSpaces (@ TempDir Path tempDir ) throws Exception {
465
490
var csvFile = writeClasspathResourceToFile ("leading-trailing-spaces.csv" ,
466
491
tempDir .resolve ("leading-trailing-spaces.csv" ));
467
492
var annotation = csvFileSource ()//
@@ -477,7 +502,7 @@ void ignoresLeadingAndTrailingSpaces(@TempDir Path tempDir) throws IOException {
477
502
}
478
503
479
504
@ Test
480
- void trimsLeadingAndTrailingSpaces (@ TempDir Path tempDir ) throws IOException {
505
+ void trimsLeadingAndTrailingSpaces (@ TempDir Path tempDir ) throws Exception {
481
506
var csvFile = writeClasspathResourceToFile ("leading-trailing-spaces.csv" ,
482
507
tempDir .resolve ("leading-trailing-spaces.csv" ));
483
508
var annotation = csvFileSource ()//
@@ -527,7 +552,7 @@ private static <T> T[] array(T... elements) {
527
552
return elements ;
528
553
}
529
554
530
- private static Path writeClasspathResourceToFile (String name , Path target ) throws IOException {
555
+ private static Path writeClasspathResourceToFile (String name , Path target ) throws Exception {
531
556
try (var in = CsvFileArgumentsProviderTests .class .getResourceAsStream (name )) {
532
557
Files .copy (in , target );
533
558
}
0 commit comments