update number 4
This commit is contained in:
@@ -313,6 +313,70 @@ class HeuristicCallGraphEnginePolymorphicTest {
|
||||
org.assertj.core.api.Assertions.assertThat(chains.get(0).getTriggerPoint().getPolymorphicEvents()).contains("POST_ACCEPTANCE_REJECTED");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolvePolymorphicEventsThroughAssertSupportedMethod() throws IOException {
|
||||
String source = """
|
||||
package com.example;
|
||||
public class Dispatcher {
|
||||
private HandlerService service;
|
||||
public void dispatchRequest(Payload domainEvent) {
|
||||
doDispatch(domainEvent);
|
||||
}
|
||||
|
||||
private void doDispatch(Payload domainEvent) {
|
||||
service.handleEvent(checkAndMapEvent(domainEvent.getType()));
|
||||
}
|
||||
|
||||
private CustomEvents checkAndMapEvent(CustomEvents e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
class HandlerService {
|
||||
public void handleEvent(CustomEvents event) {}
|
||||
}
|
||||
|
||||
interface Payload {
|
||||
CustomEvents getType();
|
||||
}
|
||||
|
||||
class AlphaPayload implements Payload {
|
||||
public CustomEvents getType() { return CustomEvents.ALPHA; }
|
||||
}
|
||||
|
||||
class BetaPayload implements Payload {
|
||||
public CustomEvents getType() { return CustomEvents.BETA; }
|
||||
}
|
||||
|
||||
enum CustomEvents { ALPHA, BETA }
|
||||
""";
|
||||
Path tempDir = Files.createTempDirectory("callgraph_test_poly_assert");
|
||||
Files.writeString(tempDir.resolve("DispatcherConfig.java"), source);
|
||||
|
||||
CodebaseContext context = new CodebaseContext();
|
||||
context.scan(tempDir);
|
||||
|
||||
HeuristicCallGraphEngine builder = new HeuristicCallGraphEngine(context);
|
||||
|
||||
EntryPoint entryPoint = EntryPoint.builder()
|
||||
.className("com.example.Dispatcher")
|
||||
.methodName("dispatchRequest")
|
||||
.build();
|
||||
|
||||
TriggerPoint trigger = TriggerPoint.builder()
|
||||
.className("com.example.HandlerService")
|
||||
.methodName("handleEvent")
|
||||
.event("event")
|
||||
.build();
|
||||
|
||||
List<CallChain> chains = builder.findChains(List.of(entryPoint), List.of(trigger));
|
||||
|
||||
assertThat(chains).hasSize(1);
|
||||
CallChain chain = chains.get(0);
|
||||
assertThat(chain.getTriggerPoint().getPolymorphicEvents())
|
||||
.containsExactlyInAnyOrder("CustomEvents.ALPHA", "CustomEvents.BETA");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveMappedTransitionEnumThroughAbstractBaseClassAndMultipleArgs() throws IOException {
|
||||
String source = """
|
||||
|
||||
Reference in New Issue
Block a user