@Test(groups = "requiresTempFile") public void testCorrectConfigurationPrefix() { final String expectedPrefix = "expected"; final String otherPrefix = "additional"; final String propertySuffixToTest = ".db.connections.max"; final int expectedValue = 1234; // Required properties for construction Map<String, String> properties = createDefaultConfigurationProperties(expectedPrefix, temporaryFile.getAbsolutePath()); // Optional property added with two different prefixes, two different values properties.put(otherPrefix + propertySuffixToTest, Integer.toString(expectedValue + 5678)); properties.put(expectedPrefix + propertySuffixToTest, Integer.toString(expectedValue)); Injector injector = createInjector(properties, new H2EmbeddedDataSourceModule(expectedPrefix, MainBinding.class)); ObjectHolder objectHolder = injector.getInstance(ObjectHolder.class); // Make sure we picked up the value with the expected prefix assertInstanceOf(objectHolder.dataSource, H2EmbeddedDataSource.class); H2EmbeddedDataSource created = (H2EmbeddedDataSource) objectHolder.dataSource; assertEquals(created.getMaxConnections(), expectedValue, "Property value not loaded from correct prefix"); }
@Test(groups = "requiresTempFile") public void testCorrectConfigurationPrefix() { final String expectedPrefix = "expected"; final String otherPrefix = "additional"; final String propertySuffixToTest = ".db.connections.max"; final int expectedValue = 1234; // Required properties for construction Map<String, String> properties = createDefaultConfigurationProperties(expectedPrefix, temporaryFile.getAbsolutePath()); // Optional property added with two different prefixes, two different values properties.put(otherPrefix + propertySuffixToTest, Integer.toString(expectedValue + 5678)); properties.put(expectedPrefix + propertySuffixToTest, Integer.toString(expectedValue)); Injector injector = createInjector(properties, new H2EmbeddedDataSourceModule(expectedPrefix, MainBinding.class)); ObjectHolder objectHolder = injector.getInstance(ObjectHolder.class); // Make sure we picked up the value with the expected prefix assertInstanceOf(objectHolder.dataSource, H2EmbeddedDataSource.class); H2EmbeddedDataSource created = (H2EmbeddedDataSource) objectHolder.dataSource; assertEquals(created.getMaxConnections(), expectedValue, "Property value not loaded from correct prefix"); }