aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/at
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-16 13:31:53 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-05-16 13:31:53 +0200
commit4501468f1ffe1a8141e0c8711cd3cf78260df0c9 (patch)
treeb3a3f2fc25018fed85c8e5abdd942fa5007d5a4f /src/test/java/at
parentf193a2165d9261c2bd3413339c954a8bba829a93 (diff)
downloadmoa-zs-4501468f1ffe1a8141e0c8711cd3cf78260df0c9.tar.gz
moa-zs-4501468f1ffe1a8141e0c8711cd3cf78260df0c9.tar.bz2
moa-zs-4501468f1ffe1a8141e0c8711cd3cf78260df0c9.zip
Refactor: Merge Converter, Validator, and Merger into Util
- Reason: All three classes opertate with the same data type, have the same clients, and have the same reasons for change. - Makes code in client more readable as it reduces number of dependencies.
Diffstat (limited to 'src/test/java/at')
-rw-r--r--src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java37
-rw-r--r--src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java8
2 files changed, 17 insertions, 28 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java b/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java
index c0ff96c..95cccd1 100644
--- a/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java
+++ b/src/test/java/at/gv/egiz/moazs/ConfigProfileGeneratorTest.java
@@ -1,7 +1,6 @@
package at.gv.egiz.moazs;
import at.gv.egiz.moazs.preprocess.*;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -22,17 +21,11 @@ public class ConfigProfileGeneratorTest {
private static final String DEFAULT = "default";
@Mock
- private ConfigProfileMerger merger;
-
- @Mock
- private ConfigProfileValidator validator;
+ private ConfigUtil util;
@Mock
private SpringPropertiesFacade properties;
- @Mock
- private MapToConfigConverter converter;
-
@Test
public void assembleDefaultProfile() {
var propMap = Map.of(
@@ -43,7 +36,7 @@ public class ConfigProfileGeneratorTest {
var profiles = generator.generate();
- verify(converter).convert(Map.of(
+ verify(util).convert(Map.of(
"property-a", "value-a",
"property-b", "value-b",
"property-c", "value-c"));
@@ -57,7 +50,7 @@ public class ConfigProfileGeneratorTest {
var profiles = generator.generate();
- verifyZeroInteractions(converter);
+ verify(util, never()).convert(any());
assertThat(profiles.keySet()).isEmpty();
}
@@ -68,7 +61,7 @@ public class ConfigProfileGeneratorTest {
var profiles = generator.generate();
- verifyZeroInteractions(converter);
+ verify(util, never()).convert(any());
assertThat(profiles.keySet()).isEmpty();
}
@@ -84,9 +77,9 @@ public class ConfigProfileGeneratorTest {
var profiles = generator.generate();
- verify(converter).convert(Map.of("property-a", "value-a", "property-b", "value-b"));
- verify(converter).convert(Map.of("property-c", "value-c"));
- verify(converter).convert(Map.of("property-d", "value-d"));
+ verify(util).convert(Map.of("property-a", "value-a", "property-b", "value-b"));
+ verify(util).convert(Map.of("property-c", "value-c"));
+ verify(util).convert(Map.of("property-d", "value-d"));
assertThat(profiles.keySet()).containsExactlyInAnyOrder(DEFAULT, "profile-1", "profile-2");
}
@@ -94,7 +87,7 @@ public class ConfigProfileGeneratorTest {
public void cancelAtIncompleteDefaultProfile() {
var propMap = Map.of(PREFIX + "." + DEFAULT + ".property-a", "value-a");
var generator = setupMocksAndBuilder(propMap).build();
- when(validator.isComplete(any())).thenReturn(false);
+ when(util.isComplete(any())).thenReturn(false);
generator.generate();
}
@@ -103,7 +96,7 @@ public class ConfigProfileGeneratorTest {
public void continueAtIncompleteDefaultWhenVerificationDisabled() {
var propMap = Map.of(PREFIX + "." + DEFAULT + ".property-a", "value-a");
- when(validator.isComplete(any())).thenReturn(false);
+ when(util.isComplete(any())).thenReturn(false);
var generator = setupMocksAndBuilder(propMap)
.withVerifyCompletenessOfDefaultConfiguration(false)
@@ -111,22 +104,20 @@ public class ConfigProfileGeneratorTest {
var profiles = generator.generate();
- verify(converter).convert(Map.of("property-a", "value-a"));
+ verify(util).convert(Map.of("property-a", "value-a"));
assertThat(profiles.keySet()).containsExactlyInAnyOrder(DEFAULT);
}
private ConfigProfileGenerator.ConfigProfileGeneratorBuilder setupMocksAndBuilder(Map<String, String> propMap) {
when(properties.getPropertyNames()).thenReturn(propMap.keySet().stream());
when(properties.getProperty(any())).thenAnswer(i -> propMap.get(i.getArgument(0)));
- when(merger.merge(any(), any())).thenAnswer(i -> i.getArgument(0));
- when(validator.isComplete(any())).thenReturn(true);
- when(converter.convert(any())).thenReturn(configTypeBuilder().build());
+ when(util.merge(any(), any())).thenAnswer(i -> i.getArgument(0));
+ when(util.isComplete(any())).thenReturn(true);
+ when(util.convert(any())).thenReturn(configTypeBuilder().build());
return configProfileGeneratorBuilder()
.withProperties(properties)
- .withConverter(converter)
- .withValidator(validator)
- .withMerger(merger)
+ .withConfigUtil(util)
.withDefaultConfigKey(DEFAULT)
.withProfilePrefix(PREFIX)
.withVerifyCompletenessOfDefaultConfiguration(true);
diff --git a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
index 73313af..c389b61 100644
--- a/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
+++ b/src/test/java/at/gv/egiz/moazs/DeliveryRequestAugmenterTest.java
@@ -1,7 +1,6 @@
package at.gv.egiz.moazs;
-import at.gv.egiz.moazs.preprocess.ConfigProfileMerger;
-import at.gv.egiz.moazs.preprocess.ConfigProfileValidator;
+import at.gv.egiz.moazs.preprocess.ConfigUtil;
import at.gv.egiz.moazs.preprocess.DeliveryRequestAugmenter;
import at.gv.zustellung.app2mzs.xsd.ConfigType;
import at.gv.zustellung.app2mzs.xsd.DeliveryRequestType;
@@ -89,14 +88,13 @@ public class DeliveryRequestAugmenterTest {
}
private DeliveryRequestAugmenter createAugmenter(ConfigType fallback) {
- return new DeliveryRequestAugmenter(Map.of("default", fallback), new ConfigProfileMerger(), new ConfigProfileValidator());
+ return new DeliveryRequestAugmenter(Map.of("default", fallback), new ConfigUtil());
}
private DeliveryRequestAugmenter createAugmenter(Map<String, ConfigType> profiles) {
- return new DeliveryRequestAugmenter(profiles, new ConfigProfileMerger(), new ConfigProfileValidator());
+ return new DeliveryRequestAugmenter(profiles, new ConfigUtil());
}
-
private ConfigType createConfig(String url, Boolean performTnvz) {
return createConfig(url, performTnvz, null);
}