-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathFileLoader.java
More file actions
43 lines (36 loc) · 1.26 KB
/
FileLoader.java
File metadata and controls
43 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.serenitydojo.exceptions;
import org.apache.commons.io.filefilter.IOFileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Paths;
public class FileLoader {
public String readHelloWorld() throws IOException {
return Files.readString(Paths.get("src/main/resources/hello.txt"));
}
public Boolean fileContainsText(String filename, String expectedText) {
try
{
String path = "src/main/resources/" + filename;
return Files.readString(Paths.get(path)).contains(expectedText);
}
catch(NoSuchFileException fileDoesNotExist)
{
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public Boolean fileHasText(String filename, String expectedText) throws IOException,MissingWelcomeFileException {
try
{
String path = "src/main/resources/" + filename;
return Files.readString(Paths.get(path)).contains(expectedText);
}
catch (NoSuchFileException missingFile)
{
throw new MissingWelcomeFileException("Unable to find the file " + filename,missingFile);
}
}
}