From a0621acf60f46f926c25a8550ea21383a8b6327e Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Fri, 25 Sep 2026 18:38:25 -0400 Subject: [PATCH] test(codepipeline): name the constraint the config stub proxy relies on (#4404) Follow-up to #4361. configWithPollInterval answers one key and assumes every other method returns a further config view, which it proxies in turn. That holds only while the constructor reads exactly one key: a second read returning a String or a primitive has no interface to proxy, and Proxy.newProxyInstance fails with "boolean is not an interface" some frames away from the method that actually could not be answered. The javadoc now states the assumption, and the handler checks it and names the offending method, so the failure points at what to add to the answers map rather than at the JDK. configStubNamesAnAccessorItCannotAnswer pins that message. It calls enabled(), which returns a primitive and is not in the answers map, so the surrounding views still proxy normally and the guard fires at the leaf. Removing the guard turns it red with the original IllegalArgumentException. SwfTimeoutSweeperTest.configWithInterval, which this stub was modelled on, carries the same constraint. Left alone here to keep the change focused. --- .../codepipeline/CodePipelineServiceTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineServiceTest.java index 2b848db10f..e9b0aded70 100644 --- a/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/codepipeline/CodePipelineServiceTest.java @@ -78,9 +78,31 @@ class CodePipelineServiceTest { } } + /** + * The guard above is unreachable while the constructor reads only the one key, so this is what + * keeps the message it produces from rotting. {@code enabled()} returns a primitive and is not + * in the answers map, which is exactly the shape that used to fail as "not an interface". + */ + @Test + void configStubNamesAnAccessorItCannotAnswer() { + EmulatorConfig stub = configWithPollInterval(500L); + + IllegalStateException thrown = assertThrows(IllegalStateException.class, + () -> stub.services().codepipeline().enabled()); + + assertTrue(thrown.getMessage().contains("enabled()"), thrown.getMessage()); + assertTrue(thrown.getMessage().contains("answers map"), thrown.getMessage()); + } + /** * Minimal {@link EmulatorConfig} view: the constructor reads only the source poll interval, so * a proxy answering that avoids standing up the Quarkus config container. + * + *

Anything not in the answers map is assumed to be a further config view and is proxied in + * turn. That assumption holds only while the constructor reads exactly one key. If a second read + * lands and it returns a {@code String} or a primitive there is no interface to proxy, so the + * handler says which method it could not answer instead of letting the JDK fail further down + * with "not an interface". */ private static EmulatorConfig configWithPollInterval(long intervalMs) { Map answers = Map.of("sourcePollIntervalMs", intervalMs); @@ -92,6 +114,11 @@ class CodePipelineServiceTest { if (answer != null) { return answer; } + if (!method.getReturnType().isInterface()) { + throw new IllegalStateException("cannot stub " + method.getName() + "(), which returns " + + method.getReturnType().getSimpleName() + + ": add it to the answers map in configWithPollInterval"); + } // services() and codepipeline() return further config views; proxy those too. return Proxy.newProxyInstance(method.getReturnType().getClassLoader(), new Class[] {method.getReturnType()}, this);