update number 5
This commit is contained in:
@@ -377,6 +377,122 @@ class HeuristicCallGraphEnginePolymorphicTest {
|
||||
.containsExactlyInAnyOrder("CustomEvents.ALPHA", "CustomEvents.BETA");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolvePolymorphicEventsThroughNestedConverters() 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) {
|
||||
// NESTED CONVERTERS
|
||||
service.handleEvent(verify(sanitize(domainEvent.type())));
|
||||
}
|
||||
|
||||
private CustomEvents sanitize(CustomEvents e) { return e; }
|
||||
private CustomEvents verify(CustomEvents e) { return e; }
|
||||
}
|
||||
|
||||
class HandlerService {
|
||||
public void handleEvent(CustomEvents event) {}
|
||||
}
|
||||
|
||||
interface Payload {
|
||||
CustomEvents type();
|
||||
}
|
||||
|
||||
class AlphaPayload implements Payload {
|
||||
public CustomEvents type() { return CustomEvents.ALPHA; }
|
||||
}
|
||||
|
||||
enum CustomEvents { ALPHA, BETA }
|
||||
""";
|
||||
Path tempDir = Files.createTempDirectory("callgraph_test_poly_nested");
|
||||
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));
|
||||
System.out.println("DEBUG context.getImplementations(Payload) = " + context.getImplementations("Payload"));
|
||||
System.out.println("DEBUG context.getImplementations(com.example.Payload) = " + context.getImplementations("com.example.Payload"));
|
||||
System.out.println("DEBUG getPolymorphicEvents() = " + chains.get(0).getTriggerPoint().getPolymorphicEvents());
|
||||
assertThat(chains).hasSize(1);
|
||||
assertThat(chains.get(0).getTriggerPoint().getPolymorphicEvents())
|
||||
.containsExactly("CustomEvents.ALPHA");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolvePolymorphicEventsWithCustomGetterSuffixes() 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) {
|
||||
// Using .event() instead of .getEvent()
|
||||
service.handleEvent(check(domainEvent.event()));
|
||||
}
|
||||
|
||||
private CustomEvents check(CustomEvents e) { return e; }
|
||||
}
|
||||
|
||||
class HandlerService {
|
||||
public void handleEvent(CustomEvents event) {}
|
||||
}
|
||||
|
||||
interface Payload {
|
||||
CustomEvents event();
|
||||
}
|
||||
|
||||
class BetaPayload implements Payload {
|
||||
public CustomEvents event() { return CustomEvents.BETA; }
|
||||
}
|
||||
|
||||
enum CustomEvents { ALPHA, BETA }
|
||||
""";
|
||||
Path tempDir = Files.createTempDirectory("callgraph_test_poly_suffix");
|
||||
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);
|
||||
assertThat(chains.get(0).getTriggerPoint().getPolymorphicEvents())
|
||||
.containsExactly("CustomEvents.BETA");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveMappedTransitionEnumThroughAbstractBaseClassAndMultipleArgs() throws IOException {
|
||||
String source = """
|
||||
|
||||
Reference in New Issue
Block a user