18
18
import org .junit .jupiter .api .DisplayName ;
19
19
import org .junit .jupiter .api .Test ;
20
20
import org .junitpioneer .jupiter .ExpectedToFail ;
21
+ import org .openrewrite .ExecutionContext ;
22
+ import org .openrewrite .InMemoryExecutionContext ;
23
+ import org .openrewrite .Parser ;
24
+ import org .openrewrite .SourceFile ;
25
+ import org .openrewrite .tree .ParsingEventListener ;
26
+ import org .openrewrite .tree .ParsingExecutionContextView ;
21
27
import org .springframework .beans .factory .annotation .Autowired ;
22
28
import org .springframework .boot .test .context .SpringBootTest ;
23
29
import org .springframework .boot .test .context .TestConfiguration ;
24
30
import org .springframework .context .event .EventListener ;
25
31
import org .springframework .sbm .boot .autoconfigure .SbmSupportRewriteConfiguration ;
32
+ import org .springframework .sbm .parsers .RewriteProjectParser ;
26
33
import org .springframework .sbm .parsers .RewriteProjectParsingResult ;
27
34
import org .springframework .sbm .parsers .events .FinishedParsingResourceEvent ;
35
+ import org .springframework .sbm .parsers .events .RewriteParsingEventListenerAdapter ;
28
36
29
37
import java .nio .file .Path ;
30
38
import java .util .ArrayList ;
@@ -49,7 +57,14 @@ public class RewriteMavenProjectParserIntegrationTest {
49
57
void shouldPublishBuildEvents () {
50
58
51
59
Path baseDir = Path .of ("./testcode/maven-projects/multi-module-1" );
52
- RewriteProjectParsingResult parsingResult = sut .parse (baseDir );
60
+ ExecutionContext executionContext = new InMemoryExecutionContext (t -> {throw new RuntimeException (t );});
61
+ ParsingExecutionContextView .view (executionContext ).setParsingListener (new ParsingEventListener () {
62
+ @ Override
63
+ public void parsed (Parser .Input input , SourceFile sourceFile ) {
64
+ capturedEvents .add (new FinishedParsingResourceEvent (input , sourceFile ));
65
+ }
66
+ });
67
+ RewriteProjectParsingResult parsingResult = sut .parse (baseDir , executionContext );
53
68
assertThat (capturedEvents ).hasSize (3 );
54
69
assertThat (capturedEvents .get (0 ).sourceFile ().getSourcePath ().toString ())
55
70
.isEqualTo ("pom.xml" );
@@ -58,13 +73,4 @@ void shouldPublishBuildEvents() {
58
73
assertThat (capturedEvents .get (2 ).sourceFile ().getSourcePath ().toString ())
59
74
.isEqualTo ("module-a/pom.xml" );
60
75
}
61
-
62
- @ TestConfiguration
63
- static class TestEventListener {
64
- @ EventListener (FinishedParsingResourceEvent .class )
65
- public void onEvent (FinishedParsingResourceEvent event ) {
66
- capturedEvents .add (event );
67
- }
68
- }
69
-
70
76
}
0 commit comments