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
This commit is contained in:
Kumar Prabhash Anand 2022-09-20 17:52:25 +02:00 committed by GitHub
parent 2842e5cee7
commit a8f010e50e
1 changed files with 38 additions and 0 deletions

View File

@ -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);
}
}