Skip to content

Commit 2cf54c0

Browse files
Move Groovy and Kotlin tests of recipes to rewrite-groovy/ and rewrite-kotlin/ (#7563)
1 parent ad0ff65 commit 2cf54c0

7 files changed

Lines changed: 134 additions & 70 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.groovy.format;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.Issue;
20+
import org.openrewrite.java.format.NoWhitespaceBefore;
21+
import org.openrewrite.test.RecipeSpec;
22+
import org.openrewrite.test.RewriteTest;
23+
24+
import static org.openrewrite.groovy.Assertions.groovy;
25+
26+
class NoWhitespaceBeforeTest implements RewriteTest {
27+
@Override
28+
public void defaults(RecipeSpec spec) {
29+
spec.recipe(new NoWhitespaceBefore());
30+
}
31+
32+
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/233")
33+
@Test
34+
void jenkinsLibrary() {
35+
rewriteRun(groovy("library 'someLibrary@version'"));
36+
}
37+
}

rewrite-java-test/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ plugins {
33
}
44

55
recipeDependencies {
6-
parserClasspath("jakarta.persistence:jakarta.persistence-api:3.1.0")
76
testParserClasspath("jakarta.validation:jakarta.validation-api:3.0.2")
87
testParserClasspath("javax.validation:validation-api:1.1.0.Final")
98
testParserClasspath("org.hibernate:hibernate-validator:5.4.3.Final")
@@ -14,12 +13,9 @@ dependencies {
1413
implementation(project(":rewrite-java"))
1514
implementation(project(":rewrite-test"))
1615

17-
testImplementation(project(":rewrite-groovy"))
18-
testImplementation(project(":rewrite-kotlin"))
1916
testImplementation("io.github.classgraph:classgraph:latest.release")
2017
testImplementation("org.junit-pioneer:junit-pioneer:2.0.0")
2118
testRuntimeOnly(project(":rewrite-java-21"))
22-
testRuntimeOnly("jakarta.persistence:jakarta.persistence-api:3.1.0")
2319
testRuntimeOnly("org.apache.hbase:hbase-shaded-client:2.4.11")
2420
testRuntimeOnly("com.google.guava:guava:latest.release")
2521
testRuntimeOnly("org.mapstruct:mapstruct:latest.release")

rewrite-java-test/src/test/java/org/openrewrite/java/FindMissingTypesTest.java

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717

1818
import org.junit.jupiter.api.Test;
1919
import org.openrewrite.DocumentExample;
20-
import org.openrewrite.InMemoryExecutionContext;
2120
import org.openrewrite.Issue;
2221
import org.openrewrite.java.search.FindMissingTypes;
2322
import org.openrewrite.java.tree.JavaType;
24-
import org.openrewrite.kotlin.KotlinParser;
2523
import org.openrewrite.test.RecipeSpec;
2624
import org.openrewrite.test.RewriteTest;
2725
import org.openrewrite.test.TypeValidation;
2826

2927
import static org.assertj.core.api.Assertions.assertThat;
3028
import static org.openrewrite.java.Assertions.java;
31-
import static org.openrewrite.kotlin.Assertions.kotlin;
3229

3330
@SuppressWarnings("ClassInitializerMayBeStatic")
3431
class FindMissingTypesTest implements RewriteTest {
@@ -269,59 +266,4 @@ interface Foo {
269266
);
270267
}
271268

272-
@Test
273-
void kotlinClassReference() {
274-
rewriteRun(
275-
spec -> spec.parser(
276-
KotlinParser.builder().classpathFromResources(new InMemoryExecutionContext(), "jakarta.persistence-api")),
277-
kotlin(
278-
"""
279-
package com.some.other
280-
281-
class EventPublisher {
282-
}
283-
"""
284-
),
285-
kotlin(
286-
"""
287-
package com.some.card
288-
289-
import com.some.other.EventPublisher
290-
import jakarta.persistence.EntityListeners
291-
292-
@EntityListeners(EventPublisher::class)
293-
data class Card(
294-
)
295-
"""
296-
)
297-
);
298-
}
299-
300-
@Test
301-
void invalidKotlinClassReference() {
302-
rewriteRun(
303-
spec -> spec.parser(
304-
KotlinParser.builder().classpathFromResources(new InMemoryExecutionContext(), "jakarta.persistence-api")),
305-
kotlin(
306-
"""
307-
package com.some.card
308-
309-
import jakarta.persistence.EntityListeners
310-
311-
@EntityListeners(EventPublisher::class)
312-
data class Card(
313-
)
314-
""",
315-
"""
316-
package com.some.card
317-
318-
import jakarta.persistence.EntityListeners
319-
320-
@EntityListeners(/*~~(MemberReference Parameterized type is missing or malformed)~~>*//*~~(Identifier type is missing or malformed)~~>*/EventPublisher::class)
321-
data class Card(
322-
)
323-
"""
324-
)
325-
);
326-
}
327269
}

rewrite-java-test/src/test/java/org/openrewrite/java/format/NoWhitespaceBeforeTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.junit.jupiter.api.condition.DisabledOnOs;
2222
import org.junit.jupiter.api.condition.OS;
2323
import org.openrewrite.DocumentExample;
24-
import org.openrewrite.Issue;
2524
import org.openrewrite.Tree;
2625
import org.openrewrite.java.JavaParser;
2726
import org.openrewrite.java.style.Checkstyle;
@@ -39,7 +38,6 @@
3938

4039
import static java.util.Collections.emptySet;
4140
import static java.util.Collections.singletonList;
42-
import static org.openrewrite.groovy.Assertions.groovy;
4341
import static org.openrewrite.java.Assertions.java;
4442

4543
@SuppressWarnings({
@@ -755,12 +753,6 @@ static void method() {
755753
);
756754
}
757755

758-
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/233")
759-
@Test
760-
void jenkinsLibrary() {
761-
rewriteRun(groovy("library 'someLibrary@version'"));
762-
}
763-
764756
private static Consumer<SourceSpec<J.CompilationUnit>> autoFormatIsIdempotent() {
765757
return spec -> spec.afterRecipe(cu ->
766758
Assertions.assertThat(new AutoFormatVisitor<>().visit(cu, 0)).isEqualTo(cu));

rewrite-kotlin/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ plugins {
1010
// the kotlin-stdlib alignment stays in lockstep across modules.
1111
val kotlinVersion = "2.3.20"
1212

13+
recipeDependencies {
14+
parserClasspath("jakarta.persistence:jakarta.persistence-api:3.1.0")
15+
}
16+
1317
dependencies {
1418
compileOnly(project(":rewrite-core"))
1519
compileOnly(project(":rewrite-test"))
@@ -29,6 +33,7 @@ dependencies {
2933
testRuntimeOnly(project(":rewrite-java-21"))
3034
testRuntimeOnly("org.antlr:antlr4-runtime:4.13.2")
3135
testRuntimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
36+
testRuntimeOnly("jakarta.persistence:jakarta.persistence-api:3.1.0")
3237

3338
testImplementation("com.github.ajalt.clikt:clikt:3.5.0")
3439
testImplementation("com.squareup:javapoet:1.13.0")
Binary file not shown.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.kotlin;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.openrewrite.InMemoryExecutionContext;
20+
import org.openrewrite.java.JavaParser;
21+
import org.openrewrite.java.search.FindMissingTypes;
22+
import org.openrewrite.test.RecipeSpec;
23+
import org.openrewrite.test.RewriteTest;
24+
import org.openrewrite.test.TypeValidation;
25+
26+
import static org.openrewrite.kotlin.Assertions.kotlin;
27+
28+
class FindMissingTypesTest implements RewriteTest {
29+
30+
@Override
31+
public void defaults(RecipeSpec spec) {
32+
spec.recipe(new FindMissingTypes(false))
33+
.parser(JavaParser.fromJavaVersion())
34+
.typeValidationOptions(TypeValidation.none());
35+
}
36+
37+
@Test
38+
void kotlinClassReference() {
39+
rewriteRun(
40+
spec -> spec.parser(
41+
KotlinParser.builder().classpathFromResources(new InMemoryExecutionContext(), "jakarta.persistence-api")),
42+
kotlin(
43+
"""
44+
package com.some.other
45+
46+
class EventPublisher {
47+
}
48+
"""
49+
),
50+
kotlin(
51+
"""
52+
package com.some.card
53+
54+
import com.some.other.EventPublisher
55+
import jakarta.persistence.EntityListeners
56+
57+
@EntityListeners(EventPublisher::class)
58+
data class Card(
59+
)
60+
"""
61+
)
62+
);
63+
}
64+
65+
@Test
66+
void invalidKotlinClassReference() {
67+
rewriteRun(
68+
spec -> spec.parser(
69+
KotlinParser.builder().classpathFromResources(new InMemoryExecutionContext(), "jakarta.persistence-api")),
70+
kotlin(
71+
"""
72+
package com.some.card
73+
74+
import jakarta.persistence.EntityListeners
75+
76+
@EntityListeners(EventPublisher::class)
77+
data class Card(
78+
)
79+
""",
80+
"""
81+
package com.some.card
82+
83+
import jakarta.persistence.EntityListeners
84+
85+
@EntityListeners(/*~~(MemberReference Parameterized type is missing or malformed)~~>*//*~~(Identifier type is missing or malformed)~~>*/EventPublisher::class)
86+
data class Card(
87+
)
88+
"""
89+
)
90+
);
91+
}
92+
}

0 commit comments

Comments
 (0)