use of org.springframework.core.env.AbstractEnvironment in project Gaffer by gchq.
the class FactoryConfigTest method shouldUsePropertiesFromEnvironmentToSetUpUserFactory.
@Test
public void shouldUsePropertiesFromEnvironmentToSetUpUserFactory() throws InstantiationException, IllegalAccessException {
// Given
FactoryConfig factoryConfig = new FactoryConfig();
AbstractEnvironment mockEnv = mock(AbstractEnvironment.class);
Properties properties = new Properties();
properties.setProperty(USER_FACTORY_CLASS, MockUserFactory.class.getName());
MockPropertySource mockPropertySource = new MockPropertySource(properties);
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(mockPropertySource);
when(mockEnv.getPropertySources()).thenReturn(propertySources);
when(mockEnv.getProperty(USER_FACTORY_CLASS)).then(invocation -> mockPropertySource.getProperty(invocation.getArgumentAt(0, String.class)));
// called by spring normally
factoryConfig.setEnvironment(mockEnv);
// When
// Called by spring
factoryConfig.setToSystemProperties();
// Then
assertEquals(MockUserFactory.class, factoryConfig.createUserFactory().getClass());
}
Aggregations