public void test_removeContext_withDeclaration() throws Exception { when(elementB.getContext()).thenReturn(contextB); when(elementC.getContext()).thenReturn(contextC); // configure B and C Location locationB = mockLocation(elementB); Location locationC = mockLocation(elementC); // record: [B -> A] and [C -> A] { store.recordRelationship(elementA, relationship, locationB); store.recordRelationship(elementA, relationship, locationC); assertEquals(2, store.internalGetLocationCount()); assertEquals(1, store.internalGetKeyCount()); assertEquals(0, store.internalGetLocationCount(contextA)); assertEquals(1, store.internalGetLocationCount(contextB)); assertEquals(1, store.internalGetLocationCount(contextC)); // we get locations from all contexts Location[] locations = store.getRelationships(elementA, relationship); assertLocations(locations, locationB, locationC); } // remove A, so no relations anymore // remove B, 1 relation and 1 location left store.removeContext(contextA); assertEquals(0, store.internalGetLocationCount()); assertEquals(0, store.internalGetLocationCount(contextA)); assertEquals(0, store.internalGetLocationCount(contextB)); assertEquals(0, store.internalGetLocationCount(contextC)); { Location[] locations = store.getRelationships(elementA, relationship); assertThat(locations).isEmpty(); } }
public void test_tryToRecord_afterContextRemove_element() throws Exception { Location locationB = mockLocation(elementB); // remove "A" - context of "elementA" store.removeContext(contextA); // so, this record request is ignored store.recordRelationship(elementA, relationship, locationB); assertEquals(0, store.internalGetLocationCount()); }
public void test_writeRead() throws Exception { when(contextA.getElement(eq(elementLocationA))).thenReturn(elementA); when(contextB.getElement(eq(elementLocationB))).thenReturn(elementB); when(elementA.getContext()).thenReturn(contextA); when(elementB.getContext()).thenReturn(contextB); // fill store Location locationA = new Location(elementA, 0, 0); Location locationB = new Location(elementB, 0, 0); store.aboutToIndex(contextA, unitElementA); store.aboutToIndex(contextB, unitElementB); store.recordRelationship(elementA, relationship, locationA); store.recordRelationship(elementB, relationship, locationB); assertEquals(2, store.internalGetKeyCount()); assertEquals(2, store.internalGetLocationCount()); assertLocations(store.getRelationships(elementA, relationship), locationA); assertLocations(store.getRelationships(elementB, relationship), locationB); // write byte[] content; { ByteArrayOutputStream baos = new ByteArrayOutputStream(); store.writeIndex(contextA, baos); content = baos.toByteArray(); } // clear store.removeContext(contextA); store.removeContext(contextB); assertEquals(0, store.internalGetKeyCount()); assertEquals(0, store.internalGetLocationCount()); // we need to re-create AnalysisContext, current instance was marked as removed { contextA = mock(AnalysisContext.class); when(contextA.getElement(eq(elementLocationA))).thenReturn(elementA); when(elementA.getContext()).thenReturn(contextA); } // read { ByteArrayInputStream bais = new ByteArrayInputStream(content); store.readIndex(contextA, bais); } // validate after read assertEquals(1, store.internalGetKeyCount()); assertEquals(1, store.internalGetLocationCount()); { Location[] locations = store.getRelationships(elementA, relationship); assertLocations(locations, locationA); } }
public void test_removeContext_instrumented() throws Exception { InstrumentedAnalysisContextImpl instrumentedContext = mock(InstrumentedAnalysisContextImpl.class); when(instrumentedContext.getBasis()).thenReturn(contextA); // configure B when(elementB.getContext()).thenReturn(contextA); Location locationB = mockLocation(elementB); // record: [B -> A] { store.recordRelationship(elementA, relationship, locationB); assertEquals(1, store.internalGetLocationCount()); assertEquals(1, store.internalGetKeyCount()); } // remove _wrapper_ of context A InstrumentedAnalysisContextImpl iContextA = mock(InstrumentedAnalysisContextImpl.class); when(iContextA.getBasis()).thenReturn(contextA); store.removeContext(iContextA); assertEquals(0, store.internalGetLocationCount()); assertEquals(0, store.internalGetKeyCount()); }
public void test_removeContext_null() throws Exception { store.removeContext(null); }
public void test_aboutToIndex_removedContext() throws Exception { store.removeContext(contextA); boolean mayIndex = store.aboutToIndex(contextA, unitElementA); assertFalse(mayIndex); }