forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package scm.address.model.file; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import scm.address.commons.exceptions.IllegalValueException; | ||
|
||
import java.io.File; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class FileFormatTest { | ||
|
||
private static final String VALID_FILENAME_JSON = "hello.json"; | ||
private static final String VALID_FILENAME_CSV = "hello.csv"; | ||
private static final String INVALID_FILENAME = "hello.xyz"; | ||
|
||
private static final String NO_FILE_FORMAT_FILENAME = "hello"; | ||
|
||
@Test | ||
public void test_getFileFormatJson_success() throws IllegalValueException { | ||
File file = new File(VALID_FILENAME_JSON); | ||
assertEquals(FileFormat.JSON_FILE, FileFormat.getFileFormat(file)); | ||
} | ||
|
||
@Test | ||
public void test_getFileFormatCsv_success() throws IllegalValueException { | ||
File file = new File(VALID_FILENAME_CSV); | ||
assertEquals(FileFormat.CSV_FILE, FileFormat.getFileFormat(file)); | ||
} | ||
|
||
@Test | ||
public void test_getFileFormatInvalidFormat_failure() { | ||
File file = new File(INVALID_FILENAME); | ||
try { | ||
FileFormat.getFileFormat(file); | ||
} catch (IllegalValueException e) { | ||
assertEquals(FileFormat.MESSAGE_UNSUPPORTED_FILE_FORMAT, e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void test_getFileFormatNoExtension_failure() { | ||
File file = new File(NO_FILE_FORMAT_FILENAME); | ||
try { | ||
FileFormat.getFileFormat(file); | ||
} catch (IllegalValueException e) { | ||
assertEquals(FileFormat.MESSAGE_INVALID_FILE_FORMAT, e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void test_getFileFormatNullFile_failure() { | ||
try { | ||
FileFormat.getFileFormat(null); | ||
} catch (Exception e) { | ||
assertFalse(e instanceof IllegalValueException); | ||
assertTrue(e instanceof NullPointerException); | ||
} | ||
} | ||
|
||
} |