diff --git a/3-0-java-core/pom.xml b/3-0-java-core/pom.xml index c64260c12..e291a887e 100644 --- a/3-0-java-core/pom.xml +++ b/3-0-java-core/pom.xml @@ -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"> 4.0.0 + + + com.bobocode + java-fundamentals-util + 1.0-SNAPSHOT + compile + + com.bobocode diff --git a/3-0-java-core/src/main/java/com/bobocode/file_reader/FileReaders.java b/3-0-java-core/src/main/java/com/bobocode/file_reader/FileReaders.java new file mode 100644 index 000000000..685d2d473 --- /dev/null +++ b/3-0-java-core/src/main/java/com/bobocode/file_reader/FileReaders.java @@ -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 + } +} diff --git a/3-0-java-core/src/test/java/com/bobocode/file_reader/FileReadersTest.java b/3-0-java-core/src/test/java/com/bobocode/file_reader/FileReadersTest.java new file mode 100644 index 000000000..a7e4311fe --- /dev/null +++ b/3-0-java-core/src/test/java/com/bobocode/file_reader/FileReadersTest.java @@ -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); + } +} diff --git a/3-0-java-core/src/test/resources/empty.txt b/3-0-java-core/src/test/resources/empty.txt new file mode 100644 index 000000000..e69de29bb diff --git a/3-0-java-core/src/test/resources/lines.txt b/3-0-java-core/src/test/resources/lines.txt new file mode 100644 index 000000000..7c294a97f --- /dev/null +++ b/3-0-java-core/src/test/resources/lines.txt @@ -0,0 +1,5 @@ +Hey! + +What's up? + +Hi! \ No newline at end of file diff --git a/3-0-java-core/src/test/resources/simple.txt b/3-0-java-core/src/test/resources/simple.txt new file mode 100644 index 000000000..ac906f0b9 --- /dev/null +++ b/3-0-java-core/src/test/resources/simple.txt @@ -0,0 +1,2 @@ +Hello! +It's a test file. \ No newline at end of file