|
| 1 | +package org.geowebcache.grid; |
| 2 | + |
| 3 | +import java.lang.reflect.Constructor; |
| 4 | +import java.lang.reflect.InvocationTargetException; |
| 5 | +import java.util.List; |
| 6 | +import org.junit.Assert; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +/** Simple Test class for testing the behavior of a {@link GridSubset} with a non-zero zoomStart parameter. */ |
| 10 | +public class SRSTest { |
| 11 | + private SRS createSRSWithReflection(int epsgCode) { |
| 12 | + return createSRSWithReflection(epsgCode, null); |
| 13 | + } |
| 14 | + |
| 15 | + private SRS createSRSWithReflection(int epsgCode, List<Integer> aliases) { |
| 16 | + try { |
| 17 | + Constructor<SRS> constructor = SRS.class.getDeclaredConstructor(int.class, List.class); |
| 18 | + constructor.setAccessible(true); |
| 19 | + |
| 20 | + return constructor.newInstance(epsgCode, aliases); |
| 21 | + } catch (NoSuchMethodException |
| 22 | + | InstantiationException |
| 23 | + | IllegalAccessException |
| 24 | + | InvocationTargetException e) { |
| 25 | + Assert.fail("Failed to invoke SRS constructor via reflection: " + e.getMessage()); |
| 26 | + return null; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + /** Two SRS objects created with the same EPSG code should be equal */ |
| 31 | + @Test |
| 32 | + public void testCompareSameSRS() { |
| 33 | + SRS srs1 = createSRSWithReflection(3308); |
| 34 | + SRS srs2 = createSRSWithReflection(3308); |
| 35 | + |
| 36 | + Assert.assertEquals("Expect two identical SRS", srs1, srs2); |
| 37 | + Assert.assertEquals("Expect two identical SRS", srs2, srs1); |
| 38 | + } |
| 39 | + |
| 40 | + /** Two SRS objects created with different EPSG codes should not be equal */ |
| 41 | + @Test |
| 42 | + public void testCompareDifferentSRS() { |
| 43 | + SRS srs1 = createSRSWithReflection(3308); |
| 44 | + SRS srs2 = createSRSWithReflection(3857); |
| 45 | + |
| 46 | + Assert.assertNotEquals("Expect two different SRS", srs1, srs2); |
| 47 | + Assert.assertNotEquals("Expect two different SRS", srs2, srs1); |
| 48 | + } |
| 49 | + |
| 50 | + /** But two different SRS objects created with alias EPSG codes should be equal */ |
| 51 | + @Test |
| 52 | + public void testCompareAliasSRS() { |
| 53 | + SRS srs1 = createSRSWithReflection(3857, List.of(900913)); |
| 54 | + SRS srs2 = createSRSWithReflection(900913, List.of(3857)); |
| 55 | + |
| 56 | + Assert.assertEquals("Expect two alias SRS to be equal", srs1, srs2); |
| 57 | + Assert.assertEquals("Expect two alias SRS to be equal", srs2, srs1); |
| 58 | + } |
| 59 | + |
| 60 | + /** Two different SRS objects. One has an alias of the other, but not vice versa. They should still be equal. */ |
| 61 | + @Test |
| 62 | + public void testCompareOneDirectionalAliasSRS() { |
| 63 | + SRS srs1 = createSRSWithReflection(900913, List.of(3857)); |
| 64 | + SRS srs2 = createSRSWithReflection(3857); |
| 65 | + |
| 66 | + Assert.assertEquals("Expect two alias SRS to be equal", srs1, srs2); |
| 67 | + Assert.assertEquals("Expect two alias SRS to be equal", srs2, srs1); |
| 68 | + } |
| 69 | +} |
0 commit comments