Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA-22498 Potential issue in "Difference Between FileReader and Buff… #14331

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.jupiter.api.Assertions;
import org.testng.annotations.Test;
public class BufferedReaderUnitTest {
import org.junit.jupiter.api.Test;

class BufferedReaderUnitTest {

@Test
public void whenReadingAFile_thenReadsLineByLine() {
void whenReadingAFile_thenReadsLineByLine() {
StringBuilder result = new StringBuilder();

try (BufferedReader br = new BufferedReader(new FileReader("src/test/resources/sampleText1.txt"))) {
final Path filePath = new File("src/test/resources/sampleText1.txt").toPath();
try (BufferedReader br = new BufferedReader(new InputStreamReader(Files.newInputStream(filePath), StandardCharsets.UTF_8))) {
String line;

while((line = br.readLine()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import org.junit.jupiter.api.Test;

public class FileReaderUnitTest {
class FileReaderUnitTest {

@Test
public void whenReadingAFile_thenReadsCharByChar() {
void whenReadingAFile_thenReadsCharByChar() {
StringBuilder result = new StringBuilder();

try (FileReader fr = new FileReader("src/test/resources/sampleText2.txt")) {
Expand Down