From 10227b8172a7f223f1944d25fbd1dd00ca8c4683 Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Sat, 21 Sep 2024 17:20:37 +0200 Subject: [PATCH] migrate to junit 5 suite --- .../Java10/ExplicitEncodingCleanUpTest.java | 37 ++++++++++++++---- .../Java10/QuickFixJava10TestSuite.java | 12 +++--- .../Java8/ExplicitEncodingCleanUpTest.java | 39 +++++++++++++++---- .../Java8/QuickFixJava8TestSuite.java | 29 +++++++++++--- 4 files changed, 91 insertions(+), 26 deletions(-) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java index 8ffc88a33ff..8cbb67e214b 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/ExplicitEncodingCleanUpTest.java @@ -1,18 +1,41 @@ package org.eclipse.jdt.ui.tests.quickfix.Java10; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IPackageFragment; +import java.util.Hashtable; + +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; + +import org.eclipse.jdt.testplugin.TestOptions; + +import org.eclipse.core.runtime.CoreException; + +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; + import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; + import org.eclipse.jdt.ui.tests.quickfix.rules.AbstractEclipseJava; import org.eclipse.jdt.ui.tests.quickfix.rules.EclipseJava10; +import org.eclipse.jdt.internal.ui.JavaPlugin; + public class ExplicitEncodingCleanUpTest { + @BeforeEach + protected void setUp() throws Exception { + Hashtable defaultOptions= TestOptions.getDefaultOptions(); + defaultOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(120)); + JavaCore.setOptions(defaultOptions); + TestOptions.initializeCodeGenerationOptions(); + // Use load since restore doesn't really restore the defaults. + JavaPlugin.getDefault().getCodeTemplateStore().load(); + } + @RegisterExtension AbstractEclipseJava context = new EclipseJava10(); @@ -582,7 +605,7 @@ static void bla() throws UnsupportedEncodingException { String url2=URLDecoder.decode("asdf", Charset.defaultCharset()); } } - """), + """), URLENCODER(""" package test1; import java.io.UnsupportedEncodingException; @@ -609,7 +632,7 @@ static void bla() throws UnsupportedEncodingException { String url4=URLEncoder.encode("asdf", Charset.defaultCharset()); } } - """), + """), SCANNER(""" package test1; import java.io.File; @@ -640,7 +663,7 @@ static void bla() throws FileNotFoundException { Scanner s3=new Scanner("asdf", Charset.defaultCharset()); } } - """), + """), FORMATTER(""" package test1; import java.io.File; @@ -668,7 +691,7 @@ static void bla() throws FileNotFoundException, UnsupportedEncodingException { Formatter s=new Formatter(new File("asdf"),StandardCharsets.UTF_8); } } - """), + """), THREE(""" package test1; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/QuickFixJava10TestSuite.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/QuickFixJava10TestSuite.java index a4fbb2c5c60..741ff9bbd84 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/QuickFixJava10TestSuite.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java10/QuickFixJava10TestSuite.java @@ -14,12 +14,12 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.quickfix.Java10; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses({ - ExplicitEncodingCleanUpTest.class, +@Suite +@SelectClasses({ + ExplicitEncodingCleanUpTest.class }) public class QuickFixJava10TestSuite { -} +} \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/ExplicitEncodingCleanUpTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/ExplicitEncodingCleanUpTest.java index 5e5e9421135..ccee9c3884d 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/ExplicitEncodingCleanUpTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/ExplicitEncodingCleanUpTest.java @@ -1,18 +1,41 @@ package org.eclipse.jdt.ui.tests.quickfix.Java8; +import java.util.Hashtable; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import org.eclipse.jdt.testplugin.TestOptions; + import org.eclipse.core.runtime.CoreException; + import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; + import org.eclipse.jdt.internal.corext.fix.CleanUpConstants; + import org.eclipse.jdt.ui.tests.quickfix.rules.AbstractEclipseJava; import org.eclipse.jdt.ui.tests.quickfix.rules.EclipseJava8; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; + +import org.eclipse.jdt.internal.ui.JavaPlugin; public class ExplicitEncodingCleanUpTest { + @BeforeEach + protected void setUp() throws Exception { + Hashtable defaultOptions= TestOptions.getDefaultOptions(); + defaultOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(120)); + JavaCore.setOptions(defaultOptions); + TestOptions.initializeCodeGenerationOptions(); + // Use load since restore doesn't really restore the defaults. + JavaPlugin.getDefault().getCodeTemplateStore().load(); + } + @RegisterExtension AbstractEclipseJava context = new EclipseJava8(); @@ -573,7 +596,7 @@ static void bla() throws UnsupportedEncodingException { String url2=URLDecoder.decode("asdf"); } } - """), + """), URLENCODER(""" package test1; import java.io.UnsupportedEncodingException; @@ -598,7 +621,7 @@ static void bla() throws UnsupportedEncodingException { String url4=URLEncoder.encode("asdf"); } } - """), + """), SCANNER(""" package test1; import java.io.File; @@ -627,7 +650,7 @@ static void bla() throws FileNotFoundException { Scanner s3=new Scanner("asdf"); } } - """), + """), FORMATTER(""" package test1; import java.io.File; @@ -655,7 +678,7 @@ static void bla() throws FileNotFoundException, UnsupportedEncodingException { Formatter s=new Formatter(new File("asdf"),StandardCharsets.UTF_8); } } - """), + """), THREE(""" package test1; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/QuickFixJava8TestSuite.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/QuickFixJava8TestSuite.java index a42e79b6807..a8ae1b335fb 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/QuickFixJava8TestSuite.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/Java8/QuickFixJava8TestSuite.java @@ -14,12 +14,31 @@ *******************************************************************************/ package org.eclipse.jdt.ui.tests.quickfix.Java8; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import java.util.Hashtable; -@RunWith(Suite.class) -@Suite.SuiteClasses({ - ExplicitEncodingCleanUpTest.class, +import org.junit.jupiter.api.BeforeEach; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; + +import org.eclipse.jdt.testplugin.TestOptions; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; + +import org.eclipse.jdt.internal.ui.JavaPlugin; + +@Suite +@SelectClasses({ + ExplicitEncodingCleanUpTest.class }) public class QuickFixJava8TestSuite { + @BeforeEach + protected void setUp() throws Exception { + Hashtable defaultOptions= TestOptions.getDefaultOptions(); + defaultOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, Integer.toString(120)); + JavaCore.setOptions(defaultOptions); + TestOptions.initializeCodeGenerationOptions(); + // Use load since restore doesn't really restore the defaults. + JavaPlugin.getDefault().getCodeTemplateStore().load(); + } }