final ValueSpecification spec2 = createValueSpec(2);
final ValueSpecification spec3 = createValueSpec(3);
final Long2ObjectMap<ValueSpecification> spec1And2 = new Long2ObjectOpenHashMap<ValueSpecification>(new long[] {1L, 2L }, new ValueSpecification[] {spec1, spec2 });
final IdentifierMap underlying = Mockito.mock(IdentifierMap.class);
final CachingIdentifierMap cache = new CachingIdentifierMap(underlying);
Mockito.when(underlying.getValueSpecifications(new LongArrayList(new long[] {1L, 2L }))).thenReturn(spec1And2);
Mockito.when(underlying.getValueSpecification(3L)).thenReturn(spec3);
Long2ObjectMap<ValueSpecification> result = cache.getValueSpecifications(new LongArrayList(new long[] {1L, 2L }));
assertEquals(result.size(), 2);
assertEquals(result.get(1L), spec1);
assertEquals(result.get(2L), spec2);
result = cache.getValueSpecifications(new LongArrayList(new long[] {1L, 2L }));
assertEquals(result.size(), 2);
assertEquals(result.get(1L), spec1);
assertEquals(result.get(2L), spec2);
Mockito.verify(underlying, Mockito.times(1)).getValueSpecifications(new LongArrayList(new long[] {1L, 2L }));
result = cache.getValueSpecifications(new LongArrayList(new long[] {2L, 3L }));
assertEquals(result.size(), 2);
assertEquals(result.get(2L), spec2);
assertEquals(result.get(3L), spec3);
result = cache.getValueSpecifications(new LongArrayList(new long[] {2L, 3L }));
assertEquals(result.size(), 2);
assertEquals(result.get(2L), spec2);
assertEquals(result.get(3L), spec3);
Mockito.verify(underlying, Mockito.times(1)).getValueSpecification(3L);
result = cache.getValueSpecifications(new LongArrayList(new long[] {1L, 2L, 3L }));
assertEquals(result.size(), 3);
assertEquals(result.get(1L), spec1);
assertEquals(result.get(2L), spec2);
assertEquals(result.get(3L), spec3);
result = cache.getValueSpecifications(new LongArrayList(new long[] {1L, 2L, 3L }));
assertEquals(result.size(), 3);
assertEquals(result.get(1L), spec1);
assertEquals(result.get(2L), spec2);
assertEquals(result.get(3L), spec3);
Mockito.verifyNoMoreInteractions(underlying);