2121import java .util .concurrent .TimeUnit ;
2222
2323import org .eclipse .lsp4j .Location ;
24+ import org .eclipse .lsp4j .Position ;
25+ import org .eclipse .lsp4j .Range ;
2426import org .eclipse .lsp4j .TextDocumentIdentifier ;
2527import org .eclipse .lsp4j .WorkspaceFolder ;
2628import org .junit .jupiter .api .BeforeEach ;
@@ -86,11 +88,7 @@ void testFindReferenceAtBeginningPropFile() throws Exception {
8688 Location location = locations .get (0 );
8789
8890 URI docURI = file .toUri ();
89- assertEquals (docURI .toString (), location .getUri ());
90- assertEquals (0 , location .getRange ().getStart ().getLine ());
91- assertEquals (0 , location .getRange ().getStart ().getCharacter ());
92- assertEquals (0 , location .getRange ().getEnd ().getLine ());
93- assertEquals (13 , location .getRange ().getEnd ().getCharacter ());
91+ assertEquals (new Location (docURI .toString (), new Range (new Position (0 , 0 ), new Position (0 , 13 ))), location );
9492 }
9593
9694 @ Test
@@ -105,11 +103,7 @@ void testFindReferenceAtBeginningYMLFile() throws Exception {
105103 Location location = locations .get (0 );
106104
107105 URI docURI = file .toUri ();
108- assertEquals (docURI .toString (), location .getUri ());
109- assertEquals (3 , location .getRange ().getStart ().getLine ());
110- assertEquals (2 , location .getRange ().getStart ().getCharacter ());
111- assertEquals (3 , location .getRange ().getEnd ().getLine ());
112- assertEquals (10 , location .getRange ().getEnd ().getCharacter ());
106+ assertEquals (new Location (docURI .toString (), new Range (new Position (3 , 2 ), new Position (3 , 10 ))), location );
113107 }
114108
115109 @ Test
@@ -123,35 +117,19 @@ void testFindReferenceWithinMultipleFiles() throws Exception {
123117
124118 Path file1 = resourceDir .resolve ("mixed-multiple-files/application-dev.properties" );
125119 Location location = getLocation (locations , file1 .toUri ());
126- assertNotNull (location );
127- assertEquals (1 , location .getRange ().getStart ().getLine ());
128- assertEquals (0 , location .getRange ().getStart ().getCharacter ());
129- assertEquals (1 , location .getRange ().getEnd ().getLine ());
130- assertEquals (10 , location .getRange ().getEnd ().getCharacter ());
120+ assertEquals (new Location (file1 .toUri ().toString (), new Range (new Position (1 , 0 ), new Position (1 , 10 ))), location );
131121
132122 Path file2 = resourceDir .resolve ("mixed-multiple-files/application.yml" );
133123 location = getLocation (locations , file2 .toUri ());
134- assertNotNull (location );
135- assertEquals (3 , location .getRange ().getStart ().getLine ());
136- assertEquals (2 , location .getRange ().getStart ().getCharacter ());
137- assertEquals (3 , location .getRange ().getEnd ().getLine ());
138- assertEquals (6 , location .getRange ().getEnd ().getCharacter ());
124+ assertEquals (new Location (file2 .toUri ().toString (), new Range (new Position (3 , 2 ), new Position (3 , 6 ))), location );
139125
140126 Path file3 = resourceDir .resolve ("another-prop-folder/application.properties" );
141127 location = getLocation (locations , file3 .toUri ());
142- assertNotNull (location );
143- assertEquals (1 , location .getRange ().getStart ().getLine ());
144- assertEquals (0 , location .getRange ().getStart ().getCharacter ());
145- assertEquals (1 , location .getRange ().getEnd ().getLine ());
146- assertEquals (10 , location .getRange ().getEnd ().getCharacter ());
128+ assertEquals (new Location (file3 .toUri ().toString (), new Range (new Position (1 , 0 ), new Position (1 , 10 ))), location );
147129
148130 Path file4 = resourceDir .resolve ("another-prop-folder/prod-application.properties" );
149131 location = getLocation (locations , file4 .toUri ());
150- assertNotNull (location );
151- assertEquals (1 , location .getRange ().getStart ().getLine ());
152- assertEquals (0 , location .getRange ().getStart ().getCharacter ());
153- assertEquals (1 , location .getRange ().getEnd ().getLine ());
154- assertEquals (10 , location .getRange ().getEnd ().getCharacter ());
132+ assertEquals (new Location (file4 .toUri ().toString (), new Range (new Position (1 , 0 ), new Position (1 , 10 ))), location );
155133 }
156134
157135 private Location getLocation (List <? extends Location > locations , URI docURI ) {
@@ -193,10 +171,7 @@ public class TestDependsOnClass {
193171
194172 Location location = references .get (0 );
195173 assertEquals (directory .toPath ().resolve ("src/main/java/application.properties" ).toUri ().toString (), location .getUri ());
196- assertEquals (0 , location .getRange ().getStart ().getLine ());
197- assertEquals (0 , location .getRange ().getStart ().getCharacter ());
198- assertEquals (0 , location .getRange ().getEnd ().getLine ());
199- assertEquals (7 , location .getRange ().getEnd ().getCharacter ());
174+ assertEquals (new Location (location .getUri (), new Range (new Position (0 , 0 ), new Position (0 , 7 ))), location );
200175 }
201176
202177 @ Test
@@ -228,10 +203,7 @@ public class TestDependsOnClass {
228203
229204 Location location = references .get (0 );
230205 assertEquals (directory .toPath ().resolve ("src/main/java/application.properties" ).toUri ().toString (), location .getUri ());
231- assertEquals (0 , location .getRange ().getStart ().getLine ());
232- assertEquals (0 , location .getRange ().getStart ().getCharacter ());
233- assertEquals (0 , location .getRange ().getEnd ().getLine ());
234- assertEquals (7 , location .getRange ().getEnd ().getCharacter ());
206+ assertEquals (new Location (location .getUri (), new Range (new Position (0 , 0 ), new Position (0 , 7 ))), location );
235207 }
236208
237209 @ Test
@@ -241,47 +213,35 @@ void testFindReferenceForPropertiesUsedInAnnotations() throws Exception {
241213 List <? extends Location > locations = provider .findReferencesToPropertyKey ("my.prop2" );
242214
243215 assertNotNull (locations );
244- assertEquals (5 , locations .size ());
216+ assertEquals (7 , locations .size ());
245217
246218 URI propertiesFile = directory .toPath ().resolve ("src/main/java/application.properties" ).toUri ();
247219 Location location = getLocation (locations , propertiesFile );
248- assertNotNull (location );
249- assertEquals (1 , location .getRange ().getStart ().getLine ());
250- assertEquals (0 , location .getRange ().getStart ().getCharacter ());
251- assertEquals (1 , location .getRange ().getEnd ().getLine ());
252- assertEquals (8 , location .getRange ().getEnd ().getCharacter ());
220+ assertEquals (new Location (propertiesFile .toString (), new Range (new Position (1 , 0 ), new Position (1 , 8 ))), location );
253221
254222 URI javaFile = directory .toPath ().resolve ("src/main/java/org/test/properties/PropertyUsageWithValue.java" ).toUri ();
255223 location = getLocation (locations , javaFile );
256- assertNotNull (location );
257- assertEquals (8 , location .getRange ().getStart ().getLine ());
258- assertEquals (8 , location .getRange ().getStart ().getCharacter ());
259- assertEquals (8 , location .getRange ().getEnd ().getLine ());
260- assertEquals (21 , location .getRange ().getEnd ().getCharacter ());
224+ assertEquals (new Location (javaFile .toString (), new Range (new Position (8 , 8 ), new Position (8 , 21 ))), location );
261225
262226 javaFile = directory .toPath ().resolve ("src/main/java/org/test/properties/PropertyUsageWithConditional.java" ).toUri ();
263227 location = getLocation (locations , javaFile );
264- assertNotNull (location );
265- assertEquals (6 , location .getRange ().getStart ().getLine ());
266- assertEquals (23 , location .getRange ().getStart ().getCharacter ());
267- assertEquals (6 , location .getRange ().getEnd ().getLine ());
268- assertEquals (33 , location .getRange ().getEnd ().getCharacter ());
228+ assertEquals (new Location (javaFile .toString (), new Range (new Position (6 , 23 ), new Position (6 , 33 ))), location );
269229
270230 javaFile = directory .toPath ().resolve ("src/main/java/org/test/properties/PropertyUsageWithConditionalAndArray.java" ).toUri ();
271231 location = getLocation (locations , javaFile );
272- assertNotNull (location );
273- assertEquals (6 , location .getRange ().getStart ().getLine ());
274- assertEquals (31 , location .getRange ().getStart ().getCharacter ());
275- assertEquals (6 , location .getRange ().getEnd ().getLine ());
276- assertEquals (41 , location .getRange ().getEnd ().getCharacter ());
232+ assertEquals (new Location (javaFile .toString (), new Range (new Position (6 , 31 ), new Position (6 , 41 ))), location );
277233
278234 javaFile = directory .toPath ().resolve ("src/main/java/org/test/properties/PropertyUsageWithConditionalWithArrayAndPrefix.java" ).toUri ();
279235 location = getLocation (locations , javaFile );
280- assertNotNull (location );
281- assertEquals (6 , location .getRange ().getStart ().getLine ());
282- assertEquals (46 , location .getRange ().getStart ().getCharacter ());
283- assertEquals (6 , location .getRange ().getEnd ().getLine ());
284- assertEquals (53 , location .getRange ().getEnd ().getCharacter ());
285- }
236+ assertEquals (new Location (javaFile .toString (), new Range (new Position (6 , 46 ), new Position (6 , 53 ))), location );
237+
238+ javaFile = directory .toPath ().resolve ("src/main/java/org/test/properties/PropertyUsageWithConstantInConditionalAnnotation.java" ).toUri ();
239+ location = getLocation (locations , javaFile );
240+ assertEquals (new Location (javaFile .toString (), new Range (new Position (6 , 23 ), new Position (6 , 52 ))), location );
241+
242+ javaFile = directory .toPath ().resolve ("src/main/java/org/test/properties/PropertyUsageWithConstantInValueAnnotation.java" ).toUri ();
243+ location = getLocation (locations , javaFile );
244+ assertEquals (new Location (javaFile .toString (), new Range (new Position (8 , 8 ), new Position (8 , 41 ))), location );
245+ }
286246
287247}
0 commit comments