From 1899d70e9150f5a43b0e12fb00da63ed26c6e529 Mon Sep 17 00:00:00 2001 From: Ana Peterlic Date: Mon, 5 Feb 2024 20:24:52 +0100 Subject: [PATCH] Update ReadInputCharByCharUnitTest.java --- .../ReadInputCharByCharUnitTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 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 eee4ee1bd8..832ae2096d 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 @@ -2,7 +2,13 @@ package com.baeldung.readinputcharbychar; import org.junit.jupiter.api.Test; -import java.io.*; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.Scanner; import static org.junit.Assert.assertArrayEquals; @@ -51,7 +57,7 @@ public class ReadInputCharByCharUnitTest { System.setIn(inputStream); try (Scanner scanner = new Scanner(System.in)) { - while (scanner.hasNext()) { + if (scanner.hasNext()) { char[] result = scanner.next().toCharArray(); assertArrayEquals("TestInput".toCharArray(), result); }