### Question:
ServiceProvision { public static <E extends RetryPolicy> Optional<E> loadRetryPolicy( Configuration configuration, Environment environment, String key, Class<? extends E> serviceClass) { return configuration .get(key, ServiceFactoryConfig.class) .map(factoryConfig -> { RetryPolicyFactory factory = newInstance(factoryConfig.factory(), RetryPolicyFactory.class); JsonNodeConfig config = factoryConfig.config(); return serviceClass.cast(factory.create(environment, config)); }); } private  ServiceProvision(); static Optional<E> loadLoadBalancer(
            Configuration configuration,
            Environment environment,
            String key,
            Class<? extends E> serviceClass,
            ActiveOrigins activeOrigins); static Optional<E> loadRetryPolicy(
            Configuration configuration,
            Environment environment,
            String key,
            Class<? extends E> serviceClass); static Map<String, T> loadServices(Configuration configuration, Environment environment, String key, Class<? extends T> serviceClass);  }### Answer:
@Test public void serviceReturnsCorrectlyFromCall() { assertThat(loadRetryPolicy(environment.configuration(), environment, "myRetry.factory", RetryPolicy.class).get(), is(instanceOf(RetryPolicy.class))); }
@Test public void serviceReturnsEmptyWhenFactoryKeyDoesNotExist() { assertThat(loadRetryPolicy(environment.configuration(), environment, "invalid.key", RetryPolicy.class), isAbsent()); }
@Test public void throwsExceptionWhenClassDoesNotExist() { Exception e = assertThrows(Exception.class, () -> loadRetryPolicy(environment.configuration(), environment, "not.real", RetryPolicy.class)); assertThat(e.getMessage(), matchesPattern("(?s).*No such class 'my.FakeClass'.*")); }