From 47079f14d3ec6502fe42830b5d4d439214c866e0 Mon Sep 17 00:00:00 2001 From: lucasstarsz Date: Sat, 5 Jun 2021 23:15:54 -0400 Subject: [PATCH] (#10) simplify error to avoid loading FastJEngine class --- src/main/java/tech/fastj/graphics/util/PsdfUtil.java | 6 +++--- .../unittest/testcases/graphics/util/PsdfUtilTests.java | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/tech/fastj/graphics/util/PsdfUtil.java b/src/main/java/tech/fastj/graphics/util/PsdfUtil.java index 7303ceb6..66342d98 100644 --- a/src/main/java/tech/fastj/graphics/util/PsdfUtil.java +++ b/src/main/java/tech/fastj/graphics/util/PsdfUtil.java @@ -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; @@ -59,7 +60,7 @@ public static Polygon2D[] loadPsdf(String fileLocation) { private static Polygon2D[] parsePsdf(String fileLocation) { try { Polygon2D[] result = null; - List lines = Files.readAllLines(Paths.get(fileLocation)); + List lines = Files.readAllLines(Path.of(fileLocation)); List polygonPoints = new ArrayList<>(); Paint paint = null; boolean fillPolygon = false; @@ -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); } } diff --git a/src/test/java/unittest/testcases/graphics/util/PsdfUtilTests.java b/src/test/java/unittest/testcases/graphics/util/PsdfUtilTests.java index f0457b9a..b59b62f8 100644 --- a/src/test/java/unittest/testcases/graphics/util/PsdfUtilTests.java +++ b/src/test/java/unittest/testcases/graphics/util/PsdfUtilTests.java @@ -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."); } }