-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Utils, UtilsTest and test file (#29)
Closes #26
- Loading branch information
1 parent
028c072
commit 9cf024a
Showing
7 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ | |
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
out/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package utils; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.util.Scanner; | ||
|
||
public class Utils { | ||
|
||
public static Scanner getFileReference(final String filePath) { | ||
|
||
File f; | ||
Scanner fileReference; | ||
|
||
try { | ||
f = new File(filePath); | ||
|
||
if(f.exists()) { | ||
System.out.println(filePath + " file opened."); | ||
} | ||
else { | ||
System.out.println(filePath + " doesn't exist."); | ||
return null; | ||
} | ||
} catch(NullPointerException | SecurityException e) { | ||
System.out.println(filePath + "couldn't be opened."); | ||
System.out.println(e.getMessage()); | ||
return null; | ||
} | ||
|
||
try { | ||
fileReference= new Scanner(f); | ||
} catch(FileNotFoundException e) { | ||
System.out.println(filePath + "couldn't be found."); | ||
System.out.println(e.getMessage()); | ||
return null; | ||
} | ||
|
||
return fileReference; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package utils; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Scanner; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class UtilsTest { | ||
|
||
@Test | ||
void getFileReference() { | ||
Scanner file = Utils.getFileReference("test/resources/fileTest.txt"); | ||
|
||
assertNotNull(file); | ||
|
||
int nLines = 0; | ||
|
||
while(file.hasNextLine()) { | ||
nLines++; | ||
System.out.println(file.nextLine()); | ||
} | ||
|
||
assertEquals(2, nLines, "The number of lines should be 2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
hello world! | ||
I'm in. |