From 7ec4a9fd1dc7b782eec9c04fe4cfb6ba39e318eb Mon Sep 17 00:00:00 2001 From: Ana Peterlic Date: Sat, 3 Feb 2024 06:37:14 +0100 Subject: [PATCH] Update givenInputFromConsole_whenUsingScanner_thenReadCharByChar --- .../readinputcharbychar/ReadInputCharByCharUnitTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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); + } } } }