Skip to content

GP-28 Migrate File Reader to main #10

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

Merged
merged 1 commit into from
Jan 5, 2021
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
8 changes: 8 additions & 0 deletions 3-0-java-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
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">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>com.bobocode</groupId>
<artifactId>java-fundamentals-util</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<parent>
<groupId>com.bobocode</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bobocode.file_reader;

import com.bobocode.util.ExerciseNotCompletedException;

/**
* {@link FileReaders} provides an API that allow to read whole file into a {@link String} by file name.
*/
public class FileReaders {

/**
* Returns a {@link String} that contains whole text from the file specified by name.
*
* @param fileName a name of a text file
* @return string that holds whole file content
*/
public static String readWholeFile(String fileName) {
throw new ExerciseNotCompletedException(); //todo
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.bobocode.file_reader;

import com.bobocode.file_reader.FileReaders;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;


public class FileReadersTest {

@Test
void testReadWholeFileOnEmptyFile() {
String fileContent = FileReaders.readWholeFile("empty.txt");

assertEquals("", fileContent);

}

@Test
void testReadWholeFileOnFileWithEmptyLines() {
String fileContent = FileReaders.readWholeFile("lines.txt");

assertEquals("Hey!\n" +
"\n" +
"What's up?\n" +
"\n" +
"Hi!", fileContent);
}

@Test
void testReadWholeFile() {
String fileContent = FileReaders.readWholeFile("simple.txt");

assertEquals("Hello!\n" + "It's a test file.", fileContent);
}
}
Empty file.
5 changes: 5 additions & 0 deletions 3-0-java-core/src/test/resources/lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hey!

What's up?

Hi!
2 changes: 2 additions & 0 deletions 3-0-java-core/src/test/resources/simple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello!
It's a test file.