String k = keys.next();
if (k.startsWith(key + ".")) {
k = k.substring(key.length() + 1);
- String subkey = k.substring(0, k.indexOf("."));
+ String subkey = k.substring(0, k.indexOf('.'));
if (!map.containsKey(subkey)) {
map.put(subkey, get(tenantId, namespace, key + "." + subkey, clazz));
}
while (k.contains(".")) {
if (k.contains(".")) {
- String subkey = k.substring(0, k.indexOf("."));
- k = k.substring(k.indexOf(".") + 1);
+ String subkey = k.substring(0, k.indexOf('.'));
+ k = k.substring(k.indexOf('.') + 1);
if (!map.containsKey(subkey)) {
- map.put(subkey, map = new HashMap<>());
+ Map tmp = new HashMap();
+ map.put(subkey, tmp);
+ map = tmp;
} else {
map = (Map) map.get(subkey);
}
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
@Test
public void testShouldLocateResourceWhenNodeConfigPropertyIsSet2() {
+ final String path = new File(sampleResourcePath).getParentFile().getPath();
+ Map<String, String> properties = Collections.singletonMap(NODE_CONFIG_LOCATION, path);
- Map<String, String> properties = Collections.singletonMap(
- NODE_CONFIG_LOCATION, new File(sampleResourcePath).getParentFile().getPath());
-
- NonConfigResource testedNonConfigResource = new NonConfigResource(properties::get);
- System.getProperties().setProperty(NODE_CONFIG_LOCATION,
- new File(sampleResourcePath).getParentFile().getPath());
+ NonConfigResource testedNonConfigResource = new NonConfigResource(properties::get);
Path thisFilePath = testedNonConfigResource.locate(RESOURCE_NAME);
- assertEquals(0, thisFilePath.compareTo(new File(sampleResourcePath).toPath()));
+
+ NonConfigResource systemNonConfigResource = new NonConfigResource(System.getProperties()::getProperty);
+ System.setProperty(NODE_CONFIG_LOCATION, path);
+ Path systemFilePath = systemNonConfigResource.locate(RESOURCE_NAME);
+
+ Path testFilePath = sampleResourceFile.toPath();
+ assertEquals(0, thisFilePath.compareTo(testFilePath));
+ assertEquals(0, systemFilePath.compareTo(testFilePath));
}
@Test
@Test
public void testShouldNotLocateResource2() {
- Map<String, String> properties = Collections.emptyMap();
+ String badResource = "noexistingresource";
+ String badPath = "noexistingpath";
+
+ Map<String, String> properties = new HashMap<>();
NonConfigResource testedObject = new NonConfigResource(properties::get);
- Path thisFilePath = testedObject.locate("nonexistingresource");
+ // empty properties and bad resource
+ Path thisFilePath = testedObject.locate(badResource);
+
+ properties.put(NODE_CONFIG_LOCATION, badPath);
+ // bad path in properties and bad resource
+ Path thisFilePath2 = testedObject.locate(badResource);
+
assertNull(thisFilePath);
+ assertNull(thisFilePath2);
}
}
\ No newline at end of file