diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/readinputcharbychar/ReadInputCharByCharUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/readinputcharbychar/ReadInputCharByCharUnitTest.java index 876b88036a..eee4ee1bd8 100644 --- a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/readinputcharbychar/ReadInputCharByCharUnitTest.java +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/readinputcharbychar/ReadInputCharByCharUnitTest.java @@ -51,9 +51,10 @@ public class ReadInputCharByCharUnitTest { System.setIn(inputStream); try (Scanner scanner = new Scanner(System.in)) { - char[] result = scanner.next().toCharArray(); - - assertArrayEquals("TestInput".toCharArray(), result); + while (scanner.hasNext()) { + char[] result = scanner.next().toCharArray(); + assertArrayEquals("TestInput".toCharArray(), result); + } } } }