Skip to content

Commit b904fea

Browse files
committed
[HK] additional test cases for Catalog.check with Envelope
Change-Id: I1d7e4a3df7d6186875f29af21fbb23c4f17d01e3 Signed-off-by: Frank Gasdorf <[email protected]>
1 parent eb2749b commit b904fea

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

plugins/org.locationtech.udig.catalog.tests2/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
88
org.junit;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
99
org.mockito;bundle-version="2.23.0",
1010
net.bytebuddy.byte-buddy;bundle-version="1.9.0",
11-
net.bytebuddy.byte-buddy-agent;bundle-version="1.9.0"
11+
net.bytebuddy.byte-buddy-agent;bundle-version="1.9.0",
12+
org.objenesis;bundle-version="2.6.0"
1213
Bundle-ActivationPolicy: lazy
1314
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1415
Fragment-Host: org.locationtech.udig.catalog;bundle-version="2.3.0"

plugins/org.locationtech.udig.catalog.tests2/src/org/locationtech/udig/catalog/internal/CatalogImplTest.java

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import java.util.Arrays;
2020
import java.util.HashSet;
2121

22+
import org.geotools.geometry.jts.ReferencedEnvelope;
23+
import org.geotools.referencing.crs.DefaultGeographicCRS;
2224
import org.junit.Test;
2325
import org.junit.runner.RunWith;
26+
import org.locationtech.jts.geom.Envelope;
2427
import org.locationtech.udig.catalog.IGeoResource;
2528
import org.locationtech.udig.catalog.IGeoResourceInfo;
2629
import org.locationtech.udig.catalog.IService;
@@ -39,6 +42,8 @@ public class CatalogImplTest {
3942

4043
private static final String NOT_MATCHING_TEXT = "whatever";
4144

45+
private static final Envelope ENVELOPE = new Envelope(15, 17, -5, 5);
46+
4247
private static final String MATCHING_TEXT = "test";
4348

4449
private final AST testAST = ASTFactory.parse(MATCHING_TEXT);
@@ -75,14 +80,59 @@ public void checkIsTrueIfResourceInfoTitleMatch() throws Exception {
7580
}
7681

7782
@Test
78-
public void checkIsTrueIfResourceInfoNameMatch() throws Exception {
83+
public void checkWithEnvelopeIsTrueIfResourceInfoNameMatch() throws Exception {
7984
when(geoResourceInfo.getTitle()).thenReturn(NOT_MATCHING_TEXT);
8085
when(geoResourceInfo.getName()).thenReturn(MATCHING_TEXT);
8186
when(geoResource.getInfo(any())).thenReturn(geoResourceInfo);
8287

8388
assertTrue(CatalogImpl.check(geoResource, testAST));
8489
}
8590

91+
@Test
92+
public void checkWithEnvelopeIsTrueIfResourceInfoNameMatchAndEnvelopeIsNull() throws Exception {
93+
when(geoResourceInfo.getTitle()).thenReturn(NOT_MATCHING_TEXT);
94+
when(geoResourceInfo.getName()).thenReturn(MATCHING_TEXT);
95+
when(geoResource.getInfo(any())).thenReturn(geoResourceInfo);
96+
97+
assertTrue(CatalogImpl.check(geoResource, testAST, null));
98+
}
99+
100+
@Test
101+
public void checkWithEnvelopeIsTrueIfResourceInfoNameMatchAndInfoBoundsisNull()
102+
throws Exception {
103+
when(geoResourceInfo.getTitle()).thenReturn(MATCHING_TEXT);
104+
when(geoResourceInfo.getBounds()).thenReturn(null);
105+
when(geoResource.getInfo(any())).thenReturn(geoResourceInfo);
106+
107+
assertTrue(CatalogImpl.check(geoResource, testAST, ENVELOPE));
108+
}
109+
110+
@Test
111+
public void checkWithEnvelopeIsTrueIfResourceInfoNameMatchAndInfoWithBounds() throws Exception {
112+
when(geoResourceInfo.getTitle()).thenReturn(MATCHING_TEXT);
113+
when(geoResourceInfo.getBounds())
114+
.thenReturn(new ReferencedEnvelope(10, 20, -10, 10, DefaultGeographicCRS.WGS84));
115+
when(geoResource.getInfo(any())).thenReturn(geoResourceInfo);
116+
117+
assertTrue(CatalogImpl.check(geoResource, testAST, ENVELOPE));
118+
}
119+
120+
@Test
121+
public void checkWithEnvelopeIsFalseWithGeoResource() {
122+
IGeoResource nullGeoResource = null;
123+
assertFalse(CatalogImpl.check(nullGeoResource, testAST, null));
124+
}
125+
126+
@Test
127+
public void checkIsTrueIfResourceInfoNameMatchAndEnvelopeIsNullCheck() throws Exception {
128+
Envelope envelope = new Envelope();
129+
when(geoResourceInfo.getTitle()).thenReturn(NOT_MATCHING_TEXT);
130+
when(geoResourceInfo.getName()).thenReturn(MATCHING_TEXT);
131+
when(geoResource.getInfo(any())).thenReturn(geoResourceInfo);
132+
133+
assertTrue(CatalogImpl.check(geoResource, testAST, envelope));
134+
}
135+
86136
@Test
87137
public void checkIsTrueIfResourceInfoAtLeastOneKeywordMatch() throws Exception {
88138
when(geoResourceInfo.getTitle()).thenReturn(NOT_MATCHING_TEXT);
@@ -185,8 +235,7 @@ public void checkIsTrueIfServiceInfoAbstractMatch() throws Exception {
185235
@Test
186236
public void checkIsTrueIfServiceInfoDescriptionMatch() throws Exception {
187237
when(serviceInfo.getTitle()).thenReturn(NOT_MATCHING_TEXT);
188-
when(serviceInfo.getDescription())
189-
.thenReturn(MATCHING_TEXT);
238+
when(serviceInfo.getDescription()).thenReturn(MATCHING_TEXT);
190239
when(serviceMock.getInfo(null)).thenReturn(serviceInfo);
191240

192241
assertTrue(CatalogImpl.check(serviceMock, testAST));
@@ -195,8 +244,7 @@ public void checkIsTrueIfServiceInfoDescriptionMatch() throws Exception {
195244
@Test
196245
public void checkIsFalseIfServiceNotMatchAnything() throws Exception {
197246
when(serviceInfo.getTitle()).thenReturn(NOT_MATCHING_TEXT);
198-
when(serviceInfo.getDescription())
199-
.thenReturn(NOT_MATCHING_TEXT);
247+
when(serviceInfo.getDescription()).thenReturn(NOT_MATCHING_TEXT);
200248
when(serviceMock.getInfo(null)).thenReturn(serviceInfo);
201249

202250
assertFalse(CatalogImpl.check(serviceMock, testAST));

0 commit comments

Comments
 (0)