final ResourceProviderEntry e = new ResourceProviderEntry("/", null);
long counter = 1;
for(String path : new String[] { "/foo", "/", "/foo/bar" }) {
final ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
final ResourceProvider p = Mockito.mock(ResourceProvider.class);
Mockito.when(p.getResource(Mockito.any(ResourceResolver.class), Mockito.startsWith(path))).thenReturn(new TestResource(resolver));
final ResourceResolverContext ctx = getResourceResolverContext();
final Map<String, Object> props = new HashMap<String, Object>();
props.put(Constants.SERVICE_ID, ++counter);
e.addResourceProvider(path, new ResourceProviderHandler(p, props));
{
final Resource r = e.getResource(ctx, null, path, false);
assertEqualsResolver(resolver, r);
assertFalse(r instanceof SyntheticResource);
}
e.removeResourceProvider(path, new ResourceProviderHandler(p, props));
{
final Resource r = e.getResource(ctx, null, path, false);
// If our provider is indeed gone, we should get one of the following conditions
if(r == null) {
//fine
} else if(!p.equals(r.getResourceResolver())) {
//fine
} else {
fail("Expecting inactive provider after removing it for " + path);
}
}