Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions geowebcache/core/src/main/java/org/geowebcache/grid/SRS.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ public boolean equals(Object obj) {
if (!(obj instanceof SRS)) {
return false;
}
boolean equivalent = false;
SRS other = (SRS) obj;
if (other.number == this.number) {
equivalent = true;
} else if (this.aliases != null && other.aliases != null) {
equivalent = this.aliases.contains(other.number) || other.aliases.contains(this.number);
return true;
} else if (this.aliases != null && this.aliases.contains(other.number)) {
return true;
} else if (other.aliases != null && other.aliases.contains(this.number)) {
return true;
}
return equivalent;
return false;
}

public int getNumber() {
Expand Down
69 changes: 69 additions & 0 deletions geowebcache/core/src/test/java/org/geowebcache/grid/SRSTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.geowebcache.grid;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;

/** Simple Test class for testing the behavior of a {@link GridSubset} with a non-zero zoomStart parameter. */
public class SRSTest {
private SRS createSRSWithReflection(int epsgCode) {
return createSRSWithReflection(epsgCode, null);
}

private SRS createSRSWithReflection(int epsgCode, List<Integer> aliases) {
try {
Constructor<SRS> constructor = SRS.class.getDeclaredConstructor(int.class, List.class);
constructor.setAccessible(true);

return constructor.newInstance(epsgCode, aliases);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using reflection here, because it simulates what the XML deserialization process is doing - invoking the private constructor without initializing the aliases list.

} catch (NoSuchMethodException
| InstantiationException
| IllegalAccessException
| InvocationTargetException e) {
Assert.fail("Failed to invoke SRS constructor via reflection: " + e.getMessage());
return null;
}
}

/** Two SRS objects created with the same EPSG code should be equal */
@Test
public void testCompareSameSRS() {
SRS srs1 = createSRSWithReflection(3308);
SRS srs2 = createSRSWithReflection(3308);

Assert.assertEquals("Expect two identical SRS", srs1, srs2);
Assert.assertEquals("Expect two identical SRS", srs2, srs1);
}

/** Two SRS objects created with different EPSG codes should not be equal */
@Test
public void testCompareDifferentSRS() {
SRS srs1 = createSRSWithReflection(3308);
SRS srs2 = createSRSWithReflection(3857);

Assert.assertNotEquals("Expect two different SRS", srs1, srs2);
Assert.assertNotEquals("Expect two different SRS", srs2, srs1);
}

/** But two different SRS objects created with alias EPSG codes should be equal */
@Test
public void testCompareAliasSRS() {
SRS srs1 = createSRSWithReflection(3857, List.of(900913));
SRS srs2 = createSRSWithReflection(900913, List.of(3857));

Assert.assertEquals("Expect two alias SRS to be equal", srs1, srs2);
Assert.assertEquals("Expect two alias SRS to be equal", srs2, srs1);
}

/** Two different SRS objects. One has an alias of the other, but not vice versa. They should still be equal. */
@Test
public void testCompareOneDirectionalAliasSRS() {
SRS srs1 = createSRSWithReflection(900913, List.of(3857));
SRS srs2 = createSRSWithReflection(3857);

Assert.assertEquals("Expect two alias SRS to be equal", srs1, srs2);
Assert.assertEquals("Expect two alias SRS to be equal", srs2, srs1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case that is failing in the current release

}
}
Loading