diff --git a/state_machine_exporter/src/test/java/click/kamil/springstatemachineexporter/analysis/service/JdtCentralDispatcherParityTest.java b/state_machine_exporter/src/test/java/click/kamil/springstatemachineexporter/analysis/service/JdtCentralDispatcherParityTest.java index 24507e1..257a72a 100644 --- a/state_machine_exporter/src/test/java/click/kamil/springstatemachineexporter/analysis/service/JdtCentralDispatcherParityTest.java +++ b/state_machine_exporter/src/test/java/click/kamil/springstatemachineexporter/analysis/service/JdtCentralDispatcherParityTest.java @@ -73,6 +73,47 @@ class JdtCentralDispatcherParityTest { assertThat(jdtLink.getEvent()).isEqualTo(heuristicLink.getEvent()); } + @Test + void jdtShouldMatchHeuristicForStaticRoutingHelper(@TempDir Path tempDir) throws Exception { + String source = """ + package com.example; + public class ApiController { + CommandGateway gateway; + public void pay() { gateway.routeAndPay(); } + public void ship() { gateway.routeAndShip(); } + } + class CommandGateway { + CentralDispatcher dispatcher; + void routeAndPay() { dispatcher.dispatch("ORDER", OrderRoutingHelper.payAction()); } + void routeAndShip() { dispatcher.dispatch("ORDER", OrderRoutingHelper.shipAction()); } + } + class OrderRoutingHelper { + static String payAction() { return "PAY"; } + static String shipAction() { return "SHIP"; } + } + class CentralDispatcher { + void dispatch(String domain, String action) { + StateMachine sm = new StateMachine(); + sm.sendEvent(OrderEvent.valueOf(action)); + } + } + enum OrderEvent { PAY, SHIP } + class StateMachine { public void sendEvent(OrderEvent e) {} } + class OrderStateMachineConfig {} + """; + CodebaseContext context = scanSource(source, tempDir); + + CallChain heuristicPay = resolveChain(context, CONTROLLER, "pay", STATE_MACHINE, EngineKind.HEURISTIC); + CallChain jdtPay = resolveChain(context, CONTROLLER, "pay", STATE_MACHINE, EngineKind.JDT); + CallChain heuristicShip = resolveChain(context, CONTROLLER, "ship", STATE_MACHINE, EngineKind.HEURISTIC); + CallChain jdtShip = resolveChain(context, CONTROLLER, "ship", STATE_MACHINE, EngineKind.JDT); + + assertThat(jdtPay.getTriggerPoint().getPolymorphicEvents()) + .containsExactlyInAnyOrderElementsOf(heuristicPay.getTriggerPoint().getPolymorphicEvents()); + assertThat(jdtShip.getTriggerPoint().getPolymorphicEvents()) + .containsExactlyInAnyOrderElementsOf(heuristicShip.getTriggerPoint().getPolymorphicEvents()); + } + @Test void jdtShouldMatchHeuristicForDtoCrossHop(@TempDir Path tempDir) throws Exception { String source = """