This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-geometry.git
commit b043ea15bae5431ab26ceb209a97c2044be9526f Author: Alex Herbert <aherb...@apache.org> AuthorDate: Fri Apr 25 15:18:32 2025 +0100 Use method reference --- .../threed/obj/ObjTriangleMeshReaderTest.java | 2 +- .../euclidean/threed/obj/PolygonObjParserTest.java | 100 +++++++++------------ .../stl/BinaryStlFacetDefinitionReaderTest.java | 8 +- .../io/euclidean/threed/stl/TextStlWriterTest.java | 4 +- .../threed/txt/TextFacetDefinitionReaderTest.java | 35 +++----- 5 files changed, 61 insertions(+), 88 deletions(-) diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java index a5c48d44..efa25c59 100644 --- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java +++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjTriangleMeshReaderTest.java @@ -143,7 +143,7 @@ class ObjTriangleMeshReaderTest { // act/assert GeometryTestUtils.assertThrowsWithMessage( - () -> reader.readTriangleMesh(), + reader::readTriangleMesh, IllegalStateException.class, Pattern.compile("^Parsing failed.*")); } diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java index 4170b0e5..f5ec99d8 100644 --- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java +++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/obj/PolygonObjParserTest.java @@ -119,9 +119,8 @@ class PolygonObjParserTest { p.setFailOnNonPolygonKeywords(true); // act/assert - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.nextKeyword(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(p::nextKeyword, + IllegalStateException.class, "Parsing failed at line 2, column 1: expected keyword to be one of " + "[f, g, mtllib, o, s, usemtl, v, vn, vt] but was [curv2]"); } @@ -144,14 +143,12 @@ class PolygonObjParserTest { )); // act/assert - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.nextKeyword(); - }, IllegalStateException.class, "Parsing failed at line 1, column 2: " + + GeometryTestUtils.assertThrowsWithMessage(p::nextKeyword, + IllegalStateException.class, "Parsing failed at line 1, column 2: " + "non-blank lines must begin with an OBJ keyword or comment character"); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.nextKeyword(); - }, IllegalStateException.class, "Parsing failed at line 2, column 1: " + + GeometryTestUtils.assertThrowsWithMessage(p::nextKeyword, + IllegalStateException.class, "Parsing failed at line 2, column 1: " + "expected OBJ keyword but found empty token followed by [-]"); } @@ -227,15 +224,13 @@ class PolygonObjParserTest { )); // act/assert - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readVector(); - }, IllegalStateException.class, "Parsing failed at line 1, column 9: expected double but found [a]"); + GeometryTestUtils.assertThrowsWithMessage(p::readVector, + IllegalStateException.class, "Parsing failed at line 1, column 9: expected double but found [a]"); p.readDataLine(); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readVector(); - }, IllegalStateException.class, "Parsing failed at line 2, column 2: expected double but found end of line"); + GeometryTestUtils.assertThrowsWithMessage(p::readVector, + IllegalStateException.class, "Parsing failed at line 2, column 2: expected double but found end of line"); } @Test @@ -276,15 +271,13 @@ class PolygonObjParserTest { )); // act/assert - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readDoubles(); - }, IllegalStateException.class, "Parsing failed at line 1, column 9: expected double but found [a]"); + GeometryTestUtils.assertThrowsWithMessage(p::readDoubles, + IllegalStateException.class, "Parsing failed at line 1, column 9: expected double but found [a]"); p.readDataLine(); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readDoubles(); - }, IllegalStateException.class, "Parsing failed at line 2, column 1: expected double but found [b]"); + GeometryTestUtils.assertThrowsWithMessage(p::readDoubles, + IllegalStateException.class, "Parsing failed at line 2, column 1: expected double but found [b]"); } @Test @@ -405,9 +398,8 @@ class PolygonObjParserTest { // act/assert nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 5, column 6: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 5, column 6: " + "face must contain at least 3 vertices but found only 2"); } @@ -427,27 +419,23 @@ class PolygonObjParserTest { // act/assert nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 2, column 3: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 2, column 3: " + "vertex index cannot be used because no values of that type have been defined"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 6, column 7: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 6, column 7: " + "vertex index must evaluate to be within the range [1, 3] but was -4"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 7, column 5: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 7, column 5: " + "vertex index must evaluate to be within the range [1, 3] but was 0"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 8, column 3: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 8, column 3: " + "vertex index must evaluate to be within the range [1, 3] but was 4"); } @@ -470,27 +458,23 @@ class PolygonObjParserTest { // act/assert nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 5, column 5: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 5, column 5: " + "texture index cannot be used because no values of that type have been defined"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 9, column 13: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 9, column 13: " + "texture index must evaluate to be within the range [1, 3] but was -4"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 10, column 9: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 10, column 9: " + "texture index must evaluate to be within the range [1, 3] but was 0"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 11, column 5: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 11, column 5: " + "texture index must evaluate to be within the range [1, 3] but was 4"); } @@ -513,27 +497,23 @@ class PolygonObjParserTest { // act/assert nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 5, column 6: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 5, column 6: " + "normal index cannot be used because no values of that type have been defined"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 9, column 16: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 9, column 16: " + "normal index must evaluate to be within the range [1, 3] but was -4"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 10, column 11: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 10, column 11: " + "normal index must evaluate to be within the range [1, 3] but was 0"); nextFace(p); - GeometryTestUtils.assertThrowsWithMessage(() -> { - p.readFace(); - }, IllegalStateException.class, "Parsing failed at line 11, column 6: " + + GeometryTestUtils.assertThrowsWithMessage(p::readFace, + IllegalStateException.class, "Parsing failed at line 11, column 6: " + "normal index must evaluate to be within the range [1, 3] but was 4"); } diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/BinaryStlFacetDefinitionReaderTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/BinaryStlFacetDefinitionReaderTest.java index 3e58e39d..1e0f7667 100644 --- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/BinaryStlFacetDefinitionReaderTest.java +++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/BinaryStlFacetDefinitionReaderTest.java @@ -121,7 +121,7 @@ class BinaryStlFacetDefinitionReaderTest { try (BinaryStlFacetDefinitionReader reader = new BinaryStlFacetDefinitionReader(getInput())) { // act/assert GeometryTestUtils.assertThrowsWithMessage( - () -> reader.getHeader(), + reader::getHeader, IllegalStateException.class, "Failed to read STL header: data not available"); } } @@ -134,7 +134,7 @@ class BinaryStlFacetDefinitionReaderTest { try (BinaryStlFacetDefinitionReader reader = new BinaryStlFacetDefinitionReader(getInput())) { // act/assert GeometryTestUtils.assertThrowsWithMessage( - () -> reader.getHeader(), + reader::getHeader, IllegalStateException.class, "Failed to read STL triangle count: data not available"); } } @@ -152,7 +152,7 @@ class BinaryStlFacetDefinitionReaderTest { try (BinaryStlFacetDefinitionReader reader = new BinaryStlFacetDefinitionReader(failIn)) { // act/assert GeometryTestUtils.assertThrowsWithMessage( - () -> reader.getHeader(), + reader::getHeader, UncheckedIOException.class, "IOException: read"); } } @@ -166,7 +166,7 @@ class BinaryStlFacetDefinitionReaderTest { try (BinaryStlFacetDefinitionReader reader = new BinaryStlFacetDefinitionReader(getInput())) { // act/assert GeometryTestUtils.assertThrowsWithMessage( - () -> reader.readFacet(), + reader::readFacet, IllegalStateException.class, "Failed to read STL triangle at index 0: data not available"); } } diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/TextStlWriterTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/TextStlWriterTest.java index 8714d090..c206e138 100644 --- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/TextStlWriterTest.java +++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/stl/TextStlWriterTest.java @@ -76,7 +76,7 @@ class TextStlWriterTest { // act/assert GeometryTestUtils.assertThrowsWithMessage( - () -> writer.startSolid(), + writer::startSolid, IllegalStateException.class, "Cannot start solid definition: a solid is already being written"); } } @@ -87,7 +87,7 @@ class TextStlWriterTest { try (TextStlWriter writer = new TextStlWriter(out)) { // act/assert GeometryTestUtils.assertThrowsWithMessage( - () -> writer.endSolid(), + writer::endSolid, IllegalStateException.class, "Cannot end solid definition: no solid has been started"); } } diff --git a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionReaderTest.java b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionReaderTest.java index 09dcd765..40ebe5aa 100644 --- a/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionReaderTest.java +++ b/commons-geometry-io-euclidean/src/test/java/org/apache/commons/geometry/io/euclidean/threed/txt/TextFacetDefinitionReaderTest.java @@ -243,9 +243,8 @@ class TextFacetDefinitionReaderTest { reader.setCommentToken(""); // act - GeometryTestUtils.assertThrowsWithMessage(() -> { - reader.readFacet(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(reader::readFacet, + IllegalStateException.class, "Parsing failed at line 1, column 1: expected double but found empty token followed by [#]"); } @@ -256,9 +255,8 @@ class TextFacetDefinitionReaderTest { reader.setCommentToken(null); // act/assert - GeometryTestUtils.assertThrowsWithMessage(() -> { - reader.readFacet(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(reader::readFacet, + IllegalStateException.class, "Parsing failed at line 1, column 1: expected double but found empty token followed by [#]"); } @@ -268,9 +266,8 @@ class TextFacetDefinitionReaderTest { TextFacetDefinitionReader reader = facetReader("1 abc 3 ; 4 5 6 ; 7 8 9"); // act/assert - GeometryTestUtils.assertThrowsWithMessage(() -> { - reader.readFacet(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(reader::readFacet, + IllegalStateException.class, "Parsing failed at line 1, column 3: expected double but found [abc]"); } @@ -284,24 +281,20 @@ class TextFacetDefinitionReaderTest { "1 2 3 ; 4 5 6;\n"); // act/assert - GeometryTestUtils.assertThrowsWithMessage(() -> { - reader.readFacet(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(reader::readFacet, + IllegalStateException.class, "Parsing failed at line 1, column 2: expected double but found end of line"); - GeometryTestUtils.assertThrowsWithMessage(() -> { - reader.readFacet(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(reader::readFacet, + IllegalStateException.class, "Parsing failed at line 2, column 4: expected double but found end of line"); - GeometryTestUtils.assertThrowsWithMessage(() -> { - reader.readFacet(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(reader::readFacet, + IllegalStateException.class, "Parsing failed at line 3, column 6: expected double but found end of line"); - GeometryTestUtils.assertThrowsWithMessage(() -> { - reader.readFacet(); - }, IllegalStateException.class, + GeometryTestUtils.assertThrowsWithMessage(reader::readFacet, + IllegalStateException.class, "Parsing failed at line 4, column 15: expected double but found end of line"); }