From 09ed63d4f5a9ed3566e6adf6d20df452f8b1447e Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 25 Mar 2023 21:10:49 +0000 Subject: [PATCH 1/2] refactor: JUnit Jupiter best practices Co-authored-by: Moderne --- .../openrewrite/python/tree/BlockTest.java | 38 +++++++++---------- .../openrewrite/python/tree/LambdaTest.java | 2 +- .../openrewrite/python/tree/SwitchTest.java | 2 +- .../openrewrite/python/tree/TernaryTest.java | 14 +++---- .../openrewrite/python/tree/ThrowsTest.java | 2 +- .../org/openrewrite/python/tree/TryTest.java | 12 +++--- .../python/tree/TypeCommentTest.java | 2 +- .../python/tree/VariableScopeTest.java | 6 +-- .../org/openrewrite/python/tree/WithTest.java | 32 ++++++++-------- 9 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/test/java/org/openrewrite/python/tree/BlockTest.java b/src/test/java/org/openrewrite/python/tree/BlockTest.java index b4eff161..8542d38f 100644 --- a/src/test/java/org/openrewrite/python/tree/BlockTest.java +++ b/src/test/java/org/openrewrite/python/tree/BlockTest.java @@ -99,7 +99,7 @@ def f(): @ParameterizedTest @ValueSource(strings = {"", "\n", "\n\n", "\n\n\n"}) - public void deeplyNested(String eof) { + void deeplyNested(String eof) { rewriteRun(python( """ def f1(): @@ -118,7 +118,7 @@ def f4(): @ParameterizedTest @ValueSource(strings = {"", "\n", "\n\n", "\n\n\n"}) - public void lineEndingLocations(String eof) { + void lineEndingLocations(String eof) { rewriteRun( python( """ @@ -134,13 +134,13 @@ public void lineEndingLocations(String eof) { @ParameterizedTest @ValueSource(strings = { - "for x in mylist: print(x)", - "def f(x): x = x + 1; return x", - "def f(x): x = x + 1 ; return x", - "def f(x): x = x + 1; return x;", - "def f(x): x = x + 1; return x ;", + "for x in mylist: print(x)", + "def f(x): x = x + 1; return x", + "def f(x): x = x + 1 ; return x", + "def f(x): x = x + 1; return x;", + "def f(x): x = x + 1; return x ;", }) - public void oneLineBlocks(String code) { + void oneLineBlocks(String code) { rewriteRun( python(code) ); @@ -148,35 +148,35 @@ public void oneLineBlocks(String code) { @ParameterizedTest @ValueSource(strings = { - """ + """ for x in xs: pass """, - """ + """ for x in xs: pass else: pass """, - """ + """ while True: pass """, - """ + """ with stuff() as x: pass """, - """ + """ if True: pass """, - """ + """ if True: pass else: pass """, - """ + """ if True: pass elif False: @@ -184,13 +184,13 @@ with stuff() as x: else: pass """, - """ + """ try: pass except: pass """, - """ + """ try: pass except: @@ -198,7 +198,7 @@ with stuff() as x: else: pass """, - """ + """ try: pass except: @@ -209,7 +209,7 @@ with stuff() as x: pass """, }) - public void nested(String block) { + void nested(String block) { rewriteRun( python( """ diff --git a/src/test/java/org/openrewrite/python/tree/LambdaTest.java b/src/test/java/org/openrewrite/python/tree/LambdaTest.java index 0c1a9ede..873c9b92 100644 --- a/src/test/java/org/openrewrite/python/tree/LambdaTest.java +++ b/src/test/java/org/openrewrite/python/tree/LambdaTest.java @@ -20,7 +20,7 @@ import static org.openrewrite.python.Assertions.python; -public class LambdaTest implements RewriteTest { +class LambdaTest implements RewriteTest { @Test void group() { diff --git a/src/test/java/org/openrewrite/python/tree/SwitchTest.java b/src/test/java/org/openrewrite/python/tree/SwitchTest.java index 8fa3e681..694f42d5 100644 --- a/src/test/java/org/openrewrite/python/tree/SwitchTest.java +++ b/src/test/java/org/openrewrite/python/tree/SwitchTest.java @@ -22,7 +22,7 @@ import static org.openrewrite.python.Assertions.python; -public class SwitchTest implements RewriteTest { +class SwitchTest implements RewriteTest { @Test void simple() { diff --git a/src/test/java/org/openrewrite/python/tree/TernaryTest.java b/src/test/java/org/openrewrite/python/tree/TernaryTest.java index c7759918..f24e50e0 100644 --- a/src/test/java/org/openrewrite/python/tree/TernaryTest.java +++ b/src/test/java/org/openrewrite/python/tree/TernaryTest.java @@ -21,17 +21,17 @@ import static org.openrewrite.python.Assertions.python; -public class TernaryTest implements RewriteTest { +class TernaryTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { - "x = 3 if True else 1", - "x = 3 if True else 1", - "x = 3 if True else 1", - "x = 3 if True else 1", - "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", }) - public void test(String expr) { + void test(String expr) { rewriteRun(python(expr)); } diff --git a/src/test/java/org/openrewrite/python/tree/ThrowsTest.java b/src/test/java/org/openrewrite/python/tree/ThrowsTest.java index e50bee99..65eea514 100644 --- a/src/test/java/org/openrewrite/python/tree/ThrowsTest.java +++ b/src/test/java/org/openrewrite/python/tree/ThrowsTest.java @@ -22,7 +22,7 @@ import static org.openrewrite.python.Assertions.python; -public class ThrowsTest implements RewriteTest { +class ThrowsTest implements RewriteTest { @Test void raise() { diff --git a/src/test/java/org/openrewrite/python/tree/TryTest.java b/src/test/java/org/openrewrite/python/tree/TryTest.java index a240565c..1f6e1fdc 100644 --- a/src/test/java/org/openrewrite/python/tree/TryTest.java +++ b/src/test/java/org/openrewrite/python/tree/TryTest.java @@ -22,7 +22,7 @@ import static org.openrewrite.python.Assertions.python; -public class TryTest implements RewriteTest { +class TryTest implements RewriteTest { @ParameterizedTest @CsvSource(textBlock = """ @@ -43,7 +43,7 @@ public class TryTest implements RewriteTest { "" , "*TypeError" "" , " *TypeError" """, quoteCharacter = '"') - public void testTryExcept(String afterTry, String afterExcept) { + void testTryExcept(String afterTry, String afterExcept) { rewriteRun(python( """ try%s: @@ -60,7 +60,7 @@ public void testTryExcept(String afterTry, String afterExcept) { " TypeError " , " OSError" " TypeError" , " OSError " """, quoteCharacter = '"') - public void testTryMultiExcept(String afterFirstExcept, String afterSecondExcept) { + void testTryMultiExcept(String afterFirstExcept, String afterSecondExcept) { rewriteRun(python( """ try: @@ -75,7 +75,7 @@ public void testTryMultiExcept(String afterFirstExcept, String afterSecondExcept @ParameterizedTest @ValueSource(strings = {"", " "}) - public void testTryFinally(String afterFinally) { + void testTryFinally(String afterFinally) { rewriteRun(python( """ try: @@ -88,7 +88,7 @@ public void testTryFinally(String afterFinally) { @ParameterizedTest @ValueSource(strings = {"", " "}) - public void testTryExceptFinally(String afterFinally) { + void testTryExceptFinally(String afterFinally) { rewriteRun(python( """ try: @@ -103,7 +103,7 @@ public void testTryExceptFinally(String afterFinally) { @ParameterizedTest @ValueSource(strings = {"", " "}) - public void testElse(String afterElse) { + void testElse(String afterElse) { rewriteRun(python( """ try: diff --git a/src/test/java/org/openrewrite/python/tree/TypeCommentTest.java b/src/test/java/org/openrewrite/python/tree/TypeCommentTest.java index 98c49779..028b07fd 100644 --- a/src/test/java/org/openrewrite/python/tree/TypeCommentTest.java +++ b/src/test/java/org/openrewrite/python/tree/TypeCommentTest.java @@ -22,7 +22,7 @@ import static org.openrewrite.python.Assertions.python; -public class TypeCommentTest implements RewriteTest { +class TypeCommentTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { diff --git a/src/test/java/org/openrewrite/python/tree/VariableScopeTest.java b/src/test/java/org/openrewrite/python/tree/VariableScopeTest.java index 2ffef2b7..171a018c 100644 --- a/src/test/java/org/openrewrite/python/tree/VariableScopeTest.java +++ b/src/test/java/org/openrewrite/python/tree/VariableScopeTest.java @@ -21,10 +21,10 @@ import static org.openrewrite.python.Assertions.python; -public class VariableScopeTest implements RewriteTest { +class VariableScopeTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = {"nonlocal", "global"}) - public void singleName(String kind) { + void singleName(String kind) { rewriteRun( python( """ @@ -37,7 +37,7 @@ def foo(): @ParameterizedTest @ValueSource(strings = {"nonlocal", "global"}) - public void multipleNames(String kind) { + void multipleNames(String kind) { rewriteRun( python( """ diff --git a/src/test/java/org/openrewrite/python/tree/WithTest.java b/src/test/java/org/openrewrite/python/tree/WithTest.java index 165b11d9..829a7b80 100644 --- a/src/test/java/org/openrewrite/python/tree/WithTest.java +++ b/src/test/java/org/openrewrite/python/tree/WithTest.java @@ -21,25 +21,25 @@ import static org.openrewrite.python.Assertions.python; -public class WithTest implements RewriteTest { +class WithTest implements RewriteTest { @ParameterizedTest - @ValueSource(strings={ - "A()", - "A() as a", - "A() as a", - "A() as a", - "A() as a ", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a , B() as b", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a, B() as b ", + @ValueSource(strings = { + "A()", + "A() as a", + "A() as a", + "A() as a", + "A() as a ", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a , B() as b", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a, B() as b ", }) - public void simple(String vars) { + void simple(String vars) { rewriteRun(python( """ with %s: From 6aa7719765a061b648fc229182eb480c58e59f35 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 25 Mar 2023 22:13:38 +0100 Subject: [PATCH 2/2] Restore whitespace for ValueSource strings --- .../openrewrite/python/tree/BlockTest.java | 30 +++++++++---------- .../openrewrite/python/tree/TernaryTest.java | 10 +++---- .../org/openrewrite/python/tree/WithTest.java | 26 ++++++++-------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/test/java/org/openrewrite/python/tree/BlockTest.java b/src/test/java/org/openrewrite/python/tree/BlockTest.java index 8542d38f..f53011ad 100644 --- a/src/test/java/org/openrewrite/python/tree/BlockTest.java +++ b/src/test/java/org/openrewrite/python/tree/BlockTest.java @@ -134,11 +134,11 @@ void lineEndingLocations(String eof) { @ParameterizedTest @ValueSource(strings = { - "for x in mylist: print(x)", - "def f(x): x = x + 1; return x", - "def f(x): x = x + 1 ; return x", - "def f(x): x = x + 1; return x;", - "def f(x): x = x + 1; return x ;", + "for x in mylist: print(x)", + "def f(x): x = x + 1; return x", + "def f(x): x = x + 1 ; return x", + "def f(x): x = x + 1; return x;", + "def f(x): x = x + 1; return x ;", }) void oneLineBlocks(String code) { rewriteRun( @@ -148,35 +148,35 @@ void oneLineBlocks(String code) { @ParameterizedTest @ValueSource(strings = { - """ + """ for x in xs: pass """, - """ + """ for x in xs: pass else: pass """, - """ + """ while True: pass """, - """ + """ with stuff() as x: pass """, - """ + """ if True: pass """, - """ + """ if True: pass else: pass """, - """ + """ if True: pass elif False: @@ -184,13 +184,13 @@ with stuff() as x: else: pass """, - """ + """ try: pass except: pass """, - """ + """ try: pass except: @@ -198,7 +198,7 @@ with stuff() as x: else: pass """, - """ + """ try: pass except: diff --git a/src/test/java/org/openrewrite/python/tree/TernaryTest.java b/src/test/java/org/openrewrite/python/tree/TernaryTest.java index f24e50e0..af1c06bf 100644 --- a/src/test/java/org/openrewrite/python/tree/TernaryTest.java +++ b/src/test/java/org/openrewrite/python/tree/TernaryTest.java @@ -25,11 +25,11 @@ class TernaryTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { - "x = 3 if True else 1", - "x = 3 if True else 1", - "x = 3 if True else 1", - "x = 3 if True else 1", - "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", + "x = 3 if True else 1", }) void test(String expr) { rewriteRun(python(expr)); diff --git a/src/test/java/org/openrewrite/python/tree/WithTest.java b/src/test/java/org/openrewrite/python/tree/WithTest.java index 829a7b80..380694c7 100644 --- a/src/test/java/org/openrewrite/python/tree/WithTest.java +++ b/src/test/java/org/openrewrite/python/tree/WithTest.java @@ -25,19 +25,19 @@ class WithTest implements RewriteTest { @ParameterizedTest @ValueSource(strings = { - "A()", - "A() as a", - "A() as a", - "A() as a", - "A() as a ", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a , B() as b", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a, B() as b", - "A() as a, B() as b ", + "A()", + "A() as a", + "A() as a", + "A() as a", + "A() as a ", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a , B() as b", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a, B() as b", + "A() as a, B() as b ", }) void simple(String vars) { rewriteRun(python(