From b804d225cb9a3cc161cb6468439878b1fb529c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Thu, 19 Oct 2023 17:29:28 +0200 Subject: [PATCH] Adjusted test --- ...riteMavenProjectParserIntegrationTest.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/maven/RewriteMavenProjectParserIntegrationTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/maven/RewriteMavenProjectParserIntegrationTest.java index 6445a1a4f..700f8c358 100644 --- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/maven/RewriteMavenProjectParserIntegrationTest.java +++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/maven/RewriteMavenProjectParserIntegrationTest.java @@ -18,13 +18,21 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; +import org.openrewrite.ExecutionContext; +import org.openrewrite.InMemoryExecutionContext; +import org.openrewrite.Parser; +import org.openrewrite.SourceFile; +import org.openrewrite.tree.ParsingEventListener; +import org.openrewrite.tree.ParsingExecutionContextView; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.event.EventListener; import org.springframework.sbm.boot.autoconfigure.SbmSupportRewriteConfiguration; +import org.springframework.sbm.parsers.RewriteProjectParser; import org.springframework.sbm.parsers.RewriteProjectParsingResult; import org.springframework.sbm.parsers.events.FinishedParsingResourceEvent; +import org.springframework.sbm.parsers.events.RewriteParsingEventListenerAdapter; import java.nio.file.Path; import java.util.ArrayList; @@ -49,7 +57,14 @@ public class RewriteMavenProjectParserIntegrationTest { void shouldPublishBuildEvents() { Path baseDir = Path.of("./testcode/maven-projects/multi-module-1"); - RewriteProjectParsingResult parsingResult = sut.parse(baseDir); + ExecutionContext executionContext = new InMemoryExecutionContext(t -> {throw new RuntimeException(t);}); + ParsingExecutionContextView.view(executionContext).setParsingListener(new ParsingEventListener() { + @Override + public void parsed(Parser.Input input, SourceFile sourceFile) { + capturedEvents.add(new FinishedParsingResourceEvent(input, sourceFile)); + } + }); + RewriteProjectParsingResult parsingResult = sut.parse(baseDir, executionContext); assertThat(capturedEvents).hasSize(3); assertThat(capturedEvents.get(0).sourceFile().getSourcePath().toString()) .isEqualTo("pom.xml"); @@ -58,13 +73,4 @@ void shouldPublishBuildEvents() { assertThat(capturedEvents.get(2).sourceFile().getSourcePath().toString()) .isEqualTo("module-a/pom.xml"); } - - @TestConfiguration - static class TestEventListener { - @EventListener(FinishedParsingResourceEvent.class) - public void onEvent(FinishedParsingResourceEvent event) { - capturedEvents.add(event); - } - } - }