mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-06-15 19:41:17 +02:00
Enhance in-memory store factories for tests
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user