test1
This commit is contained in:
@@ -44,4 +44,42 @@ public class GenericEventDetectorTest {
|
||||
assertThat(triggers.get(0).getEvent()).isEqualTo("myEvent");
|
||||
assertThat(triggers.get(0).getMethodName()).isEqualTo("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEnumGetterUnionExtraction(@TempDir Path tempDir) throws IOException {
|
||||
Path dir = tempDir.resolve("com/example");
|
||||
Files.createDirectories(dir);
|
||||
Files.writeString(dir.resolve("MyEnum.java"),
|
||||
"package com.example;\n" +
|
||||
"public enum MyEnum {\n" +
|
||||
" STATE_A, STATE_B;\n" +
|
||||
"}\n");
|
||||
|
||||
Files.writeString(dir.resolve("MyService.java"),
|
||||
"package com.example;\n" +
|
||||
"import org.springframework.statemachine.StateMachine;\n" +
|
||||
"public class MyService {\n" +
|
||||
" private StateMachine<String, String> stateMachine;\n" +
|
||||
" public MyEnum getEvent() { return MyEnum.STATE_A; }\n" + // Pretend it returns the enum
|
||||
" public void trigger() {\n" +
|
||||
" stateMachine.sendEvent(this.getEvent());\n" +
|
||||
" }\n" +
|
||||
"}\n");
|
||||
|
||||
CodebaseContext context = new CodebaseContext();
|
||||
context.scan(tempDir);
|
||||
|
||||
GenericEventDetector detector = new GenericEventDetector(context, new ConstantResolver(), List.of());
|
||||
|
||||
CompilationUnit serviceCu = context.getCompilationUnits().stream()
|
||||
.filter(cu -> cu.getJavaElement() == null || cu.getJavaElement().getElementName().contains("MyService"))
|
||||
.findFirst().orElseThrow();
|
||||
|
||||
List<TriggerPoint> triggers = detector.detect(serviceCu);
|
||||
|
||||
System.out.println("TRIGGERS: " + triggers);
|
||||
assertThat(triggers).hasSize(2);
|
||||
assertThat(triggers).anyMatch(t -> t.getEvent().equals("com.example.MyEnum.STATE_A"));
|
||||
assertThat(triggers).anyMatch(t -> t.getEvent().equals("com.example.MyEnum.STATE_B"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user