Add files via upload (#13978)

This commit is contained in:
Bahaa El-Din Helmy 2023-05-09 00:11:33 +03:00 committed by GitHub
parent 4cc0380249
commit 53d269ca68
10 changed files with 502 additions and 353 deletions

View File

@ -1,46 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>core-java-io-apis-2</artifactId> <artifactId>core-java-io-apis-2</artifactId>
<name>core-java-io-apis-2</name> <name>core-java-io-apis-2</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<parent> <parent>
<groupId>com.baeldung.core-java-modules</groupId> <groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId> <artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
<dependencies> <dependencies>
<!-- logging --> <!-- logging -->
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
<version>${log4j.version}</version> <version>${log4j.version}</version>
</dependency> </dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly --> <dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId> <artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version> <version>${org.slf4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>${lombok.version}</version> <version>${lombok.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> <dependency>
<groupId>org.junit.jupiter</groupId>
<build> <artifactId>junit-jupiter-engine</artifactId>
<finalName>core-java-io-apis-2</finalName> <version>5.7.2</version>
<resources> <scope>test</scope>
<resource> </dependency>
<directory>src/main/resources</directory> <dependency>
<filtering>true</filtering> <groupId>org.junit.jupiter</groupId>
</resource> <artifactId>junit-jupiter</artifactId>
</resources> </dependency>
</build> <dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<!-- this is all you need to write tests with JUnit Jupiter -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit-jupiter-version}</version>
<scope>test</scope>
</dependency>
<!-- this dependency is needed to create parameterized tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter-version}</version>
<scope>test</scope>
</dependency>
<!-- contains the engine that actually runs the Jupiter-tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<junit-jupiter-version>5.2.0</junit-jupiter-version>
</properties>
<build>
<finalName>core-java-io-apis-2</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project> </project>

View File

@ -0,0 +1,36 @@
package com.baeldung.multinput;
import java.util.InputMismatchException;
import java.util.Scanner;
public class MultiInputs {
public void UsingSpaceDelimiter(){
Scanner scanner = new Scanner(System.in);
System.out.print("Enter two numbers: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
System.out.println("You entered " + num1 + " and " + num2);
}
public void UsingREDelimiter(){
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter("[\\s,]+");
System.out.print("Enter two numbers separated by a space or a comma: ");
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
System.out.println("You entered " + num1 + " and " + num2);
}
public void UsingCustomDelimiter(){
Scanner scanner = new Scanner(System.in);
scanner.useDelimiter(";");
System.out.print("Enter two numbers separated by a semicolon: ");
try { int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
System.out.println("You entered " + num1 + " and " + num2); }
catch (InputMismatchException e)
{ System.out.println("Invalid input. Please enter two integers separated by a semicolon."); }
}
}

View File

@ -1,93 +1,92 @@
package com.baeldung.absolutetorelative; package com.baeldung.absolutetorelative;
import org.assertj.core.api.Assertions; import java.net.URI;
import org.junit.jupiter.api.Test; import java.nio.file.Path;
import java.nio.file.Paths;
import java.net.URI; import org.junit.jupiter.api.Assertions;
import java.nio.file.Path; import org.junit.jupiter.api.Test;
import java.nio.file.Paths;
public class AbsoluteToRelativeUnitTest {
public class AbsoluteToRelativeUnitTest {
// given - until using Paths, no need to create physical files
// given - until using Paths, no need to create physical files private final Path pathOne = Paths.get("/baeldung/bar/one.txt");
private final Path pathOne = Paths.get("/baeldung/bar/one.txt"); private final Path pathTwo = Paths.get("/baeldung/bar/two.txt");
private final Path pathTwo = Paths.get("/baeldung/bar/two.txt"); private final Path pathThree = Paths.get("/baeldung/foo/three.txt");
private final Path pathThree = Paths.get("/baeldung/foo/three.txt");
private final URI uriOne = pathOne.toUri();
private final URI uriOne = pathOne.toUri(); private final URI uriTwo = pathTwo.toUri();
private final URI uriTwo = pathTwo.toUri(); private final URI uriThree = pathThree.toUri();
private final URI uriThree = pathThree.toUri();
@Test
@Test public void givenAbsolutePaths_whenRelativizePathOneToPathTwo_thenRelativeIsReturned() {
public void givenAbsolutePaths_whenRelativizePathOneToPathTwo_thenRelativeIsReturned() { Path result = pathOne.relativize(pathTwo);
Path result = pathOne.relativize(pathTwo);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .isRelative()
.isRelative() .isEqualTo(Paths.get("../two.txt"));
.isEqualTo(Paths.get("../two.txt")); }
}
@Test
@Test public void givenAbsolutePaths_whenRelativizePathTwoToPathOne_thenRelativeIsReturned() {
public void givenAbsolutePaths_whenRelativizePathTwoToPathOne_thenRelativeIsReturned() { Path result = pathTwo.relativize(pathOne);
Path result = pathTwo.relativize(pathOne);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .isRelative()
.isRelative() .isEqualTo(Paths.get("../one.txt"));
.isEqualTo(Paths.get("../one.txt")); }
}
@Test
@Test public void givenAbsolutePaths_whenRelativizePathOneParentToPathTwo_thenRelativeIsReturned() {
public void givenAbsolutePaths_whenRelativizePathOneParentToPathTwo_thenRelativeIsReturned() { Path result = pathOne.getParent().relativize(pathTwo);
Path result = pathOne.getParent().relativize(pathTwo);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .isRelative()
.isRelative() .isEqualTo(Paths.get("two.txt"));
.isEqualTo(Paths.get("two.txt")); }
}
@Test
@Test public void givenAbsolutePaths_whenRelativizePathOneToPathThree_thenRelativeIsReturned() {
public void givenAbsolutePaths_whenRelativizePathOneToPathThree_thenRelativeIsReturned() { Path result = pathOne.relativize(pathThree);
Path result = pathOne.relativize(pathThree);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .isRelative()
.isRelative() .isEqualTo(Paths.get("../../foo/three.txt"));
.isEqualTo(Paths.get("../../foo/three.txt")); }
}
@Test
@Test public void givenAbsolutePaths_whenRelativizePathThreeToPathOne_thenRelativeIsReturned() {
public void givenAbsolutePaths_whenRelativizePathThreeToPathOne_thenRelativeIsReturned() { Path result = pathThree.relativize(pathOne);
Path result = pathThree.relativize(pathOne);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .isRelative()
.isRelative() .isEqualTo(Paths.get("../../bar/one.txt"));
.isEqualTo(Paths.get("../../bar/one.txt")); }
}
@Test
@Test public void givenAbsoluteURIs_whenRelativizeUriOneToUriTwo_thenAbsoluteIsReturned() {
public void givenAbsoluteURIs_whenRelativizeUriOneToUriTwo_thenAbsoluteIsReturned() { URI result = uriOne.relativize(uriTwo);
URI result = uriOne.relativize(uriTwo);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .asString()
.asString() .contains("/baeldung/bar/two.txt");
.contains("/baeldung/bar/two.txt"); }
}
@Test
@Test public void givenAbsoluteURIs_whenRelativizeUriOneParentToUriTwo_thenRelativeIsReturned() {
public void givenAbsoluteURIs_whenRelativizeUriOneParentToUriTwo_thenRelativeIsReturned() { URI result = pathOne.getParent().toUri().relativize(uriTwo);
URI result = pathOne.getParent().toUri().relativize(uriTwo);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .asString()
.asString() .contains("two.txt");
.contains("two.txt"); }
}
@Test
@Test public void givenAbsoluteURIs_whenRelativizeUriOneParentToUriThree_thenAbsoluteIsReturned() {
public void givenAbsoluteURIs_whenRelativizeUriOneParentToUriThree_thenAbsoluteIsReturned() { URI result = pathOne.getParent().toUri().relativize(uriThree);
URI result = pathOne.getParent().toUri().relativize(uriThree);
org.assertj.core.api.Assertions.assertThat(result)
Assertions.assertThat(result) .asString()
.asString() .contains("/baeldung/foo/three.txt");
.contains("/baeldung/foo/three.txt"); }
}
}
}

View File

@ -1,31 +1,31 @@
package com.baeldung.bufferedreadervsfilereader; package com.baeldung.bufferedreadervsfilereader;
import org.junit.Test; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.BufferedReader;
import java.io.FileReader;
import java.io.BufferedReader; import java.io.IOException;
import java.io.FileReader;
import java.io.IOException; import org.junit.jupiter.api.Assertions;
import org.testng.annotations.Test;
public class BufferedReaderUnitTest { public class BufferedReaderUnitTest {
@Test @Test
public void whenReadingAFile_thenReadsLineByLine() { public void whenReadingAFile_thenReadsLineByLine() {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader("src/test/resources/sampleText1.txt"))) { try (BufferedReader br = new BufferedReader(new FileReader("src/test/resources/sampleText1.txt"))) {
String line; String line;
while((line = br.readLine()) != null) { while((line = br.readLine()) != null) {
result.append(line); result.append(line);
result.append('\n'); result.append('\n');
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
assertEquals("first line\nsecond line\nthird line\n", result.toString()); assertEquals("first line\nsecond line\nthird line\n", result.toString());
} }
} }

View File

@ -1,30 +1,30 @@
package com.baeldung.bufferedreadervsfilereader; package com.baeldung.bufferedreadervsfilereader;
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test;
public class FileReaderUnitTest { public class FileReaderUnitTest {
@Test @Test
public void whenReadingAFile_thenReadsCharByChar() { public void whenReadingAFile_thenReadsCharByChar() {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
try (FileReader fr = new FileReader("src/test/resources/sampleText2.txt")) { try (FileReader fr = new FileReader("src/test/resources/sampleText2.txt")) {
int i = fr.read(); int i = fr.read();
while(i != -1) { while(i != -1) {
result.append((char)i); result.append((char)i);
i = fr.read(); i = fr.read();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
assertEquals("qwerty", result.toString()); assertEquals("qwerty", result.toString());
} }
} }

View File

@ -0,0 +1,47 @@
package com.baeldung.multinput;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.InputMismatchException;
import org.junit.jupiter.api.Assertions;
import org.testng.annotations.Test;
import com.baeldung.multinput.MultiInputs;
public class TestMultipleInputsUnitTest {
@Test
public void givenMultipleInputs_whenUsingSpaceDelimiter_thenExpectPrintingOutputs() {
String input = "10 20\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
mi.UsingSpaceDelimiter();
// You can add assertions here to verify the behavior of the method
}
@Test
public void givenMultipleInputs_whenUsingREDelimiter_thenExpectPrintingOutputs() {
String input = "30, 40\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
mi.UsingREDelimiter();
// You can add assertions here to verify the behavior of the method
}
@Test
public void givenMultipleInputs_whenUsingCustomDelimiter_thenExpectPrintingOutputs() {
String input = "50; 60\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
mi.UsingCustomDelimiter();
// You can add assertions here to verify the behavior of the method
}
@Test
public void givenInvalidInput_whenUsingSpaceDelimiter_thenExpectInputMismatchException() {
String input = "abc\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
MultiInputs mi = new MultiInputs();
Assertions.assertThrows(InputMismatchException.class, mi::UsingSpaceDelimiter);
}
}

View File

@ -1,29 +1,27 @@
package com.baeldung.path; package com.baeldung.path;
import org.junit.jupiter.api.Test; import java.io.File;
import java.io.File; import javax.swing.filechooser.FileSystemView;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Test;
import javax.swing.filechooser.FileSystemView; public class DesktopPathUnitTest {
// Adapt DESKTOP_PATH variable to your own system path
public class DesktopPathUnitTest { // private static final String DESKTOP_PATH = "C:\\Users\\HRAF\\Desktop";
// Adapt DESKTOP_PATH variable to your own system path
// private static final String DESKTOP_PATH = "C:\\Users\\HRAF\\Desktop"; @Test
public void whenUsingGetUserHomeProperty_thenShouldEqualDesktopPath() {
@Test String desktopPath = System.getProperty("user.home") + File.separator + "Desktop";
public void whenUsingGetUserHomeProperty_thenShouldEqualDesktopPath() { // assertEquals(DESKTOP_PATH, desktopPath);
String desktopPath = System.getProperty("user.home") + File.separator + "Desktop"; }
// assertEquals(DESKTOP_PATH, desktopPath);
} @Test
public void whenUsingFileSystemViewGetHomeDirectory_thenShouldEqualDesktopPath() {
@Test FileSystemView view = FileSystemView.getFileSystemView();
public void whenUsingFileSystemViewGetHomeDirectory_thenShouldEqualDesktopPath() { File file = view.getHomeDirectory();
FileSystemView view = FileSystemView.getFileSystemView(); String path = file.getPath();
File file = view.getHomeDirectory(); // assertEquals(DESKTOP_PATH, path);
String path = file.getPath(); }
// assertEquals(DESKTOP_PATH, path);
} }
}

View File

@ -1,85 +1,85 @@
package com.baeldung.scanner; package com.baeldung.scanner;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.InputMismatchException; import java.util.InputMismatchException;
import java.util.Scanner; import java.util.Scanner;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class NextLineVsNextIntUnitTest { public class NextLineVsNextIntUnitTest {
@Test @Test
void whenInputLineIsNumber_thenNextLineAndNextIntBothWork() { void whenInputLineIsNumber_thenNextLineAndNextIntBothWork() {
String input = "42\n"; String input = "42\n";
//nextLine() //nextLine()
Scanner sc1 = new Scanner(input); Scanner sc1 = new Scanner(input);
int num1 = Integer.parseInt(sc1.nextLine()); int num1 = Integer.parseInt(sc1.nextLine());
assertEquals(42, num1); assertEquals(42, num1);
//nextInt() //nextInt()
Scanner sc2 = new Scanner(input); Scanner sc2 = new Scanner(input);
int num2 = sc2.nextInt(); int num2 = sc2.nextInt();
assertEquals(42, num2); assertEquals(42, num2);
} }
@Test @Test
void whenInputIsNotValidNumber_thenNextLineAndNextIntThrowDifferentException() { void whenInputIsNotValidNumber_thenNextLineAndNextIntThrowDifferentException() {
String input = "Nan\n"; String input = "Nan\n";
//nextLine() -> NumberFormatException //nextLine() -> NumberFormatException
Scanner sc1 = new Scanner(input); Scanner sc1 = new Scanner(input);
assertThrows(NumberFormatException.class, () -> Integer.parseInt(sc1.nextLine())); assertThrows(NumberFormatException.class, () -> Integer.parseInt(sc1.nextLine()));
//nextInt() -> InputMismatchException //nextInt() -> InputMismatchException
Scanner sc2 = new Scanner(input); Scanner sc2 = new Scanner(input);
assertThrows(InputMismatchException.class, sc2::nextInt); assertThrows(InputMismatchException.class, sc2::nextInt);
} }
@Test @Test
void whenUsingNextInt_thenTheNextTokenAfterItFailsToParseIsNotConsumed() { void whenUsingNextInt_thenTheNextTokenAfterItFailsToParseIsNotConsumed() {
String input = "42 is a magic number\n"; String input = "42 is a magic number\n";
//nextInt() to read '42' //nextInt() to read '42'
Scanner sc2 = new Scanner(input); Scanner sc2 = new Scanner(input);
int num2 = sc2.nextInt(); int num2 = sc2.nextInt();
assertEquals(42, num2); assertEquals(42, num2);
// call nextInt() again on "is" // call nextInt() again on "is"
assertThrows(InputMismatchException.class, sc2::nextInt); assertThrows(InputMismatchException.class, sc2::nextInt);
String theNextToken = sc2.next(); String theNextToken = sc2.next();
assertEquals("is", theNextToken); assertEquals("is", theNextToken);
theNextToken = sc2.next(); theNextToken = sc2.next();
assertEquals("a", theNextToken); assertEquals("a", theNextToken);
} }
@Test @Test
void whenReadingTwoInputLines_thenNextLineAndNextIntBehaveDifferently() { void whenReadingTwoInputLines_thenNextLineAndNextIntBehaveDifferently() {
String input = new StringBuilder().append("42\n") String input = new StringBuilder().append("42\n")
.append("It is a magic number.\n") .append("It is a magic number.\n")
.toString(); .toString();
//nextLine() //nextLine()
Scanner sc1 = new Scanner(input); Scanner sc1 = new Scanner(input);
int num1 = Integer.parseInt(sc1.nextLine()); int num1 = Integer.parseInt(sc1.nextLine());
String nextLineText1 = sc1.nextLine(); String nextLineText1 = sc1.nextLine();
assertEquals(42, num1); assertEquals(42, num1);
assertEquals("It is a magic number.", nextLineText1); assertEquals("It is a magic number.", nextLineText1);
//nextInt() //nextInt()
Scanner sc2 = new Scanner(input); Scanner sc2 = new Scanner(input);
int num2 = sc2.nextInt(); int num2 = sc2.nextInt();
assertEquals(42, num2); assertEquals(42, num2);
// nextInt() leaves the newline character (\n) behind // nextInt() leaves the newline character (\n) behind
String nextLineText2 = sc2.nextLine(); String nextLineText2 = sc2.nextLine();
assertEquals("", nextLineText2); assertEquals("", nextLineText2);
} }
} }

View File

@ -1,38 +1,38 @@
package com.baeldung.scanner; package com.baeldung.scanner;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Scanner; import java.util.Scanner;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class ScanACharacterUnitTest { public class ScanACharacterUnitTest {
// given - input scanner source, no need to scan from console // given - input scanner source, no need to scan from console
String input = new StringBuilder().append("abc\n") String input = new StringBuilder().append("abc\n")
.append("mno\n") .append("mno\n")
.append("xyz\n") .append("xyz\n")
.toString(); .toString();
@Test @Test
public void givenInputSource_whenScanCharUsingNext_thenOneCharIsRead() { public void givenInputSource_whenScanCharUsingNext_thenOneCharIsRead() {
Scanner sc = new Scanner(input); Scanner sc = new Scanner(input);
char c = sc.next().charAt(0); char c = sc.next().charAt(0);
assertEquals('a', c); assertEquals('a', c);
} }
@Test @Test
public void givenInputSource_whenScanCharUsingFindInLine_thenOneCharIsRead() { public void givenInputSource_whenScanCharUsingFindInLine_thenOneCharIsRead() {
Scanner sc = new Scanner(input); Scanner sc = new Scanner(input);
char c = sc.findInLine(".").charAt(0); char c = sc.findInLine(".").charAt(0);
assertEquals('a', c); assertEquals('a', c);
} }
@Test @Test
public void givenInputSource_whenScanCharUsingUseDelimiter_thenOneCharIsRead() { public void givenInputSource_whenScanCharUsingUseDelimiter_thenOneCharIsRead() {
Scanner sc = new Scanner(input); Scanner sc = new Scanner(input);
char c = sc.useDelimiter("").next().charAt(0); char c = sc.useDelimiter("").next().charAt(0);
assertEquals('a', c); assertEquals('a', c);
} }
} }

View File

@ -1,3 +1,3 @@
first line first line
second line second line
third line third line