From 71ed14f930289bfb2f41b7e27e09b2afd417f97e Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Thu, 30 Nov 2023 15:52:21 +0100 Subject: [PATCH] fix: use gradle artifact from MAVEN_HOME --- pom.xml | 6 +- .../java/io/getunleash/strategy/Strategy.java | 2 - .../io/getunleash/strategy/StrategyUtils.java | 1 - .../ApplicationHostnameStrategyTest.java | 79 +++++---- .../strategy/FlexibleRolloutStrategyTest.java | 165 +++++++++--------- .../GradualRolloutRandomStrategyTest.java | 103 +++++------ .../GradualRolloutSessionIdStrategyTest.java | 125 ++++++------- .../GradualRolloutUserIdStrategyTest.java | 129 +++++++------- .../strategy/RemoteAddressStrategyTest.java | 45 ++--- .../io/getunleash/strategy/StrategyTest.java | 107 +++++++----- .../strategy/StrategyUtilsTest.java | 4 +- .../strategy/UserWithIdStrategyTest.java | 116 ++++++------ 12 files changed, 447 insertions(+), 435 deletions(-) diff --git a/pom.xml b/pom.xml index a6c3dcb09..af1db9973 100644 --- a/pom.xml +++ b/pom.xml @@ -56,11 +56,9 @@ - unleash-engine + yggdrasil-engine io.getunleash - system - 0.0.1-SNAPSHOT - ${project.basedir}/unleash-engine-all.jar + 0.1.0-SNAPSHOT com.google.code.gson diff --git a/src/main/java/io/getunleash/strategy/Strategy.java b/src/main/java/io/getunleash/strategy/Strategy.java index 8e1760d88..9c2f0d753 100644 --- a/src/main/java/io/getunleash/strategy/Strategy.java +++ b/src/main/java/io/getunleash/strategy/Strategy.java @@ -1,7 +1,6 @@ package io.getunleash.strategy; import io.getunleash.UnleashContext; - import java.util.Map; public interface Strategy { @@ -13,5 +12,4 @@ public interface Strategy { default boolean isEnabled(Map parameters, UnleashContext unleashContext) { return isEnabled(parameters); } - } diff --git a/src/main/java/io/getunleash/strategy/StrategyUtils.java b/src/main/java/io/getunleash/strategy/StrategyUtils.java index fe418e163..d5c630b5f 100644 --- a/src/main/java/io/getunleash/strategy/StrategyUtils.java +++ b/src/main/java/io/getunleash/strategy/StrategyUtils.java @@ -18,5 +18,4 @@ public static int getNormalizedNumber(String identifier, String groupId, long se long hash = Murmur3.hash_x86_32(value, value.length, seed); return (int) (hash % ONE_HUNDRED) + 1; } - } diff --git a/src/test/java/io/getunleash/strategy/ApplicationHostnameStrategyTest.java b/src/test/java/io/getunleash/strategy/ApplicationHostnameStrategyTest.java index 5e75bdea5..4e3f463ca 100644 --- a/src/test/java/io/getunleash/strategy/ApplicationHostnameStrategyTest.java +++ b/src/test/java/io/getunleash/strategy/ApplicationHostnameStrategyTest.java @@ -1,5 +1,9 @@ package io.getunleash.strategy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + import com.google.common.collect.ImmutableList; import io.getunleash.ActivationStrategy; import io.getunleash.DefaultUnleash; @@ -7,18 +11,13 @@ import io.getunleash.repository.UnleashEngineStateHandler; import io.getunleash.util.UnleashConfig; import io.getunleash.util.UnleashScheduledExecutor; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import java.net.InetAddress; import java.net.UnknownHostException; import java.util.HashMap; import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ApplicationHostnameStrategyTest { @@ -28,13 +27,12 @@ public class ApplicationHostnameStrategyTest { @BeforeEach void init() { UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .build(); engine = new DefaultUnleash(config); stateHandler = new UnleashEngineStateHandler(engine); @@ -50,11 +48,11 @@ public void should_be_disabled_if_no_HostNames_in_params() { Map params = new HashMap<>(); params.put("hostNames", null); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("applicationHostname", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("applicationHostname", params)))); assertFalse(engine.isEnabled("test")); } @@ -63,11 +61,11 @@ public void should_be_disabled_if_hostname_not_in_list() { Map params = new HashMap<>(); params.put("hostNames", "MegaHost,MiniHost, happyHost"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("applicationHostname", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("applicationHostname", params)))); assertFalse(engine.isEnabled("test")); } @@ -79,11 +77,11 @@ public void so_close_but_no_cigar() { Map params = new HashMap<>(); params.put("hostNames", "MegaHost, MiniHost, SuperhostOne"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("applicationHostname", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("applicationHostname", params)))); assertFalse(engine.isEnabled("test")); } @@ -94,21 +92,22 @@ public void should_be_enabled_for_InetAddress() throws UnknownHostException { Map params = new HashMap<>(); params.put("hostNames", "MegaHost," + hostName + ",MiniHost, happyHost"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("applicationHostname", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("applicationHostname", params)))); assertTrue(engine.isEnabled("test")); } @Test public void null_test() { - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("applicationHostname", new HashMap<>())) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("applicationHostname", new HashMap<>())))); assertFalse(engine.isEnabled("test")); } } diff --git a/src/test/java/io/getunleash/strategy/FlexibleRolloutStrategyTest.java b/src/test/java/io/getunleash/strategy/FlexibleRolloutStrategyTest.java index 8c804314c..8fd698b16 100644 --- a/src/test/java/io/getunleash/strategy/FlexibleRolloutStrategyTest.java +++ b/src/test/java/io/getunleash/strategy/FlexibleRolloutStrategyTest.java @@ -1,21 +1,20 @@ package io.getunleash.strategy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + import com.google.common.collect.ImmutableList; import io.getunleash.*; import io.getunleash.repository.UnleashEngineStateHandler; import io.getunleash.util.UnleashConfig; import io.getunleash.util.UnleashScheduledExecutor; +import java.util.HashMap; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; - class FlexibleRolloutStrategyTest { private DefaultUnleash engine; @@ -24,13 +23,12 @@ class FlexibleRolloutStrategyTest { @BeforeEach void init() { UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .build(); engine = new DefaultUnleash(config); stateHandler = new UnleashEngineStateHandler(engine); @@ -38,11 +36,12 @@ void init() { @Test public void should_always_be_false() { - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", new HashMap<>())) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("flexibleRollout", new HashMap<>())))); assertFalse(engine.isEnabled("test")); } @@ -54,11 +53,11 @@ public void should_NOT_be_enabled_for_rollout_9_and_userId_61() { params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().userId("61").build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertFalse(engine.isEnabled("test", context)); } @@ -70,11 +69,11 @@ public void should_be_enabled_for_rollout_10_and_userId_61() { params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().userId("61").build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertTrue(engine.isEnabled("test", context)); } @@ -86,11 +85,11 @@ public void should_be_enabled_for_rollout_10_and_userId_61_and_stickiness_userId params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().userId("61").build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertTrue(engine.isEnabled("test", context)); } @@ -102,11 +101,11 @@ public void should_be_disabled_when_userId_missing() { params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertFalse(engine.isEnabled("test", context)); } @@ -118,11 +117,11 @@ public void should_be_enabled_for_rollout_10_and_sessionId_61() { params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().sessionId("61").build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertTrue(engine.isEnabled("test", context)); } @@ -134,16 +133,18 @@ public void should_be_enabled_for_rollout_10_and_randomId_61_and_stickiness_sess params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().sessionId("61").build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertTrue(engine.isEnabled("test", context)); } @Test - @Disabled // TODO we can't inject a random generator into the strategy it can be done providing a custom strategy though in which case we should keep the strategy classes around but it can't override the existing flexibleRollout + @Disabled // TODO we can't inject a random generator into the strategy it can be done providing + // a custom strategy though in which case we should keep the strategy classes around + // but it can't override the existing flexibleRollout public void should_be_enabled_for_rollout_10_and_randomId_61_and_stickiness_default() { Map params = new HashMap<>(); params.put("rollout", "10"); @@ -151,16 +152,18 @@ public void should_be_enabled_for_rollout_10_and_randomId_61_and_stickiness_defa params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertTrue(engine.isEnabled("test", context)); } @Test - @Disabled // TODO we can't inject a random generator into the strategy it can be done providing a custom strategy though in which case we should keep the strategy classes around but it can't override the existing flexibleRollout + @Disabled // TODO we can't inject a random generator into the strategy it can be done providing + // a custom strategy though in which case we should keep the strategy classes around + // but it can't override the existing flexibleRollout public void should_be_enabled_for_rollout_10_and_randomId_61_and_stickiness_random() { Map params = new HashMap<>(); params.put("rollout", "10"); @@ -168,11 +171,11 @@ public void should_be_enabled_for_rollout_10_and_randomId_61_and_stickiness_rand params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertTrue(engine.isEnabled("test", context)); } @@ -184,11 +187,11 @@ public void should_NOT_be_enabled_for_rollout_10_and_randomId_1() { params.put("groupId", "Demo"); UnleashContext context = UnleashContext.builder().build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertFalse(engine.isEnabled("test", context)); } @@ -200,11 +203,11 @@ public void should_not_be_enabled_for_custom_field_402() { params.put("groupId", "Feature.flexible.rollout.custom.stickiness_50"); UnleashContext context = UnleashContext.builder().addProperty("customField", "402").build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertFalse(engine.isEnabled("test", context)); } @@ -215,11 +218,11 @@ public void should_not_be_enabled_for_custom_field_388_and_39() { params.put("stickiness", "customField"); params.put("groupId", "Feature.flexible.rollout.custom.stickiness_50"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); UnleashContext context = UnleashContext.builder().addProperty("customField", "388").build(); assertTrue(engine.isEnabled("test", context)); @@ -234,11 +237,11 @@ public void should_not_be_enabled_with_custom_stickiness_if_custom_field_is_miss params.put("stickiness", "customField"); params.put("groupId", "Feature.flexible.rollout.custom.stickiness_50"); UnleashContext context = UnleashContext.builder().build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("flexibleRollout", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("flexibleRollout", params)))); assertFalse(engine.isEnabled("test", context)); } } diff --git a/src/test/java/io/getunleash/strategy/GradualRolloutRandomStrategyTest.java b/src/test/java/io/getunleash/strategy/GradualRolloutRandomStrategyTest.java index 78ea9aeb7..6b655e9ee 100644 --- a/src/test/java/io/getunleash/strategy/GradualRolloutRandomStrategyTest.java +++ b/src/test/java/io/getunleash/strategy/GradualRolloutRandomStrategyTest.java @@ -1,21 +1,19 @@ package io.getunleash.strategy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + import com.google.common.collect.ImmutableList; import io.getunleash.*; import io.getunleash.repository.UnleashEngineStateHandler; import io.getunleash.util.UnleashConfig; import io.getunleash.util.UnleashScheduledExecutor; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import java.util.Collections; import java.util.HashMap; import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public final class GradualRolloutRandomStrategyTest { private DefaultUnleash engine; @@ -24,13 +22,12 @@ public final class GradualRolloutRandomStrategyTest { @BeforeEach void setUp() { UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .build(); engine = new DefaultUnleash(config); stateHandler = new UnleashEngineStateHandler(engine); @@ -40,11 +37,12 @@ void setUp() { public void should_not_be_enabled_when_percentage_not_set() { final Map parameters = new HashMap<>(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutRandom", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutRandom", parameters)))); final boolean enabled = engine.isEnabled("test"); assertFalse(enabled); @@ -59,12 +57,13 @@ public void should_not_be_enabled_when_percentage_is_not_a_not_a_number() { } }; - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutRandom", parameters)), - Collections.emptyList() - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutRandom", parameters)), + Collections.emptyList())); final boolean enabled = engine.isEnabled("test"); assertFalse(enabled); @@ -79,12 +78,13 @@ public void should_not_be_enabled_when_percentage_is_not_a_not_a_valid_percentag } }; - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutRandom", parameters)), - Collections.emptyList() - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutRandom", parameters)), + Collections.emptyList())); final boolean enabled = engine.isEnabled("test"); assertFalse(enabled); @@ -99,12 +99,13 @@ public void should_never_be_enabled_when_0_percent() { } }; - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutRandom", parameters)), - Collections.emptyList() - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutRandom", parameters)), + Collections.emptyList())); for (int i = 0; i < 1000; i++) { final boolean enabled = engine.isEnabled("test"); @@ -121,12 +122,13 @@ public void should_always_be_enabled_when_100_percent() { } }; - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutRandom", parameters)), - Collections.emptyList() - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutRandom", parameters)), + Collections.emptyList())); for (int i = 0; i <= 100; i++) { final boolean enabled = engine.isEnabled("test"); assertTrue(enabled, "Should be enabled for p=" + i); @@ -149,12 +151,13 @@ public void should_diverage_at_most_with_one_percent_point() { int rounds = 20000; int countEnabled = 0; - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutRandom", parameters)), - Collections.emptyList() - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutRandom", parameters)), + Collections.emptyList())); for (int i = 0; i < rounds; i++) { final boolean enabled = engine.isEnabled("test"); if (enabled) { diff --git a/src/test/java/io/getunleash/strategy/GradualRolloutSessionIdStrategyTest.java b/src/test/java/io/getunleash/strategy/GradualRolloutSessionIdStrategyTest.java index 2a322628d..461f1cc86 100644 --- a/src/test/java/io/getunleash/strategy/GradualRolloutSessionIdStrategyTest.java +++ b/src/test/java/io/getunleash/strategy/GradualRolloutSessionIdStrategyTest.java @@ -4,19 +4,16 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import io.getunleash.*; - +import io.getunleash.repository.UnleashEngineStateHandler; +import io.getunleash.util.UnleashConfig; +import io.getunleash.util.UnleashScheduledExecutor; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; - -import io.getunleash.repository.UnleashEngineStateHandler; -import io.getunleash.util.UnleashConfig; -import io.getunleash.util.UnleashScheduledExecutor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -35,26 +32,25 @@ public class GradualRolloutSessionIdStrategyTest { @BeforeEach void setUp() { percentages = - ImmutableList.builder() - .add(1) - .add(2) - .add(5) - .add(10) - .add(25) - .add(50) - .add(90) - .add(99) - .add(100) - .build(); + ImmutableList.builder() + .add(1) + .add(2) + .add(5) + .add(10) + .add(25) + .add(50) + .add(90) + .add(99) + .add(100) + .build(); UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .build(); engine = new DefaultUnleash(config); stateHandler = new UnleashEngineStateHandler(engine); @@ -62,22 +58,26 @@ void setUp() { @Test public void should_require_context() { - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutSessionId", new HashMap<>())) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "gradualRolloutSessionId", new HashMap<>())))); assertThat(engine.isEnabled("test")).isFalse(); } @Test public void should_be_disabled_when_missing_user_id() { UnleashContext context = UnleashContext.builder().build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutSessionId", new HashMap<>())) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "gradualRolloutSessionId", new HashMap<>())))); assertThat(engine.isEnabled("test", context)).isFalse(); } @@ -86,11 +86,12 @@ public void should_have_same_result_for_multiple_executions() { UnleashContext context = UnleashContext.builder().sessionId("1574576830").build(); Map params = buildParams(1, "innfinn"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutSessionId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutSessionId", params)))); boolean firstRunResult = engine.isEnabled("test", context); for (int i = 0; i < 10; i++) { @@ -106,11 +107,12 @@ public void should_be_enabled_when_using_100percent_rollout() { UnleashContext context = UnleashContext.builder().sessionId("1574576830").build(); Map params = buildParams(100, "innfinn"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutSessionId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutSessionId", params)))); boolean result = engine.isEnabled("test", context); assertThat(result).isTrue(); @@ -121,11 +123,12 @@ public void should_not_be_enabled_when_0percent_rollout() { UnleashContext context = UnleashContext.builder().sessionId("1574576830").build(); Map params = buildParams(0, "innfinn"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutSessionId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutSessionId", params)))); boolean actual = engine.isEnabled("test", context); assertFalse(actual, "should not be enabled when 0% rollout"); @@ -139,15 +142,15 @@ public void should_be_enabled_above_minimum_percentage() { UnleashContext context = UnleashContext.builder().sessionId(sessionId).build(); - for (int p = minimumPercentage; p <= 100; p++) { Map params = buildParams(p, groupId); // Ok, we're going to stress the setting the state - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutSessionId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutSessionId", params)))); boolean actual = engine.isEnabled("test", context); assertTrue(actual, "should be enabled when " + p + "% rollout"); } @@ -181,13 +184,13 @@ protected int checkRandomLoginIDs(int numberOfIDs, int percentage) { UnleashContext context = UnleashContext.builder().sessionId(sessionId.toString()).build(); - Map params = buildParams(percentage, ""); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutSessionId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutSessionId", params)))); boolean enabled = engine.isEnabled("test", context); if (enabled) { numberOfEnabledUsers++; diff --git a/src/test/java/io/getunleash/strategy/GradualRolloutUserIdStrategyTest.java b/src/test/java/io/getunleash/strategy/GradualRolloutUserIdStrategyTest.java index 95978a53a..ef4734653 100644 --- a/src/test/java/io/getunleash/strategy/GradualRolloutUserIdStrategyTest.java +++ b/src/test/java/io/getunleash/strategy/GradualRolloutUserIdStrategyTest.java @@ -4,19 +4,16 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import io.getunleash.*; - +import io.getunleash.repository.UnleashEngineStateHandler; +import io.getunleash.util.UnleashConfig; +import io.getunleash.util.UnleashScheduledExecutor; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; - -import io.getunleash.repository.UnleashEngineStateHandler; -import io.getunleash.util.UnleashConfig; -import io.getunleash.util.UnleashScheduledExecutor; import org.assertj.core.data.Offset; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -36,26 +33,25 @@ public class GradualRolloutUserIdStrategyTest { @BeforeEach public void init() { percentages = - ImmutableList.builder() - .add(1) - .add(2) - .add(5) - .add(10) - .add(25) - .add(50) - .add(90) - .add(99) - .add(100) - .build(); + ImmutableList.builder() + .add(1) + .add(2) + .add(5) + .add(10) + .add(25) + .add(50) + .add(90) + .add(99) + .add(100) + .build(); UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .build(); engine = new DefaultUnleash(config); stateHandler = new UnleashEngineStateHandler(engine); @@ -63,11 +59,12 @@ public void init() { @Test public void should_require_context() { - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", new HashMap<>())) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutUserId", new HashMap<>())))); assertThat(engine.isEnabled("test")).isFalse(); } @@ -75,11 +72,12 @@ public void should_require_context() { public void should_be_disabled_when_missing_user_id() { UnleashContext context = UnleashContext.builder().build(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", new HashMap<>())) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutUserId", new HashMap<>())))); assertThat(engine.isEnabled("test", context)).isFalse(); } @@ -88,11 +86,11 @@ public void should_have_same_result_for_multiple_executions() { UnleashContext context = UnleashContext.builder().userId("1574576830").build(); Map params = buildParams(1, "innfinn"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)))); boolean firstRunResult = engine.isEnabled("test", context); for (int i = 0; i < 10; i++) { @@ -106,11 +104,11 @@ public void should_be_enabled_when_using_100percent_rollout() { UnleashContext context = UnleashContext.builder().userId("1574576830").build(); Map params = buildParams(100, "innfinn"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)))); boolean result = engine.isEnabled("test", context); assertThat(result).isTrue(); @@ -121,11 +119,11 @@ public void should_not_be_enabled_when_0percent_rollout() { UnleashContext context = UnleashContext.builder().userId("1574576830").build(); Map params = buildParams(0, "innfinn"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)))); boolean actual = engine.isEnabled("test", context); assertFalse(actual, "should not be enabled when 0% rollout"); } @@ -139,11 +137,12 @@ public void should_be_enabled_above_minimum_percentage() { UnleashContext context = UnleashContext.builder().userId(userId).build(); for (int p = minimumPercentage; p <= 100; p++) { Map params = buildParams(p, groupId); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutUserId", params)))); boolean actual = engine.isEnabled("test", context); assertTrue(actual, "should be enabled when " + p + "% rollout"); } @@ -158,11 +157,11 @@ public void should_at_most_miss_with_one_percent_when_rolling_out_to_specified_p Map params = buildParams(percentage, groupId); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)))); for (int userId = 0; userId < rounds; userId++) { UnleashContext context = UnleashContext.builder().userId("user" + userId).build(); @@ -204,13 +203,13 @@ protected int checkRandomLoginIDs(int numberOfIDs, int percentage) { Long userId = getRandomLoginId(); UnleashContext context = UnleashContext.builder().userId(userId.toString()).build(); - Map params = buildParams(percentage, ""); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("gradualRolloutUserId", params)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("gradualRolloutUserId", params)))); boolean enabled = engine.isEnabled("test", context); if (enabled) { numberOfEnabledUsers++; diff --git a/src/test/java/io/getunleash/strategy/RemoteAddressStrategyTest.java b/src/test/java/io/getunleash/strategy/RemoteAddressStrategyTest.java index 739212e22..b9d4993d2 100644 --- a/src/test/java/io/getunleash/strategy/RemoteAddressStrategyTest.java +++ b/src/test/java/io/getunleash/strategy/RemoteAddressStrategyTest.java @@ -1,21 +1,20 @@ package io.getunleash.strategy; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import com.google.common.collect.ImmutableList; import io.getunleash.*; import io.getunleash.repository.UnleashEngineStateHandler; import io.getunleash.util.UnleashConfig; import io.getunleash.util.UnleashScheduledExecutor; +import java.util.*; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.util.*; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - class RemoteAddressStrategyTest { private static final String FIRST_IPV4 = "127.0.0.1"; private static final String SECOND_IPV4 = "10.0.0.1"; @@ -74,27 +73,29 @@ static Stream data() { @MethodSource("data") void test_all_combinations(String actualIp, String parameterString, boolean expected) { UnleashContextProvider contextProvider = mock(UnleashContextProvider.class); - when(contextProvider.getContext()).thenReturn(UnleashContext.builder().remoteAddress(actualIp).build()); + when(contextProvider.getContext()) + .thenReturn(UnleashContext.builder().remoteAddress(actualIp).build()); UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .unleashContextProvider(contextProvider) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .unleashContextProvider(contextProvider) + .build(); Map parameters = setupParameterMap(parameterString); DefaultUnleash engine = new DefaultUnleash(config); - new UnleashEngineStateHandler(engine).setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("remoteAddress", parameters)), - Collections.emptyList() - )); + new UnleashEngineStateHandler(engine) + .setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy("remoteAddress", parameters)), + Collections.emptyList())); assertThat(engine.isEnabled("test")).isEqualTo(expected); } diff --git a/src/test/java/io/getunleash/strategy/StrategyTest.java b/src/test/java/io/getunleash/strategy/StrategyTest.java index 1693be3e0..5fcba2b00 100644 --- a/src/test/java/io/getunleash/strategy/StrategyTest.java +++ b/src/test/java/io/getunleash/strategy/StrategyTest.java @@ -6,16 +6,14 @@ import com.google.common.collect.ImmutableList; import io.getunleash.*; - +import io.getunleash.repository.UnleashEngineStateHandler; +import io.getunleash.util.UnleashConfig; +import io.getunleash.util.UnleashScheduledExecutor; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; - -import io.getunleash.repository.UnleashEngineStateHandler; -import io.getunleash.util.UnleashConfig; -import io.getunleash.util.UnleashScheduledExecutor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,14 +40,13 @@ void init() { when(contextProvider.getContext()).thenReturn(UnleashContext.builder().build()); UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .unleashContextProvider(contextProvider) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .unleashContextProvider(contextProvider) + .build(); engine = new DefaultUnleash(config, new AlwaysEnabled()); stateHandler = new UnleashEngineStateHandler(engine); @@ -60,11 +57,13 @@ public void should_be_enabled_for_empty_constraints() { Map parameters = new HashMap(); UnleashContext context = UnleashContext.builder().build(); List constraints = new ArrayList<>(); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("enabled", parameters, constraints, null, null)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "enabled", parameters, constraints, null, null)))); boolean result = engine.isEnabled("test", context); assertTrue(result); @@ -76,11 +75,13 @@ public void should_be_enabled_for_null_constraints() { UnleashContext context = UnleashContext.builder().build(); List constraints = null; - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("enabled", parameters, constraints, null, null)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "enabled", parameters, constraints, null, null)))); boolean result = engine.isEnabled("test", context); assertTrue(result); @@ -93,11 +94,13 @@ public void should_be_disabled_when_constraint_not_satisfied() { List constraints = new ArrayList<>(); constraints.add(new Constraint("environment", Operator.IN, Arrays.asList("prod"))); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("enabled", parameters, constraints, null, null)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "enabled", parameters, constraints, null, null)))); boolean result = engine.isEnabled("test", context); assertFalse(result); @@ -110,11 +113,13 @@ public void should_be_enabled_when_constraint_is_satisfied() { List constraints = new ArrayList<>(); constraints.add(new Constraint("environment", Operator.IN, Arrays.asList("test", "prod"))); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("enabled", parameters, constraints, null, null)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "enabled", parameters, constraints, null, null)))); boolean result = engine.isEnabled("test", context); assertTrue(result); @@ -127,11 +132,13 @@ public void should_be_enabled_when_constraint_NOT_IN_satisfied() { List constraints = new ArrayList<>(); constraints.add(new Constraint("environment", Operator.NOT_IN, Arrays.asList("prod"))); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("enabled", parameters, constraints, null, null)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "enabled", parameters, constraints, null, null)))); boolean result = engine.isEnabled("test", context); assertTrue(result); @@ -151,11 +158,13 @@ public void should_be_enabled_when_all_constraints_are_satisfied() { constraints.add(new Constraint("userId", Operator.IN, Arrays.asList("123"))); constraints.add(new Constraint("customerId", Operator.IN, Arrays.asList("red", "blue"))); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("enabled", parameters, constraints, null, null)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "enabled", parameters, constraints, null, null)))); boolean result = engine.isEnabled("test", context); assertTrue(result); @@ -175,11 +184,13 @@ public void should_be_disabled_when_not_all_constraints_are_satisfied() { constraints.add(new Constraint("userId", Operator.IN, Arrays.asList("123"))); constraints.add(new Constraint("customerId", Operator.IN, Arrays.asList("red", "blue"))); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("enabled", parameters, constraints, null, null)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of( + new ActivationStrategy( + "enabled", parameters, constraints, null, null)))); boolean result = engine.isEnabled("test", context); assertFalse(result); diff --git a/src/test/java/io/getunleash/strategy/StrategyUtilsTest.java b/src/test/java/io/getunleash/strategy/StrategyUtilsTest.java index c9f788877..a9135dbc0 100644 --- a/src/test/java/io/getunleash/strategy/StrategyUtilsTest.java +++ b/src/test/java/io/getunleash/strategy/StrategyUtilsTest.java @@ -1,9 +1,9 @@ package io.getunleash.strategy; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; + public class StrategyUtilsTest { @Test diff --git a/src/test/java/io/getunleash/strategy/UserWithIdStrategyTest.java b/src/test/java/io/getunleash/strategy/UserWithIdStrategyTest.java index 422b5c327..096d17f0c 100644 --- a/src/test/java/io/getunleash/strategy/UserWithIdStrategyTest.java +++ b/src/test/java/io/getunleash/strategy/UserWithIdStrategyTest.java @@ -1,5 +1,9 @@ package io.getunleash.strategy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + import com.google.common.collect.ImmutableList; import io.getunleash.ActivationStrategy; import io.getunleash.DefaultUnleash; @@ -8,15 +12,10 @@ import io.getunleash.repository.UnleashEngineStateHandler; import io.getunleash.util.UnleashConfig; import io.getunleash.util.UnleashScheduledExecutor; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - import java.util.HashMap; import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.mock; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class UserWithIdStrategyTest { private DefaultUnleash engine; @@ -25,13 +24,12 @@ public class UserWithIdStrategyTest { @BeforeEach void setup() { UnleashConfig config = - new UnleashConfig.Builder() - .appName("test") - .unleashAPI("http://localhost:4242/api/") - .environment("test") - .scheduledExecutor(mock(UnleashScheduledExecutor.class)) - .build(); - + new UnleashConfig.Builder() + .appName("test") + .unleashAPI("http://localhost:4242/api/") + .environment("test") + .scheduledExecutor(mock(UnleashScheduledExecutor.class)) + .build(); engine = new DefaultUnleash(config); stateHandler = new UnleashEngineStateHandler(engine); @@ -44,11 +42,11 @@ public void should_match_one_userId() { UnleashContext context = UnleashContext.builder().userId("123").build(); parameters.put("userIds", "123"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertTrue(engine.isEnabled("test", context)); } @@ -58,11 +56,11 @@ public void should_match_first_userId_in_list() { UnleashContext context = UnleashContext.builder().userId("123").build(); parameters.put("userIds", "123, 122, 121"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertTrue(engine.isEnabled("test", context)); } @@ -72,11 +70,11 @@ public void should_match_middle_userId_in_list() { UnleashContext context = UnleashContext.builder().userId("123").build(); parameters.put("userIds", "123, 122, 121"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertTrue(engine.isEnabled("test", context)); } @@ -86,11 +84,11 @@ public void should_match_last_userId_in_list() { UnleashContext context = UnleashContext.builder().userId("123").build(); parameters.put("userIds", "123, 122, 121"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertTrue(engine.isEnabled("test", context)); } @@ -100,11 +98,11 @@ public void should_not_match_subparts_of_ids() { UnleashContext context = UnleashContext.builder().userId("12").build(); parameters.put("userIds", "123, 122, 121, 212"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertFalse(engine.isEnabled("test", context)); } @@ -114,11 +112,11 @@ public void should_not_match_csv_without_space() { UnleashContext context = UnleashContext.builder().userId("123").build(); parameters.put("userIds", "123,122,121"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertTrue(engine.isEnabled("test", context)); } @@ -130,11 +128,11 @@ public void should_match_real_ids() { parameters.put( "userIds", "160118738, 1823311338, 1422637466, 2125981185, 298261117, 1829486714, 463568019, 271166598"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertTrue(engine.isEnabled("test", context)); } @@ -146,11 +144,11 @@ public void should_not_match_real_ids() { parameters.put( "userIds", "160118738, 1823311338, 1422637466, 2125981185, 298261117, 1829486714, 463568019, 271166598"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertFalse(engine.isEnabled("test", context)); } @@ -159,11 +157,11 @@ public void should_not_be_enabled_without_id() { Map parameters = new HashMap<>(); parameters.put("userIds", "160118738, 1823311338"); - stateHandler.setState(new FeatureToggle( - "test", - true, - ImmutableList.of(new ActivationStrategy("userWithId", parameters)) - )); + stateHandler.setState( + new FeatureToggle( + "test", + true, + ImmutableList.of(new ActivationStrategy("userWithId", parameters)))); assertFalse(engine.isEnabled("test")); } }