Skip to content

Commit ca5f644

Browse files
authored
Resolve stale @Disabled and demo tests (K11 of #1330) (#1353)
* Turn disabled `UseVarForObjectsTest` cases into no-change tests `UseVarForObject` deliberately skips variables initialized by static methods (since #608) and by ternaries, so assert that instead of keeping disabled tests that expect a change. * Turn disabled `UseVarKeywordTest.withTernary` into a no-change test `UseVar` deliberately leaves ternary-initialized variables alone. * Remove disabled `UseTextBlocksTest.textBlockDemo` It never exercised the recipe; it only demonstrated text block semantics and was permanently disabled. * Drop redundant `expectedCyclesThatMakeChanges(0)` from `UseTextBlocksTest` A source spec without an `after` already asserts that no change is made. * Describe the actual parser failure behind `LombokOnXToOnX_Test.handleWithAnnotation` Re-running the test against the current parser still fails before the recipe runs: parsing and printing `@With(onParam=@__({@SuppressWarnings("unused")}))` on a final field yields `@With(onParam=@__({@SuppressWarnings("unused")String private final String field;`. The same syntax on `@Getter`/`@Setter` round-trips fine.
1 parent e9cebdd commit ca5f644

4 files changed

Lines changed: 62 additions & 143 deletions

File tree

‎src/test/java/org/openrewrite/java/migrate/lang/UseTextBlocksTest.java‎

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.openrewrite.java.migrate.lang;
1717

18-
import org.junit.jupiter.api.Disabled;
1918
import org.junit.jupiter.api.Test;
2019
import org.openrewrite.DocumentExample;
2120
import org.openrewrite.Issue;
@@ -30,7 +29,6 @@
3029
import java.util.function.Consumer;
3130
import java.util.function.UnaryOperator;
3231

33-
import static org.assertj.core.api.Assertions.assertThat;
3432
import static org.openrewrite.Tree.randomId;
3533
import static org.openrewrite.java.Assertions.java;
3634
import static org.openrewrite.java.Assertions.javaVersion;
@@ -656,47 +654,6 @@ public static void main(String[] args) {
656654
);
657655
}
658656

659-
@Disabled("""
660-
This test is to demonstrate that the text block conversion is correct.
661-
In this test, s1, s2, and s3 are equivalent, and we translate s1 to s2.
662-
""")
663-
@Test
664-
void textBlockDemo() {
665-
var s1 = """
666-
667-
=========================================================
668-
\s
669-
Welcome to Spring Integration! \s
670-
\s
671-
For more information please visit: \s
672-
https://www.springsource.org/spring-integration \s
673-
\s
674-
=========================================================\
675-
""";
676-
var s2 = """
677-
678-
=========================================================
679-
\s
680-
Welcome to Spring Integration! \s
681-
\s
682-
For more information please visit: \s
683-
https://www.springsource.org/spring-integration \s
684-
\s
685-
=========================================================\
686-
""";
687-
var s3 = """
688-
\n=========================================================\
689-
\n \
690-
\n Welcome to Spring Integration! \
691-
\n \
692-
\n For more information please visit: \
693-
\n https://www.springsource.org/spring-integration \
694-
\n \
695-
\n=========================================================\
696-
""";
697-
assertThat(s1).isEqualTo(s2).isEqualTo(s3);
698-
}
699-
700657
@Test
701658
void consecutiveNewLines() {
702659
rewriteRun(
@@ -968,7 +925,6 @@ public void method() {
968925
@Test
969926
void shouldNotUpdateKotlinCode() {
970927
rewriteRun(
971-
spec -> spec.expectedCyclesThatMakeChanges(0),
972928
kotlin(
973929
"""
974930
const val MULTI_LINE_MESSAGE =

‎src/test/java/org/openrewrite/java/migrate/lang/UseVarKeywordTest.java‎

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.openrewrite.java.migrate.lang;
1717

18-
import org.junit.jupiter.api.Disabled;
1918
import org.junit.jupiter.api.Nested;
2019
import org.junit.jupiter.api.Test;
2120
import org.openrewrite.DocumentExample;
@@ -214,34 +213,6 @@ void m() {
214213
);
215214
}
216215

217-
@Disabled("this should be possible, but it needs very hard type inference")
218-
@Test
219-
void withTernary() {
220-
//language=java
221-
rewriteRun(
222-
java(
223-
"""
224-
package com.example.app;
225-
226-
class A {
227-
void m() {
228-
String o = true ? "isTrue" : "Test";
229-
}
230-
}
231-
""",
232-
"""
233-
package com.example.app;
234-
235-
class A {
236-
void m() {
237-
var o = true ? "isTrue" : "Test";
238-
}
239-
}
240-
"""
241-
)
242-
);
243-
}
244-
245216
@Test
246217
void inStaticInitializer() {
247218
//language=java
@@ -335,6 +306,24 @@ Object m() {
335306
)
336307
);
337308
}
309+
310+
@Test
311+
void withTernary() {
312+
//language=java
313+
rewriteRun(
314+
java(
315+
"""
316+
package com.example.app;
317+
318+
class A {
319+
void m() {
320+
String o = true ? "isTrue" : "Test";
321+
}
322+
}
323+
"""
324+
)
325+
);
326+
}
338327
}
339328
}
340329

‎src/test/java/org/openrewrite/java/migrate/lang/var/UseVarForObjectsTest.java‎

Lines changed: 43 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.openrewrite.java.migrate.lang.var;
1717

18-
import org.junit.jupiter.api.Disabled;
1918
import org.junit.jupiter.api.Nested;
2019
import org.junit.jupiter.api.Test;
2120
import org.openrewrite.DocumentExample;
@@ -115,34 +114,6 @@ void m() {
115114
);
116115
}
117116

118-
@Disabled("this should be possible, but it needs very hard type inference")
119-
@Test
120-
void withTernary() {
121-
//language=java
122-
rewriteRun(
123-
java(
124-
"""
125-
package com.example.app;
126-
127-
class A {
128-
void m() {
129-
String o = true ? "isTrue" : "Test";
130-
}
131-
}
132-
""",
133-
"""
134-
package com.example.app;
135-
136-
class A {
137-
void m() {
138-
var o = true ? "isTrue" : "Test";
139-
}
140-
}
141-
"""
142-
)
143-
);
144-
}
145-
146117
@Test
147118
void inStaticInitializer() {
148119
//language=java
@@ -310,46 +281,6 @@ void m() {
310281
);
311282
}
312283

313-
@Disabled("in favor to https://github.com/openrewrite/rewrite-migrate-java/issues/608 we skip all static methods ATM")
314-
@Test
315-
void staticMethods() {
316-
//language=java
317-
rewriteRun(
318-
version(
319-
java("""
320-
package com.example.app;
321-
322-
class A {
323-
static class B {
324-
private B() {}
325-
static B newInstance() {
326-
return new B();
327-
}
328-
}
329-
void m() {
330-
B b = B.newInstance();
331-
}
332-
}
333-
""", """
334-
package com.example.app;
335-
336-
class A {
337-
static class B {
338-
private B() {}
339-
static B newInstance() {
340-
return new B();
341-
}
342-
}
343-
void m() {
344-
var b = B.newInstance();
345-
}
346-
}
347-
"""),
348-
10
349-
)
350-
);
351-
}
352-
353284
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/550")
354285
@Test
355286
void classLevelGenericType() {
@@ -720,6 +651,49 @@ public String test() {
720651
);
721652
}
722653

654+
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/608")
655+
@Test
656+
void staticMethod() {
657+
//language=java
658+
rewriteRun(
659+
java(
660+
"""
661+
package com.example.app;
662+
663+
class A {
664+
static class B {
665+
private B() {}
666+
static B newInstance() {
667+
return new B();
668+
}
669+
}
670+
void m() {
671+
B b = B.newInstance();
672+
}
673+
}
674+
"""
675+
)
676+
);
677+
}
678+
679+
@Test
680+
void withTernary() {
681+
//language=java
682+
rewriteRun(
683+
java(
684+
"""
685+
package com.example.app;
686+
687+
class A {
688+
void m() {
689+
String o = true ? "isTrue" : "Test";
690+
}
691+
}
692+
"""
693+
)
694+
);
695+
}
696+
723697
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/551")
724698
@Test
725699
void arrayInitializer() {

‎src/test/java/org/openrewrite/java/migrate/lombok/LombokOnXToOnX_Test.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Example {
185185
);
186186
}
187187

188-
@ExpectedToFail("Parser bug with @__ syntax causes test failure")
188+
@ExpectedToFail("Java parser does not round-trip `@With(onParam=@__({...}))`: the printed source drops the closing `}))` and repeats the field type")
189189
@Test
190190
void handleWithAnnotation() {
191191
//language=java

0 commit comments

Comments
 (0)