From dde0dde86b739f5e21c8d5abbc1997ed7944602d Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Thu, 7 Dec 2023 10:29:05 +0100 Subject: [PATCH] chore(format): spotless apply --- .../java/io/getunleash/DefaultUnleash.java | 20 ++++++++++---- src/main/java/io/getunleash/FakeUnleash.java | 3 ++- .../java/io/getunleash/strategy/Strategy.java | 7 +++-- .../io/getunleash/variant/VariantUtil.java | 13 +++++----- src/test/java/io/getunleash/UnleashTest.java | 13 +++++----- .../getunleash/variant/VariantUtilTest.java | 26 +++++++++---------- 6 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/main/java/io/getunleash/DefaultUnleash.java b/src/main/java/io/getunleash/DefaultUnleash.java index 58547125c..7480ec1e9 100644 --- a/src/main/java/io/getunleash/DefaultUnleash.java +++ b/src/main/java/io/getunleash/DefaultUnleash.java @@ -221,14 +221,16 @@ private FeatureEvaluationResult getFeatureEvaluationResult( /** * Uses the old, statistically broken Variant seed for finding the correct variant + * * @deprecated * @param toggleName Name of the toggle * @param context The UnleashContext * @param fallbackAction What to do if we fail to find the toggle * @param defaultVariant If we can't resolve a variant, what are we returning - * @return A wrapper containing whether the feature was enabled as well which Variant was selected + * @return A wrapper containing whether the feature was enabled as well which Variant was + * selected */ - private FeatureEvaluationResult deprecatedGetFeatureEvaluationResult( + private FeatureEvaluationResult deprecatedGetFeatureEvaluationResult( String toggleName, UnleashContext context, BiPredicate fallbackAction, @@ -244,7 +246,9 @@ private FeatureEvaluationResult deprecatedGetFeatureEvaluationResult( return new FeatureEvaluationResult(false, defaultVariant); } else if (featureToggle.getStrategies().isEmpty()) { return new FeatureEvaluationResult( - true, VariantUtil.selectDeprecatedVariantHashingAlgo(featureToggle, context, defaultVariant)); + true, + VariantUtil.selectDeprecatedVariantHashingAlgo( + featureToggle, context, defaultVariant)); } else { // Dependent toggles, no point in evaluating child strategies if our dependencies are // not satisfied @@ -388,6 +392,7 @@ public Variant getVariant(String toggleName, Variant defaultValue) { /** * Uses the old, statistically broken Variant seed for finding the correct variant + * * @deprecated * @param toggleName * @param context @@ -400,6 +405,7 @@ public Variant deprecatedGetVariant(String toggleName, UnleashContext context) { /** * Uses the old, statistically broken Variant seed for finding the correct variant + * * @deprecated * @param toggleName * @param context @@ -407,14 +413,16 @@ public Variant deprecatedGetVariant(String toggleName, UnleashContext context) { * @return */ @Override - public Variant deprecatedGetVariant(String toggleName, UnleashContext context, Variant defaultValue) { + public Variant deprecatedGetVariant( + String toggleName, UnleashContext context, Variant defaultValue) { return deprecatedGetVariant(toggleName, context, defaultValue, false); } private Variant deprecatedGetVariant( String toggleName, UnleashContext context, Variant defaultValue, boolean isParent) { FeatureEvaluationResult result = - deprecatedGetFeatureEvaluationResult(toggleName, context, (n, c) -> false, defaultValue); + deprecatedGetFeatureEvaluationResult( + toggleName, context, (n, c) -> false, defaultValue); Variant variant = result.getVariant(); if (!isParent) { metricService.countVariant(toggleName, variant.getName()); @@ -428,6 +436,7 @@ private Variant deprecatedGetVariant( /** * Uses the old, statistically broken Variant seed for finding the correct variant + * * @deprecated * @param toggleName * @return @@ -439,6 +448,7 @@ public Variant deprecatedGetVariant(String toggleName) { /** * Uses the old, statistically broken Variant seed for finding the correct variant + * * @deprecated * @param toggleName * @param defaultValue diff --git a/src/main/java/io/getunleash/FakeUnleash.java b/src/main/java/io/getunleash/FakeUnleash.java index 7c414b633..11b5bf425 100644 --- a/src/main/java/io/getunleash/FakeUnleash.java +++ b/src/main/java/io/getunleash/FakeUnleash.java @@ -112,7 +112,8 @@ public Variant deprecatedGetVariant(String toggleName, UnleashContext context) { } @Override - public Variant deprecatedGetVariant(String toggleName, UnleashContext context, Variant defaultValue) { + public Variant deprecatedGetVariant( + String toggleName, UnleashContext context, Variant defaultValue) { return null; } diff --git a/src/main/java/io/getunleash/strategy/Strategy.java b/src/main/java/io/getunleash/strategy/Strategy.java index 7a1272b5b..fe940303b 100644 --- a/src/main/java/io/getunleash/strategy/Strategy.java +++ b/src/main/java/io/getunleash/strategy/Strategy.java @@ -26,9 +26,9 @@ default FeatureEvaluationResult getResult( enabled ? VariantUtil.selectVariant(parameters, variants, unleashContext) : null); } - /** * Uses the old pre 9.0.0 way of hashing for finding the Variant to return + * * @deprecated * @param parameters * @param unleashContext @@ -44,7 +44,10 @@ default FeatureEvaluationResult getDeprecatedHashingAlgoResult( boolean enabled = isEnabled(parameters, unleashContext, constraints); return new FeatureEvaluationResult( enabled, - enabled ? VariantUtil.selectDeprecatedVariantHashingAlgo(parameters, variants, unleashContext) : null); + enabled + ? VariantUtil.selectDeprecatedVariantHashingAlgo( + parameters, variants, unleashContext) + : null); } default boolean isEnabled(Map parameters, UnleashContext unleashContext) { diff --git a/src/main/java/io/getunleash/variant/VariantUtil.java b/src/main/java/io/getunleash/variant/VariantUtil.java index 4bc22acc1..4e3796bf7 100644 --- a/src/main/java/io/getunleash/variant/VariantUtil.java +++ b/src/main/java/io/getunleash/variant/VariantUtil.java @@ -136,6 +136,7 @@ public static Variant selectVariant( /** * Uses the old pre 9.0.0 way of hashing for finding the Variant to return + * * @deprecated * @param parameters * @param variants @@ -186,6 +187,7 @@ public static Variant selectVariant( /** * Uses the old pre 9.0.0 way of hashing for finding the Variant to return + * * @deprecated * @param featureToggle * @param context @@ -193,17 +195,16 @@ public static Variant selectVariant( * @return */ public static @Nullable Variant selectDeprecatedVariantHashingAlgo( - FeatureToggle featureToggle, UnleashContext context, Variant defaultVariant - ) { + FeatureToggle featureToggle, UnleashContext context, Variant defaultVariant) { if (featureToggle == null) { return defaultVariant; } Variant variant = - selectDeprecatedVariantHashingAlgo( - Collections.singletonMap("groupId", featureToggle.getName()), - featureToggle.getVariants(), - context); + selectDeprecatedVariantHashingAlgo( + Collections.singletonMap("groupId", featureToggle.getName()), + featureToggle.getVariants(), + context); return variant != null ? variant : defaultVariant; } diff --git a/src/test/java/io/getunleash/UnleashTest.java b/src/test/java/io/getunleash/UnleashTest.java index 3db7636f8..f80c976bc 100644 --- a/src/test/java/io/getunleash/UnleashTest.java +++ b/src/test/java/io/getunleash/UnleashTest.java @@ -431,8 +431,6 @@ public void get_default_variant_without_context() { assertThat(result.isEnabled()).isTrue(); } - - @Test public void get_first_variant_with_context_provider() { @@ -490,7 +488,8 @@ public void get_second_variant_with_context_provider_and_deprecated_algorithm() params.put("userIds", "123, 5, 121"); ActivationStrategy strategy = new ActivationStrategy("userWithId", params); FeatureToggle featureToggle = - new FeatureToggle("test", true, asList(strategy), getTestVariantsForDeprecatedHash()); + new FeatureToggle( + "test", true, asList(strategy), getTestVariantsForDeprecatedHash()); when(toggleRepository.getToggle("test")).thenReturn(featureToggle); @@ -506,7 +505,6 @@ public void get_second_variant_with_context_provider_and_deprecated_algorithm() assertThat(newHash.getName()).isEqualTo("to"); assertThat(newHash.getPayload().map(Payload::getValue).get()).isEqualTo("to"); assertThat(newHash.isEnabled()).isTrue(); - } @Test @@ -640,8 +638,9 @@ private List getTestVariants() { private List getTestVariantsForDeprecatedHash() { return asList( - new VariantDefinition("en", 65, new Payload("string", "en"), Collections.emptyList()), - new VariantDefinition("to", 35, new Payload("string", "to"), Collections.emptyList()) - ); + new VariantDefinition( + "en", 65, new Payload("string", "en"), Collections.emptyList()), + new VariantDefinition( + "to", 35, new Payload("string", "to"), Collections.emptyList())); } } diff --git a/src/test/java/io/getunleash/variant/VariantUtilTest.java b/src/test/java/io/getunleash/variant/VariantUtilTest.java index a551984e3..16325169f 100644 --- a/src/test/java/io/getunleash/variant/VariantUtilTest.java +++ b/src/test/java/io/getunleash/variant/VariantUtilTest.java @@ -391,27 +391,27 @@ public void feature_variants_variant_d_client_spec_tests() { public void feature_variants_variant_d_client_spec_tests_with_deprecated_seed() { List variants = new ArrayList<>(); variants.add( - new VariantDefinition( - "variant1", 1, new Payload("string", "val1"), Collections.emptyList())); + new VariantDefinition( + "variant1", 1, new Payload("string", "val1"), Collections.emptyList())); variants.add( - new VariantDefinition( - "variant2", 49, new Payload("string", "val2"), Collections.emptyList())); + new VariantDefinition( + "variant2", 49, new Payload("string", "val2"), Collections.emptyList())); variants.add( - new VariantDefinition( - "variant3", 50, new Payload("string", "val3"), Collections.emptyList())); + new VariantDefinition( + "variant3", 50, new Payload("string", "val3"), Collections.emptyList())); FeatureToggle toggle = - new FeatureToggle("Feature.Variants.D", true, Collections.emptyList(), variants); + new FeatureToggle("Feature.Variants.D", true, Collections.emptyList(), variants); Variant variantUser712 = - VariantUtil.selectDeprecatedVariantHashingAlgo( - toggle, UnleashContext.builder().userId("712").build(), DISABLED_VARIANT); + VariantUtil.selectDeprecatedVariantHashingAlgo( + toggle, UnleashContext.builder().userId("712").build(), DISABLED_VARIANT); assertThat(variantUser712.getName()).isEqualTo("variant3"); Variant variantUser525 = - VariantUtil.selectDeprecatedVariantHashingAlgo( - toggle, UnleashContext.builder().userId("525").build(), DISABLED_VARIANT); + VariantUtil.selectDeprecatedVariantHashingAlgo( + toggle, UnleashContext.builder().userId("525").build(), DISABLED_VARIANT); assertThat(variantUser525.getName()).isEqualTo("variant3"); Variant variantUser537 = - VariantUtil.selectDeprecatedVariantHashingAlgo( - toggle, UnleashContext.builder().userId("537").build(), DISABLED_VARIANT); + VariantUtil.selectDeprecatedVariantHashingAlgo( + toggle, UnleashContext.builder().userId("537").build(), DISABLED_VARIANT); assertThat(variantUser537.getName()).isEqualTo("variant2"); }