File tree 6 files changed +70
-0
lines changed
main/java/com/bobocode/file_reader
java/com/bobocode/file_reader
6 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 3
3
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
4
xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
5
<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 >
6
14
7
15
<parent >
8
16
<groupId >com.bobocode</groupId >
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ Hey!
2
+
3
+ What's up?
4
+
5
+ Hi!
Original file line number Diff line number Diff line change
1
+ Hello!
2
+ It's a test file.
You can’t perform that action at this time.
0 commit comments