InMemoryBackendServiceFactory implements BusinessParametersBackendFactory { @Override public BusinessParametersBackend<InMemoryQuery<?>> getInstance() { return getInstance(DATA_STORE_SUPPLIER.get()); }  static synchronized void setDataStoreSupplier(Supplier<GroupDataStore> supplier); @Override BusinessParametersBackend<InMemoryQuery<?>> getInstance();  }
@Test @DisplayName("Creates an InMemoryBackend") void testGetInstance() { BusinessParametersBackend<?> backend = factory.getInstance(); assertThat(backend).isInstanceOf(InMemoryBackend.class); }
@Test @DisplayName("Supplies definitions from ServiceLoader") void testGetInstanceWithDefinitions(@Mock ParameterGroupDefinition<?> definition1, @Mock ParameterGroupDefinition<?> definition2) throws Exception { exposeService(ParameterGroupDefinitionCatalog.class, TestCatalog.class); when(definition1.getName()).thenReturn("group1"); when(definition2.getName()).thenReturn("group-B"); testState.get().definitions = Arrays.asList(definition1, definition2); factory.getInstance(); @SuppressWarnings("unchecked") ArgumentCaptor<Supplier<Stream<ParameterGroupDefinition<?>>>> supplier = ArgumentCaptor.forClass(Supplier.class); verify(backendConstructor).create(any(), supplier.capture(), any()); assertThat(supplier.getValue().get()).contains(definition1, definition2); }
@Test @DisplayName("Supplies group factories from ServiceLoader") void testGetInstanceWithFactoryContext() throws Exception { exposeService(InMemoryGroupFactory.class, TestGroupFactory.class); factory.getInstance(); ArgumentCaptor<InMemoryBackendGroupFactoryContext> context = ArgumentCaptor.forClass(InMemoryBackendGroupFactoryContext.class); verify(backendConstructor).create(context.capture(), any(), any()); assertThat(context.getValue().getVisitor(TestGroupFactory.class)).isNotNull(); }