Extract call-site and link policy helpers to clarify analysis pipeline rules.

Move functional-interface checks, cross-frame Supplier resolution, and transition link resolution into dedicated types so call graph and linker share one DRY implementation.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-13 20:22:33 +02:00
parent c7e826c0fb
commit 423bb4e819
7 changed files with 326 additions and 144 deletions

View File

@@ -0,0 +1,36 @@
package click.kamil.springstatemachineexporter.analysis.enricher;
import click.kamil.springstatemachineexporter.analysis.model.LinkResolution;
import click.kamil.springstatemachineexporter.analysis.model.TriggerPoint;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
class CallChainLinkPolicyTest {
@Test
void shouldFailClosedOnEnumSetAmbiguousWiden() {
TriggerPoint trigger = TriggerPoint.builder()
.ambiguous(true)
.event("ENUM_SET:com.example.OrderEvent.PAY,com.example.OrderEvent.SHIP")
.polymorphicEvents(List.of("com.example.OrderEvent.PAY", "com.example.OrderEvent.SHIP"))
.build();
assertThat(CallChainLinkPolicy.shouldFailClosedOnAmbiguousCallGraphWiden(trigger)).isTrue();
assertThat(CallChainLinkPolicy.resolveLinkResolution(trigger, List.of(), false))
.isEqualTo(LinkResolution.AMBIGUOUS_WIDEN);
}
@Test
void shouldMarkExternalTriggersUnresolved() {
TriggerPoint trigger = TriggerPoint.builder()
.external(true)
.event("eventString")
.build();
assertThat(CallChainLinkPolicy.resolveLinkResolution(trigger, List.of(), false))
.isEqualTo(LinkResolution.UNRESOLVED_EXTERNAL);
}
}

View File

@@ -0,0 +1,28 @@
package click.kamil.springstatemachineexporter.analysis.service;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class FunctionalInterfaceTypesTest {
@Test
void shouldRecognizeSupplierParameter() {
assertThat(FunctionalInterfaceTypes.isFunctionalInterface("java.util.function.Supplier"))
.isTrue();
}
@Test
void shouldAcceptLambdaIntoSupplierParameter() {
assertThat(FunctionalInterfaceTypes.isProvablyResolvedCallSiteArgument(
"() -> OrderEvent.CANCEL", "java.util.function.Supplier"))
.isTrue();
}
@Test
void shouldRejectNonFunctionalParameter() {
assertThat(FunctionalInterfaceTypes.isProvablyResolvedCallSiteArgument(
"OrderEvent.CANCEL", "com.example.OrderEvent"))
.isFalse();
}
}