Skip to content

Commit a548fac

Browse files
authored
Merge pull request #10 from bobocode-projects/GP-28_Migrate_FileReader_into_main
GP-28 Migrate File Reader to main
2 parents 6a0554e + 53c1be2 commit a548fac

File tree

6 files changed

+70
-0
lines changed

6 files changed

+70
-0
lines changed

3-0-java-core/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6+
<dependencies>
7+
<dependency>
8+
<groupId>com.bobocode</groupId>
9+
<artifactId>java-fundamentals-util</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<scope>compile</scope>
12+
</dependency>
13+
</dependencies>
614

715
<parent>
816
<groupId>com.bobocode</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.bobocode.file_reader;
2+
3+
import com.bobocode.util.ExerciseNotCompletedException;
4+
5+
/**
6+
* {@link FileReaders} provides an API that allow to read whole file into a {@link String} by file name.
7+
*/
8+
public class FileReaders {
9+
10+
/**
11+
* Returns a {@link String} that contains whole text from the file specified by name.
12+
*
13+
* @param fileName a name of a text file
14+
* @return string that holds whole file content
15+
*/
16+
public static String readWholeFile(String fileName) {
17+
throw new ExerciseNotCompletedException(); //todo
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.bobocode.file_reader;
2+
3+
import com.bobocode.file_reader.FileReaders;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
9+
public class FileReadersTest {
10+
11+
@Test
12+
void testReadWholeFileOnEmptyFile() {
13+
String fileContent = FileReaders.readWholeFile("empty.txt");
14+
15+
assertEquals("", fileContent);
16+
17+
}
18+
19+
@Test
20+
void testReadWholeFileOnFileWithEmptyLines() {
21+
String fileContent = FileReaders.readWholeFile("lines.txt");
22+
23+
assertEquals("Hey!\n" +
24+
"\n" +
25+
"What's up?\n" +
26+
"\n" +
27+
"Hi!", fileContent);
28+
}
29+
30+
@Test
31+
void testReadWholeFile() {
32+
String fileContent = FileReaders.readWholeFile("simple.txt");
33+
34+
assertEquals("Hello!\n" + "It's a test file.", fileContent);
35+
}
36+
}

3-0-java-core/src/test/resources/empty.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Hey!
2+
3+
What's up?
4+
5+
Hi!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello!
2+
It's a test file.

0 commit comments

Comments
 (0)