forked from nus-cs2113-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from DextheChik3n/196-junit-test-for-file-man…
…ager-v2.1 Add JUnit tests for file manager
- Loading branch information
Showing
4 changed files
with
84 additions
and
48 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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package seedu.cafectrl.storage; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import seedu.cafectrl.ui.ErrorMessages; | ||
import seedu.cafectrl.ui.Ui; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
/** | ||
* Junit test for FileManager.java | ||
*/ | ||
public class FileManagerTest { | ||
@Test | ||
public void readTextFile_emptyFilePath_fileNotFoundExceptionThrown() { | ||
String inputFilePath = ""; | ||
|
||
FileManager fileManager = new FileManager(new Ui()); | ||
assertThrows(FileNotFoundException.class, () -> fileManager.readTextFile(inputFilePath)); | ||
} | ||
|
||
@Test | ||
public void readTextFile_nullFilePath_nullPointerExceptionThrown() { | ||
|
||
FileManager fileManager = new FileManager(new Ui()); | ||
assertThrows(NullPointerException.class, () -> fileManager.readTextFile(null)); | ||
} | ||
|
||
@Test | ||
public void checkFileExists_emptyFilePath_fileNotFoundExceptionThrown() { | ||
String inputFilePath = ""; | ||
|
||
FileManager fileManager = new FileManager(new Ui()); | ||
assertThrows(Exception.class, () -> fileManager.checkFileExists(inputFilePath)); | ||
} | ||
|
||
@Test | ||
public void checkFileExists_nullFilePath_nullPointerExceptionThrown() { | ||
FileManager fileManager = new FileManager(new Ui()); | ||
assertThrows(NullPointerException.class, () -> fileManager.checkFileExists(null)); | ||
} | ||
|
||
@Test | ||
public void overwriteFile_emptyFilePath_emptyFileInputMessage() { | ||
ArrayList<String> actualOutput = new ArrayList<>(); | ||
Ui ui = new Ui() { | ||
@Override | ||
public void showToUser(String... message) { | ||
actualOutput.addAll(Arrays.asList(message)); | ||
} | ||
}; | ||
FileManager fileManager = new FileManager(ui); | ||
|
||
String inputFilePath = ""; | ||
ArrayList<String> inputTextList = new ArrayList<>(); | ||
|
||
fileManager.overwriteFile(inputFilePath, inputTextList); | ||
assertEquals(ErrorMessages.MISSING_FILEPATH, actualOutput.get(0)); | ||
} | ||
} |