import com.github.stefanbirkner.systemlambda.SystemLambda; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.converter.ArgumentConversionException; import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.converter.SimpleArgumentConverter; import org.junit.jupiter.params.provider.CsvFileSource; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @ExtendWith( BenchmarkExtension.class ) class SolutionTest { static class FileContentConverter extends SimpleArgumentConverter { @Override protected Object convert( Object source, Class targetType ) throws ArgumentConversionException { try { assertEquals( String.class, targetType, "Can only convert to String" ); final InputStream resource = SolutionTest.class.getResourceAsStream( String.valueOf( source )); if ( null == resource ) { return source; } BufferedReader res = new BufferedReader( new InputStreamReader( resource )); return res.lines().collect( Collectors.joining( System.lineSeparator() )); } catch ( Exception e ) { throw new ArgumentConversionException( e.getLocalizedMessage() ); } } } static class MultilineConverter extends SimpleArgumentConverter { @Override protected Object convert( Object source, Class targetType ) throws ArgumentConversionException { try { assertEquals( String.class, targetType, "Can only convert to String" ); return String.valueOf( source ).replaceAll( "\\s*[|]\\s*", System.lineSeparator() ); } catch ( Exception e ) { throw new ArgumentConversionException( e.getLocalizedMessage() ); } } } @ParameterizedTest @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() ); } }