@Test public void testConfigurationThroughLegacyConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); LegacyConfigPresent legacyConfigPresent = injector.getInstance(LegacyConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'string-value' has been replaced. Use 'string-a' instead."); assertNotNull(legacyConfigPresent); assertEquals(legacyConfigPresent.getStringA(), "this is a"); assertEquals(legacyConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationWithPrefixThroughDeprecatedConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("example.string-a", "this is a"); properties.put("example.string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(DeprecatedConfigPresent.class, "example")); DeprecatedConfigPresent deprecatedConfigPresent = injector.getInstance(DeprecatedConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'example.string-a' is deprecated and should not be used"); assertNotNull(deprecatedConfigPresent); assertEquals(deprecatedConfigPresent.getStringA(), "this is a"); assertEquals(deprecatedConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationWithPrefixThroughLegacyConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("example.string-value", "this is a"); properties.put("example.string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class, "example")); LegacyConfigPresent legacyConfigPresent = injector.getInstance(LegacyConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'example.string-value' has been replaced. Use 'example.string-a' instead."); assertNotNull(legacyConfigPresent); assertEquals(legacyConfigPresent.getStringA(), "this is a"); assertEquals(legacyConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationWithPrefixThroughLegacyConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("example.string-value", "this is a"); properties.put("example.string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class, "example")); LegacyConfigPresent legacyConfigPresent = injector.getInstance(LegacyConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'example.string-value' has been replaced. Use 'example.string-a' instead."); assertNotNull(legacyConfigPresent); assertEquals(legacyConfigPresent.getStringA(), "this is a"); assertEquals(legacyConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationThroughDeprecatedConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(DeprecatedConfigPresent.class)); DeprecatedConfigPresent deprecatedConfigPresent = injector.getInstance(DeprecatedConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-a", "deprecated and should not be used"); Assert.assertNotNull(deprecatedConfigPresent); Assert.assertEquals(deprecatedConfigPresent.getStringA(), "this is a"); Assert.assertEquals(deprecatedConfigPresent.getStringB(), "this is b"); }
@Test public void testLegacyConfigOnNonDeprecatedSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigOnNonDeprecatedSetterClass.class, monitor); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Replaced @LegacyConfig method", "setValue(int)", "should be @Deprecated"); }
@Test public void testConfigurationWithRedundantLegacyConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); LegacyConfigPresent legacyConfigPresent = injector.getInstance(LegacyConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); Assert.assertNotNull(legacyConfigPresent); Assert.assertEquals(legacyConfigPresent.getStringA(), "this is a"); Assert.assertEquals(legacyConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationThroughDeprecatedConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(DeprecatedConfigPresent.class)); DeprecatedConfigPresent deprecatedConfigPresent = injector.getInstance(DeprecatedConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'string-a' is deprecated and should not be used"); assertNotNull(deprecatedConfigPresent); assertEquals(deprecatedConfigPresent.getStringA(), "this is a"); assertEquals(deprecatedConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationThroughLegacyConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); LegacyConfigPresent legacyConfigPresent = injector.getInstance(LegacyConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); Assert.assertNotNull(legacyConfigPresent); Assert.assertEquals(legacyConfigPresent.getStringA(), "this is a"); Assert.assertEquals(legacyConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationWithPrefixThroughDeprecatedConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("example.string-a", "this is a"); properties.put("example.string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(DeprecatedConfigPresent.class, "example")); DeprecatedConfigPresent deprecatedConfigPresent = injector.getInstance(DeprecatedConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'example.string-a' is deprecated and should not be used"); assertNotNull(deprecatedConfigPresent); assertEquals(deprecatedConfigPresent.getStringA(), "this is a"); assertEquals(deprecatedConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationThroughLegacyConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); LegacyConfigPresent legacyConfigPresent = injector.getInstance(LegacyConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'string-value' has been replaced. Use 'string-a' instead."); assertNotNull(legacyConfigPresent); assertEquals(legacyConfigPresent.getStringA(), "this is a"); assertEquals(legacyConfigPresent.getStringB(), "this is b"); }
@Test public void testConfigurationThroughDeprecatedConfig() { Map<String, String> properties = new TreeMap<>(); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); Injector injector = createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(DeprecatedConfigPresent.class)); DeprecatedConfigPresent deprecatedConfigPresent = injector.getInstance(DeprecatedConfigPresent.class); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration property 'string-a' is deprecated and should not be used"); assertNotNull(deprecatedConfigPresent); assertEquals(deprecatedConfigPresent.getStringA(), "this is a"); assertEquals(deprecatedConfigPresent.getStringB(), "this is b"); }
@Test public void testLegacyConfigOnNonDeprecatedSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigOnNonDeprecatedSetterClass.class, monitor); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Replaced @LegacyConfig method", "setValue(int)", "should be @Deprecated"); }
@Test public void testLegacyConfigOnNonDeprecatedSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigOnNonDeprecatedSetterClass.class, monitor); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Replaced @LegacyConfig method", "setValue(int)", "should be @Deprecated"); }
@Test public void testConfigurationWithConflictingLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is the old value"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); Assert.fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); Assertions.assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a") ; } }
@Test public void testConfigurationWithConflictingLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is the old value"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a"); } }
@Test public void testConfigurationWithRedundantLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a"); } }
@Test public void testConfigurationWithConflictingLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is the old value"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); fail("Expected an exception in object creation due to conflicting configuration"); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a"); } }
@Test public void testConfigurationWithRedundantLegacyConfigThrows() { Map<String, String> properties = new TreeMap<>(); properties.put("string-value", "this is a"); properties.put("string-a", "this is a"); properties.put("string-b", "this is b"); TestMonitor monitor = new TestMonitor(); try { createInjector(properties, monitor, binder -> configBinder(binder).bindConfig(LegacyConfigPresent.class)); } catch (CreationException e) { monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("string-value", "replaced", "Use 'string-a'"); assertContainsAllOf(e.getMessage(), "string-value", "conflicts with property", "string-a"); } }