use of com.google.inject.OutOfScopeException in project roboguice by roboguice.
the class ScopeRequestIntegrationTest method testNullReplacement.
public final void testNullReplacement() throws Exception {
Injector injector = Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
bindConstant().annotatedWith(Names.named(SomeObject.INVALID)).to(SHOULDNEVERBESEEN);
bind(SomeObject.class).in(RequestScoped.class);
}
});
Callable<SomeObject> callable = injector.getInstance(Caller.class);
try {
assertNotNull(callable.call());
fail();
} catch (ProvisionException pe) {
assertTrue(pe.getCause() instanceof OutOfScopeException);
}
// Validate that an actual null entry in the map results in a null injected object.
Map<Key<?>, Object> map = Maps.newHashMap();
map.put(Key.get(SomeObject.class), null);
callable = ServletScopes.scopeRequest(injector.getInstance(Caller.class), map);
assertNull(callable.call());
}
use of com.google.inject.OutOfScopeException in project gerrit by GerritCodeReview.
the class IdentifiedUser method materializedCopy.
/**
* Returns a materialized copy of the user with all dependencies.
*
* <p>Invoke all providers and factories of dependent objects and store the references to a copy
* of the current identified user.
*
* @return copy of the identified user
*/
public IdentifiedUser materializedCopy() {
CapabilityControl capabilities = getCapabilities();
Provider<SocketAddress> remotePeer;
try {
remotePeer = Providers.of(remotePeerProvider.get());
} catch (OutOfScopeException | ProvisionException e) {
remotePeer = new Provider<SocketAddress>() {
@Override
public SocketAddress get() {
throw e;
}
};
}
return new IdentifiedUser(new CapabilityControl.Factory() {
@Override
public CapabilityControl create(CurrentUser user) {
return capabilities;
}
}, authConfig, realm, anonymousCowardName, Providers.of(canonicalUrl.get()), accountCache, groupBackend, disableReverseDnsLookup, remotePeer, state, realUser);
}
Aggregations