Skip to content

Commit e4ae778

Browse files
dirk-jamieson-aemaaime
authored andcommitted
fix(gwc-core): srs equals(..) should allow one-directional aliases
1 parent 8237f30 commit e4ae778

File tree

2 files changed

+75
-5
lines changed
  • geowebcache/core/src

2 files changed

+75
-5
lines changed

geowebcache/core/src/main/java/org/geowebcache/grid/SRS.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ public boolean equals(Object obj) {
110110
if (!(obj instanceof SRS)) {
111111
return false;
112112
}
113-
boolean equivalent = false;
114113
SRS other = (SRS) obj;
115114
if (other.number == this.number) {
116-
equivalent = true;
117-
} else if (this.aliases != null && other.aliases != null) {
118-
equivalent = this.aliases.contains(other.number) || other.aliases.contains(this.number);
115+
return true;
116+
} else if (this.aliases != null && this.aliases.contains(other.number)) {
117+
return true;
118+
} else if (other.aliases != null && other.aliases.contains(this.number)) {
119+
return true;
119120
}
120-
return equivalent;
121+
return false;
121122
}
122123

123124
public int getNumber() {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)