From 53ea2ad822a166c7e4b2e9b76f398daca23d3413 Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Thu, 19 May 2022 08:54:15 +0530 Subject: [PATCH] Fix Files.copy() such that parent dirs are created Closes #2761 Also toggled the version back to a bug fix version --- CHANGES.txt | 3 + gradle.properties | 2 +- .../main/java/org/testng/JarFileUtils.java | 1 + .../java/org/testng/reporters/jq/Main.java | 4 +- .../java/org/testng/JarFileUtilsTest.java | 2 +- .../testng}/testhelper/CompiledCode.java | 19 ++++- .../JarCreator.java | 2 +- .../testhelper/OutputDirectoryPatch.java | 2 +- .../testng}/testhelper/SimpleCompiler.java | 16 ++++- .../org/testng/testhelper/SourceCode.java | 69 +++++++++++++++++++ .../testng/testhelper/TestClassGenerator.java | 38 ++++++++++ .../testhelper/TestNGSimpleClassLoader.java | 36 ++++++++++ .../src/test/java/test/CommandLineTest.java | 2 +- .../test/java/test/JUnitTestClassLoader.java | 6 +- .../java/test/alwaysrun/AlwaysRunTest.java | 2 +- .../src/test/java/test/cli/CliTest.java | 60 ++++++++++++++++ .../commandline/CommandLineOverridesXml.java | 2 +- .../conffailure/ConfigurationFailure.java | 2 +- .../FailurePolicyTest.java | 2 +- .../InterleavedInvocationTest.java | 2 +- .../test/mannotation/issue1976/IssueTest.java | 18 ++--- .../test/methodselectors/CommandLineTest.java | 2 +- .../MethodSelectorInSuiteTest.java | 2 +- .../src/test/java/test/mixed/MixedTest.java | 2 +- .../test/simple/IncludedExcludedTest.java | 2 +- .../test/java/test/uniquesuite/TestAfter.java | 2 +- .../src/test/java/testhelper/SourceCode.java | 43 ------------ 27 files changed, 262 insertions(+), 81 deletions(-) rename testng-core/src/test/java/{ => org/testng}/testhelper/CompiledCode.java (50%) rename testng-core/src/test/java/org/testng/{jarfileutils => testhelper}/JarCreator.java (98%) rename testng-core/src/test/java/{ => org/testng}/testhelper/OutputDirectoryPatch.java (98%) rename testng-core/src/test/java/{ => org/testng}/testhelper/SimpleCompiler.java (72%) create mode 100644 testng-core/src/test/java/org/testng/testhelper/SourceCode.java create mode 100644 testng-core/src/test/java/org/testng/testhelper/TestClassGenerator.java create mode 100644 testng-core/src/test/java/org/testng/testhelper/TestNGSimpleClassLoader.java delete mode 100644 testng-core/src/test/java/testhelper/SourceCode.java diff --git a/CHANGES.txt b/CHANGES.txt index 4c0e273c05..fd5f8ae525 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,7 @@ Current + +7.6.1 +Fixed: GITHUB-2761: Exception: ERROR java.nio.file.NoSuchFileException: /tmp/testngXmlPathInJar-15086412835569336174 (Krishnan Mahadevan) 7.6.0 Fixed: GITHUB-2741: Show fully qualified name of the test instead of just the function name for better readability of test output.(Krishnan Mahadevan) Fixed: GITHUB-2725: Honour custom attribute values in TestNG default reports (Krishnan Mahadevan) diff --git a/gradle.properties b/gradle.properties index 554181f1fe..3323d24fa1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.code.style=official # Note: testng.kotlin-library.gradle.kts adds kotlin-stdlib for testImplementation kotlin.stdlib.default.dependency=false -testng.version=7.7.0 +testng.version=7.6.1 group=org.testng diff --git a/testng-core/src/main/java/org/testng/JarFileUtils.java b/testng-core/src/main/java/org/testng/JarFileUtils.java index 86ad2fbbbe..87237dfdd7 100644 --- a/testng-core/src/main/java/org/testng/JarFileUtils.java +++ b/testng-core/src/main/java/org/testng/JarFileUtils.java @@ -76,6 +76,7 @@ private boolean testngXmlExistsInJar(File jarFile, List classes) throws if (Parser.canParse(jeName.toLowerCase())) { InputStream inputStream = jf.getInputStream(je); File copyFile = new File(file, jeName); + copyFile.getParentFile().mkdirs(); Files.copy(inputStream, copyFile.toPath()); if (matchesXmlPathInJar(je)) { suitePath = copyFile.toString(); diff --git a/testng-core/src/main/java/org/testng/reporters/jq/Main.java b/testng-core/src/main/java/org/testng/reporters/jq/Main.java index a020810b97..b0bc7ba093 100644 --- a/testng-core/src/main/java/org/testng/reporters/jq/Main.java +++ b/testng-core/src/main/java/org/testng/reporters/jq/Main.java @@ -90,7 +90,9 @@ public void generateReport( if (is == null) { throw new AssertionError("Couldn't find resource: " + fileName); } - java.nio.file.Files.copy(is, new File(outputDirectory, fileName).toPath()); + File fileToCopy = new File(outputDirectory, fileName); + fileToCopy.getParentFile().mkdirs(); + java.nio.file.Files.copy(is, fileToCopy.toPath()); } } all = Files.readFile(header); diff --git a/testng-core/src/test/java/org/testng/JarFileUtilsTest.java b/testng-core/src/test/java/org/testng/JarFileUtilsTest.java index 471356f752..5e3816ec9a 100644 --- a/testng-core/src/test/java/org/testng/JarFileUtilsTest.java +++ b/testng-core/src/test/java/org/testng/JarFileUtilsTest.java @@ -14,7 +14,7 @@ import java.util.List; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import org.testng.jarfileutils.JarCreator; +import org.testng.testhelper.JarCreator; import org.testng.xml.IPostProcessor; import org.testng.xml.XmlClass; import org.testng.xml.XmlSuite; diff --git a/testng-core/src/test/java/testhelper/CompiledCode.java b/testng-core/src/test/java/org/testng/testhelper/CompiledCode.java similarity index 50% rename from testng-core/src/test/java/testhelper/CompiledCode.java rename to testng-core/src/test/java/org/testng/testhelper/CompiledCode.java index 4c75c7a29f..991e8e2081 100644 --- a/testng-core/src/test/java/testhelper/CompiledCode.java +++ b/testng-core/src/test/java/org/testng/testhelper/CompiledCode.java @@ -1,4 +1,4 @@ -package testhelper; +package org.testng.testhelper; import java.io.File; import java.io.IOException; @@ -11,9 +11,22 @@ public class CompiledCode { private final String name; public CompiledCode(String name, File directory, boolean skipLoading) throws IOException { + this("", name, directory, skipLoading); + } + + public CompiledCode(String packageName, String name, File directory, boolean skipLoading) + throws IOException { this.skipLoading = skipLoading; - this.name = name; - File classFile = new File(directory, name + Kind.CLASS.extension); + if (packageName != null && !packageName.trim().isEmpty()) { + this.name = packageName + "." + name; + } else { + this.name = name; + } + String location = name; + if (packageName != null && !packageName.trim().isEmpty()) { + location = packageName.replaceAll("\\Q.\\E", "/") + "/" + name; + } + File classFile = new File(directory, location + Kind.CLASS.extension); this.byteCode = Files.readAllBytes(classFile.toPath()); } diff --git a/testng-core/src/test/java/org/testng/jarfileutils/JarCreator.java b/testng-core/src/test/java/org/testng/testhelper/JarCreator.java similarity index 98% rename from testng-core/src/test/java/org/testng/jarfileutils/JarCreator.java rename to testng-core/src/test/java/org/testng/testhelper/JarCreator.java index 5a1c78f2e7..d75b3a38b3 100644 --- a/testng-core/src/test/java/org/testng/jarfileutils/JarCreator.java +++ b/testng-core/src/test/java/org/testng/testhelper/JarCreator.java @@ -1,4 +1,4 @@ -package org.testng.jarfileutils; +package org.testng.testhelper; import java.io.File; import java.io.IOException; diff --git a/testng-core/src/test/java/testhelper/OutputDirectoryPatch.java b/testng-core/src/test/java/org/testng/testhelper/OutputDirectoryPatch.java similarity index 98% rename from testng-core/src/test/java/testhelper/OutputDirectoryPatch.java rename to testng-core/src/test/java/org/testng/testhelper/OutputDirectoryPatch.java index bf829a52fa..80a0cfb024 100644 --- a/testng-core/src/test/java/testhelper/OutputDirectoryPatch.java +++ b/testng-core/src/test/java/org/testng/testhelper/OutputDirectoryPatch.java @@ -1,4 +1,4 @@ -package testhelper; +package org.testng.testhelper; /** * OutputDirectoryPatch is a helper class to provide an output directory for TestNG diff --git a/testng-core/src/test/java/testhelper/SimpleCompiler.java b/testng-core/src/test/java/org/testng/testhelper/SimpleCompiler.java similarity index 72% rename from testng-core/src/test/java/testhelper/SimpleCompiler.java rename to testng-core/src/test/java/org/testng/testhelper/SimpleCompiler.java index 6794d74e11..8f20951209 100644 --- a/testng-core/src/test/java/testhelper/SimpleCompiler.java +++ b/testng-core/src/test/java/org/testng/testhelper/SimpleCompiler.java @@ -1,4 +1,4 @@ -package testhelper; +package org.testng.testhelper; import java.io.File; import java.io.IOException; @@ -25,8 +25,18 @@ public static List compileSourceCode(SourceCode... sources) throws List compiledCodes = Lists.newArrayList(); for (SourceCode source : sources) { source.getLocation().delete(); - CompiledCode compiledCode = - new CompiledCode(source.getName(), source.getDirectory(), source.isSkipLoading()); + CompiledCode compiledCode; + if (source.hasPackageName()) { + compiledCode = + new CompiledCode( + source.getPackageName(), + source.getName(), + source.getDirectory(), + source.isSkipLoading()); + } else { + compiledCode = + new CompiledCode(source.getName(), source.getDirectory(), source.isSkipLoading()); + } compiledCodes.add(compiledCode); } return compiledCodes; diff --git a/testng-core/src/test/java/org/testng/testhelper/SourceCode.java b/testng-core/src/test/java/org/testng/testhelper/SourceCode.java new file mode 100644 index 0000000000..ed7eecb02e --- /dev/null +++ b/testng-core/src/test/java/org/testng/testhelper/SourceCode.java @@ -0,0 +1,69 @@ +package org.testng.testhelper; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import javax.tools.JavaFileObject.Kind; + +public class SourceCode { + + private final String packageName; + private final String name; + private final File directory; + private final boolean skipLoading; + private final File location; + + public SourceCode(String name, String src, File directory, boolean skipLoading) + throws IOException { + this("", name, src, directory, skipLoading); + } + + public SourceCode( + String packageName, String name, String src, File directory, boolean skipLoading) + throws IOException { + this.packageName = packageName; + this.name = name; + this.directory = directory; + this.skipLoading = skipLoading; + String path = name; + boolean includesPackageName = false; + if (packageName != null && !packageName.trim().isEmpty()) { + path = packageName.replaceAll("\\Q.\\E", "/") + "/" + name; + includesPackageName = true; + } + this.location = new File(directory, path + Kind.SOURCE.extension); + if (!includesPackageName && this.location.exists()) { + this.location.delete(); + } + Path parentDir = this.location.getParentFile().toPath(); + if (!Files.exists(parentDir)) { + Files.createDirectories(parentDir); + } + Files.write(location.toPath(), src.getBytes()); + } + + public File getDirectory() { + return directory; + } + + public String getName() { + return name; + } + + public boolean hasPackageName() { + return packageName != null && !packageName.trim().isEmpty(); + } + + public String getPackageName() { + return packageName; + } + + public boolean isSkipLoading() { + return skipLoading; + } + + public File getLocation() { + return location; + } +} diff --git a/testng-core/src/test/java/org/testng/testhelper/TestClassGenerator.java b/testng-core/src/test/java/org/testng/testhelper/TestClassGenerator.java new file mode 100644 index 0000000000..520001431f --- /dev/null +++ b/testng-core/src/test/java/org/testng/testhelper/TestClassGenerator.java @@ -0,0 +1,38 @@ +package org.testng.testhelper; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +public final class TestClassGenerator { + private static final File projectDir = SimpleCompiler.createTempDir(); + + private TestClassGenerator() { + // Utility class. Defeat instantiation. + } + + public static File getProjectDir() { + return projectDir; + } + + public static SourceCode[] generate(String packageName, List classNames) { + return classNames.stream() + .map(className -> generateCode(packageName, className)) + .toArray(SourceCode[]::new); + } + + private static SourceCode generateCode(String packageName, String className) { + String source = "package " + packageName + ";\n\n"; + source += "import org.testng.annotations.Test;\n"; + source += "public class " + className + " {\n"; + source += " @Test\n"; + source += " public void testMethod() {\n"; + source += " }\n"; + source += "}\n"; + try { + return new SourceCode(packageName, className, source, projectDir, false); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/testng-core/src/test/java/org/testng/testhelper/TestNGSimpleClassLoader.java b/testng-core/src/test/java/org/testng/testhelper/TestNGSimpleClassLoader.java new file mode 100644 index 0000000000..dc37e3f494 --- /dev/null +++ b/testng-core/src/test/java/org/testng/testhelper/TestNGSimpleClassLoader.java @@ -0,0 +1,36 @@ +package org.testng.testhelper; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; + +public final class TestNGSimpleClassLoader extends ClassLoader { + + private final File baseDir; + + public TestNGSimpleClassLoader() { + this(null); + } + + public TestNGSimpleClassLoader(File baseDir) { + this.baseDir = baseDir; + } + + public Class injectByteCode(CompiledCode byteCode) throws ClassNotFoundException { + Class clazz = + defineClass(byteCode.getName(), byteCode.getByteCode(), 0, byteCode.getByteCode().length); + return loadClass(clazz.getName()); + } + + @Override + protected URL findResource(String name) { + if (this.baseDir != null) { + try { + return new File(this.baseDir.getAbsolutePath() + "/" + name).toURI().toURL(); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + return super.findResource(name); + } +} diff --git a/testng-core/src/test/java/test/CommandLineTest.java b/testng-core/src/test/java/test/CommandLineTest.java index 096d7b3ffb..6a853f420c 100644 --- a/testng-core/src/test/java/test/CommandLineTest.java +++ b/testng-core/src/test/java/test/CommandLineTest.java @@ -19,8 +19,8 @@ import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.internal.IConfiguration; +import org.testng.testhelper.OutputDirectoryPatch; import test.sample.JUnitSample1; -import testhelper.OutputDirectoryPatch; public class CommandLineTest { diff --git a/testng-core/src/test/java/test/JUnitTestClassLoader.java b/testng-core/src/test/java/test/JUnitTestClassLoader.java index be783d48a0..1274347afd 100644 --- a/testng-core/src/test/java/test/JUnitTestClassLoader.java +++ b/testng-core/src/test/java/test/JUnitTestClassLoader.java @@ -6,9 +6,9 @@ import java.util.List; import org.testng.*; import org.testng.annotations.Test; -import testhelper.CompiledCode; -import testhelper.SimpleCompiler; -import testhelper.SourceCode; +import org.testng.testhelper.CompiledCode; +import org.testng.testhelper.SimpleCompiler; +import org.testng.testhelper.SourceCode; public class JUnitTestClassLoader extends ClassLoader { diff --git a/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java b/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java index a93987141f..ed628782d8 100644 --- a/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java +++ b/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java @@ -5,8 +5,8 @@ import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; +import org.testng.testhelper.OutputDirectoryPatch; import test.SimpleBaseTest; -import testhelper.OutputDirectoryPatch; public class AlwaysRunTest extends SimpleBaseTest { diff --git a/testng-core/src/test/java/test/cli/CliTest.java b/testng-core/src/test/java/test/cli/CliTest.java index 975de67b4e..64c0547d8b 100644 --- a/testng-core/src/test/java/test/cli/CliTest.java +++ b/testng-core/src/test/java/test/cli/CliTest.java @@ -2,14 +2,28 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.function.Supplier; import org.testng.Assert; import org.testng.CommandLineArgs; +import org.testng.IInvokedMethod; +import org.testng.IInvokedMethodListener; +import org.testng.ITestResult; import org.testng.TestNG; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import org.testng.testhelper.CompiledCode; +import org.testng.testhelper.JarCreator; +import org.testng.testhelper.SimpleCompiler; +import org.testng.testhelper.SourceCode; +import org.testng.testhelper.TestClassGenerator; +import org.testng.testhelper.TestNGSimpleClassLoader; import test.SimpleBaseTest; import test.cli.github1517.TestClassWithConfigFailureSample; import test.cli.github1517.TestClassWithConfigSkipAndFailureSample; @@ -70,6 +84,52 @@ public Object[][] getData() { }; } + @Test(description = "GITHUB-2761") + public void testToEnsureSuitesInJarAreExecutedViaCli() throws IOException { + SourceCode[] sources = + TestClassGenerator.generate("com.kungfu.panda", Arrays.asList("DragonWarrior", "Tigress")); + List compiledSources = SimpleCompiler.compileSourceCode(sources); + TestNGSimpleClassLoader classLoader = + new TestNGSimpleClassLoader(TestClassGenerator.getProjectDir()); + Class[] classes = + compiledSources.stream() + .map(compiledCode -> compile(classLoader, compiledCode)) + .toArray(size -> new Class[size]); + File jar = JarCreator.generateJar(classes); + LogInvocations logInvocations = new LogInvocations(); + TestNG testng = new TestNG(); + testng.addClassLoader(classLoader); + testng.setTestJar(jar.getAbsolutePath()); + testng.addListener(logInvocations); + testng.setVerbose(2); + testng.run(); + assertThat(testng.getStatus()).isEqualTo(0); + assertThat(logInvocations.logs) + .containsExactlyInAnyOrder( + "com.kungfu.panda.DragonWarrior.testMethod", "com.kungfu.panda.Tigress.testMethod"); + } + + private static Class compile(TestNGSimpleClassLoader loader, CompiledCode code) { + try { + return loader.injectByteCode(code); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + public static class LogInvocations implements IInvokedMethodListener { + private final List logs = new ArrayList<>(); + + @Override + public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { + logs.add(method.getTestMethod().getQualifiedName()); + } + + public List getLogs() { + return logs; + } + } + public static class CustomTestNG extends TestNG { @Override diff --git a/testng-core/src/test/java/test/commandline/CommandLineOverridesXml.java b/testng-core/src/test/java/test/commandline/CommandLineOverridesXml.java index b647dd01e3..e6ba273c48 100644 --- a/testng-core/src/test/java/test/commandline/CommandLineOverridesXml.java +++ b/testng-core/src/test/java/test/commandline/CommandLineOverridesXml.java @@ -14,7 +14,7 @@ import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; -import org.testng.jarfileutils.JarCreator; +import org.testng.testhelper.JarCreator; import org.testng.xml.XmlSuite; import test.SimpleBaseTest; import test.TestHelper; diff --git a/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java b/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java index ac22a92be2..2dee53088f 100644 --- a/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java +++ b/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java @@ -6,11 +6,11 @@ import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; +import org.testng.testhelper.OutputDirectoryPatch; import org.testng.xml.XmlSuite; import test.SimpleBaseTest; import test.conffailure.github990.AbstractBaseSample; import test.conffailure.github990.ChildClassSample; -import testhelper.OutputDirectoryPatch; /** * Test various cases where the @Configuration methods fail diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java b/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java index 329fe4248a..62bf417a96 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java @@ -9,8 +9,8 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import org.testng.testhelper.OutputDirectoryPatch; import org.testng.xml.XmlSuite; -import testhelper.OutputDirectoryPatch; public class FailurePolicyTest { diff --git a/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java b/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java index a8d3b508d1..bc306b8c98 100644 --- a/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java +++ b/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java @@ -7,8 +7,8 @@ import org.testng.TestNG; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import org.testng.testhelper.OutputDirectoryPatch; import test.BaseTest; -import testhelper.OutputDirectoryPatch; public class InterleavedInvocationTest extends BaseTest { public static List LOG = new ArrayList<>(); diff --git a/testng-core/src/test/java/test/mannotation/issue1976/IssueTest.java b/testng-core/src/test/java/test/mannotation/issue1976/IssueTest.java index fb41feb58a..6520ca8a7c 100644 --- a/testng-core/src/test/java/test/mannotation/issue1976/IssueTest.java +++ b/testng-core/src/test/java/test/mannotation/issue1976/IssueTest.java @@ -8,30 +8,22 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.testng.collections.Lists; -import testhelper.CompiledCode; -import testhelper.SimpleCompiler; -import testhelper.SourceCode; +import org.testng.testhelper.CompiledCode; +import org.testng.testhelper.SimpleCompiler; +import org.testng.testhelper.SourceCode; +import org.testng.testhelper.TestNGSimpleClassLoader; public class IssueTest extends ClassLoader { private static final File dir = SimpleCompiler.createTempDir(); - private static final class MyClassLoader extends ClassLoader { - - public Class injectByteCode(CompiledCode byteCode) throws ClassNotFoundException { - Class clazz = - defineClass(byteCode.getName(), byteCode.getByteCode(), 0, byteCode.getByteCode().length); - return loadClass(clazz.getName()); - } - } - @Test( dataProvider = "dp", expectedExceptions = TypeNotPresentException.class, description = "GITHUB-1976") public void testMethod(SourceCode... sources) throws IOException, ClassNotFoundException { TestNG tng = new TestNG(false); - MyClassLoader classLoader = new MyClassLoader(); + TestNGSimpleClassLoader classLoader = new TestNGSimpleClassLoader(); tng.addClassLoader(classLoader); List byteCodes = SimpleCompiler.compileSourceCode(sources); List> classes = Lists.newArrayList(); diff --git a/testng-core/src/test/java/test/methodselectors/CommandLineTest.java b/testng-core/src/test/java/test/methodselectors/CommandLineTest.java index b79a45ad96..fcffea3aba 100644 --- a/testng-core/src/test/java/test/methodselectors/CommandLineTest.java +++ b/testng-core/src/test/java/test/methodselectors/CommandLineTest.java @@ -7,8 +7,8 @@ import org.testng.TestNG; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import org.testng.testhelper.OutputDirectoryPatch; import test.SimpleBaseTest; -import testhelper.OutputDirectoryPatch; public class CommandLineTest extends SimpleBaseTest { diff --git a/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java b/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java index c68e43689c..a953bf4f42 100644 --- a/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java +++ b/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java @@ -10,12 +10,12 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.testng.collections.Lists; +import org.testng.testhelper.OutputDirectoryPatch; import org.testng.xml.XmlClass; import org.testng.xml.XmlMethodSelector; import org.testng.xml.XmlSuite; import org.testng.xml.XmlTest; import test.SimpleBaseTest; -import testhelper.OutputDirectoryPatch; public class MethodSelectorInSuiteTest extends SimpleBaseTest { diff --git a/testng-core/src/test/java/test/mixed/MixedTest.java b/testng-core/src/test/java/test/mixed/MixedTest.java index e338847df6..db757f2700 100644 --- a/testng-core/src/test/java/test/mixed/MixedTest.java +++ b/testng-core/src/test/java/test/mixed/MixedTest.java @@ -4,8 +4,8 @@ import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; +import org.testng.testhelper.OutputDirectoryPatch; import test.BaseTest; -import testhelper.OutputDirectoryPatch; /** @author lukas */ public class MixedTest extends BaseTest { diff --git a/testng-core/src/test/java/test/simple/IncludedExcludedTest.java b/testng-core/src/test/java/test/simple/IncludedExcludedTest.java index 166b89701e..9008876f97 100644 --- a/testng-core/src/test/java/test/simple/IncludedExcludedTest.java +++ b/testng-core/src/test/java/test/simple/IncludedExcludedTest.java @@ -11,8 +11,8 @@ import org.testng.TestNG; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import org.testng.testhelper.OutputDirectoryPatch; import org.testng.xml.XmlSuite; -import testhelper.OutputDirectoryPatch; public class IncludedExcludedTest { diff --git a/testng-core/src/test/java/test/uniquesuite/TestAfter.java b/testng-core/src/test/java/test/uniquesuite/TestAfter.java index 3dddee4b90..a8565a562a 100644 --- a/testng-core/src/test/java/test/uniquesuite/TestAfter.java +++ b/testng-core/src/test/java/test/uniquesuite/TestAfter.java @@ -4,7 +4,7 @@ import org.testng.TestNG; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; -import testhelper.OutputDirectoryPatch; +import org.testng.testhelper.OutputDirectoryPatch; public class TestAfter { diff --git a/testng-core/src/test/java/testhelper/SourceCode.java b/testng-core/src/test/java/testhelper/SourceCode.java deleted file mode 100644 index 18fc570863..0000000000 --- a/testng-core/src/test/java/testhelper/SourceCode.java +++ /dev/null @@ -1,43 +0,0 @@ -package testhelper; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; -import javax.tools.JavaFileObject.Kind; - -public class SourceCode { - - private final String name; - private final File directory; - private final boolean skipLoading; - private final File location; - - public SourceCode(String name, String src, File directory, boolean skipLoading) - throws IOException { - this.name = name; - this.directory = directory; - this.skipLoading = skipLoading; - this.location = new File(directory, name + Kind.SOURCE.extension); - if (this.location.exists()) { - this.location.delete(); - } - Files.write(location.toPath(), src.getBytes(), StandardOpenOption.CREATE_NEW); - } - - public File getDirectory() { - return directory; - } - - public String getName() { - return name; - } - - public boolean isSkipLoading() { - return skipLoading; - } - - public File getLocation() { - return location; - } -}