Skip to content

Commit

Permalink
(#10) simplify error to avoid loading FastJEngine class
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasstarsz committed Jun 6, 2021
1 parent 318525f commit 47079f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 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 @@ -16,6 +16,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -59,7 +60,7 @@ public static Polygon2D[] loadPsdf(String fileLocation) {
private static Polygon2D[] parsePsdf(String fileLocation) {
try {
Polygon2D[] result = null;
List<String> lines = Files.readAllLines(Paths.get(fileLocation));
List<String> lines = Files.readAllLines(Path.of(fileLocation));
List<Pointf> polygonPoints = new ArrayList<>();
Paint paint = null;
boolean fillPolygon = false;
Expand Down Expand Up @@ -162,8 +163,7 @@ private static Polygon2D[] parsePsdf(String fileLocation) {
}
return result;
} catch (IOException e) {
FastJEngine.error(PsdfReadErrorMessage, e);
return null;
throw new IllegalStateException("An issue occurred while trying to parse file \"" + fileLocation + "\".", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ void tryReadPsdf_withIncorrectFileExtension() {
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.");
Throwable exception = assertThrows(IllegalStateException.class, () -> PsdfUtil.loadPsdf(invalid_pathThatDoesNotResolveToFile));
assertEquals(NoSuchFileException.class, exception.getCause().getClass(), "The underlying exception's class should match the expected class.");

assertEquals(invalid_pathThatDoesNotResolveToFile, exception.getMessage(), "The thrown exception's message should match the expected exception message.");
String expectedExceptionMessage = "An issue occurred while trying to parse file \"" + invalid_pathThatDoesNotResolveToFile + "\".";
assertEquals(expectedExceptionMessage, exception.getMessage(), "The thrown exception's message should match the expected exception message.");
assertEquals(invalid_pathThatDoesNotResolveToFile, exception.getCause().getMessage(), "The thrown exception's message should match the expected exception message.");
}
}

0 comments on commit 47079f1

Please sign in to comment.