From 144b91d9c33b1c025babbc790d932e4a9518f102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= <56278322+fabapp2@users.noreply.github.com> Date: Wed, 1 Nov 2023 17:33:16 +0100 Subject: [PATCH] Parser parity test (#984) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduce `ParserParityTestHelper` which takes a dir and parses the given project with `RewriteMavenProjectParser` (comparing) and `RewritePropjectParser` (system under test). The parsing result is then compared using AssertJ's `usingRecursiveComparison` which verifies that all markers and their fields of both parsing results are equal proving that both parsers yield the same result. - Introduce ´TestProjectHelper` which helps set up test projects. - Fixes multiple bugs, e.g. calculation of the classpath. - Cleanups and refactorings --- .../parsers/RewriteProjectParserParityTest.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java index 2c4e1e022..9f42c1ab5 100644 --- a/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java +++ b/sbm-support-rewrite/src/test/java/org/springframework/sbm/parsers/RewriteProjectParserParityTest.java @@ -16,17 +16,18 @@ package org.springframework.sbm.parsers; import org.intellij.lang.annotations.Language; -import org.junit.jupiter.api.BeforeEach; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.junitpioneer.jupiter.Issue; -import org.mockito.Mockito; import org.openrewrite.ExecutionContext; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.Parser; import org.openrewrite.SourceFile; +import org.openrewrite.java.JavaParser; +import org.openrewrite.java.internal.JavaTypeCache; import org.openrewrite.java.marker.JavaProject; import org.openrewrite.java.marker.JavaSourceSet; import org.openrewrite.java.marker.JavaVersion; @@ -40,15 +41,11 @@ import org.openrewrite.maven.MavenSettings; import org.openrewrite.maven.cache.CompositeMavenPomCache; import org.openrewrite.maven.tree.MavenResolutionResult; -import org.openrewrite.shaded.jgit.api.Git; import org.openrewrite.shaded.jgit.api.errors.GitAPIException; import org.openrewrite.tree.ParsingEventListener; import org.openrewrite.tree.ParsingExecutionContextView; import org.openrewrite.xml.style.Autodetect; import org.openrewrite.xml.tree.Xml; -import org.sonatype.plexus.components.cipher.DefaultPlexusCipher; -import org.sonatype.plexus.components.cipher.PlexusCipherException; -import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.io.DefaultResourceLoader; @@ -58,10 +55,9 @@ import org.springframework.sbm.parsers.events.RewriteParsingEventListenerAdapter; import org.springframework.sbm.scopes.ScanScope; import org.springframework.sbm.test.util.DummyResource; -import org.springframework.sbm.utils.ResourceUtil; +import org.springframework.sbm.test.util.ParserParityTestHelper; import org.springframework.test.util.ReflectionTestUtils; -import java.io.File; import java.nio.charset.Charset; import java.nio.file.Path; import java.time.Duration; @@ -77,6 +73,8 @@ import static org.assertj.core.api.Fail.fail; import static org.mockito.Mockito.mock; + + /** * Test parity between OpenRewrite parser logic and RewriteProjectParser. *