Using java7 syntax for Map and Set

This commit is contained in:
m.raheem 2020-01-23 21:42:44 +02:00
parent cc283b4233
commit 5b245cde28
2 changed files with 22 additions and 8 deletions

View File

@ -1,6 +1,9 @@
package com.baeldung.boot.configurationproperties; package com.baeldung.boot.configurationproperties;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -20,13 +23,17 @@ public class BindingPropertiesToUserDefinedPOJOUnitTest {
assertEquals("node1", serverConfig.getName()); assertEquals("node1", serverConfig.getName());
assertEquals(Set.of("img1.jpg", "img2.jpg"), Set<String> expectedImgs = new HashSet<>();
serverConfig.getImgIds()); expectedImgs.add("img1.jpg");
expectedImgs.add("img2.jpg");
assertEquals(expectedImgs, serverConfig.getImgIds());
assertEquals("192.168.0.1", serverConfig.getAddress().getIp()); assertEquals("192.168.0.1", serverConfig.getAddress().getIp());
assertEquals(8099, serverConfig.getAddress().getPort()); assertEquals(8099, serverConfig.getAddress().getPort());
assertEquals(Map.of("imgs", "/root/imgs", "html", "/root/html"), Map<String, String> expectedDirs = new HashMap<>();
serverConfig.getDirs()); expectedDirs.put("imgs", "/root/imgs");
expectedDirs.put("html", "/root/html");
assertEquals(expectedDirs, serverConfig.getDirs());
} }
} }

View File

@ -1,6 +1,9 @@
package com.baeldung.boot.configurationproperties; package com.baeldung.boot.configurationproperties;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -18,13 +21,17 @@ public class BindingYMLPropertiesUnitTest {
assertEquals("node2", serverConfig.getName()); assertEquals("node2", serverConfig.getName());
assertEquals(Set.of("img1.png", "img2.png"), Set<String> expectedImgs = new HashSet<>();
serverConfig.getImgIds()); expectedImgs.add("img1.png");
expectedImgs.add("img2.png");
assertEquals(expectedImgs, serverConfig.getImgIds());
assertEquals("192.168.0.2", serverConfig.getAddress().getIp()); assertEquals("192.168.0.2", serverConfig.getAddress().getIp());
assertEquals(5000, serverConfig.getAddress().getPort()); assertEquals(5000, serverConfig.getAddress().getPort());
assertEquals(Map.of("imgs", "/etc/imgs", "html", "/etc/html"), Map<String, String> expectedDirs = new HashMap<>();
serverConfig.getDirs()); expectedDirs.put("imgs", "/etc/imgs");
expectedDirs.put("html", "/etc/html");
assertEquals(expectedDirs, serverConfig.getDirs());
} }
} }