Enhance in-memory store factories for tests

This commit is contained in:
René Pfeuffer
2019-06-19 10:14:29 +02:00
parent fae3de7b6c
commit d43ad44da9
6 changed files with 32 additions and 37 deletions

View File

@@ -1,28 +1,23 @@
package sonia.scm.store;
import java.util.HashMap;
import java.util.Map;
public class InMemoryConfigurationEntryStoreFactory implements ConfigurationEntryStoreFactory {
private final Map<String, InMemoryConfigurationEntryStore> stores = new HashMap<>();
private ConfigurationEntryStore store;
public static ConfigurationEntryStoreFactory create() {
return new InMemoryConfigurationEntryStoreFactory(new InMemoryConfigurationEntryStore());
}
public InMemoryConfigurationEntryStoreFactory() {
}
public InMemoryConfigurationEntryStoreFactory(ConfigurationEntryStore store) {
this.store = store;
public static InMemoryConfigurationEntryStoreFactory create() {
return new InMemoryConfigurationEntryStoreFactory();
}
@Override
public <T> ConfigurationEntryStore<T> getStore(TypedStoreParameters<T> storeParameters) {
if (store != null) {
return store;
}
return new InMemoryConfigurationEntryStore<>();
String name = storeParameters.getName();
return get(name);
}
public InMemoryConfigurationEntryStore get(String name) {
return stores.computeIfAbsent(name, x -> new InMemoryConfigurationEntryStore());
}
}

View File

@@ -35,6 +35,9 @@ package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
import java.util.HashMap;
import java.util.Map;
/**
* In memory configuration store factory for testing purposes.
*
@@ -44,24 +47,19 @@ package sonia.scm.store;
*/
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
private ConfigurationStore store;
private final Map<String, InMemoryConfigurationStore> stores = new HashMap<>();
public static ConfigurationStoreFactory create() {
return new InMemoryConfigurationStoreFactory(new InMemoryConfigurationStore());
}
public InMemoryConfigurationStoreFactory() {
}
public InMemoryConfigurationStoreFactory(ConfigurationStore store) {
this.store = store;
public static InMemoryConfigurationStoreFactory create() {
return new InMemoryConfigurationStoreFactory();
}
@Override
public ConfigurationStore getStore(TypedStoreParameters storeParameters) {
if (store != null) {
return store;
}
return new InMemoryConfigurationStore<>();
String name = storeParameters.getName();
return get(name);
}
public ConfigurationStore get(String name) {
return stores.computeIfAbsent(name, x -> new InMemoryConfigurationStore());
}
}