final ComputationTargetResolver.AtVersionCorrection underlying = Mockito.mock(ComputationTargetResolver.AtVersionCorrection.class);
final ConcurrentMap<ComputationTargetReference, UniqueId> resolutions = new ConcurrentHashMap<ComputationTargetReference, UniqueId>();
final Set<UniqueId> expiredResolutions = new HashSet<UniqueId>();
final ComputationTargetResolver.AtVersionCorrection resolver = TargetResolutionLogger.of(underlying, resolutions, expiredResolutions);
final ComputationTargetSpecification spec = new ComputationTargetSpecification(ComputationTargetType.PRIMITIVE, UniqueId.of("Foo", "Bar"));
final ComputationTarget target = new ComputationTarget(spec.replaceIdentifier(UniqueId.of("Foo", "Bar", "Cow")), new Primitive(UniqueId.of("Foo", "Bar", "Cow")));
Mockito.when(underlying.resolve(spec)).thenReturn(target);
final ObjectResolver deepResolver = Mockito.mock(ObjectResolver.class);
Mockito.when(deepResolver.deepResolver()).thenReturn(new DeepResolver() {
@SuppressWarnings("serial")
@Override
public UniqueIdentifiable withLogger(final UniqueIdentifiable underlying, final ResolutionLogger logger) {
assertSame(underlying, target.getValue());
return new Primitive(UniqueId.of("Foo", "Bar", "Cow")) {
@Override
public int hashCode() {
// Pretend that this is a deep-resolving operation
logger.log(spec, underlying.getUniqueId());
return super.hashCode();
}
};
}
});
Mockito.when(underlying.getResolver(spec)).thenReturn(deepResolver);
final ComputationTarget resolvedTarget = resolver.resolve(spec);
assertNotSame(resolvedTarget, target);
assertTrue(resolutions.isEmpty());
resolvedTarget.getValue().hashCode();
assertFalse(resolutions.isEmpty());
}