### Question:
BackendProviderHandlerRegistry extends AbstractProviderHandlerRegistry<BackendProviderHandler> { public BackendProviderHandler ensureHandler(ProviderTypeKey providerTypeKey) { final BackendProviderHandler handler = getProviderHandler(providerTypeKey); if (handler == null) { throw new RuntimeException("BackendProviderHandler was not found for providerTypeKey: " + providerTypeKey); } return handler; } BackendProviderHandlerRegistry(); @Inject  BackendProviderHandlerRegistry(final @Any Instance<BackendProviderHandler> handlerInstance); BackendProviderHandler ensureHandler(ProviderTypeKey providerTypeKey);  }### Answer:
@Test public void testEnsureHandlerForRegisteredProviderType() throws Exception { ProviderTypeKey providerTypeKey = expectedKeys.get(0); BackendProviderHandler handler = ((BackendProviderHandlerRegistry) handlerRegistry).ensureHandler(providerTypeKey); assertEquals(expectedHandlers.get(0), handler); }
@Test public void testEnsureHandlerForNonRegisteredProviderType() throws Exception { ProviderTypeKey providerTypeKey = mock(ProviderTypeKey.class); expectedException.expectMessage("BackendProviderHandler was not found for providerTypeKey: " + providerTypeKey); ((BackendProviderHandlerRegistry) handlerRegistry).ensureHandler(providerTypeKey); }