From a8f010e50e516dae6aed45846f063c492fcbd8ed Mon Sep 17 00:00:00 2001 From: Kumar Prabhash Anand Date: Tue, 20 Sep 2022 17:52:25 +0200 Subject: [PATCH] BAEL-5765 - Adding scan a char unit tests (#12741) * BAEL-5765 Adding scan a char unit tests * BAEL-5765 updated class name as per the convention * BAEL-5765 updated test cases naming strategy --- .../scanner/ScanACharacterUnitTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/scanner/ScanACharacterUnitTest.java diff --git a/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/scanner/ScanACharacterUnitTest.java b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/scanner/ScanACharacterUnitTest.java new file mode 100644 index 0000000000..49d6e78f14 --- /dev/null +++ b/core-java-modules/core-java-io-apis-2/src/test/java/com/baeldung/scanner/ScanACharacterUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.scanner; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Scanner; + +import org.junit.jupiter.api.Test; + +public class ScanACharacterUnitTest { + + // given - input scanner source, no need to scan from console + String Input = new StringBuilder().append("abc\n") + .append("mno\n") + .append("xyz\n") + .toString(); + + @Test + public void givenInputSource_whenScanCharUsingNext_thenOneCharIsRead() { + Scanner sc = new Scanner(Input); + char c = sc.next().charAt(0); + assertEquals('a', c); + } + + @Test + public void givenInputSource_whenScanCharUsingFindInLine_thenOneCharIsRead() { + Scanner sc = new Scanner(Input); + char c = sc.findInLine(".").charAt(0); + assertEquals('a', c); + } + + @Test + public void givenInputSource_whenScanCharUsingUseDelimiter_thenOneCharIsRead() { + Scanner sc = new Scanner(Input); + String c = sc.useDelimiter("").next(); + assertEquals("a", c); + } + +}