diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-09 21:30:41 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-09 21:30:41 +0200 |
commit | 36b085c8f9a1b5ac7f113799ceb29c4058b63077 (patch) | |
tree | c7c5cb113aef3b80660957322bd3ea114206742e /config-model/src | |
parent | a6eb5bd18f651603a2bb72a02d2e6190439f8060 (diff) |
Use static create methods instead of having many public constructor only used for testing.
Diffstat (limited to 'config-model/src')
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java | 23 | ||||
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java | 10 |
2 files changed, 20 insertions, 13 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java index 39e9617b12c..dac1f1ed15a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModelFactory.java @@ -75,18 +75,13 @@ public class VespaModelFactory implements ModelFactory { } // For testing only - public VespaModelFactory(ConfigModelRegistry configModelRegistry) { - this(configModelRegistry, Clock.systemUTC()); - } - - // For testing only - public VespaModelFactory(ConfigModelRegistry configModelRegistry, Clock clock) { + protected VespaModelFactory(ConfigModelRegistry configModelRegistry) { this(new Version(VespaVersion.major, VespaVersion.minor, VespaVersion.micro), configModelRegistry, - clock, Zone.defaultZone()); + Clock.systemUTC(), Zone.defaultZone()); } // For testing only - public VespaModelFactory(Version version, ConfigModelRegistry configModelRegistry, Clock clock, Zone zone) { + private VespaModelFactory(Version version, ConfigModelRegistry configModelRegistry, Clock clock, Zone zone) { this.version = version; if (configModelRegistry == null) { this.configModelRegistry = new NullConfigModelRegistry(); @@ -100,6 +95,18 @@ public class VespaModelFactory implements ModelFactory { this.clock = clock; } + public static VespaModelFactory createTestFactory() { + return createTestFactory(new NullConfigModelRegistry(), Clock.systemUTC()); + } + public static VespaModelFactory createTestFactory(ConfigModelRegistry configModelRegistry, Clock clock) { + return createTestFactory(new Version(VespaVersion.major, VespaVersion.minor, VespaVersion.micro), configModelRegistry, + clock, Zone.defaultZone()); + } + + public static VespaModelFactory createTestFactory(Version version, ConfigModelRegistry configModelRegistry, Clock clock, Zone zone) { + return new VespaModelFactory(version, configModelRegistry, clock, zone); + } + /** Returns the version this model is build for */ @Override public Version version() { return version; } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java b/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java index bff90080115..104fdea0e40 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/VespaModelFactoryTest.java @@ -44,7 +44,7 @@ public class VespaModelFactoryTest { @Test public void testThatFactoryCanBuildModel() { - VespaModelFactory modelFactory = new VespaModelFactory(new NullConfigModelRegistry()); + VespaModelFactory modelFactory = VespaModelFactory.createTestFactory(); Model model = modelFactory.createModel(testModelContext); assertNotNull(model); assertTrue(model instanceof VespaModel); @@ -53,20 +53,20 @@ public class VespaModelFactoryTest { // Uses an application package that throws IllegalArgumentException when validating @Test(expected = IllegalArgumentException.class) public void testThatFactoryModelValidationFailsWithIllegalArgumentException() { - VespaModelFactory modelFactory = new VespaModelFactory(new NullConfigModelRegistry()); + VespaModelFactory modelFactory = VespaModelFactory.createTestFactory(); modelFactory.createAndValidateModel(new MockModelContext(createApplicationPackageThatFailsWhenValidating()), new ValidationParameters()); } // Uses a MockApplicationPackage that throws throws UnsupportedOperationException (rethrown as RuntimeException) when validating @Test(expected = RuntimeException.class) public void testThatFactoryModelValidationFails() { - VespaModelFactory modelFactory = new VespaModelFactory(new NullConfigModelRegistry()); + VespaModelFactory modelFactory = VespaModelFactory.createTestFactory(); modelFactory.createAndValidateModel(testModelContext, new ValidationParameters()); } @Test public void testThatFactoryModelValidationCanBeIgnored() { - VespaModelFactory modelFactory = new VespaModelFactory(new NullConfigModelRegistry()); + VespaModelFactory modelFactory = VespaModelFactory.createTestFactory(); ModelCreateResult createResult = modelFactory.createAndValidateModel( new MockModelContext(createApplicationPackageThatFailsWhenValidating()), new ValidationParameters(ValidationParameters.IgnoreValidationErrors.TRUE)); @@ -118,7 +118,7 @@ public class VespaModelFactoryTest { }; ModelContext modelContext = createMockModelContext(hosts, services, provisionerToOverride); - Model model = new VespaModelFactory(new NullConfigModelRegistry()).createModel(modelContext); + Model model = VespaModelFactory.createTestFactory().createModel(modelContext); List<HostInfo> allocatedHosts = new ArrayList<>(model.getHosts()); assertEquals(1, allocatedHosts.size()); |