Skip to content

Commit

Permalink
(#10) Added extra unit tests for PsdfUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasstarsz committed Jun 6, 2021
1 parent c082670 commit 731e80a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/tech/fastj/graphics/util/PsdfUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public class PsdfUtil {
public static Polygon2D[] loadPsdf(String fileLocation) {
// check for correct file extension
if (!fileLocation.substring(fileLocation.lastIndexOf(".") + 1).equalsIgnoreCase("psdf")) {
FastJEngine.error(PsdfReadErrorMessage,
new IllegalArgumentException("Unsupported file type."
throw new IllegalArgumentException(
"Unsupported file type."
+ System.lineSeparator()
+ "This engine currently only supports files of the extension \".psdf\".")
+ "This engine currently only supports files of the extension \".psdf\"."
);
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/unittest/testcases/graphics/util/PsdfUtilTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;

import org.junit.jupiter.api.AfterAll;
Expand All @@ -28,6 +30,7 @@

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class PsdfUtilTests {
Expand Down Expand Up @@ -137,4 +140,25 @@ void checkReadPsdf_shouldMatchOriginal() {
assertArrayEquals(expectedHouseArray, actualHouseArray, "The actual Polygon2D array should match the expected array.");
assertEquals(expectedHouse, actualHouse, "The actual Model2D should match the expected Model2D.");
}

@Test
void tryReadPsdf_withIncorrectFileExtension() {
String invalid_path = UUID.randomUUID() + ".notsupported";
Throwable exception = assertThrows(IllegalArgumentException.class, () -> PsdfUtil.loadPsdf(invalid_path));

String expectedExceptionMessage = "Unsupported file type."
+ System.lineSeparator()
+ "This engine currently only supports files of the extension \".psdf\".";
assertEquals(expectedExceptionMessage, exception.getMessage(), "The thrown exception's message should match the expected exception message.");
}

@Test
void tryReadPsdf_withFileThatDoesNotExist() {
String invalid_pathThatDoesNotResolveToFile = UUID.randomUUID() + ".psdf";

Throwable exception = assertThrows(IllegalStateException.class, () -> PsdfUtil.loadPsdf(invalid_pathThatDoesNotResolveToFile)).getCause();
assertEquals(NoSuchFileException.class, exception.getClass(), "The exception's class should match the expected class.");

assertEquals(invalid_pathThatDoesNotResolveToFile, exception.getMessage(), "The thrown exception's message should match the expected exception message.");
}
}

0 comments on commit 731e80a

Please sign in to comment.