mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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.
This commit is contained in:
1 parent
6f75f68aea
commit
a0621acf60
1 file changed
+27
+27
@@ -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.
|
||||
*
|
||||
* <p>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<String, Object> 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);
|
||||
|
||||
Reference in new issue
Block a user