From 12789848edbb67a5dfedc9be1454c57d51a5c6af Mon Sep 17 00:00:00 2001 From: Junfu Chen Date: Tue, 28 Nov 2023 11:44:41 -0800 Subject: [PATCH] fix: pr comment --- .../java/com/aws/greengrass/detector/config/Config.java | 5 +++-- .../com/aws/greengrass/detector/config/ConfigTest.java | 9 +++++---- .../aws/greengrass/detector/detector/IpDetectorTest.java | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/aws/greengrass/detector/config/Config.java b/src/main/java/com/aws/greengrass/detector/config/Config.java index 9075856..3fe76ce 100644 --- a/src/main/java/com/aws/greengrass/detector/config/Config.java +++ b/src/main/java/com/aws/greengrass/detector/config/Config.java @@ -13,8 +13,9 @@ import com.aws.greengrass.util.Coerce; import lombok.Getter; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -33,7 +34,7 @@ public class Config { private AtomicBoolean includeIPv4LoopbackAddrs = new AtomicBoolean(DEFAULT_INCLUDE_IPV4_LOOPBACK_ADDRESSES); private AtomicBoolean includeIPv4LinkLocalAddrs = new AtomicBoolean(DEFAULT_INCLUDE_IPV4_LINK_LOCAL_ADDRESSES); @Getter - private final List excludedIPAddresses = new ArrayList<>(); + private final Set excludedIPAddresses = new HashSet<>(); /** * Config constructor. diff --git a/src/test/java/com/aws/greengrass/detector/config/ConfigTest.java b/src/test/java/com/aws/greengrass/detector/config/ConfigTest.java index 3b421f3..fc6be40 100644 --- a/src/test/java/com/aws/greengrass/detector/config/ConfigTest.java +++ b/src/test/java/com/aws/greengrass/detector/config/ConfigTest.java @@ -15,7 +15,7 @@ import org.mockito.Mockito; import org.mockito.stubbing.Answer; -import java.util.Collections; +import java.util.Arrays; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -39,8 +39,8 @@ public void GIVEN_config_topics_WHEN_initialize_THEN_configuration_created() { Topic excludedIpTopic = Mockito.mock(Topic.class); String mockIncludeIPv4LoopbackAddrsConfig = "true"; String mockIncludeIPv4LinkLocalAddrsConfig = "true"; - String mockExcludeIPsConfig = String.format("[%s]", TestConstants.IP_1); - List mockList = Collections.singletonList(TestConstants.IP_1); + String mockExcludeIPsConfig = String.format("[%s, %s]", TestConstants.IP_1, TestConstants.IP_2); + List mockList = Arrays.asList(TestConstants.IP_1, TestConstants.IP_2); int mockPortValue = 9000; // stub subscribe() to call just the callback method without adding watcher @@ -67,7 +67,8 @@ public void GIVEN_config_topics_WHEN_initialize_THEN_configuration_created() { assertEquals(mockPortValue, config.getDefaultPort()); assertEquals(Coerce.toBoolean(mockIncludeIPv4LoopbackAddrsConfig), config.isIncludeIPv4LoopbackAddrs()); assertEquals(Coerce.toBoolean(mockIncludeIPv4LinkLocalAddrsConfig), config.isIncludeIPv4LinkLocalAddrs()); - assertEquals(Coerce.toStringList(mockExcludeIPsConfig), config.getExcludedIPAddresses()); + assertEquals(config.getExcludedIPAddresses().size(), Coerce.toStringList(mockExcludeIPsConfig).size()); + assertTrue(config.getExcludedIPAddresses().containsAll(Coerce.toStringList(mockExcludeIPsConfig))); } @Test diff --git a/src/test/java/com/aws/greengrass/detector/detector/IpDetectorTest.java b/src/test/java/com/aws/greengrass/detector/detector/IpDetectorTest.java index 38acc52..442ca06 100644 --- a/src/test/java/com/aws/greengrass/detector/detector/IpDetectorTest.java +++ b/src/test/java/com/aws/greengrass/detector/detector/IpDetectorTest.java @@ -114,7 +114,7 @@ public void GIVEN_excludeIPAddresses_WHEN_get_ipAddresses_THEN_excludeIPs_filter // Exclude IPv4 Loopback addresses and Link-Local addresses Mockito.doReturn(true).when(config).isIncludeIPv4LoopbackAddrs(); Mockito.doReturn(true).when(config).isIncludeIPv4LinkLocalAddrs(); - Mockito.doReturn(Collections.singletonList(TestConstants.IP_1)).when(config).getExcludedIPAddresses(); + Mockito.doReturn(Collections.singleton(TestConstants.IP_1)).when(config).getExcludedIPAddresses(); networkInterfaces.add(networkInterface); Enumeration enumeration = Collections.enumeration(networkInterfaces);