From 53a553ebe667d72251af8d074f7c32888820f3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 21 Dec 2022 12:25:54 +0100 Subject: [PATCH] fix: non-independent unit tests because static state (#1670) --- .../dependent/DependentResourceConfigurationResolver.java | 6 ++++++ .../api/config/ControllerConfigurationOverriderTest.java | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java index 9a143fc57c..ebe8b2ad0e 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/DependentResourceConfigurationResolver.java @@ -147,6 +147,12 @@ public static void registerConverter(Class dependen knownConverters.put(converterClass, converter); } + /** To support independent unit tests */ + public static void clear() { + converters.clear(); + knownConverters.clear(); + } + private static class ConfiguredClassPair { private final Configured configured; private final Class annotatedClass; diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java index 98c071e942..7626d8bfd0 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ControllerConfigurationOverriderTest.java @@ -3,6 +3,7 @@ import java.util.Optional; import java.util.Set; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.ConfigMap; @@ -30,6 +31,12 @@ class ControllerConfigurationOverriderTest { private final BaseConfigurationService configurationService = new BaseConfigurationService(); + + @BeforeEach + void clearStaticState() { + DependentResourceConfigurationResolver.clear(); + } + @Test void overridingNSShouldPreserveUntouchedDependents() { var configuration = createConfiguration(new NamedDependentReconciler());