OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014, the Dart project authors. |
| 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. |
| 13 */ |
| 14 package com.google.dart.engine.internal.index.file; |
| 15 |
| 16 import com.google.common.base.Objects; |
| 17 import com.google.common.collect.Lists; |
| 18 import com.google.dart.engine.EngineTestCase; |
| 19 import com.google.dart.engine.context.AnalysisContext; |
| 20 import com.google.dart.engine.element.CompilationUnitElement; |
| 21 import com.google.dart.engine.element.Element; |
| 22 import com.google.dart.engine.element.ElementKind; |
| 23 import com.google.dart.engine.element.ElementLocation; |
| 24 import com.google.dart.engine.element.HtmlElement; |
| 25 import com.google.dart.engine.element.LibraryElement; |
| 26 import com.google.dart.engine.index.Location; |
| 27 import com.google.dart.engine.index.Relationship; |
| 28 import com.google.dart.engine.index.UniverseElement; |
| 29 import com.google.dart.engine.internal.context.InstrumentedAnalysisContextImpl; |
| 30 import com.google.dart.engine.internal.element.ElementLocationImpl; |
| 31 import com.google.dart.engine.source.Source; |
| 32 import com.google.dart.engine.source.SourceContainer; |
| 33 |
| 34 import static org.fest.assertions.Assertions.assertThat; |
| 35 import static org.mockito.Mockito.mock; |
| 36 import static org.mockito.Mockito.when; |
| 37 |
| 38 import java.util.List; |
| 39 |
| 40 public class SplitIndexStoreImplTest extends EngineTestCase { |
| 41 /** |
| 42 * {@link Location} has no "equals" and "hasCode", so to compare locations by
value we need to |
| 43 * wrap them into such object. |
| 44 */ |
| 45 private static class LocationEqualsWrapper { |
| 46 private final Location location; |
| 47 |
| 48 LocationEqualsWrapper(Location location) { |
| 49 this.location = location; |
| 50 } |
| 51 |
| 52 @Override |
| 53 public boolean equals(Object obj) { |
| 54 if (!(obj instanceof LocationEqualsWrapper)) { |
| 55 return false; |
| 56 } |
| 57 LocationEqualsWrapper other = (LocationEqualsWrapper) obj; |
| 58 return other.location.getOffset() == location.getOffset() |
| 59 && other.location.getLength() == location.getLength() |
| 60 && Objects.equal(other.location.getElement(), location.getElement()); |
| 61 } |
| 62 |
| 63 @Override |
| 64 public int hashCode() { |
| 65 return Objects.hashCode(location.getElement(), location.getOffset(), locat
ion.getLength()); |
| 66 } |
| 67 } |
| 68 |
| 69 /** |
| 70 * Asserts that the "actual" locations have all the "expected" locations and o
nly them. |
| 71 */ |
| 72 private static void assertLocations(Location[] actual, Location... expected) { |
| 73 LocationEqualsWrapper[] actualWrappers = wrapLocations(actual); |
| 74 LocationEqualsWrapper[] expectedWrappers = wrapLocations(expected); |
| 75 assertThat(actualWrappers).containsOnly((Object[]) expectedWrappers); |
| 76 } |
| 77 |
| 78 /** |
| 79 * @return the new {@link Location} mock. |
| 80 */ |
| 81 private static Location mockLocation(Element element) { |
| 82 Location location = mock(Location.class); |
| 83 when(location.newClone()).thenReturn(location); |
| 84 when(location.getElement()).thenReturn(element); |
| 85 return location; |
| 86 } |
| 87 |
| 88 /** |
| 89 * Wraps the given locations into {@link LocationEqualsWrapper}. |
| 90 */ |
| 91 private static LocationEqualsWrapper[] wrapLocations(Location[] locations) { |
| 92 List<LocationEqualsWrapper> wrappers = Lists.newArrayList(); |
| 93 for (Location location : locations) { |
| 94 wrappers.add(new LocationEqualsWrapper(location)); |
| 95 } |
| 96 return wrappers.toArray(new LocationEqualsWrapper[wrappers.size()]); |
| 97 } |
| 98 |
| 99 private MemoryNodeManager nodeManager = new MemoryNodeManager(); |
| 100 private SplitIndexStoreImpl store = new SplitIndexStoreImpl(nodeManager); |
| 101 |
| 102 private AnalysisContext contextA = mock(AnalysisContext.class); |
| 103 private AnalysisContext contextB = mock(AnalysisContext.class); |
| 104 private AnalysisContext contextC = mock(AnalysisContext.class); |
| 105 private ElementLocation elementLocationA = new ElementLocationImpl(new String[
] { |
| 106 "/home/user/sourceA.dart", "ClassA"}); |
| 107 private ElementLocation elementLocationB = new ElementLocationImpl(new String[
] { |
| 108 "/home/user/sourceB.dart", "ClassB"}); |
| 109 private ElementLocation elementLocationC = new ElementLocationImpl(new String[
] { |
| 110 "/home/user/sourceC.dart", "ClassC"}); |
| 111 private ElementLocation elementLocationD = new ElementLocationImpl(new String[
] { |
| 112 "/home/user/sourceD.dart", "ClassD"}); |
| 113 private Element elementA = mock(Element.class); |
| 114 private Element elementB = mock(Element.class); |
| 115 private Element elementC = mock(Element.class); |
| 116 private Element elementD = mock(Element.class); |
| 117 private Source librarySource = mock(Source.class); |
| 118 private Source sourceA = mock(Source.class); |
| 119 private Source sourceB = mock(Source.class); |
| 120 private Source sourceC = mock(Source.class); |
| 121 private Source sourceD = mock(Source.class); |
| 122 private LibraryElement libraryElement = mock(LibraryElement.class); |
| 123 private CompilationUnitElement libraryUnitElement = mock(CompilationUnitElemen
t.class); |
| 124 private CompilationUnitElement unitElementA = mock(CompilationUnitElement.clas
s); |
| 125 private CompilationUnitElement unitElementB = mock(CompilationUnitElement.clas
s); |
| 126 private CompilationUnitElement unitElementC = mock(CompilationUnitElement.clas
s); |
| 127 private CompilationUnitElement unitElementD = mock(CompilationUnitElement.clas
s); |
| 128 private HtmlElement htmlElementA = mock(HtmlElement.class); |
| 129 private HtmlElement htmlElementB = mock(HtmlElement.class); |
| 130 private Relationship relationship = Relationship.getRelationship("test-relatio
nship"); |
| 131 |
| 132 public void test_aboutToIndexDart_disposedContext() throws Exception { |
| 133 when(contextA.isDisposed()).thenReturn(true); |
| 134 assertEquals(false, store.aboutToIndexDart(contextA, unitElementA)); |
| 135 } |
| 136 |
| 137 public void test_aboutToIndexDart_disposedContext_wrapped() throws Exception { |
| 138 when(contextA.isDisposed()).thenReturn(true); |
| 139 InstrumentedAnalysisContextImpl instrumentedContext = mock(InstrumentedAnaly
sisContextImpl.class); |
| 140 when(instrumentedContext.getBasis()).thenReturn(contextA); |
| 141 assertEquals(false, store.aboutToIndexDart(instrumentedContext, unitElementA
)); |
| 142 } |
| 143 |
| 144 public void test_aboutToIndexDart_library_first() throws Exception { |
| 145 when(libraryElement.getParts()).thenReturn( |
| 146 new CompilationUnitElement[] {unitElementA, unitElementB}); |
| 147 { |
| 148 store.aboutToIndexDart(contextA, libraryUnitElement); |
| 149 store.doneIndex(); |
| 150 } |
| 151 { |
| 152 Location[] locations = store.getRelationships(elementA, relationship); |
| 153 assertLocations(locations); |
| 154 } |
| 155 } |
| 156 |
| 157 public void test_aboutToIndexDart_library_secondWithoutOneUnit() throws Except
ion { |
| 158 Location locationA = mockLocation(elementA); |
| 159 Location locationB = mockLocation(elementB); |
| 160 { |
| 161 store.aboutToIndexDart(contextA, unitElementA); |
| 162 store.recordRelationship(elementA, relationship, locationA); |
| 163 store.doneIndex(); |
| 164 } |
| 165 { |
| 166 store.aboutToIndexDart(contextA, unitElementB); |
| 167 store.recordRelationship(elementA, relationship, locationB); |
| 168 store.doneIndex(); |
| 169 } |
| 170 // "A" and "B" locations |
| 171 { |
| 172 Location[] locations = store.getRelationships(elementA, relationship); |
| 173 assertLocations(locations, locationA, locationB); |
| 174 } |
| 175 // apply "libraryUnitElement", only with "B" |
| 176 when(libraryElement.getParts()).thenReturn(new CompilationUnitElement[] {uni
tElementB}); |
| 177 { |
| 178 store.aboutToIndexDart(contextA, libraryUnitElement); |
| 179 store.doneIndex(); |
| 180 } |
| 181 { |
| 182 Location[] locations = store.getRelationships(elementA, relationship); |
| 183 assertLocations(locations, locationB); |
| 184 } |
| 185 } |
| 186 |
| 187 public void test_aboutToIndexDart_nullLibraryElement() throws Exception { |
| 188 when(unitElementA.getLibrary()).thenReturn(null); |
| 189 assertEquals(false, store.aboutToIndexDart(contextA, unitElementA)); |
| 190 } |
| 191 |
| 192 public void test_aboutToIndexDart_nullLibraryUnitElement() throws Exception { |
| 193 when(libraryElement.getDefiningCompilationUnit()).thenReturn(null); |
| 194 assertEquals(false, store.aboutToIndexDart(contextA, unitElementA)); |
| 195 } |
| 196 |
| 197 public void test_aboutToIndexDart_nullUnitElement() throws Exception { |
| 198 assertEquals(false, store.aboutToIndexDart(contextA, null)); |
| 199 } |
| 200 |
| 201 public void test_aboutToIndexHtml_() throws Exception { |
| 202 Location locationA = mockLocation(elementA); |
| 203 Location locationB = mockLocation(elementB); |
| 204 { |
| 205 store.aboutToIndexHtml(contextA, htmlElementA); |
| 206 store.recordRelationship(elementA, relationship, locationA); |
| 207 store.doneIndex(); |
| 208 } |
| 209 { |
| 210 store.aboutToIndexHtml(contextA, htmlElementB); |
| 211 store.recordRelationship(elementA, relationship, locationB); |
| 212 store.doneIndex(); |
| 213 } |
| 214 // "A" and "B" locations |
| 215 { |
| 216 Location[] locations = store.getRelationships(elementA, relationship); |
| 217 assertLocations(locations, locationA, locationB); |
| 218 } |
| 219 } |
| 220 |
| 221 public void test_aboutToIndexHtml_disposedContext() throws Exception { |
| 222 when(contextA.isDisposed()).thenReturn(true); |
| 223 assertEquals(false, store.aboutToIndexHtml(contextA, htmlElementA)); |
| 224 } |
| 225 |
| 226 public void test_clear() throws Exception { |
| 227 Location locationA = mockLocation(elementA); |
| 228 store.aboutToIndexDart(contextA, unitElementA); |
| 229 store.recordRelationship(elementA, relationship, locationA); |
| 230 store.doneIndex(); |
| 231 assertFalse(nodeManager.isEmpty()); |
| 232 // clear |
| 233 store.clear(); |
| 234 assertTrue(nodeManager.isEmpty()); |
| 235 } |
| 236 |
| 237 public void test_getRelationships_empty() throws Exception { |
| 238 Location[] locations = store.getRelationships(elementA, relationship); |
| 239 assertThat(locations).isEmpty(); |
| 240 } |
| 241 |
| 242 public void test_getStatistics() throws Exception { |
| 243 // empty initially |
| 244 assertThat(store.getStatistics()).contains("0 locations").contains("0 source
s"); |
| 245 // add 2 locations |
| 246 Location locationA = mockLocation(elementA); |
| 247 Location locationB = mockLocation(elementB); |
| 248 { |
| 249 store.aboutToIndexDart(contextA, unitElementA); |
| 250 store.recordRelationship(elementA, relationship, locationA); |
| 251 store.doneIndex(); |
| 252 } |
| 253 { |
| 254 store.aboutToIndexDart(contextA, unitElementB); |
| 255 store.recordRelationship(elementA, relationship, locationB); |
| 256 store.doneIndex(); |
| 257 } |
| 258 assertThat(store.getStatistics()).contains("2 locations").contains("3 source
s"); |
| 259 } |
| 260 |
| 261 public void test_recordRelationship_errorElementKind() throws Exception { |
| 262 when(elementA.getKind()).thenReturn(ElementKind.ERROR); |
| 263 Location locationA = mockLocation(elementA); |
| 264 store.recordRelationship(elementA, relationship, locationA); |
| 265 store.doneIndex(); |
| 266 assertTrue(nodeManager.isEmpty()); |
| 267 } |
| 268 |
| 269 public void test_recordRelationship_nullElement() throws Exception { |
| 270 Location locationA = mockLocation(elementA); |
| 271 store.recordRelationship(null, relationship, locationA); |
| 272 store.doneIndex(); |
| 273 assertTrue(nodeManager.isEmpty()); |
| 274 } |
| 275 |
| 276 public void test_recordRelationship_nullLocation() throws Exception { |
| 277 store.recordRelationship(elementA, relationship, null); |
| 278 store.doneIndex(); |
| 279 assertTrue(nodeManager.isEmpty()); |
| 280 } |
| 281 |
| 282 public void test_recordRelationship_oneElement_twoNodes() throws Exception { |
| 283 Location locationA = mockLocation(elementA); |
| 284 Location locationB = mockLocation(elementB); |
| 285 { |
| 286 store.aboutToIndexDart(contextA, unitElementA); |
| 287 store.recordRelationship(elementA, relationship, locationA); |
| 288 store.doneIndex(); |
| 289 } |
| 290 { |
| 291 store.aboutToIndexDart(contextA, unitElementB); |
| 292 store.recordRelationship(elementA, relationship, locationB); |
| 293 store.doneIndex(); |
| 294 } |
| 295 { |
| 296 Location[] locations = store.getRelationships(elementA, relationship); |
| 297 assertLocations(locations, locationA, locationB); |
| 298 } |
| 299 } |
| 300 |
| 301 public void test_recordRelationship_oneLocation() throws Exception { |
| 302 Location locationA = mockLocation(elementA); |
| 303 store.aboutToIndexDart(contextA, unitElementA); |
| 304 store.recordRelationship(elementA, relationship, locationA); |
| 305 store.doneIndex(); |
| 306 { |
| 307 Location[] locations = store.getRelationships(elementA, relationship); |
| 308 assertLocations(locations, locationA); |
| 309 } |
| 310 } |
| 311 |
| 312 public void test_recordRelationship_twoLocations() throws Exception { |
| 313 Location locationA = mockLocation(elementA); |
| 314 Location locationB = mockLocation(elementA); |
| 315 store.aboutToIndexDart(contextA, unitElementA); |
| 316 store.recordRelationship(elementA, relationship, locationA); |
| 317 store.recordRelationship(elementA, relationship, locationB); |
| 318 store.doneIndex(); |
| 319 { |
| 320 Location[] locations = store.getRelationships(elementA, relationship); |
| 321 assertLocations(locations, locationA, locationB); |
| 322 } |
| 323 } |
| 324 |
| 325 public void test_removeContext() throws Exception { |
| 326 Location locationA = mockLocation(elementA); |
| 327 Location locationB = mockLocation(elementB); |
| 328 { |
| 329 store.aboutToIndexDart(contextA, unitElementA); |
| 330 store.recordRelationship(elementA, relationship, locationA); |
| 331 store.doneIndex(); |
| 332 } |
| 333 { |
| 334 store.aboutToIndexDart(contextA, unitElementB); |
| 335 store.recordRelationship(elementA, relationship, locationB); |
| 336 store.doneIndex(); |
| 337 } |
| 338 // "A" and "B" locations |
| 339 { |
| 340 Location[] locations = store.getRelationships(elementA, relationship); |
| 341 assertLocations(locations, locationA, locationB); |
| 342 } |
| 343 // remove "A" context |
| 344 store.removeContext(contextA); |
| 345 { |
| 346 Location[] locations = store.getRelationships(elementA, relationship); |
| 347 assertLocations(locations); |
| 348 } |
| 349 } |
| 350 |
| 351 public void test_removeContext_nullContext() throws Exception { |
| 352 store.removeContext(null); |
| 353 } |
| 354 |
| 355 public void test_removeSource_library() throws Exception { |
| 356 Location locationA = mockLocation(elementA); |
| 357 Location locationB = mockLocation(elementB); |
| 358 Location locationC = mockLocation(elementC); |
| 359 { |
| 360 store.aboutToIndexDart(contextA, unitElementA); |
| 361 store.recordRelationship(elementA, relationship, locationA); |
| 362 store.doneIndex(); |
| 363 } |
| 364 { |
| 365 store.aboutToIndexDart(contextA, unitElementB); |
| 366 store.recordRelationship(elementA, relationship, locationB); |
| 367 store.doneIndex(); |
| 368 } |
| 369 { |
| 370 store.aboutToIndexDart(contextA, unitElementC); |
| 371 store.recordRelationship(elementA, relationship, locationC); |
| 372 store.doneIndex(); |
| 373 } |
| 374 // "A", "B" and "C" locations |
| 375 { |
| 376 Location[] locations = store.getRelationships(elementA, relationship); |
| 377 assertLocations(locations, locationA, locationB, locationC); |
| 378 } |
| 379 // remove "librarySource" |
| 380 store.removeSource(contextA, librarySource); |
| 381 { |
| 382 Location[] locations = store.getRelationships(elementA, relationship); |
| 383 assertLocations(locations); |
| 384 } |
| 385 } |
| 386 |
| 387 public void test_removeSource_nullContext() throws Exception { |
| 388 store.removeSource(null, sourceA); |
| 389 } |
| 390 |
| 391 public void test_removeSource_unit() throws Exception { |
| 392 Location locationA = mockLocation(elementA); |
| 393 Location locationB = mockLocation(elementB); |
| 394 Location locationC = mockLocation(elementC); |
| 395 { |
| 396 store.aboutToIndexDart(contextA, unitElementA); |
| 397 store.recordRelationship(elementA, relationship, locationA); |
| 398 store.doneIndex(); |
| 399 } |
| 400 { |
| 401 store.aboutToIndexDart(contextA, unitElementB); |
| 402 store.recordRelationship(elementA, relationship, locationB); |
| 403 store.doneIndex(); |
| 404 } |
| 405 { |
| 406 store.aboutToIndexDart(contextA, unitElementC); |
| 407 store.recordRelationship(elementA, relationship, locationC); |
| 408 store.doneIndex(); |
| 409 } |
| 410 // "A", "B" and "C" locations |
| 411 { |
| 412 Location[] locations = store.getRelationships(elementA, relationship); |
| 413 assertLocations(locations, locationA, locationB, locationC); |
| 414 } |
| 415 // remove "A" source |
| 416 store.removeSource(contextA, sourceA); |
| 417 { |
| 418 Location[] locations = store.getRelationships(elementA, relationship); |
| 419 assertLocations(locations, locationB, locationC); |
| 420 } |
| 421 } |
| 422 |
| 423 public void test_removeSources_library() throws Exception { |
| 424 Location locationA = mockLocation(elementA); |
| 425 Location locationB = mockLocation(elementB); |
| 426 { |
| 427 store.aboutToIndexDart(contextA, unitElementA); |
| 428 store.recordRelationship(elementA, relationship, locationA); |
| 429 store.doneIndex(); |
| 430 } |
| 431 { |
| 432 store.aboutToIndexDart(contextA, unitElementB); |
| 433 store.recordRelationship(elementA, relationship, locationB); |
| 434 store.doneIndex(); |
| 435 } |
| 436 // "A" and "B" locations |
| 437 { |
| 438 Location[] locations = store.getRelationships(elementA, relationship); |
| 439 assertLocations(locations, locationA, locationB); |
| 440 } |
| 441 // remove "librarySource" |
| 442 store.removeSources(contextA, new SourceContainer() { |
| 443 @Override |
| 444 public boolean contains(Source source) { |
| 445 return source == librarySource; |
| 446 } |
| 447 }); |
| 448 { |
| 449 Location[] locations = store.getRelationships(elementA, relationship); |
| 450 assertLocations(locations); |
| 451 } |
| 452 } |
| 453 |
| 454 public void test_removeSources_nullContext() throws Exception { |
| 455 store.removeSources(null, null); |
| 456 } |
| 457 |
| 458 public void test_removeSources_unit() throws Exception { |
| 459 Location locationA = mockLocation(elementA); |
| 460 Location locationB = mockLocation(elementB); |
| 461 Location locationC = mockLocation(elementC); |
| 462 { |
| 463 store.aboutToIndexDart(contextA, unitElementA); |
| 464 store.recordRelationship(elementA, relationship, locationA); |
| 465 store.doneIndex(); |
| 466 } |
| 467 { |
| 468 store.aboutToIndexDart(contextA, unitElementB); |
| 469 store.recordRelationship(elementA, relationship, locationB); |
| 470 store.doneIndex(); |
| 471 } |
| 472 { |
| 473 store.aboutToIndexDart(contextA, unitElementC); |
| 474 store.recordRelationship(elementA, relationship, locationC); |
| 475 store.doneIndex(); |
| 476 } |
| 477 // "A", "B" and "C" locations |
| 478 { |
| 479 Location[] locations = store.getRelationships(elementA, relationship); |
| 480 assertLocations(locations, locationA, locationB, locationC); |
| 481 } |
| 482 // remove "A" source |
| 483 store.removeSources(contextA, new SourceContainer() { |
| 484 @Override |
| 485 public boolean contains(Source source) { |
| 486 return source == sourceA; |
| 487 } |
| 488 }); |
| 489 { |
| 490 Location[] locations = store.getRelationships(elementA, relationship); |
| 491 assertLocations(locations, locationB, locationC); |
| 492 } |
| 493 } |
| 494 |
| 495 public void test_universe_aboutToIndex() throws Exception { |
| 496 when(contextA.getElement(elementLocationA)).thenReturn(elementA); |
| 497 when(contextB.getElement(elementLocationB)).thenReturn(elementB); |
| 498 Location locationA = mockLocation(elementA); |
| 499 Location locationB = mockLocation(elementB); |
| 500 { |
| 501 store.aboutToIndexDart(contextA, unitElementA); |
| 502 store.recordRelationship(UniverseElement.INSTANCE, relationship, locationA
); |
| 503 store.doneIndex(); |
| 504 } |
| 505 { |
| 506 store.aboutToIndexDart(contextB, unitElementB); |
| 507 store.recordRelationship(UniverseElement.INSTANCE, relationship, locationB
); |
| 508 store.doneIndex(); |
| 509 } |
| 510 { |
| 511 Location[] locations = store.getRelationships(UniverseElement.INSTANCE, re
lationship); |
| 512 assertLocations(locations, locationA, locationB); |
| 513 } |
| 514 // re-index "unitElementA" |
| 515 store.aboutToIndexDart(contextA, unitElementA); |
| 516 store.doneIndex(); |
| 517 { |
| 518 Location[] locations = store.getRelationships(UniverseElement.INSTANCE, re
lationship); |
| 519 assertLocations(locations, locationB); |
| 520 } |
| 521 } |
| 522 |
| 523 public void test_universe_removeContext() throws Exception { |
| 524 when(contextA.getElement(elementLocationA)).thenReturn(elementA); |
| 525 when(contextB.getElement(elementLocationB)).thenReturn(elementB); |
| 526 Location locationA = mockLocation(elementA); |
| 527 Location locationB = mockLocation(elementB); |
| 528 { |
| 529 store.aboutToIndexDart(contextA, unitElementA); |
| 530 store.recordRelationship(UniverseElement.INSTANCE, relationship, locationA
); |
| 531 store.doneIndex(); |
| 532 } |
| 533 { |
| 534 store.aboutToIndexDart(contextB, unitElementB); |
| 535 store.recordRelationship(UniverseElement.INSTANCE, relationship, locationB
); |
| 536 store.doneIndex(); |
| 537 } |
| 538 { |
| 539 Location[] locations = store.getRelationships(UniverseElement.INSTANCE, re
lationship); |
| 540 assertLocations(locations, locationA, locationB); |
| 541 } |
| 542 // remove "contextA" |
| 543 store.removeContext(contextA); |
| 544 { |
| 545 Location[] locations = store.getRelationships(UniverseElement.INSTANCE, re
lationship); |
| 546 assertLocations(locations, locationB); |
| 547 } |
| 548 } |
| 549 |
| 550 @Override |
| 551 protected void setUp() throws Exception { |
| 552 super.setUp(); |
| 553 when(contextA.toString()).thenReturn("contextA"); |
| 554 when(contextB.toString()).thenReturn("contextB"); |
| 555 when(contextC.toString()).thenReturn("contextC"); |
| 556 when(contextA.getElement(elementLocationA)).thenReturn(elementA); |
| 557 when(contextA.getElement(elementLocationB)).thenReturn(elementB); |
| 558 when(contextA.getElement(elementLocationC)).thenReturn(elementC); |
| 559 when(contextA.getElement(elementLocationD)).thenReturn(elementD); |
| 560 when(sourceA.toString()).thenReturn("sourceA"); |
| 561 when(sourceB.toString()).thenReturn("sourceB"); |
| 562 when(sourceC.toString()).thenReturn("sourceC"); |
| 563 when(sourceD.toString()).thenReturn("sourceD"); |
| 564 when(sourceA.getFullName()).thenReturn("/home/user/sourceA.dart"); |
| 565 when(sourceB.getFullName()).thenReturn("/home/user/sourceB.dart"); |
| 566 when(sourceC.getFullName()).thenReturn("/home/user/sourceC.dart"); |
| 567 when(sourceD.getFullName()).thenReturn("/home/user/sourceD.dart"); |
| 568 when(elementA.toString()).thenReturn("elementA"); |
| 569 when(elementB.toString()).thenReturn("elementB"); |
| 570 when(elementC.toString()).thenReturn("elementC"); |
| 571 when(elementD.toString()).thenReturn("elementD"); |
| 572 when(elementA.getContext()).thenReturn(contextA); |
| 573 when(elementB.getContext()).thenReturn(contextA); |
| 574 when(elementC.getContext()).thenReturn(contextA); |
| 575 when(elementD.getContext()).thenReturn(contextA); |
| 576 when(elementA.getLocation()).thenReturn(elementLocationA); |
| 577 when(elementB.getLocation()).thenReturn(elementLocationB); |
| 578 when(elementC.getLocation()).thenReturn(elementLocationC); |
| 579 when(elementD.getLocation()).thenReturn(elementLocationD); |
| 580 when(elementA.getEnclosingElement()).thenReturn(unitElementA); |
| 581 when(elementB.getEnclosingElement()).thenReturn(unitElementB); |
| 582 when(elementC.getEnclosingElement()).thenReturn(unitElementC); |
| 583 when(elementD.getEnclosingElement()).thenReturn(unitElementD); |
| 584 when(elementA.getSource()).thenReturn(sourceA); |
| 585 when(elementB.getSource()).thenReturn(sourceB); |
| 586 when(elementC.getSource()).thenReturn(sourceC); |
| 587 when(elementD.getSource()).thenReturn(sourceD); |
| 588 when(elementA.getLibrary()).thenReturn(libraryElement); |
| 589 when(elementB.getLibrary()).thenReturn(libraryElement); |
| 590 when(elementC.getLibrary()).thenReturn(libraryElement); |
| 591 when(elementD.getLibrary()).thenReturn(libraryElement); |
| 592 when(unitElementA.getSource()).thenReturn(sourceA); |
| 593 when(unitElementB.getSource()).thenReturn(sourceB); |
| 594 when(unitElementC.getSource()).thenReturn(sourceC); |
| 595 when(unitElementD.getSource()).thenReturn(sourceD); |
| 596 when(unitElementA.getLibrary()).thenReturn(libraryElement); |
| 597 when(unitElementB.getLibrary()).thenReturn(libraryElement); |
| 598 when(unitElementC.getLibrary()).thenReturn(libraryElement); |
| 599 when(unitElementD.getLibrary()).thenReturn(libraryElement); |
| 600 when(htmlElementA.getSource()).thenReturn(sourceA); |
| 601 when(htmlElementB.getSource()).thenReturn(sourceB); |
| 602 // library |
| 603 when(librarySource.toString()).thenReturn("libSource"); |
| 604 when(libraryUnitElement.getLibrary()).thenReturn(libraryElement); |
| 605 when(libraryUnitElement.getSource()).thenReturn(librarySource); |
| 606 when(libraryElement.getSource()).thenReturn(librarySource); |
| 607 when(libraryElement.getDefiningCompilationUnit()).thenReturn(libraryUnitElem
ent); |
| 608 } |
| 609 } |
OLD | NEW |