from ai two
This commit is contained in:
@@ -66,4 +66,59 @@ class BuilderLocalVariableTest {
|
||||
assertThat(chain.getTriggerPoint().getPolymorphicEvents())
|
||||
.containsExactlyInAnyOrder("OrderEvents.PAY");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTraceFluentBuilder(@TempDir Path tempDir) throws IOException {
|
||||
String source = """
|
||||
package com.example;
|
||||
public class MyController {
|
||||
private MyService service;
|
||||
public void processEvent() {
|
||||
MyEvent event = MyEvent.builder().type(MyEnum.STATE_2).build();
|
||||
service.process(event.getType());
|
||||
}
|
||||
}
|
||||
|
||||
class MyService {
|
||||
public void process(MyEnum event) {}
|
||||
}
|
||||
|
||||
class MyEvent {
|
||||
private MyEnum type;
|
||||
public static Builder builder() { return new Builder(); }
|
||||
public MyEnum getType() { return type; }
|
||||
public static class Builder {
|
||||
private MyEnum type;
|
||||
public Builder type(MyEnum type) { this.type = type; return this; }
|
||||
public MyEvent build() { return new MyEvent(); }
|
||||
}
|
||||
}
|
||||
|
||||
enum MyEnum { STATE_1, STATE_2 }
|
||||
""";
|
||||
Files.writeString(tempDir.resolve("MyConfig.java"), source);
|
||||
|
||||
CodebaseContext context = new CodebaseContext();
|
||||
context.scan(tempDir);
|
||||
|
||||
HeuristicCallGraphEngine builder = new HeuristicCallGraphEngine(context);
|
||||
|
||||
EntryPoint entryPoint = EntryPoint.builder()
|
||||
.className("com.example.MyController")
|
||||
.methodName("processEvent")
|
||||
.build();
|
||||
|
||||
TriggerPoint trigger = TriggerPoint.builder()
|
||||
.className("com.example.MyService")
|
||||
.methodName("process")
|
||||
.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("MyEnum.STATE_2");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user