diff --git a/src/main/java/de/tum/in/test/api/io/TestInStream.java b/src/main/java/de/tum/in/test/api/io/TestInStream.java index 808f5fe4..49507b74 100644 --- a/src/main/java/de/tum/in/test/api/io/TestInStream.java +++ b/src/main/java/de/tum/in/test/api/io/TestInStream.java @@ -19,7 +19,7 @@ final class TestInStream extends InputStream { @Override public int read() throws IOException { if (input == null) - tryLoadNextLine(true); + tryLoadNextLine(); int res = input.read(); if (input.available() == 0) input = null; @@ -28,15 +28,13 @@ public int read() throws IOException { @Override public int available() throws IOException { - if (input == null) - tryLoadNextLine(false); return input == null ? 0 : input.available(); } @Override public int read(byte[] b, int off, int len) throws IOException { if (input == null) - tryLoadNextLine(true); + tryLoadNextLine(); int res = input.read(b, off, len); if (input.available() == 0) input = null; @@ -47,11 +45,9 @@ void resetInternalState() { input = null; } - private void tryLoadNextLine(boolean force) { - if (force || lineProvider.hasNextLine()) { - Line currentLine = lineProvider.getNextLine(); - byte[] bytes = currentLine.text().concat(IOTester.LINE_SEPERATOR).getBytes(StandardCharsets.UTF_8); - input = new ByteArrayInputStream(bytes); - } + private void tryLoadNextLine() { + Line currentLine = lineProvider.getNextLine(); + byte[] bytes = currentLine.text().concat(IOTester.LINE_SEPERATOR).getBytes(StandardCharsets.UTF_8); + input = new ByteArrayInputStream(bytes); } } diff --git a/src/test/java/de/tum/in/test/api/io/IOTesterTest.java b/src/test/java/de/tum/in/test/api/io/IOTesterTest.java index 69e9c421..1a3b66df 100644 --- a/src/test/java/de/tum/in/test/api/io/IOTesterTest.java +++ b/src/test/java/de/tum/in/test/api/io/IOTesterTest.java @@ -27,7 +27,7 @@ void testUninstall() { @Test void testReset() { try (Scanner scanner = new Scanner(System.in)) { - tester.in().addLinesToInput("X"); + tester.in().addLinesToInput("X", "Y"); System.out.println("A"); System.err.println("B"); @@ -36,7 +36,7 @@ void testReset() { assertThat(tester.err().getLines()).isNotEmpty(); assertThat(scanner.nextLine()).isEqualTo("X"); - tester.in().addLinesToInput("Y"); + tester.in().addLinesToInput("Z"); tester.reset();