From 8c09e9241e9a827d3d4774256c13fb0a763fb1d9 Mon Sep 17 00:00:00 2001 From: Karel Maesen Date: Sat, 28 Jan 2023 16:29:28 +0100 Subject: [PATCH] Code cleanup --- .../geom/PackedPointSequenceTest.java | 75 +++++++++---------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/geom/src/test/java/org/geolatte/geom/PackedPointSequenceTest.java b/geom/src/test/java/org/geolatte/geom/PackedPointSequenceTest.java index a1e5ab5..1854f78 100644 --- a/geom/src/test/java/org/geolatte/geom/PackedPointSequenceTest.java +++ b/geom/src/test/java/org/geolatte/geom/PackedPointSequenceTest.java @@ -21,13 +21,11 @@ package org.geolatte.geom; -import org.locationtech.jts.geom.Coordinate; -import org.locationtech.jts.geom.CoordinateSequence; import org.junit.Assert; import org.junit.Before; import org.junit.Test; - -import java.util.Arrays; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.CoordinateSequence; import static junit.framework.Assert.assertEquals; import static org.junit.Assert.*; @@ -37,11 +35,11 @@ */ public class PackedPointSequenceTest { - private static PositionFactory des2D = Positions.getFactoryFor(C2D.class); + private final static PositionFactory des2D = Positions.getFactoryFor(C2D.class); - private static PositionFactory des3D = Positions.getFactoryFor(C3D.class); - private static PositionFactory des2DM = Positions.getFactoryFor(C2DM.class); - private static PositionFactory des3DM = Positions.getFactoryFor(C3DM.class); + private final static PositionFactory des3D = Positions.getFactoryFor(C3D.class); + private final static PositionFactory des2DM = Positions.getFactoryFor(C2DM.class); + private final static PositionFactory des3DM = Positions.getFactoryFor(C3DM.class); PackedPositionSequence testSeq2D; PackedPositionSequence testSeq3D; @@ -52,30 +50,30 @@ public class PackedPointSequenceTest { @Before public void setUp() { - testSeq2D = new PackedPositionSequence(des2D, new double[]{0, 0, 1, -1, 2, -2}); - testSeq3D = new PackedPositionSequence(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}); - testSeq2DM = new PackedPositionSequence(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}); - testSeq3DM = new PackedPositionSequence(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3}); - testEmpty = new PackedPositionSequence(des2D, new double[0]); + testSeq2D = new PackedPositionSequence<>(des2D, new double[]{0, 0, 1, -1, 2, -2}); + testSeq3D = new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}); + testSeq2DM = new PackedPositionSequence<>(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2}); + testSeq3DM = new PackedPositionSequence<>(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3}); + testEmpty = new PackedPositionSequence<>(des2D, new double[0]); } @Test public void testConstructorThrowsIllegalArgumentOnWrongNumberOfCoordinates() { try { - new PackedPositionSequence(des2D, new double[]{0, 0, 1, 1, 3}); + new PackedPositionSequence<>(des2D, new double[]{0, 0, 1, 1, 3}); fail(); } catch (IllegalArgumentException e) { } try { - new PackedPositionSequence(des3D, new double[]{0, 0, 0, 1, 1, 1, 1}); + new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, 1, 1, 1}); fail(); } catch (IllegalArgumentException e) { } try { - new PackedPositionSequence(des3D, new double[]{0, 0, 0, 1, 1, 1, 1, 1}); + new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, 1, 1, 1, 1}); fail(); } catch (IllegalArgumentException e) { } @@ -83,7 +81,7 @@ public void testConstructorThrowsIllegalArgumentOnWrongNumberOfCoordinates() { @Test - public void testGetDimension() throws Exception { + public void testGetDimension() { assertEquals(2, testSeq2D.getCoordinateDimension()); assertEquals(3, testSeq3D.getCoordinateDimension()); assertEquals(3, testSeq2DM.getCoordinateDimension()); @@ -91,7 +89,7 @@ public void testGetDimension() throws Exception { } @Test - public void testGetCoordinate() throws Exception { + public void testGetCoordinate() { // test2D assertEquals(new Coordinate(0, 0), testSeq2D.getCoordinate(0)); assertEquals(new Coordinate(1, -1), testSeq2D.getCoordinate(1)); @@ -141,35 +139,35 @@ public void testGetCoordinates() throws Exception { double[] result; result = new double[2]; testSeq2D.getCoordinates(0, result); - assertTrue(Arrays.equals(new double[]{0, 0}, result)); + assertArrayEquals(new double[]{0, 0}, result, 0.0); testSeq2D.getCoordinates(1, result); - assertTrue(Arrays.equals(new double[]{1, -1}, result)); + assertArrayEquals(new double[]{1, -1}, result, 0.0); testSeq2D.getCoordinates(2, result); - assertTrue(Arrays.equals(new double[]{2, -2}, result)); + assertArrayEquals(new double[]{2, -2}, result, 0.0); result = new double[3]; testSeq3D.getCoordinates(0, result); - assertTrue(Arrays.equals(new double[]{0, 0, 0}, result)); + assertArrayEquals(new double[]{0, 0, 0}, result, 0.0); testSeq3D.getCoordinates(1, result); - assertTrue(Arrays.equals(new double[]{1, -1, 1}, result)); + assertArrayEquals(new double[]{1, -1, 1}, result, 0.0); testSeq3D.getCoordinates(2, result); - assertTrue(Arrays.equals(new double[]{2, -2, 2}, result)); + assertArrayEquals(new double[]{2, -2, 2}, result, 0.0); testSeq2DM.getCoordinates(0, result); - assertTrue(Arrays.equals(new double[]{0, 0, 0}, result)); + assertArrayEquals(new double[]{0, 0, 0}, result, 0.0); testSeq2DM.getCoordinates(1, result); - assertTrue(Arrays.equals(new double[]{1, -1, 1}, result)); + assertArrayEquals(new double[]{1, -1, 1}, result, 0.0); testSeq2DM.getCoordinates(2, result); - assertTrue(Arrays.equals(new double[]{2, -2, 2}, result)); + assertArrayEquals(new double[]{2, -2, 2}, result, 0.0); result = new double[4]; testSeq3DM.getCoordinates(0, result); - assertTrue(Arrays.equals(new double[]{0, 0, 0, 1}, result)); + assertArrayEquals(new double[]{0, 0, 0, 1}, result, 0.0); testSeq3DM.getCoordinates(1, result); - assertTrue(Arrays.equals(new double[]{1, -1, 1, 2}, result)); + assertArrayEquals(new double[]{1, -1, 1, 2}, result, 0.0); testSeq3DM.getCoordinates(2, result); - assertTrue(Arrays.equals(new double[]{2, -2, 2, 3}, result)); + assertArrayEquals(new double[]{2, -2, 2, 3}, result, 0.0); try { testSeq2D.getCoordinates(3, result); @@ -369,12 +367,11 @@ public void testGetOrdinate() { @Test public void testEquals() { - assertEquals(testSeq2D, new PackedPositionSequence(des2D, new double[]{0, 0, 1, -1, 2, -2})); - assertEquals(testSeq3D, new PackedPositionSequence(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2})); - assertEquals(testSeq2DM, new PackedPositionSequence(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2})); - assertEquals(testSeq3DM, new PackedPositionSequence(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3})); - assertFalse(testSeq2DM.equals(testSeq3D)); - assertFalse(testSeq2D.equals(new PackedPositionSequence(des2D, new double[]{0, 1, 1, -1, 2, -2}))); + assertEquals(testSeq2D, new PackedPositionSequence<>(des2D, new double[]{0, 0, 1, -1, 2, -2})); + assertEquals(testSeq3D, new PackedPositionSequence<>(des3D, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2})); + assertEquals(testSeq2DM, new PackedPositionSequence<>(des2DM, new double[]{0, 0, 0, 1, -1, 1, 2, -2, 2})); + assertEquals(testSeq3DM, new PackedPositionSequence<>(des3DM, new double[]{0, 0, 0, 1, 1, -1, 1, 2, 2, -2, 2, 3})); + assertNotEquals(testSeq2D, new PackedPositionSequence<>(des2D, new double[]{0, 1, 1, -1, 2, -2})); } @@ -389,9 +386,9 @@ public void testClone() { @Test public void testCloneReturnsIndependentCopy() { - PositionSequence clone = testSeq2D.clone(); - ((CoordinateSequence)testSeq2D).setOrdinate(0, 0, 3); - Assert.assertFalse(testSeq2D.equals(clone)); + PositionSequence clone = testSeq2D.clone(); + ((CoordinateSequence) testSeq2D).setOrdinate(0, 0, 3); + assertNotEquals(testSeq2D, clone); }