Skip to content

Commit

Permalink
Added tests for FileFormatTest
Browse files Browse the repository at this point in the history
  • Loading branch information
tah5in committed Apr 4, 2024
1 parent cda4191 commit 84c6258
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/test/java/scm/address/model/file/FileFormatTest.java
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);
}
}

}

0 comments on commit 84c6258

Please sign in to comment.