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_writeRead_invalidVersion() throws Exception {
   // write fake content with invalid version
   byte[] content;
   {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream dos = new DataOutputStream(baos);
     dos.writeInt(-1);
     content = baos.toByteArray();
   }
   // read
   try {
     ByteArrayInputStream bais = new ByteArrayInputStream(content);
     store.readIndex(contextA, bais);
     fail();
   } catch (IOException e) {
   }
 }