From f876f51e5199da9aa71a840a8d96b74ecc9642ed Mon Sep 17 00:00:00 2001 From: Lothar Buchholz Date: Sat, 16 May 2020 22:54:42 +0200 Subject: [PATCH] skip input lines with // or # or ; in front ignore sonarlint issue store --- .gitignore | 3 +-- src/test/java/SolutionTest.java | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 40f974f..a9d94d8 100644 --- a/.gitignore +++ b/.gitignore @@ -28,12 +28,11 @@ local.properties bin/ # IntelliJ -*.iml -*.ipr *.iws *.uml .idea/compiler.xml .idea/workspace.xml +.idea/sonarlint/ out/ # NDK diff --git a/src/test/java/SolutionTest.java b/src/test/java/SolutionTest.java index bb1d61a..ea00408 100644 --- a/src/test/java/SolutionTest.java +++ b/src/test/java/SolutionTest.java @@ -9,6 +9,7 @@ import org.junit.jupiter.params.provider.CsvFileSource; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.Objects; import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -21,9 +22,13 @@ class SolutionTest { protected Object convert( Object source, Class targetType ) throws ArgumentConversionException { try { assertEquals( String.class, targetType, "Can only convert to String" ); + assertTrue( source instanceof String, "Can only convert to String" ); final InputStream resource = SolutionTest.class.getResourceAsStream( String.valueOf( source )); if ( null == resource ) { - return source; + if ( ((String) source).matches( "^(?!//|#|;).+" )) { + return source; + } + return null; } BufferedReader res = new BufferedReader( new InputStreamReader( resource )); @@ -52,12 +57,13 @@ class SolutionTest { @CsvFileSource( resources = "testdata.csv" ) void main( @ConvertWith( FileContentConverter.class ) final String input, @ConvertWith( MultilineConverter.class ) final String expected ) throws Exception { - String output = SystemLambda.tapSystemOut( () -> - SystemLambda.withTextFromSystemIn( input ) - .execute( () -> Solution.main( new String[0] )) - ); - - assertEquals( expected, output.trim() ); + if ( Objects.nonNull( input )) { + String output = SystemLambda.tapSystemOut( () -> + SystemLambda.withTextFromSystemIn( input ) + .execute( () -> Solution.main( new String[0] )) + ); + assertEquals( expected, output.trim() ); + } } }