From 4501468f1ffe1a8141e0c8711cd3cf78260df0c9 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Thu, 16 May 2019 13:31:53 +0200 Subject: 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. --- .../gv/egiz/moazs/ConfigProfileGeneratorTest.java | 37 ++++++++-------------- .../egiz/moazs/DeliveryRequestAugmenterTest.java | 8 ++--- 2 files changed, 17 insertions(+), 28 deletions(-) (limited to 'src/test/java/at/gv/egiz') 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 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 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); } -- cgit v1.2.3