diff --git a/testng-core/src/test/java/org/testng/internal/ClassHelperTest.java b/testng-core/src/test/java/org/testng/internal/ClassHelperTest.java deleted file mode 100644 index 8fa9175746..0000000000 --- a/testng-core/src/test/java/org/testng/internal/ClassHelperTest.java +++ /dev/null @@ -1,151 +0,0 @@ -package org.testng.internal; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.UUID; -import org.assertj.core.api.Assertions; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import org.testng.internal.issue1339.BabyPanda; -import org.testng.internal.issue1339.LittlePanda; -import org.testng.internal.issue1456.TestClassSample; -import org.testng.internal.misamples.AbstractMoves; -import org.testng.internal.misamples.Batman; -import org.testng.internal.misamples.JohnTravoltaMoves; -import org.testng.internal.misamples.MickJagger; -import org.testng.xml.XmlClass; -import org.testng.xml.XmlSuite; -import org.testng.xml.XmlTest; - -public class ClassHelperTest { - - @Test - public void testGetAvailableMethods() { - runTest(getExpected(), LittlePanda.class); - } - - @Test - public void testGetAvailableMethodsWhenOverrdingIsInvolved() { - List expected = getExpected("equals", "hashCode", "toString"); - runTest(expected, BabyPanda.class); - } - - @Test - public void testFindClassInSameTest() { - runTest(TestClassSample.class, 1, TestClassSample.class); - } - - @Test - public void testFindClassesInSameTest() { - runTest(TestClassSample.class, 2, TestClassSample.class, BabyPanda.class); - } - - @Test - public void testNoClassDefFoundError() { - URLClassLoader urlClassLoader = - new URLClassLoader(new URL[] {}) { - @Override - public Class loadClass(String name) throws ClassNotFoundException { - throw new NoClassDefFoundError(); - } - }; - ClassHelper.addClassLoader(urlClassLoader); - String fakeClassName = UUID.randomUUID().toString(); - Assert.assertNull( - ClassHelper.forName(fakeClassName), - "The result should be null; no exception should be thrown."); - } - - @Test(dataProvider = "data") - public void testWithDefaultMethodsBeingOverridden( - Class cls, int expectedCount, String... expected) { - Set methods = ClassHelper.getAvailableMethodsExcludingDefaults(cls); - Assertions.assertThat(methods).hasSize(expectedCount); - for (Method m : methods) { - String actual = m.getDeclaringClass().getName() + "." + m.getName(); - Assertions.assertThat(expected).contains(actual); - } - } - - @DataProvider(name = "data") - public Object[][] getTestData() { - return new Object[][] { - {MickJagger.class, 1, MickJagger.class.getName() + ".dance"}, - { - JohnTravoltaMoves.class, - 2, - new String[] { - JohnTravoltaMoves.class.getName() + ".walk", AbstractMoves.class.getName() + ".dance" - } - }, - { - Batman.class, - 3, - new String[] { - Batman.class.getName() + ".fly", - Batman.class.getName() + ".liftWeights", - Batman.class.getName() + ".yellSlogan" - } - } - }; - } - - private static void runTest(Class classToBeFound, int expectedCount, Class... classes) { - XmlSuite xmlSuite = new XmlSuite(); - xmlSuite.setName("xml_suite"); - newXmlTest("test1", xmlSuite, classes); - newXmlTest("test2", xmlSuite, classes); - newXmlTest("test3", xmlSuite, classes); - XmlClass[] xmlClasses = ClassHelper.findClassesInSameTest(classToBeFound, xmlSuite); - assertThat(xmlClasses.length).isEqualTo(expectedCount); - } - - private static void newXmlTest(String testname, XmlSuite xmlSuite, Class... clazz) { - XmlTest xmlTest = new XmlTest(xmlSuite); - xmlTest.setName(testname); - xmlTest.setXmlClasses(newXmlClass(clazz)); - } - - private static List newXmlClass(Class... classes) { - List xmlClasses = new ArrayList<>(); - for (Class clazz : classes) { - xmlClasses.add(new XmlClass(clazz)); - } - return xmlClasses; - } - - private static void runTest(List expected, Class whichClass) { - Set methods = ClassHelper.getAvailableMethods(whichClass); - // Intentionally not using assertEquals because when this test is executed via gradle an - // additional method - // called "jacocoInit()" is getting added, which does not get added when this test is executed - // individually - int size = expected.size(); - Assert.assertTrue( - methods.size() >= size, "Number of methods found should have been atleast " + size); - for (Method method : methods) { - if ("$jacocoInit".equalsIgnoreCase(method.getName())) { - continue; - } - Assert.assertTrue(expected.contains(method.getName())); - } - } - - private static List getExpected(String... additionalMethods) { - String[] defaultMethods = new String[] {"announcer", "announcer", "inheritable", "inheritable"}; - if (additionalMethods == null) { - return Arrays.asList(defaultMethods); - } - List expected = new ArrayList<>(Arrays.asList(defaultMethods)); - expected.addAll(Arrays.asList(additionalMethods)); - return expected; - } -} diff --git a/testng-core/src/test/java/org/testng/internal/issue1339/BabyPanda.java b/testng-core/src/test/java/org/testng/internal/issue1339/BabyPanda.java deleted file mode 100644 index c014b59191..0000000000 --- a/testng-core/src/test/java/org/testng/internal/issue1339/BabyPanda.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.testng.internal.issue1339; - -public class BabyPanda extends LittlePanda { - String name; - - @Override - public String toString() { - return "BabyPanda{" + "name='" + name + '\'' + '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - BabyPanda babyPanda = (BabyPanda) o; - - return name != null ? name.equals(babyPanda.name) : babyPanda.name == null; - } - - @Override - public int hashCode() { - return name != null ? name.hashCode() : 0; - } -} diff --git a/testng-core/src/test/java/org/testng/internal/issue1339/GrandpaBear.java b/testng-core/src/test/java/org/testng/internal/issue1339/GrandpaBear.java deleted file mode 100644 index 5f0b6cc6ad..0000000000 --- a/testng-core/src/test/java/org/testng/internal/issue1339/GrandpaBear.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.testng.internal.issue1339; - -public class GrandpaBear { - private void secretMethod() {} - - public void announcer() {} - - public void inheritable() {} -} diff --git a/testng-core/src/test/java/org/testng/internal/issue1339/LittlePanda.java b/testng-core/src/test/java/org/testng/internal/issue1339/LittlePanda.java deleted file mode 100644 index 761754d200..0000000000 --- a/testng-core/src/test/java/org/testng/internal/issue1339/LittlePanda.java +++ /dev/null @@ -1,3 +0,0 @@ -package org.testng.internal.issue1339; - -public class LittlePanda extends PapaBear {} diff --git a/testng-core/src/test/java/org/testng/internal/issue1339/PapaBear.java b/testng-core/src/test/java/org/testng/internal/issue1339/PapaBear.java deleted file mode 100644 index 0c8c3a64b8..0000000000 --- a/testng-core/src/test/java/org/testng/internal/issue1339/PapaBear.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.testng.internal.issue1339; - -public class PapaBear extends GrandpaBear { - private void secretMethod(String foo) {} - - public void announcer(String foo) {} - - public void inheritable(String foo) {} -} diff --git a/testng-core/src/test/java/org/testng/internal/issue1456/TestClassSample.java b/testng-core/src/test/java/org/testng/internal/issue1456/TestClassSample.java deleted file mode 100644 index 74933e7656..0000000000 --- a/testng-core/src/test/java/org/testng/internal/issue1456/TestClassSample.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.testng.internal.issue1456; - -import org.testng.ITest; - -public class TestClassSample implements ITest { - private String testname; - - public TestClassSample(String testname) { - this.testname = testname; - } - - @Override - public String getTestName() { - return testname; - } -} diff --git a/testng-core/src/test/java/org/testng/internal/misamples/AbstractMoves.java b/testng-core/src/test/java/org/testng/internal/misamples/AbstractMoves.java deleted file mode 100644 index 9ac6ac95dd..0000000000 --- a/testng-core/src/test/java/org/testng/internal/misamples/AbstractMoves.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.testng.internal.misamples; - -public abstract class AbstractMoves implements IDance { - - @Override - public void dance() {} - - public abstract void walk(); -} diff --git a/testng-core/src/test/java/org/testng/internal/misamples/Batman.java b/testng-core/src/test/java/org/testng/internal/misamples/Batman.java deleted file mode 100644 index 49f1500e7f..0000000000 --- a/testng-core/src/test/java/org/testng/internal/misamples/Batman.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.testng.internal.misamples; - -public class Batman implements SuperHeroCapabilities { - - @Override - public void fly() {} - - @Override - public void liftWeights() {} - - @Override - public void yellSlogan() {} -} diff --git a/testng-core/src/test/java/org/testng/internal/misamples/IDance.java b/testng-core/src/test/java/org/testng/internal/misamples/IDance.java deleted file mode 100644 index b77adb8490..0000000000 --- a/testng-core/src/test/java/org/testng/internal/misamples/IDance.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.testng.internal.misamples; - -public interface IDance { - - default void dance() {} -} diff --git a/testng-core/src/test/java/org/testng/internal/misamples/JohnTravoltaMoves.java b/testng-core/src/test/java/org/testng/internal/misamples/JohnTravoltaMoves.java deleted file mode 100644 index cf86ab33f2..0000000000 --- a/testng-core/src/test/java/org/testng/internal/misamples/JohnTravoltaMoves.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.testng.internal.misamples; - -public class JohnTravoltaMoves extends AbstractMoves { - - @Override - public void walk() {} -} diff --git a/testng-core/src/test/java/org/testng/internal/misamples/MickJagger.java b/testng-core/src/test/java/org/testng/internal/misamples/MickJagger.java deleted file mode 100644 index 49c0e9ac09..0000000000 --- a/testng-core/src/test/java/org/testng/internal/misamples/MickJagger.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.testng.internal.misamples; - -public class MickJagger implements IDance { - - @Override - public void dance() {} -} diff --git a/testng-core/src/test/java/org/testng/internal/misamples/SuperHeroCapabilities.java b/testng-core/src/test/java/org/testng/internal/misamples/SuperHeroCapabilities.java deleted file mode 100644 index d6c26f35b2..0000000000 --- a/testng-core/src/test/java/org/testng/internal/misamples/SuperHeroCapabilities.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.testng.internal.misamples; - -public interface SuperHeroCapabilities { - - default void yellSlogan() {} - - void fly(); - - void liftWeights(); -} diff --git a/testng-core/src/test/java/org/testng/internal/objects/InstanceCreatorTest.java b/testng-core/src/test/java/org/testng/internal/objects/InstanceCreatorTest.java index 0de177cf26..d56de45601 100644 --- a/testng-core/src/test/java/org/testng/internal/objects/InstanceCreatorTest.java +++ b/testng-core/src/test/java/org/testng/internal/objects/InstanceCreatorTest.java @@ -10,7 +10,7 @@ import org.testng.internal.annotations.DefaultAnnotationTransformer; import org.testng.internal.annotations.IAnnotationFinder; import org.testng.internal.annotations.JDK15AnnotationFinder; -import org.testng.internal.issue1456.TestClassSample; +import org.testng.internal.samples.classhelper.issue1456.TestClassSample; import org.testng.xml.XmlSuite; import org.testng.xml.XmlTest; diff --git a/testng-core/src/test/java/org/testng/reporters/jq/TimesPanelTest.java b/testng-core/src/test/java/org/testng/reporters/jq/TimesPanelTest.java deleted file mode 100644 index eb49676da4..0000000000 --- a/testng-core/src/test/java/org/testng/reporters/jq/TimesPanelTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.testng.reporters.jq; - -import static org.testng.AssertJUnit.assertTrue; - -import java.util.ArrayList; -import java.util.List; -import org.testng.ISuite; -import org.testng.annotations.Test; -import org.testng.internal.paramhandler.FakeSuite; -import org.testng.reporters.XMLStringBuffer; -import org.testng.xml.XmlTest; -import test.SimpleBaseTest; - -public class TimesPanelTest extends SimpleBaseTest { - - private static final String GITHUB_1931 = "GITHUB-1931 [NPE] TimesPanel.maxTime(ISuite suite)"; - - @Test(description = GITHUB_1931) - public void generateReportTimesPanelContentForSuiteWithoutStartedTests() { - XmlTest xmlTest = createXmlTest("GITHUB_1931", "NPE", Object.class); - ISuite iSuite = new FakeSuite(xmlTest); - List suites = new ArrayList<>(); - suites.add(iSuite); - Model model = new Model(suites); - TimesPanel panel = new TimesPanel(model); - XMLStringBuffer buffer = new XMLStringBuffer(); - panel.getContent(iSuite, buffer); - assertTrue( - "TimesPanel contains total running time", - panel.getContent(iSuite, buffer).contains("Total running time: 0 ms")); - } -} diff --git a/testng-core/src/test/java/org/testng/util/StringsTest.java b/testng-core/src/test/java/org/testng/util/StringsTest.java deleted file mode 100644 index a25c1cb3b8..0000000000 --- a/testng-core/src/test/java/org/testng/util/StringsTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.testng.util; - -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.Test; - -/** Unit tests for {@link Strings} */ -public class StringsTest { - @Test - public void joinEmptyArray() { - String[] emptyArray = new String[0]; - assertEquals(Strings.join(",", emptyArray), ""); - } - - @Test - public void joinArrayWithOneElement() { - String[] array = new String[] {"one"}; - assertEquals(Strings.join(",", array), "one"); - } - - @Test - public void joinArrayWithTwoElements() { - String[] array = new String[] {"one", "two"}; - assertEquals(Strings.join(",", array), "one,two"); - } -} diff --git a/testng-core/src/test/kotlin/org/testng/internal/ClassHelperTest.kt b/testng-core/src/test/kotlin/org/testng/internal/ClassHelperTest.kt new file mode 100644 index 0000000000..798e53249c --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/ClassHelperTest.kt @@ -0,0 +1,146 @@ +package org.testng.internal + +import org.assertj.core.api.Assertions.assertThat +import org.testng.Reporter + +import java.net.URL +import java.net.URLClassLoader +import java.util.UUID +import org.testng.annotations.DataProvider +import org.testng.annotations.Test +import org.testng.internal.samples.classhelper.issue1339.BabyPandaSample +import org.testng.internal.samples.classhelper.issue1339.LittlePandaSample +import org.testng.internal.samples.classhelper.issue1456.TestClassSample +import org.testng.internal.samples.classhelper.misamples.AbstractMovesSample +import org.testng.internal.samples.classhelper.misamples.BatmanSample +import org.testng.internal.samples.classhelper.misamples.JohnTravoltaMovesSample +import org.testng.internal.samples.classhelper.misamples.MickJaggerSample +import org.testng.xml.XmlClass +import org.testng.xml.XmlSuite +import org.testng.xml.XmlTest +import kotlin.reflect.KClass + +typealias TestData = Array> + +class ClassHelperTest { + + private val defaultMethods = listOf("announcer", "announcer", "inheritable", "inheritable") + + @Test(dataProvider = "testDataProvider") + fun runFindClassesInSameTestScenarios( + scenarioName: String,//This parameter will help us differentiate scenarios in reports + classToBeFound: KClass<*>, + expectedCount: Int, vararg classes: KClass<*>, + ) { + Reporter.log("Running Scenario $scenarioName") + val xmlSuite = XmlSuite().apply { + name = "xml_suite" + } + listOf("test1", "test2", "test3").forEach { + xmlSuite.addXmlTest(it, *classes) + } + val xmlClasses = ClassHelper.findClassesInSameTest(classToBeFound.java, xmlSuite) + assertThat(xmlClasses).hasSize(expectedCount) + } + + @DataProvider(name = "testDataProvider") + fun testDataProvider(): TestData { + return arrayOf( + arrayOf("FindClassInSameTest", TestClassSample::class, 1, TestClassSample::class), + arrayOf( + "FindClassesInSameTest", + TestClassSample::class, 2, TestClassSample::class, BabyPandaSample::class + ), + ) + } + + @Test(dataProvider = "scenariosData") + fun runAvailableMethodsScenarios( + scenarioName: String,//This parameter will help us differentiate scenarios in reports + expected: List, + whichClass: KClass<*> + ) { + Reporter.log("Running Scenario $scenarioName") + val actual = ClassHelper.getAvailableMethods(whichClass.java) + .filter { + //jacocoInit() is something that Gradle adds. So filter it out. + !"\$jacocoInit".contentEquals(it.name) + } + .map { + it.name + }.toList() + assertThat(actual).containsAll(expected) + } + + @DataProvider(name = "scenariosData") + fun scenariosData(): TestData { + return arrayOf( + arrayOf("AllAvailableMethods", defaultMethods, LittlePandaSample::class), + arrayOf( + "AvailableMethodsWhenOverridingIsInvolved", + defaultMethods + listOf("equals", "hashCode", "toString"), + BabyPandaSample::class + ), + ) + } + + @Test + fun testNoClassDefFoundError() { + val urlClassLoader = object : URLClassLoader(emptyArray()) { + override fun loadClass(className: String?): Class<*> { + throw NoClassDefFoundError() + } + } + ClassHelper.addClassLoader(urlClassLoader) + val fakeClassName = UUID.randomUUID().toString() + assertThat(ClassHelper.forName(fakeClassName)) + .withFailMessage("The result should be null; no exception should be thrown.") + .isNull() + } + + @Test(dataProvider = "data") + fun testWithDefaultMethodsBeingOverridden( + cls: KClass<*>, expectedCount: Int, vararg expected: String + ) { + val methods = ClassHelper.getAvailableMethodsExcludingDefaults(cls.java) + .map { + it.declaringClass.name + "." + it.name + } + assertThat(methods).hasSize(expectedCount) + assertThat(methods).contains(*expected) + } + + @DataProvider(name = "data") + fun getTestData(): TestData { + return arrayOf( + arrayOf(MickJaggerSample::class, 1, MickJaggerSample::class.java.name + ".dance"), + arrayOf( + JohnTravoltaMovesSample::class, + 2, + JohnTravoltaMovesSample::class.java.name + ".walk", + AbstractMovesSample::class.java.name + ".dance" + ), + arrayOf( + BatmanSample::class, + 3, + BatmanSample::class.java.name + ".fly", + BatmanSample::class.java.name + ".liftWeights", + BatmanSample::class.java.name + ".yellSlogan" + ) + ) + } + + private fun XmlSuite.addXmlTest(testName: String, vararg clazz: KClass<*>): XmlSuite { + XmlTest(this).apply { + name = testName + xmlClasses = newXmlClasses(*clazz) + } + return this + } + + private fun newXmlClasses(vararg classes: KClass<*>): List { + return classes.map { + XmlClass(it.java) + }.toList() + } +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/BabyPandaSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/BabyPandaSample.kt new file mode 100644 index 0000000000..04793c2674 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/BabyPandaSample.kt @@ -0,0 +1,20 @@ +package org.testng.internal.samples.classhelper.issue1339 + +class BabyPandaSample : LittlePandaSample() { + private var name = "Po" + + override fun toString() = "BabyPanda{name='$name'}" + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as BabyPandaSample + + if (name != other.name) return false + + return true + } + + override fun hashCode() = name.hashCode() +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/GrandpaBearSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/GrandpaBearSample.kt new file mode 100644 index 0000000000..656ad0fdb6 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/GrandpaBearSample.kt @@ -0,0 +1,9 @@ +package org.testng.internal.samples.classhelper.issue1339; + +open class GrandpaBearSample { + private fun secretMethod() {} + + fun announcer() {} + + fun inheritable() {} +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/LittlePandaSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/LittlePandaSample.kt new file mode 100644 index 0000000000..3ecaaf0130 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/LittlePandaSample.kt @@ -0,0 +1,3 @@ +package org.testng.internal.samples.classhelper.issue1339; + +open class LittlePandaSample : PapaBearSample() diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/PapaBearSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/PapaBearSample.kt new file mode 100644 index 0000000000..936a0b58f4 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1339/PapaBearSample.kt @@ -0,0 +1,9 @@ +package org.testng.internal.samples.classhelper.issue1339; + +open class PapaBearSample : GrandpaBearSample() { + private fun secretMethod(foo: String) {} + + fun announcer(foo: String) {} + + fun inheritable(foo: String) {} +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1456/TestClassSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1456/TestClassSample.kt new file mode 100644 index 0000000000..2225673f95 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/issue1456/TestClassSample.kt @@ -0,0 +1,7 @@ +package org.testng.internal.samples.classhelper.issue1456 + +import org.testng.ITest + +class TestClassSample(var name: String) : ITest { + override fun getTestName() = name +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/AbstractMovesSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/AbstractMovesSample.kt new file mode 100644 index 0000000000..c400a5dd29 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/AbstractMovesSample.kt @@ -0,0 +1,8 @@ +package org.testng.internal.samples.classhelper.misamples + +abstract class AbstractMovesSample : IDance { + + override fun dance() {} + + abstract fun walk() +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/BatmanSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/BatmanSample.kt new file mode 100644 index 0000000000..8895bb3419 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/BatmanSample.kt @@ -0,0 +1,10 @@ +package org.testng.internal.samples.classhelper.misamples + +class BatmanSample : SuperHeroCapabilities { + + override fun fly() {} + + override fun liftWeights() {} + + override fun yellSlogan() {} +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/IDance.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/IDance.kt new file mode 100644 index 0000000000..0505888645 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/IDance.kt @@ -0,0 +1,5 @@ +package org.testng.internal.samples.classhelper.misamples + +interface IDance { + fun dance() {} +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/JohnTravoltaMovesSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/JohnTravoltaMovesSample.kt new file mode 100644 index 0000000000..5a77663a6a --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/JohnTravoltaMovesSample.kt @@ -0,0 +1,6 @@ +package org.testng.internal.samples.classhelper.misamples + +class JohnTravoltaMovesSample : AbstractMovesSample() { + + override fun walk() {} +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/MickJaggerSample.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/MickJaggerSample.kt new file mode 100644 index 0000000000..e59c0768f1 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/MickJaggerSample.kt @@ -0,0 +1,5 @@ +package org.testng.internal.samples.classhelper.misamples + +class MickJaggerSample : IDance { + override fun dance() {} +} diff --git a/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/SuperHeroCapabilities.kt b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/SuperHeroCapabilities.kt new file mode 100644 index 0000000000..0693e6bc8d --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/internal/samples/classhelper/misamples/SuperHeroCapabilities.kt @@ -0,0 +1,9 @@ +package org.testng.internal.samples.classhelper.misamples + +interface SuperHeroCapabilities { + fun yellSlogan() {} + + fun fly() + + fun liftWeights() +} diff --git a/testng-core/src/test/kotlin/org/testng/reporters/jq/TimesPanelTest.kt b/testng-core/src/test/kotlin/org/testng/reporters/jq/TimesPanelTest.kt new file mode 100644 index 0000000000..52a200dcd5 --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/reporters/jq/TimesPanelTest.kt @@ -0,0 +1,29 @@ +package org.testng.reporters.jq + +import org.assertj.core.api.Assertions.assertThat + +import org.testng.annotations.Test +import org.testng.internal.paramhandler.FakeSuite +import org.testng.reporters.XMLStringBuffer +import test.SimpleBaseTest + +class TimesPanelTest : SimpleBaseTest() { + + companion object { + const val GITHUB_1931 = "GITHUB-1931 [NPE] TimesPanel.maxTime(ISuite suite)" + } + + @Test(description = GITHUB_1931) + fun generateReportTimesPanelContentForSuiteWithoutStartedTests() { + val xmlTest = createXmlTest("GITHUB_1931", "NPE", Object::class.java) + val iSuite = FakeSuite(xmlTest) + val suites = listOf(iSuite) + val model = Model(suites) + val panel = TimesPanel(model) + val buffer = XMLStringBuffer() + panel.getContent(iSuite, buffer) + assertThat(panel.getContent(iSuite, buffer)) + .withFailMessage { "TimesPanel contains total running time" } + .contains("Total running time: 0 ms") + } +} diff --git a/testng-core/src/test/kotlin/org/testng/util/StringsTest.kt b/testng-core/src/test/kotlin/org/testng/util/StringsTest.kt new file mode 100644 index 0000000000..923e70316b --- /dev/null +++ b/testng-core/src/test/kotlin/org/testng/util/StringsTest.kt @@ -0,0 +1,24 @@ +package org.testng.util + +import org.assertj.core.api.Assertions.assertThat +import org.testng.annotations.Test + +class StringsTest { + @Test + fun joinEmptyArray() { + val emptyArray = arrayOf() + assertThat(Strings.join(",", emptyArray)).isEmpty() + } + + @Test + fun joinArrayWithOneElement() { + val array = arrayOf("one") + assertThat(Strings.join(",", array)).isEqualTo("one") + } + + @Test + fun joinArrayWithTwoElements() { + val array = arrayOf("one", "two") + assertThat(Strings.join(",", array)).isEqualTo("one,two") + } +}