### Question:
PropertyLoader { public String getUniqueName() { return properties.getProperty(PropertyKey.DATA_SOURCE_UNIQUE_NAME.getKey()); } PropertyLoader();  PropertyLoader(Properties overridingProperties); String getUniqueName(); T getDataSource(); PoolAdapterFactory<T> getPoolAdapterFactory(); MetricsFactory getMetricsFactory(); ConnectionProxyFactory getConnectionProxyFactory(); Integer getMetricLogReporterMillis(); Boolean isJmxEnabled(); Boolean isJmxAutoStart(); MetricNamingStrategy getMetricNamingStrategy(); boolean isJndiLazyLookup(); @SuppressWarnings("unchecked") List<ConnectionAcquiringStrategyFactory<? extends ConnectionAcquiringStrategy, T>> getConnectionAcquiringStrategyFactories(); EventListenerResolver getEventListenerResolver(); Long getConnectionAcquireTimeThresholdMillis(); Long getConnectionLeaseTimeThresholdMillis(); static final String PROPERTIES_FILE_PATH; static final String PROPERTIES_FILE_NAME; }### Answer:
@Test public void testLoadPropertiesFromURLSystemProperty() { try { Properties properties = new Properties(); properties.put(PropertyLoader.PropertyKey.DATA_SOURCE_UNIQUE_NAME.getKey(), "jdbc/DS"); File propertiesFile = PropertiesTestUtils.setProperties(properties); try { System.setProperty(PropertyLoader.PROPERTIES_FILE_PATH, propertiesFile.toURI().toURL().toString()); PropertyLoader propertyLoader = new PropertyLoader(); assertEquals("jdbc/DS", propertyLoader.getUniqueName()); } finally { System.clearProperty(PropertyLoader.PROPERTIES_FILE_PATH); } } catch (IOException e) { fail("Can't save/load properties"); } }
@Test public void testLoadPropertiesFromFileSystemProperty() { try { Properties properties = new Properties(); properties.put(PropertyLoader.PropertyKey.DATA_SOURCE_UNIQUE_NAME.getKey(), "jdbc/DS"); File propertiesFile = PropertiesTestUtils.setProperties(properties); try { System.setProperty(PropertyLoader.PROPERTIES_FILE_PATH, propertiesFile.getAbsolutePath()); PropertyLoader propertyLoader = new PropertyLoader(); assertEquals("jdbc/DS", propertyLoader.getUniqueName()); } finally { System.clearProperty(PropertyLoader.PROPERTIES_FILE_PATH); } } catch (IOException e) { fail("Can't save/load properties"); } }
@Test public void testLoadPropertiesFromNestedClassPathSystemProperty() { try { Properties properties = new Properties(); properties.put(PropertyLoader.PropertyKey.DATA_SOURCE_UNIQUE_NAME.getKey(), "jdbc/DS"); File propertiesFile = PropertiesTestUtils.setProperties(properties); String resourceFolder = "nested"; File newFileFolder = new File(propertiesFile.getParentFile().getAbsolutePath() + "/" + resourceFolder); newFileFolder.mkdirs(); String resourceFile = "fp.properties"; File newFile = new File(newFileFolder, resourceFile); propertiesFile.renameTo(newFile); String resourcePath = resourceFolder + "/" + resourceFile; try { System.setProperty(PropertyLoader.PROPERTIES_FILE_PATH, resourcePath); PropertyLoader propertyLoader = new PropertyLoader(); assertEquals("jdbc/DS", propertyLoader.getUniqueName()); } finally { System.clearProperty(PropertyLoader.PROPERTIES_FILE_PATH); newFile.delete(); newFileFolder.delete(); } } catch (IOException e) { fail("Can't save/load properties"); } }
@Test public void testOverrideProperties() { try { Properties properties = new Properties(); properties.put(PropertyLoader.PropertyKey.DATA_SOURCE_UNIQUE_NAME.getKey(), "jdbc/DS"); File propertiesFile = PropertiesTestUtils.setProperties(properties); try { System.setProperty(PropertyLoader.PROPERTIES_FILE_PATH, propertiesFile.toURI().toURL().toString()); Properties overridingProperties = new Properties(); overridingProperties.setProperty( PropertyLoader.PropertyKey.DATA_SOURCE_UNIQUE_NAME.getKey(), "jta/DS" ); PropertyLoader propertyLoader = new PropertyLoader(overridingProperties); assertEquals("jta/DS", propertyLoader.getUniqueName()); } finally { System.clearProperty(PropertyLoader.PROPERTIES_FILE_PATH); } } catch (IOException e) { fail("Can't save/load properties"); } }