ServiceInstance createService(TestContext testContext, TestDescriptor testDescriptor, TestConfigurer testConfigurer) { ServiceInstance serviceInstance; Optional<ServiceInstance> foundServiceInstance = testContext.<ServiceInstance>findProperty(SERVICE_INSTANCE); if (foundServiceInstance.isPresent()) { serviceInstance = foundServiceInstance.get(); } else { ServiceProvider serviceProvider = serviceLocatorUtil.getFromHintOrDefault( testContext, ServiceProvider.class, DefaultServiceProvider.class, Hint::serviceProvider); Object serviceContext = serviceProvider.create(testContext); testConfigurer.configure(testContext, serviceContext); serviceInstance = serviceProvider.configure(testContext, serviceContext); testContext.addProperty(SERVICE_INSTANCE, serviceInstance); serviceProvider.postConfigure(testContext, serviceInstance); } return serviceInstance; }
testContext.addProperty(SERVICE_INSTANCE, serviceInstance); serviceProvider.postConfigure(testContext, serviceInstance);