diff --git a/build-logic/code-quality/src/main/kotlin/testng.testing.gradle.kts b/build-logic/code-quality/src/main/kotlin/testng.testing.gradle.kts index c9e71d0617..325f53765e 100644 --- a/build-logic/code-quality/src/main/kotlin/testng.testing.gradle.kts +++ b/build-logic/code-quality/src/main/kotlin/testng.testing.gradle.kts @@ -6,7 +6,7 @@ plugins { } dependencies { - testImplementation("org.assertj:assertj-core:3.23.1") + testImplementation("org.assertj:assertj-core:3.27.7") } tasks.withType().configureEach { diff --git a/testng-api/testng-api-build.gradle.kts b/testng-api/testng-api-build.gradle.kts index ce14b05045..f50396786a 100644 --- a/testng-api/testng-api-build.gradle.kts +++ b/testng-api/testng-api-build.gradle.kts @@ -6,6 +6,5 @@ plugins { javaPlatform.allowDependencies() dependencies { - api(projects.testngAsserts) api(projects.testngCoreApi) } diff --git a/testng-core/src/test/groovy/test/groovy/issue2854/AssertionsTestSample.groovy b/testng-core/src/test/groovy/test/groovy/issue2854/AssertionsTestSample.groovy index befdf752dd..a4cdd79a24 100644 --- a/testng-core/src/test/groovy/test/groovy/issue2854/AssertionsTestSample.groovy +++ b/testng-core/src/test/groovy/test/groovy/issue2854/AssertionsTestSample.groovy @@ -2,56 +2,56 @@ package test.groovy.issue2854 import org.testng.annotations.Test -import static org.testng.Assert.assertEquals +import static org.assertj.core.api.Assertions.assertThat class AssertionsTestSample { @Test void testAssertEqualsWorksWithBooleans() { - assertEquals(true, true) - assertEquals(true, true, "Sample Message") + assertThat(true).isEqualTo(true) + assertThat(true).as("Sample Message").isEqualTo(true) } @Test void testAssertEqualsWorksWithBytes() { - assertEquals(Byte.valueOf((byte) 10), Byte.valueOf((byte) 10)) - assertEquals(Byte.valueOf((byte) 10), Byte.valueOf((byte) 10), "Sample Message") + assertThat(Byte.valueOf((byte) 10)).isEqualTo(Byte.valueOf((byte) 10)) + assertThat(Byte.valueOf((byte) 10)).as("Sample Message").isEqualTo(Byte.valueOf((byte) 10)) } @Test void testAssertEqualsWorksWithChars() { - assertEquals(Character.valueOf((char) 10), Character.valueOf((char) 10)) - assertEquals(Character.valueOf((char) 10), Character.valueOf((char) 10), "Sample Message") + assertThat(Character.valueOf((char) 10)).isEqualTo(Character.valueOf((char) 10)) + assertThat(Character.valueOf((char) 10)).as("Sample Message").isEqualTo(Character.valueOf((char) 10)) } @Test void testAssertEqualsWorksWithShorts() { - assertEquals(Short.valueOf((short) 10), Short.valueOf((short) 10)) - assertEquals(Short.valueOf((short) 10), Short.valueOf((short) 10), "Sample Message") + assertThat(Short.valueOf((short) 10)).isEqualTo(Short.valueOf((short) 10)) + assertThat(Short.valueOf((short) 10)).as("Sample Message").isEqualTo(Short.valueOf((short) 10)) } @Test void testAssertEqualsWorksWithInts() { - assertEquals(10, 10) - assertEquals(10, 10, "Sample Message") + assertThat(10).isEqualTo(10) + assertThat(10).as("Sample Message").isEqualTo(10) } @Test void testAssertEqualsWorksWithLongs() { - assertEquals(Long.valueOf((long) 10), Long.valueOf((long) 10)) - assertEquals(Long.valueOf((long) 10), Long.valueOf((long) 10), "Sample Message") + assertThat(Long.valueOf((long) 10)).isEqualTo(Long.valueOf((long) 10)) + assertThat(Long.valueOf((long) 10)).as("Sample Message").isEqualTo(Long.valueOf((long) 10)) } @Test void testAssertEqualsWorksWithFloats() { - assertEquals(Float.valueOf((float) 10), Float.valueOf((float) 10)) - assertEquals(Float.valueOf((float) 10), Float.valueOf((float) 10), "Sample Message") + assertThat(Float.valueOf((float) 10)).isEqualTo(Float.valueOf((float) 10)) + assertThat(Float.valueOf((float) 10)).as("Sample Message").isEqualTo(Float.valueOf((float) 10)) } @Test void testAssertEqualsWorksWithDoubles() { - assertEquals(Double.valueOf((double) 10), Double.valueOf((double) 10)) - assertEquals(Double.valueOf((double) 10), Double.valueOf((double) 10), "Sample Message") + assertThat(Double.valueOf((double) 10)).isEqualTo(Double.valueOf((double) 10)) + assertThat(Double.valueOf((double) 10)).as("Sample Message").isEqualTo(Double.valueOf((double) 10)) } } diff --git a/testng-core/src/test/java/NoPackageTest.java b/testng-core/src/test/java/NoPackageTest.java index f7f8cf2455..91aaf217d3 100644 --- a/testng-core/src/test/java/NoPackageTest.java +++ b/testng-core/src/test/java/NoPackageTest.java @@ -1,4 +1,4 @@ -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; @@ -14,6 +14,6 @@ public void test() { @AfterMethod(groups = {"nopackage"}) public void after() { - assertTrue(m_run, "test method was not run"); + assertThat(m_run).withFailMessage("test method was not run").isTrue(); } } diff --git a/testng-core/src/test/java/ReporterConfigTest.java b/testng-core/src/test/java/ReporterConfigTest.java index 4d1b9d19fd..ef0a6ca599 100644 --- a/testng-core/src/test/java/ReporterConfigTest.java +++ b/testng-core/src/test/java/ReporterConfigTest.java @@ -1,5 +1,4 @@ -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Objects; import org.testng.annotations.Test; @@ -16,9 +15,8 @@ public class ReporterConfigTest { @Test public void testDeserialize() { ReporterConfig config = ReporterConfig.deserialize(CONFIG_STR); - assertEquals(Objects.requireNonNull(config).getClassName(), CLASS_NAME); + assertThat(Objects.requireNonNull(config).getClassName()).isEqualTo(CLASS_NAME); String serial = config.serialize(); - assertTrue(serial.contains(PROP_NAME_1 + "=true")); - assertTrue(serial.contains(PROP_NAME_2 + "=true")); + assertThat(serial).contains(PROP_NAME_1 + "=true").contains(PROP_NAME_2 + "=true"); } } diff --git a/testng-core/src/test/java/org/testng/JarFileUtilsTest.java b/testng-core/src/test/java/org/testng/JarFileUtilsTest.java index 3d3afee6eb..34b6114647 100644 --- a/testng-core/src/test/java/org/testng/JarFileUtilsTest.java +++ b/testng-core/src/test/java/org/testng/JarFileUtilsTest.java @@ -135,7 +135,7 @@ public void ensureThatExceptionAreNotThrown() throws MalformedURLException { testNg.initializeSuitesAndJarFile(); // "testng-tests-child2", "testng-tests-child4", "testng-tests-child5" are from 3 different test // suites - Assert.assertEquals(testNg.m_suites.size(), 3); + assertThat(testNg.m_suites).hasSize(3); } /** @@ -154,7 +154,7 @@ public void ensureThatExceptionAreThrown() throws MalformedURLException { testNg.setXmlPathInJar("jarfileutils/testng-tests.xml"); testNg.setTestJar(jar.getAbsolutePath()); testNg.initializeSuitesAndJarFile(); - Assert.assertEquals(testNg.m_suites.size(), 1); + assertThat(testNg.m_suites).hasSize(1); } @Test diff --git a/testng-core/src/test/java/org/testng/internal/DynamicGraphHelperTest.java b/testng-core/src/test/java/org/testng/internal/DynamicGraphHelperTest.java index 5b94ea28ab..a8ac0dcda7 100644 --- a/testng-core/src/test/java/org/testng/internal/DynamicGraphHelperTest.java +++ b/testng-core/src/test/java/org/testng/internal/DynamicGraphHelperTest.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import org.testng.ITestClass; import org.testng.ITestNGMethod; import org.testng.ITestObjectFactory; @@ -150,10 +149,8 @@ public void testCreateDynamicGraphWithPackageWithAbstractClassPreserveOrderTrue( XmlTest xmlTest = createXmlTest("2249_suite", "2249_test", classes); xmlTest.setPreserveOrder(true); DynamicGraph graph = newGraph(xmlTest, classes); - assertThat( - graph.getFreeNodes().stream() - .map(ITestNGMethod::getMethodName) - .collect(Collectors.toList())) + assertThat(graph.getFreeNodes()) + .extracting(ITestNGMethod::getMethodName) .containsExactly("a1", "a2"); } @@ -162,10 +159,8 @@ public void testCreateDynamicGraphWithPackageWithoutAbstractClass(Class[] cla XmlTest xmlTest = createXmlTest("2249_suite", "2249_test", classes); xmlTest.setPreserveOrder(false); DynamicGraph graph = newGraph(xmlTest, classes); - assertThat( - graph.getFreeNodes().stream() - .map(ITestNGMethod::getMethodName) - .collect(Collectors.toList())) + assertThat(graph.getFreeNodes()) + .extracting(ITestNGMethod::getMethodName) .containsExactly("a1", "a2", "b2", "b1"); } diff --git a/testng-core/src/test/java/org/testng/internal/DynamicGraphTest.java b/testng-core/src/test/java/org/testng/internal/DynamicGraphTest.java index 05c8c87d74..7883ad970f 100644 --- a/testng-core/src/test/java/org/testng/internal/DynamicGraphTest.java +++ b/testng-core/src/test/java/org/testng/internal/DynamicGraphTest.java @@ -5,7 +5,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.testng.Assert; import org.testng.IDynamicGraph; import org.testng.IDynamicGraph.Status; import org.testng.ITestNGMethod; @@ -44,7 +43,7 @@ private static void assertFreeNodesEquals(IDynamicGraph graph, T... expec private static void assertFreeNodesEquals(IDynamicGraph graph, List expected) { // Compare free nodes using isEqualTo instead of containsOnly as we care about ordering too. - assertThat(graph.getFreeNodes()).isEqualTo(expected); + assertThat(graph.getFreeNodes()).containsExactlyElementsOf(expected); } @Test @@ -262,7 +261,7 @@ public void edgeWeightTest1() { InvokedMethodNameListener listener = new InvokedMethodNameListener(); tng.addListener(listener); tng.run(); - Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder1); + assertThat(listener.getSucceedMethodNames()).containsExactlyElementsOf(expectedOrder1); } @Test @@ -272,15 +271,15 @@ public void edgeWeightTest2() { InvokedMethodNameListener listener = new InvokedMethodNameListener(); tng.addListener(listener); tng.run(); - Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder2); + assertThat(listener.getSucceedMethodNames()).containsExactlyElementsOf(expectedOrder2); } private static void runAssertion(IDynamicGraph graph, List expected) { List p1Methods = graph.getFreeNodes(); - Assert.assertEquals(p1Methods.size(), 3); + assertThat(p1Methods).hasSize(3); graph.setStatus(p1Methods, Status.FINISHED); for (ITestNGMethod p1Method : p1Methods) { - Assert.assertTrue(expected.contains(constructName(p1Method))); + assertThat(expected).contains(constructName(p1Method)); } } @@ -298,7 +297,7 @@ public void testDuplicationFunctionality() { testng.addListener(tla); testng.run(); int expected = tla.getMultiplyCount() + tla.getOriginalMethodCount(); - assertThat(tla.getPassedTests().size()).isEqualTo(expected); + assertThat(tla.getPassedTests()).hasSize(expected); } @Test(expectedExceptions = IllegalStateException.class) @@ -325,22 +324,22 @@ public void testAllowedCycles() { public void testGainWeight() { DynamicGraph dg = new DynamicGraph<>(); dg.addEdge(1, "a", "b"); - assertThat(dg.getEdges().values().size()).isEqualTo(1); - assertThat(dg.getEdges().get("a").get("b")).isEqualTo(1); + assertThat(dg.getEdges().values()).hasSize(1); + assertThat(dg.getEdges().get("a")).containsEntry("b", 1); // Duplicated edge, but with lower weight dg.addEdge(0, "a", "b"); // Should only be one edge with same weight - assertThat(dg.getEdges().values().size()).isEqualTo(1); - assertThat(dg.getEdges().get("a").get("b")).isEqualTo(1); + assertThat(dg.getEdges().values()).hasSize(1); + assertThat(dg.getEdges().get("a")).containsEntry("b", 1); // Duplicated edge, but with higher weight dg.addEdge(2, "a", "b"); // Should only be one edge with weight of 2 now. - assertThat(dg.getEdges().values().size()).isEqualTo(1); - assertThat(dg.getEdges().get("a").get("b")).isEqualTo(2); + assertThat(dg.getEdges().values()).hasSize(1); + assertThat(dg.getEdges().get("a")).containsEntry("b", 2); } /** @@ -422,7 +421,7 @@ public void testParallel() { // all done assertThat(dg.getFreeNodes()).isEmpty(); - assertThat(dg.getNodeCountWithStatus(Status.READY)).isEqualTo(0); + assertThat(dg.getNodeCountWithStatus(Status.READY)).isZero(); assertThat(dg.getNodeCountWithStatus(Status.FINISHED)).isEqualTo(100); } } diff --git a/testng-core/src/test/java/org/testng/internal/MethodInstanceTest.java b/testng-core/src/test/java/org/testng/internal/MethodInstanceTest.java index bcd0840e27..a3ce5bcdb3 100644 --- a/testng-core/src/test/java/org/testng/internal/MethodInstanceTest.java +++ b/testng-core/src/test/java/org/testng/internal/MethodInstanceTest.java @@ -1,11 +1,12 @@ package org.testng.internal; +import static org.assertj.core.api.Assertions.fail; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; -import org.testng.Assert; import org.testng.IClass; import org.testng.IRetryAnalyzer; import org.testng.ITestClass; @@ -69,7 +70,7 @@ public void sortByIndexSatisfiesContract() { try { methods.sort(MethodInstance.SORT_BY_INDEX); } catch (IllegalArgumentException ex) { - Assert.fail("Comparison method violates its general contract!"); + fail("Comparison method violates its general contract!"); } } diff --git a/testng-core/src/test/java/org/testng/internal/ParametersTest.java b/testng-core/src/test/java/org/testng/internal/ParametersTest.java index 497098a2aa..c37f69bf03 100644 --- a/testng-core/src/test/java/org/testng/internal/ParametersTest.java +++ b/testng-core/src/test/java/org/testng/internal/ParametersTest.java @@ -1,7 +1,8 @@ package org.testng.internal; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -22,7 +23,7 @@ public void filterOutInJectedTypesFromOptionalValuesTest( FilterOutInjectedTypesResult filterOutResult = org.testng.internal.Parameters.filterOutInjectedTypesFromOptionalValues( curMethod.getParameterTypes(), finder.findOptionalValues(curMethod)); - Assert.assertEquals(filterOutResult.getOptionalValues()[0], "optionaltestdata"); - Assert.assertEquals(filterOutResult.getParameterTypes()[0], String.class); + assertThat(filterOutResult.getOptionalValues()[0]).isEqualTo("optionaltestdata"); + assertThat(filterOutResult.getParameterTypes()[0]).isEqualTo(String.class); } } diff --git a/testng-core/src/test/java/org/testng/internal/UtilsTest.java b/testng-core/src/test/java/org/testng/internal/UtilsTest.java index c2b9726bd3..00a058e70c 100644 --- a/testng-core/src/test/java/org/testng/internal/UtilsTest.java +++ b/testng-core/src/test/java/org/testng/internal/UtilsTest.java @@ -3,7 +3,6 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; import static org.testng.internal.Utils.join; import java.util.List; @@ -20,27 +19,27 @@ public class UtilsTest { @Test public void escapeUnicode() { - assertEquals(Utils.escapeUnicode("test"), "test"); - assertEquals( - Utils.escapeUnicode(String.valueOf(INVALID_CHAR)), String.valueOf(REPLACEMENT_CHAR)); + assertThat(Utils.escapeUnicode("test")).isEqualTo("test"); + assertThat(Utils.escapeUnicode(String.valueOf(INVALID_CHAR))) + .isEqualTo(String.valueOf(REPLACEMENT_CHAR)); } @Test public void createEmptyStringWhenJoiningEmptyListWithJoin() { List emptyList = emptyList(); - assertEquals("", join(emptyList, ",")); + assertThat("").isEqualTo(join(emptyList, ",")); } @Test public void joinTwoStringsWithJoinStrings() { List twoStrings = asList("one", "two"); - assertEquals("one,two", Utils.join(twoStrings, ",")); + assertThat("one,two").isEqualTo(Utils.join(twoStrings, ",")); } @Test public void createEmptyStringWhenJoiningEmptyListWithJoinStrings() { List emptyList = emptyList(); - assertEquals("", Utils.join(emptyList, ",")); + assertThat("").isEqualTo(Utils.join(emptyList, ",")); } @Test diff --git a/testng-core/src/test/java/org/testng/internal/objects/GuiceHelperTest.java b/testng-core/src/test/java/org/testng/internal/objects/GuiceHelperTest.java index eaf22649dc..ab2c6e2f02 100644 --- a/testng-core/src/test/java/org/testng/internal/objects/GuiceHelperTest.java +++ b/testng-core/src/test/java/org/testng/internal/objects/GuiceHelperTest.java @@ -1,13 +1,11 @@ package org.testng.internal.objects; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.Stage; import org.jetbrains.annotations.Nullable; -import org.testng.Assert; import org.testng.IInjectorFactory; import org.testng.ITest; import org.testng.ITestObjectFactory; @@ -28,11 +26,11 @@ public void getInjector_spiModule_injectorHasModule() { MockInjector injector = (MockInjector) guiceHelper.getInjector(new MockClass(), new MockInjectorFactory()); - assertNotNull(injector); + assertThat(injector).isNotNull(); Module[] modules = injector.getModules(); - assertNotNull(modules); - assertEquals(modules.length, 1); - Assert.assertEquals(modules[0], new SampleIModule().getModule()); + assertThat(modules).isNotNull(); + assertThat(modules.length).isOne(); + assertThat(modules[0]).isEqualTo(new SampleIModule().getModule()); } private static final class MockInjectorFactory implements IInjectorFactory { 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 d56de45601..71a775bc47 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 @@ -1,7 +1,8 @@ package org.testng.internal.objects; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Map; -import org.testng.Assert; import org.testng.IClass; import org.testng.ITest; import org.testng.ITestObjectFactory; @@ -28,7 +29,7 @@ public void testCreateInstance1WithOneArgStringParamForConstructor() { Object object = SimpleObjectDispenser.createInstance( declaringClass, classes, xmlTest, finder, objectFactory, false, ""); - Assert.assertTrue(object instanceof ITest); - Assert.assertEquals(((ITest) object).getTestName(), GITHUB_1456); + assertThat(object).isInstanceOf(ITest.class); + assertThat(((ITest) object).getTestName()).isEqualTo(GITHUB_1456); } } diff --git a/testng-core/src/test/java/org/testng/internal/paramhandler/DataDrivenSampleTestClass.java b/testng-core/src/test/java/org/testng/internal/paramhandler/DataDrivenSampleTestClass.java index 5c23f63119..7ea3c9939e 100644 --- a/testng-core/src/test/java/org/testng/internal/paramhandler/DataDrivenSampleTestClass.java +++ b/testng-core/src/test/java/org/testng/internal/paramhandler/DataDrivenSampleTestClass.java @@ -1,13 +1,14 @@ package org.testng.internal.paramhandler; -import org.assertj.core.api.Assertions; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class DataDrivenSampleTestClass { @Test(dataProvider = "dp") public void testMethod(String i) { - Assertions.assertThat(i).isNotEmpty(); + assertThat(i).isNotEmpty(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/org/testng/internal/paramhandler/ExceptionThrowingDataDrivenSampleTestClass.java b/testng-core/src/test/java/org/testng/internal/paramhandler/ExceptionThrowingDataDrivenSampleTestClass.java index 4926ea7ae6..0790a04539 100644 --- a/testng-core/src/test/java/org/testng/internal/paramhandler/ExceptionThrowingDataDrivenSampleTestClass.java +++ b/testng-core/src/test/java/org/testng/internal/paramhandler/ExceptionThrowingDataDrivenSampleTestClass.java @@ -1,13 +1,14 @@ package org.testng.internal.paramhandler; -import org.assertj.core.api.Assertions; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class ExceptionThrowingDataDrivenSampleTestClass { @Test(dataProvider = "dp") public void testMethod(String i) { - Assertions.assertThat(i).isNotEmpty(); + assertThat(i).isNotEmpty(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/org/testng/xml/ParserTest.java b/testng-core/src/test/java/org/testng/xml/ParserTest.java index c1416ca34b..c586571ca7 100644 --- a/testng-core/src/test/java/org/testng/xml/ParserTest.java +++ b/testng-core/src/test/java/org/testng/xml/ParserTest.java @@ -1,6 +1,6 @@ package org.testng.xml; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.util.List; @@ -16,7 +16,7 @@ public class ParserTest { public void testParsing(String file) throws Exception { Parser parser = new Parser(file); List suites = parser.parseToList(); - assertEquals(suites.size(), 1); + assertThat(suites).hasSize(1); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/org/testng/xml/SuiteXmlParserTest.java b/testng-core/src/test/java/org/testng/xml/SuiteXmlParserTest.java index ac81a5eafa..f9fb724fe9 100644 --- a/testng-core/src/test/java/org/testng/xml/SuiteXmlParserTest.java +++ b/testng-core/src/test/java/org/testng/xml/SuiteXmlParserTest.java @@ -1,10 +1,10 @@ package org.testng.xml; +import static org.assertj.core.api.Assertions.fail; import static test.SimpleBaseTest.getPathToResource; import java.io.File; import java.io.FileInputStream; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -30,11 +30,11 @@ public void testParse(String fileName, boolean shouldWork) { try (FileInputStream stream = new FileInputStream(new File(PARENT, fileName))) { XmlSuite suite = parser.parse(fileName, stream, false); if (!shouldWork) { - Assert.fail("Parsing of " + fileName + " is supposed to fail"); + fail("Parsing of " + fileName + " is supposed to fail"); } } catch (Exception e) { if (shouldWork) { - Assert.fail("Parsing of " + fileName + " is supposed to work"); + fail("Parsing of " + fileName + " is supposed to work"); } } } diff --git a/testng-core/src/test/java/org/testng/xml/XmlSuiteTest.java b/testng-core/src/test/java/org/testng/xml/XmlSuiteTest.java index 2dbc05d187..c557383462 100644 --- a/testng-core/src/test/java/org/testng/xml/XmlSuiteTest.java +++ b/testng-core/src/test/java/org/testng/xml/XmlSuiteTest.java @@ -1,7 +1,6 @@ package org.testng.xml; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; import java.io.IOException; import java.io.OutputStream; @@ -55,8 +54,8 @@ public void testTimeOut(String timeout, int size, int lineNumber) { StringReader stringReader = new StringReader(suite.toXml()); List resultLines = Lists.newArrayList(); List lineNumbers = grep(stringReader, "time-out=\"1000\"", resultLines); - assertThat(lineNumbers).size().isEqualTo(size); - assertThat(resultLines).size().isEqualTo(size); + assertThat(lineNumbers).hasSize(size); + assertThat(resultLines).hasSize(size); if (size > 0) { assertThat(lineNumbers.get(size - 1)).isEqualTo(lineNumber); } @@ -89,12 +88,12 @@ public void ensureSuiteLevelPackageIsAppliedToAllTests() throws IOException { Parser parser = new Parser("src/test/resources/xml/issue435.xml"); List suites = parser.parseToList(); XmlSuite xmlsuite = suites.get(0); - assertThat(xmlsuite.getTests().get(0).getClasses().size()).isEqualTo(0); + assertThat(xmlsuite.getTests().get(0).getClasses()).isEmpty(); TestNG testNG = create(); testNG.setXmlSuites(suites); testNG.setUseDefaultListeners(false); testNG.run(); - assertThat(xmlsuite.getTests().get(0).getClasses().size()).isEqualTo(1); + assertThat(xmlsuite.getTests().get(0).getClasses()).hasSize(1); } @Test(description = "GITHUB-1674") @@ -106,12 +105,12 @@ public void ensureSuiteLevelBeanshellIsAppliedToAllTests() throws IOException { Parser parser = new Parser("src/test/resources/xml/issue1674.xml"); List suites = parser.parseToList(); XmlSuite xmlsuite = suites.get(0); - assertThat(xmlsuite.getTests().get(0).getMethodSelectors().size()).isEqualTo(0); + assertThat(xmlsuite.getTests().get(0).getMethodSelectors()).isEmpty(); TestNG testNG = create(); testNG.setXmlSuites(suites); testNG.setUseDefaultListeners(false); testNG.run(); - assertThat(xmlsuite.getTests().get(0).getMethodSelectors().size()).isEqualTo(1); + assertThat(xmlsuite.getTests().get(0).getMethodSelectors()).hasSize(1); assertThat(stream.toString()).contains(Arrays.asList("rajni", "kamal", "mgr")); } finally { System.setOut(current); @@ -194,23 +193,23 @@ public void checkDuplicateChildSuites() throws IOException { Parser parser = new Parser(path); List suites = parser.parseToList(); XmlSuite rootSuite = suites.get(0); - assertEquals(rootSuite.getChildSuites().size(), 4); + assertThat(rootSuite.getChildSuites()).hasSize(4); XmlSuite suite3 = rootSuite.getChildSuites().get(1); - assertEquals(suite3.getName(), "Child Suite 3"); - assertEquals(suite3.getChildSuites().size(), 3); + assertThat(suite3.getName()).isEqualTo("Child Suite 3"); + assertThat(suite3.getChildSuites()).hasSize(3); XmlSuite suite3_0 = rootSuite.getChildSuites().get(3); - assertEquals(suite3.getName(), "Child Suite 3"); - assertEquals(suite3_0.getChildSuites().size(), 3); + assertThat(suite3.getName()).isEqualTo("Child Suite 3"); + assertThat(suite3_0.getChildSuites()).hasSize(3); XmlSuite suite5 = suite3.getChildSuites().get(2); - assertEquals(suite5.getName(), "Child Suite 5"); - assertEquals(suite5.getTests().size(), 1); + assertThat(suite5.getName()).isEqualTo("Child Suite 5"); + assertThat(suite5.getTests()).hasSize(1); XmlSuite suite5_0 = suite3_0.getChildSuites().get(2); - assertEquals(suite5_0.getName(), "Child Suite 5"); - assertEquals(suite5_0.getTests().size(), 1); + assertThat(suite5_0.getName()).isEqualTo("Child Suite 5"); + assertThat(suite5_0.getTests()).hasSize(1); } private static void runTests( @@ -221,13 +220,13 @@ private static void runTests( } catch (IOException e) { throw new TestNGException(e); } - assertEquals(suites.size(), 1); - assertEquals(suites.get(0).getChildSuites().size(), childSuitesCount); + assertThat(suites).hasSize(1); + assertThat(suites.get(0).getChildSuites()).hasSize(childSuitesCount); TestNG testng = create(suites); SuiteCounter listener = new SuiteCounter(); testng.addListener((ITestNGListener) listener); testng.run(); - assertEquals(listener.getCounter(), suiteCounter); + assertThat(listener.getCounter()).isEqualTo(suiteCounter); assertThat(listener.getSuiteNames()).containsExactly(suiteNames); } diff --git a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java index d5f06c5ab0..bd4a0e8470 100644 --- a/testng-core/src/test/java/org/testng/xml/XmlTestTest.java +++ b/testng-core/src/test/java/org/testng/xml/XmlTestTest.java @@ -4,7 +4,6 @@ import java.util.Collections; import java.util.Map; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.testng.collections.Maps; @@ -33,7 +32,7 @@ public void testNullOrEmptyParameter(Map data) { XmlTest test = createXmlTest("suite", "test", Issue1716TestSample.class); test.setParameters(data); test.toXml(" "); - Assert.assertTrue(true, "No exceptions should have been thrown"); + assertThat(true).withFailMessage("No exceptions should have been thrown").isTrue(); } @DataProvider(name = "dp") @@ -47,9 +46,9 @@ public void testXMLClassesInCloneMethod() { XmlTest xmlTest = createXmlTest(xmlSuite, "test"); createXmlClass(xmlTest, SimpleTestSample.class); XmlTest copyXmlTest = (XmlTest) xmlTest.clone(); - Assert.assertNotNull(copyXmlTest); - Assert.assertNotNull(copyXmlTest.getXmlClasses()); - Assert.assertEquals(xmlTest.getXmlClasses().size(), copyXmlTest.getXmlClasses().size()); + assertThat(copyXmlTest).isNotNull(); + assertThat(copyXmlTest.getXmlClasses()).isNotNull(); + assertThat(xmlTest.getXmlClasses()).hasSameSizeAs(copyXmlTest.getXmlClasses()); } private static Map newSetOfParameters(String key, String value) { diff --git a/testng-core/src/test/java/org/testng/xml/issue1668/TestClassSample.java b/testng-core/src/test/java/org/testng/xml/issue1668/TestClassSample.java index 8dda94b44e..39699e1b3e 100644 --- a/testng-core/src/test/java/org/testng/xml/issue1668/TestClassSample.java +++ b/testng-core/src/test/java/org/testng/xml/issue1668/TestClassSample.java @@ -1,11 +1,12 @@ package org.testng.xml.issue1668; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class TestClassSample { @Test public void testMethod() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/BaseDistributedTest.java b/testng-core/src/test/java/test/BaseDistributedTest.java index c624ea25fc..2804af466d 100644 --- a/testng-core/src/test/java/test/BaseDistributedTest.java +++ b/testng-core/src/test/java/test/BaseDistributedTest.java @@ -1,8 +1,9 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; import java.util.Map; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.collections.Maps; import org.testng.log4testng.Logger; @@ -16,8 +17,9 @@ protected void verifyTests(String title, String[] exp, Map> m) { } protected void run() { - assertNotNull( - getTest(), "Test wasn't set, maybe @Configuration methodSetUp() was never called"); + assertThat(getTest()) + .withFailMessage("Test wasn't set, maybe @Configuration methodSetUp() was never called") + .isNotNull(); setPassedTests(Maps.newHashMap()); setFailedTests(Maps.newHashMap()); setSkippedTests(Maps.newHashMap()); @@ -307,9 +307,13 @@ protected void verifyResults(Map> tests, int expected, Object firstKey = keys.iterator().next(); List passedResult = tests.get(firstKey); int n = passedResult.size(); - assertEquals(n, expected, "Expected " + expected + " " + message + " but found " + n); + assertThat(n) + .withFailMessage("Expected " + expected + " " + message + " but found " + n) + .isEqualTo(expected); } else { - assertEquals(0, expected, "Expected " + expected + " " + message + " but found 0."); + assertThat(0) + .withFailMessage("Expected " + expected + " " + message + " but found 0.") + .isEqualTo(expected); } } diff --git a/testng-core/src/test/java/test/CheckSuitesInitializationTest.java b/testng-core/src/test/java/test/CheckSuitesInitializationTest.java index 9b01becd15..9af5d9bb31 100644 --- a/testng-core/src/test/java/test/CheckSuitesInitializationTest.java +++ b/testng-core/src/test/java/test/CheckSuitesInitializationTest.java @@ -1,7 +1,8 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -33,6 +34,6 @@ public void check() { tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener(tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 4); + assertThat(tla.getPassedTests()).hasSize(4); } } diff --git a/testng-core/src/test/java/test/ClassConfigurations.java b/testng-core/src/test/java/test/ClassConfigurations.java index bfe477267c..5bc3387522 100644 --- a/testng-core/src/test/java/test/ClassConfigurations.java +++ b/testng-core/src/test/java/test/ClassConfigurations.java @@ -1,6 +1,6 @@ package test; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeClass; @@ -31,19 +31,19 @@ public void afterTestClass() { @Test public void testOne() { - assertEquals(beforeCount, 1); - assertEquals(afterCount, 0); + assertThat(beforeCount).isOne(); + assertThat(afterCount).isZero(); } @Test public void testTwo() { - assertEquals(beforeCount, 1); - assertEquals(afterCount, 0); + assertThat(beforeCount).isOne(); + assertThat(afterCount).isZero(); } @Test public void testThree() { - assertEquals(beforeCount, 1); - assertEquals(afterCount, 0); + assertThat(beforeCount).isOne(); + assertThat(afterCount).isZero(); } } diff --git a/testng-core/src/test/java/test/CountSampleTest.java b/testng-core/src/test/java/test/CountSampleTest.java index 9e68817782..990ead916b 100644 --- a/testng-core/src/test/java/test/CountSampleTest.java +++ b/testng-core/src/test/java/test/CountSampleTest.java @@ -1,6 +1,7 @@ package test; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.SkipException; import org.testng.annotations.Test; @@ -20,7 +21,7 @@ public void testInvokedAndSkipped() throws SkipException { @Test(groups = {"functional"}) public static void testInvokedAndFailed() { // System.out.println("Failing this test after it is invoked."); - Assert.fail("Failing this test on purpose"); + fail("Failing this test on purpose"); } @Test( diff --git a/testng-core/src/test/java/test/CountTest.java b/testng-core/src/test/java/test/CountTest.java index 11ed6ddb26..2d4f95429d 100644 --- a/testng-core/src/test/java/test/CountTest.java +++ b/testng-core/src/test/java/test/CountTest.java @@ -1,7 +1,8 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.IReporter; import org.testng.ISuite; import org.testng.ISuiteResult; @@ -24,7 +25,7 @@ public void generateReport( for (ISuite s : suites) { for (ISuiteResult sr : s.getResults().values()) { ITestContext ctx = sr.getTestContext(); - Assert.assertEquals(2, ctx.getSkippedTests().size()); + assertThat(2).isEqualTo(ctx.getSkippedTests().size()); } } } diff --git a/testng-core/src/test/java/test/CtorCalledOnce.java b/testng-core/src/test/java/test/CtorCalledOnce.java index 2df5bd6f07..b93bd93081 100644 --- a/testng-core/src/test/java/test/CtorCalledOnce.java +++ b/testng-core/src/test/java/test/CtorCalledOnce.java @@ -1,6 +1,6 @@ package test; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; @@ -18,17 +18,23 @@ public CtorCalledOnce() { @Test public void testMethod1() { - assertEquals(instantiated, 1, "Expected 1, was invoked " + instantiated + " times"); + assertThat(instantiated) + .withFailMessage("Expected 1, was invoked " + instantiated + " times") + .isOne(); } @Test public void testMethod2() { - assertEquals(instantiated, 1, "Expected 1, was invoked " + instantiated + " times"); + assertThat(instantiated) + .withFailMessage("Expected 1, was invoked " + instantiated + " times") + .isOne(); } @Test public void testMethod3() { - assertEquals(instantiated, 1, "Expected 1, was invoked " + instantiated + " times"); + assertThat(instantiated) + .withFailMessage("Expected 1, was invoked " + instantiated + " times") + .isOne(); } @AfterTest diff --git a/testng-core/src/test/java/test/EclipseTest.java b/testng-core/src/test/java/test/EclipseTest.java index 508b5e7937..96fc6ba029 100644 --- a/testng-core/src/test/java/test/EclipseTest.java +++ b/testng-core/src/test/java/test/EclipseTest.java @@ -1,6 +1,7 @@ package test; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestContext; import org.testng.annotations.Test; @@ -14,6 +15,6 @@ public class EclipseTest { @Test public void xmlFileShouldBeRunAtItsPlaceAndNotCopied(ITestContext ctx) { String fileName = ctx.getSuite().getXmlSuite().getFileName().replace("\\", "/"); - Assert.assertTrue(fileName.contains("src/test/resources")); + assertThat(fileName).contains("src/test/resources"); } } diff --git a/testng-core/src/test/java/test/Exclude.java b/testng-core/src/test/java/test/Exclude.java index 23fafd1364..0e7e599546 100644 --- a/testng-core/src/test/java/test/Exclude.java +++ b/testng-core/src/test/java/test/Exclude.java @@ -1,6 +1,6 @@ package test; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -34,15 +34,16 @@ public void excluded2() { dependsOnGroups = {"group1"}, groups = {"group2"}) public void verify() { - assertTrue( - m_included1 && m_included2 && m_excluded1 && m_excluded2, - "Should all be true: " - + m_included1 - + " " - + m_included2 - + " " - + m_excluded1 - + " " - + m_excluded2); + assertThat(m_included1 && m_included2 && m_excluded1 && m_excluded2) + .withFailMessage( + "Should all be true: " + + m_included1 + + " " + + m_included2 + + " " + + m_excluded1 + + " " + + m_excluded2) + .isTrue(); } } diff --git a/testng-core/src/test/java/test/GraphTest.java b/testng-core/src/test/java/test/GraphTest.java index 318d9797ad..a199b01ba3 100644 --- a/testng-core/src/test/java/test/GraphTest.java +++ b/testng-core/src/test/java/test/GraphTest.java @@ -1,8 +1,9 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Comparator; import java.util.List; -import org.testng.Assert; import org.testng.TestNGException; import org.testng.annotations.Test; import org.testng.internal.Graph; @@ -33,17 +34,17 @@ public void sort() { g.topologicalSort(); List l = g.getStrictlySortedNodes(); int i = 0; - Assert.assertEquals("1", l.get(i)); + assertThat(l.get(i)).isEqualTo("1"); i++; - Assert.assertTrue("2".equals(l.get(i)) || "2.1".equals(l.get(i)) || "2.2".equals(l.get(i))); + assertThat(l.get(i)).isIn("2", "2.1", "2.2"); i++; - Assert.assertTrue("2".equals(l.get(i)) || "2.1".equals(l.get(i)) || "2.2".equals(l.get(i))); + assertThat(l.get(i)).isIn("2", "2.1", "2.2"); i++; - Assert.assertTrue("2".equals(l.get(i)) || "2.1".equals(l.get(i)) || "2.2".equals(l.get(i))); + assertThat(l.get(i)).isIn("2", "2.1", "2.2"); i++; - Assert.assertEquals("3", l.get(i)); + assertThat(l.get(i)).isEqualTo("3"); - Assert.assertEquals(1, g.getIndependentNodes().size()); + assertThat(g.getIndependentNodes()).hasSize(1); } @Test(expectedExceptions = org.testng.TestNGException.class) @@ -60,7 +61,7 @@ public void cycleShouldBeCorrect() { g.topologicalSort(); } catch (TestNGException ex) { Tarjan t = new Tarjan<>(g, "1"); - Assert.assertEquals(t.getCycle().size(), 3); + assertThat(t.getCycle()).hasSize(3); } } @@ -103,27 +104,18 @@ public void findPredecessors() { // { List predecessors = g.findPredecessors("2"); - Assert.assertEquals(1, predecessors.size()); - Assert.assertEquals("1", predecessors.get(0)); + assertThat(predecessors).hasSize(1); + assertThat(predecessors.get(0)).isEqualTo("1"); } { List predecessors = g.findPredecessors("3"); - Assert.assertEquals(4, predecessors.size()); - Assert.assertEquals("1", predecessors.get(0)); - Assert.assertTrue( - predecessors.get(1).equals("2.1") - || predecessors.get(1).equals("2.2") - || predecessors.get(1).equals("2")); - Assert.assertTrue( - predecessors.get(2).equals("2.1") - || predecessors.get(2).equals("2.2") - || predecessors.get(2).equals("2")); - Assert.assertTrue( - predecessors.get(3).equals("2.1") - || predecessors.get(3).equals("2.2") - || predecessors.get(3).equals("2")); + assertThat(predecessors).hasSize(4); + assertThat(predecessors.get(0)).isEqualTo("1"); + assertThat(predecessors.get(1)).isIn("2.1", "2.2", "2"); + assertThat(predecessors.get(2)).isIn("2.1", "2.2", "2"); + assertThat(predecessors.get(3)).isIn("2.1", "2.2", "2"); } } @@ -189,7 +181,7 @@ public void findPredecessorsTiming() { // { List predecessors = g.findPredecessors(rootNode); - Assert.assertEquals(predecessors.size(), (maxDepth * nodesPerDepth)); + assertThat(predecessors).hasSize(maxDepth * nodesPerDepth); } } } diff --git a/testng-core/src/test/java/test/IndividualMethodsTest.java b/testng-core/src/test/java/test/IndividualMethodsTest.java index 5bfa613332..c63d938e6c 100644 --- a/testng-core/src/test/java/test/IndividualMethodsTest.java +++ b/testng-core/src/test/java/test/IndividualMethodsTest.java @@ -1,6 +1,7 @@ package test; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -23,6 +24,6 @@ public void setUp() { @Test public void testMethod() { // this line causes the test to fail, showing that setUp() hadn't been run - Assert.assertTrue(m_setUpCalled); + assertThat(m_setUpCalled).isTrue(); } } diff --git a/testng-core/src/test/java/test/MethodTest.java b/testng-core/src/test/java/test/MethodTest.java index dbd261068e..80024cb489 100644 --- a/testng-core/src/test/java/test/MethodTest.java +++ b/testng-core/src/test/java/test/MethodTest.java @@ -1,8 +1,8 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; import static org.testng.AssertJUnit.assertEquals; -import org.testng.Assert; import org.testng.annotations.Test; import test.sample.Sample2; @@ -12,7 +12,7 @@ public class MethodTest extends BaseTest { @Test(groups = {"current"}) public void includeMethodsOnly() { addClass(CLASS_NAME); - Assert.assertEquals(getTest().getXmlClasses().size(), 1); + assertThat(getTest().getXmlClasses()).hasSize(1); addIncludedMethod(CLASS_NAME, ".*method2"); run(); String[] passed = { @@ -26,7 +26,7 @@ public void includeMethodsOnly() { @Test(groups = {"current"}) public void excludeMethodsOnly() { addClass(CLASS_NAME); - Assert.assertEquals(getTest().getXmlClasses().size(), 1); + assertThat(getTest().getXmlClasses()).hasSize(1); addExcludedMethod(CLASS_NAME, ".*method2"); run(); String[] passed = {"method1", "method3"}; diff --git a/testng-core/src/test/java/test/NestedStaticTest.java b/testng-core/src/test/java/test/NestedStaticTest.java index 1d2870bdc0..02361ea150 100644 --- a/testng-core/src/test/java/test/NestedStaticTest.java +++ b/testng-core/src/test/java/test/NestedStaticTest.java @@ -1,8 +1,9 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; import java.util.Set; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -25,6 +26,6 @@ public void nestedClassShouldBeIncluded() { actual.add(t.getMethod().getMethodName()); } - Assert.assertEquals(actual, expected); + assertThat(actual).hasSameElementsAs(expected); } } diff --git a/testng-core/src/test/java/test/ParameterConstructorTest.java b/testng-core/src/test/java/test/ParameterConstructorTest.java index 763f73a515..63c5f385b0 100644 --- a/testng-core/src/test/java/test/ParameterConstructorTest.java +++ b/testng-core/src/test/java/test/ParameterConstructorTest.java @@ -1,8 +1,8 @@ package test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import org.assertj.core.data.Offset; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -38,14 +38,14 @@ public ParameterConstructorTest( @Test public void verify() { - assertEquals("Cedric", m_string); - assertEquals(42, m_int); - assertTrue(m_boolean); - assertEquals(43, m_byte); - assertEquals('c', m_char); - assertEquals(44.0, m_double, 0.1); - assertEquals(45.0f, m_float, 0.1); - assertEquals(46, m_long); - assertEquals(47, m_short); + assertThat("Cedric").isEqualTo(m_string); + assertThat(42).isEqualTo(m_int); + assertThat(m_boolean).isTrue(); + assertThat(43).isEqualTo(m_byte); + assertThat('c').isEqualTo(m_char); + assertThat(44.0).isCloseTo(m_double, Offset.offset(0.1)); + assertThat(45.0f).isCloseTo(m_float, Offset.offset(0.1f)); + assertThat(46).isEqualTo(m_long); + assertThat(47).isEqualTo(m_short); } } diff --git a/testng-core/src/test/java/test/ReflectionHelperTest.java b/testng-core/src/test/java/test/ReflectionHelperTest.java index fe7d74c017..847b121100 100644 --- a/testng-core/src/test/java/test/ReflectionHelperTest.java +++ b/testng-core/src/test/java/test/ReflectionHelperTest.java @@ -1,8 +1,9 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; import org.testng.collections.Lists; import org.testng.internal.reflect.ReflectionHelper; @@ -16,23 +17,23 @@ public void testMethodCount() { // Testing exclusion of synthetic methods Refer https://stackoverflow.com/a/5007394 to learn // more Method[] methods = prune(ReflectionHelper.getLocalMethods(DuplicateCallsSample.class)); - Assert.assertEquals(methods.length, 2); + assertThat(methods).hasSize(2); // Testing a straight forward use case of retrieving concrete methods methods = prune(ReflectionHelper.getLocalMethods(Dog.class)); - Assert.assertEquals(methods.length, 1); + assertThat(methods.length).isOne(); // When class has no methods count should be zero. methods = prune(ReflectionHelper.getLocalMethods(Dinosaur.class)); - Assert.assertEquals(methods.length, 0); + assertThat(methods).isEmpty(); // Abstract methods should be included. methods = prune(ReflectionHelper.getLocalMethods(Dragon.class)); - Assert.assertEquals(methods.length, 2); + assertThat(methods).hasSize(2); // main methods should be pruned methods = prune(ReflectionHelper.getLocalMethods(TestClassSample.class)); - Assert.assertEquals(methods.length, 1); + assertThat(methods.length).isOne(); } /** diff --git a/testng-core/src/test/java/test/ReturnValueTest.java b/testng-core/src/test/java/test/ReturnValueTest.java index bde53e52a8..a0e71d865e 100644 --- a/testng-core/src/test/java/test/ReturnValueTest.java +++ b/testng-core/src/test/java/test/ReturnValueTest.java @@ -1,7 +1,8 @@ package test; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.BeforeMethod; @@ -45,13 +46,13 @@ private void runTest(boolean allowed) { tng.run(); if (allowed) { - Assert.assertEquals(tla.getFailedTests().size(), 0); - Assert.assertEquals(tla.getSkippedTests().size(), 0); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).isEmpty(); assertTestResultsEqual(tla.getPassedTests(), Collections.singletonList("shouldRun")); } else { - Assert.assertEquals(tla.getFailedTests().size(), 0); - Assert.assertEquals(tla.getPassedTests().size(), 0); - Assert.assertEquals(tla.getSkippedTests().size(), 0); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getPassedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).isEmpty(); } } } diff --git a/testng-core/src/test/java/test/SampleInheritance.java b/testng-core/src/test/java/test/SampleInheritance.java index 139980f69f..a815e33f20 100644 --- a/testng-core/src/test/java/test/SampleInheritance.java +++ b/testng-core/src/test/java/test/SampleInheritance.java @@ -1,7 +1,6 @@ package test; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -20,9 +19,15 @@ public void configuration0() { groups = "final", dependsOnGroups = {"configuration1"}) public void configuration2() { - assertEquals(m_configurations.size(), 2, "Expected size 2 found " + m_configurations.size()); - assertEquals(m_configurations.get(0), "configuration0", "Expected configuration0 to be run"); - assertEquals(m_configurations.get(1), "configuration1", "Expected configuration1 to be run"); + assertThat(m_configurations) + .withFailMessage("Expected size 2 found " + m_configurations.size()) + .hasSize(2); + assertThat(m_configurations.get(0)) + .withFailMessage("Expected configuration0 to be run") + .isEqualTo("configuration0"); + assertThat(m_configurations.get(1)) + .withFailMessage("Expected configuration1 to be run") + .isEqualTo("configuration1"); addConfiguration("configuration2"); } @@ -30,15 +35,25 @@ public void configuration2() { groups = "final", dependsOnGroups = {"inheritedTestMethod"}) public void inheritedMethodsWereCalledInOrder() { - assertTrue(m_invokedBaseMethod, "Didn't invoke test method in base class"); - assertTrue(m_invokedBaseConfiguration, "Didn't invoke configuration method in base class"); + assertThat(m_invokedBaseMethod) + .withFailMessage("Didn't invoke test method in base class") + .isTrue(); + assertThat(m_invokedBaseConfiguration) + .withFailMessage("Didn't invoke configuration method in base class") + .isTrue(); } @Test(groups = "final2", dependsOnGroups = "final") public void configurationsWereCalledInOrder() { - assertEquals(m_configurations.size(), 3); - assertEquals(m_configurations.get(0), "configuration0", "Expected configuration0 to be run"); - assertEquals(m_configurations.get(1), "configuration1", "Expected configuration1 to be run"); - assertEquals(m_configurations.get(2), "configuration2", "Expected configuration1 to be run"); + assertThat(m_configurations).hasSize(3); + assertThat(m_configurations.get(0)) + .withFailMessage("Expected configuration0 to be run") + .isEqualTo("configuration0"); + assertThat(m_configurations.get(1)) + .withFailMessage("Expected configuration1 to be run") + .isEqualTo("configuration1"); + assertThat(m_configurations.get(2)) + .withFailMessage("Expected configuration1 to be run") + .isEqualTo("configuration2"); } } diff --git a/testng-core/src/test/java/test/Test1.java b/testng-core/src/test/java/test/Test1.java index 8f9af08bbc..1e9a81f02a 100644 --- a/testng-core/src/test/java/test/Test1.java +++ b/testng-core/src/test/java/test/Test1.java @@ -5,7 +5,6 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestNG; import org.testng.annotations.Test; @@ -25,7 +24,7 @@ public class Test1 extends SimpleBaseTest { public void includedGroups() { XmlSuite suite = createXmlSuite("Internal_suite"); XmlTest test = createXmlTest(suite, "Internal_test_failures_are_expected", Sample1.class); - Assert.assertEquals(test.getXmlClasses().size(), 1); + assertThat(test.getXmlClasses()).hasSize(1); test.addIncludedGroup("odd"); TestNG tng = create(suite); @@ -42,7 +41,7 @@ public void includedGroups() { public void groupsOfGroupsSimple() { XmlSuite suite = createXmlSuite("Internal_suite"); XmlTest test = createXmlTest(suite, "Internal_test_failures_are_expected", Sample1.class); - Assert.assertEquals(test.getXmlClasses().size(), 1); + assertThat(test.getXmlClasses()).hasSize(1); // should match all methods belonging to group "odd" and "even" test.addIncludedGroup("evenodd"); test.addMetaGroup("evenodd", "even", "odd"); diff --git a/testng-core/src/test/java/test/Test2.java b/testng-core/src/test/java/test/Test2.java index 0bf5b155f0..9e5763ff03 100644 --- a/testng-core/src/test/java/test/Test2.java +++ b/testng-core/src/test/java/test/Test2.java @@ -1,6 +1,7 @@ package test; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -39,7 +40,9 @@ public void noGroups() { @Test public void setUpWithGroups() { run(); - Assert.assertTrue(m_initializedCorrectly, "Should have run the correctSetup method"); + assertThat(m_initializedCorrectly) + .withFailMessage("Should have run the correctSetup method") + .isTrue(); } @Test diff --git a/testng-core/src/test/java/test/TestClassContainerForGitHubIssue1360.java b/testng-core/src/test/java/test/TestClassContainerForGitHubIssue1360.java index 75578725ad..76e7fc16b0 100644 --- a/testng-core/src/test/java/test/TestClassContainerForGitHubIssue1360.java +++ b/testng-core/src/test/java/test/TestClassContainerForGitHubIssue1360.java @@ -1,57 +1,58 @@ package test; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class TestClassContainerForGitHubIssue1360 { public static class TestNG1 { @Test(priority = 1) public void test1TestNG1() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 2) public void test2TestNG1() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 3) public void test3TestNG1() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } public static class TestNG2 { @Test(priority = 1) public void test1TestNG2() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 2) public void test2TestNG2() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 3) public void test3TestNG2() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } public static class TestNG3 { @Test(priority = 1) public void test1TestNG3() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 2) public void test2TestNG3() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 3) public void test3TestNG3() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } } diff --git a/testng-core/src/test/java/test/abstractmethods/AbstractTest.java b/testng-core/src/test/java/test/abstractmethods/AbstractTest.java index f0268c4e37..cdf032f64b 100644 --- a/testng-core/src/test/java/test/abstractmethods/AbstractTest.java +++ b/testng-core/src/test/java/test/abstractmethods/AbstractTest.java @@ -1,6 +1,7 @@ package test.abstractmethods; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -15,6 +16,6 @@ public void abstractShouldRun() { tng.addListener(tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 2); + assertThat(tla.getPassedTests()).hasSize(2); } } diff --git a/testng-core/src/test/java/test/access/PrivateAccessConfigurationMethods.java b/testng-core/src/test/java/test/access/PrivateAccessConfigurationMethods.java index 765928811a..995647d33d 100644 --- a/testng-core/src/test/java/test/access/PrivateAccessConfigurationMethods.java +++ b/testng-core/src/test/java/test/access/PrivateAccessConfigurationMethods.java @@ -1,6 +1,7 @@ package test.access; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -37,13 +38,21 @@ public void publicConfBeforeMethod() { @Test public void allAccessModifiersConfiguration() { - Assert.assertTrue(m_private, "private @Configuration should have been run"); - Assert.assertTrue(m_default, "default @Configuration should have been run"); - Assert.assertTrue(m_protected, "protected @Configuration should have been run"); - Assert.assertTrue(m_public, "public @Configuration should have been run"); - - Assert.assertTrue(m_baseProtected, "protected base @Configuration should have been run"); - Assert.assertTrue(m_baseDefault, "default base @Configuration should have been run"); - Assert.assertTrue(m_basePrivate, "private base @Configuration should not have been run"); + assertThat(m_private).withFailMessage("private @Configuration should have been run").isTrue(); + assertThat(m_default).withFailMessage("default @Configuration should have been run").isTrue(); + assertThat(m_protected) + .withFailMessage("protected @Configuration should have been run") + .isTrue(); + assertThat(m_public).withFailMessage("public @Configuration should have been run").isTrue(); + + assertThat(m_baseProtected) + .withFailMessage("protected base @Configuration should have been run") + .isTrue(); + assertThat(m_baseDefault) + .withFailMessage("default base @Configuration should have been run") + .isTrue(); + assertThat(m_basePrivate) + .withFailMessage("private base @Configuration should not have been run") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/alwaysrun/AlwaysRunBefore1.java b/testng-core/src/test/java/test/alwaysrun/AlwaysRunBefore1.java index d170d7fa66..f6c23ba36c 100644 --- a/testng-core/src/test/java/test/alwaysrun/AlwaysRunBefore1.java +++ b/testng-core/src/test/java/test/alwaysrun/AlwaysRunBefore1.java @@ -1,6 +1,7 @@ package test.alwaysrun; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; @@ -36,10 +37,10 @@ public void initTestMethod() { @Test(groups = "A") public void foo() { - Assert.assertTrue(m_beforeSuiteSuccess); - Assert.assertTrue(m_beforeTestSuccess); - Assert.assertTrue(m_beforeTestClassSuccess); - Assert.assertTrue(m_beforeTestMethodSuccess); + assertThat(m_beforeSuiteSuccess).isTrue(); + assertThat(m_beforeTestSuccess).isTrue(); + assertThat(m_beforeTestClassSuccess).isTrue(); + assertThat(m_beforeTestMethodSuccess).isTrue(); } public static boolean success() { diff --git a/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java b/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java index ed628782d8..357c138749 100644 --- a/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java +++ b/testng-core/src/test/java/test/alwaysrun/AlwaysRunTest.java @@ -1,6 +1,6 @@ package test.alwaysrun; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -18,7 +18,9 @@ public void withAlwaysRunAfter() { testng.setTestClasses(new Class[] {AlwaysRunAfter1.class}); testng.addListener(tla); testng.run(); - assertTrue(AlwaysRunAfter1.success(), "afterTestMethod should have run"); + assertThat(AlwaysRunAfter1.success()) + .withFailMessage("afterTestMethod should have run") + .isTrue(); } @Test @@ -29,7 +31,7 @@ public void withAlwaysRunAfterMethod() { testng.setTestClasses(new Class[] {AlwaysRunAfter3.class}); testng.addListener(tla); testng.run(); - assertTrue(AlwaysRunAfter3.success(), "afterMethod should have run"); + assertThat(AlwaysRunAfter3.success()).withFailMessage("afterMethod should have run").isTrue(); } @Test @@ -40,7 +42,9 @@ public void withoutAlwaysRunAfter() { testng.setTestClasses(new Class[] {AlwaysRunAfter2.class}); testng.addListener(tla); testng.run(); - assertTrue(AlwaysRunAfter2.success(), "afterTestMethod should not have run"); + assertThat(AlwaysRunAfter2.success()) + .withFailMessage("afterTestMethod should not have run") + .isTrue(); } @Test @@ -52,6 +56,8 @@ public void withoutAlwaysRunBefore() { testng.setGroups("A"); testng.addListener(tla); testng.run(); - assertTrue(AlwaysRunBefore1.success(), "before alwaysRun methods should have been run"); + assertThat(AlwaysRunBefore1.success()) + .withFailMessage("before alwaysRun methods should have been run") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerDataProviderSampleTest.java b/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerDataProviderSampleTest.java index d05de442d8..dfce2b526c 100644 --- a/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerDataProviderSampleTest.java +++ b/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerDataProviderSampleTest.java @@ -1,6 +1,7 @@ package test.annotationtransformer; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -15,6 +16,6 @@ public Object[][] dp() { @Test(dataProvider = "dataProvider") public void f(Integer n) { - Assert.assertEquals(n, Integer.valueOf(42)); + assertThat(n).isEqualTo(Integer.valueOf(42)); } } diff --git a/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java b/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java index eeb9ea0be5..5e0846b56e 100644 --- a/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java +++ b/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerSampleTest.java @@ -1,6 +1,7 @@ package test.annotationtransformer; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class AnnotationTransformerSampleTest { @@ -32,9 +33,9 @@ public void five() { @Test(dependsOnMethods = {"two", "three", "four", "five"}) public void verify() { - Assert.assertEquals(m_two, 2); - Assert.assertEquals(m_three, 3); - Assert.assertEquals(m_four, 4); - Assert.assertEquals(m_five, 5); + assertThat(m_two).isEqualTo(2); + assertThat(m_three).isEqualTo(3); + assertThat(m_four).isEqualTo(4); + assertThat(m_five).isEqualTo(5); } } diff --git a/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java b/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java index 47c02797ab..73e77c0202 100644 --- a/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java +++ b/testng-core/src/test/java/test/annotationtransformer/AnnotationTransformerTest.java @@ -8,7 +8,6 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; -import org.testng.Assert; import org.testng.IAnnotationTransformer; import org.testng.ITestResult; import org.testng.TestListenerAdapter; @@ -136,10 +135,10 @@ private void runTest(IAnnotationTransformer transformer, String passedName, Stri List results = passedName != null ? tla.getPassedTests() : tla.getFailedTests(); String name = passedName != null ? passedName : failedName; - Assert.assertEquals(results.size(), 1); - Assert.assertEquals(name, results.get(0).getMethod().getMethodName()); - Assert.assertTrue(MySuiteListener.triggered); - Assert.assertFalse(MySuiteListener2.triggered); + assertThat(results).hasSize(1); + assertThat(name).isEqualTo(results.get(0).getMethod().getMethodName()); + assertThat(MySuiteListener.triggered).isTrue(); + assertThat(MySuiteListener2.triggered).isFalse(); } @Test @@ -151,8 +150,8 @@ public void verifyListenerAnnotationTransformerClass() { tng.setTestClasses(new Class[] {AnnotationTransformerClassSampleTest.class}); tng.run(); - Assert.assertFalse(MySuiteListener.triggered); - Assert.assertTrue(MySuiteListener2.triggered); + assertThat(MySuiteListener.triggered).isFalse(); + assertThat(MySuiteListener2.triggered).isTrue(); } @Test @@ -165,7 +164,7 @@ public void verifyConfigurationTransformer() { tng.run(); - Assert.assertEquals(ConfigurationSampleTest.getBefore(), "correct"); + assertThat(ConfigurationSampleTest.getBefore()).isEqualTo("correct"); } @Test @@ -178,7 +177,7 @@ public void verifyDataProviderTransformer() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); } public static class CustomizedTestListenerAdaptor extends TestListenerAdapter {} @@ -194,7 +193,7 @@ public void verifyAnnotationTransformerInvocationForAllApplicableEvents() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); String[] expectedLogs = new String[] { "transform_data_provider", @@ -215,7 +214,7 @@ public void verifyInvocationCountTransformer() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 3); + assertThat(tla.getPassedTests()).hasSize(3); tng = create(); tng.addListener(new AnnotationTransformerInvocationCountTest.InvocationCountTransformer(5)); @@ -225,7 +224,7 @@ public void verifyInvocationCountTransformer() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 5); + assertThat(tla.getPassedTests()).hasSize(5); } @Test @@ -253,7 +252,7 @@ public void annotationTransformerInXmlShouldBeRun() throws Exception { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); } @Test(description = "GITHUB-1790") @@ -274,7 +273,7 @@ public void ensureAnnotationTransformerIsNotInvokedMultipleTimes() { TestNG myTestNG = create(myTest.getSuite()); myTestNG.run(); int retried = RetryListener.getExecutionCount(); - assertThat(retried).isEqualTo(1); + assertThat(retried).isOne(); } @Test(description = "GITHUB-2536", dataProvider = "getXmlPackages") diff --git a/testng-core/src/test/java/test/annotationtransformer/SimpleTest.java b/testng-core/src/test/java/test/annotationtransformer/SimpleTest.java index a319fabaa2..72813b6dba 100644 --- a/testng-core/src/test/java/test/annotationtransformer/SimpleTest.java +++ b/testng-core/src/test/java/test/annotationtransformer/SimpleTest.java @@ -1,6 +1,7 @@ package test.annotationtransformer; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Listeners; @@ -19,6 +20,6 @@ public void beforeMethod() {} @Test public void run() { - Assert.assertEquals(m_n, 42); + assertThat(m_n).isEqualTo(42); } } diff --git a/testng-core/src/test/java/test/annotationtransformer/issue2312/SampleTestClass.java b/testng-core/src/test/java/test/annotationtransformer/issue2312/SampleTestClass.java index 743c0466cb..9f9a7339db 100644 --- a/testng-core/src/test/java/test/annotationtransformer/issue2312/SampleTestClass.java +++ b/testng-core/src/test/java/test/annotationtransformer/issue2312/SampleTestClass.java @@ -1,12 +1,13 @@ package test.annotationtransformer.issue2312; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class SampleTestClass { @Test public void testMethod() { - Assert.assertEquals(1, 1); + assertThat(1).isOne(); } } diff --git a/testng-core/src/test/java/test/attributes/AttributeTest.java b/testng-core/src/test/java/test/attributes/AttributeTest.java index 5dab26dfdd..4b0a474274 100644 --- a/testng-core/src/test/java/test/attributes/AttributeTest.java +++ b/testng-core/src/test/java/test/attributes/AttributeTest.java @@ -20,8 +20,7 @@ public void bc(ITestContext ctx) { @Test public void f1(ITestContext ctx) { Set names = ctx.getAttributeNames(); - assertThat(names).hasSize(1); - assertThat(names).contains("test"); + assertThat(names).hasSize(1).contains("test"); assertThat(ctx.getAttribute("test")).isEqualTo("1"); Object v = ctx.removeAttribute("test"); assertThat(v).isNotNull(); @@ -31,8 +30,7 @@ public void f1(ITestContext ctx) { @Test(dependsOnMethods = "f1") public void f2(ITestContext ctx) { Set names = ctx.getAttributeNames(); - assertThat(names).hasSize(1); - assertThat(names).contains("test2"); + assertThat(names).hasSize(1).contains("test2"); assertThat(ctx.getAttribute("test2")).isEqualTo("2"); } diff --git a/testng-core/src/test/java/test/attributes/issue2346/IssueTest.java b/testng-core/src/test/java/test/attributes/issue2346/IssueTest.java index 96ca5a0c08..d034abf20e 100644 --- a/testng-core/src/test/java/test/attributes/issue2346/IssueTest.java +++ b/testng-core/src/test/java/test/attributes/issue2346/IssueTest.java @@ -15,8 +15,9 @@ public void ensureAttributesAreIntactForSkippedMethods() { String cls = SingleTest.class.getCanonicalName() + ".test"; tng.run(); Map actual = LocalTestListener.data; - assertThat(actual.get("onTestSkipped_" + cls)).isEqualTo(false); - assertThat(actual.get("onTestStart_" + cls)).isEqualTo(false); - assertThat(actual.get("tearDown_" + cls)).isEqualTo(false); + assertThat(actual) + .containsEntry("onTestSkipped_" + cls, false) + .containsEntry("onTestStart_" + cls, false) + .containsEntry("tearDown_" + cls, false); } } diff --git a/testng-core/src/test/java/test/attributes/issue2346/SingleTest.java b/testng-core/src/test/java/test/attributes/issue2346/SingleTest.java index 6fd8d6a668..3c08ee7560 100644 --- a/testng-core/src/test/java/test/attributes/issue2346/SingleTest.java +++ b/testng-core/src/test/java/test/attributes/issue2346/SingleTest.java @@ -1,6 +1,6 @@ package test.attributes.issue2346; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; diff --git a/testng-core/src/test/java/test/beforegroups/BeforeGroupsTest.java b/testng-core/src/test/java/test/beforegroups/BeforeGroupsTest.java index 18f6ec803d..0c3d4618a0 100644 --- a/testng-core/src/test/java/test/beforegroups/BeforeGroupsTest.java +++ b/testng-core/src/test/java/test/beforegroups/BeforeGroupsTest.java @@ -68,14 +68,14 @@ public void ensureBeforeGroupsAreInvokedWhenCoupledWithAfterGroups() { Map> expected = new HashMap<>(); expected.put(TEST_1, Collections.singletonList("beforeGroups:" + TEST_1 + TEST_1)); expected.put(TEST_2, Collections.singletonList("afterGroups:" + TEST_2 + TEST_2)); - assertThat(SampleTestClass.logs).isEqualTo(expected); + assertThat(SampleTestClass.logs).containsExactlyInAnyOrderEntriesOf(expected); } @Test(description = "GITHUB-2229") public void ensureBeforeGroupsAreInvokedByDefaultEvenWithoutGrouping() { TestNG testng = create(TestClassSample.class, AnotherTestClassSample.class); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); List expectedLogs = Arrays.asList( "TestA", diff --git a/testng-core/src/test/java/test/beforegroups/issue118/TestclassSample.java b/testng-core/src/test/java/test/beforegroups/issue118/TestclassSample.java index 303d063651..e67cb6015b 100644 --- a/testng-core/src/test/java/test/beforegroups/issue118/TestclassSample.java +++ b/testng-core/src/test/java/test/beforegroups/issue118/TestclassSample.java @@ -1,6 +1,7 @@ package test.beforegroups.issue118; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -14,6 +15,8 @@ public void setUpGroup() { } public void test1() { - Assert.assertNotNull(testObject, "@BeforeGroups not invoked if nothing explicitly specified"); + assertThat(testObject) + .withFailMessage("@BeforeGroups not invoked if nothing explicitly specified") + .isNotNull(); } } diff --git a/testng-core/src/test/java/test/beforegroups/issue2229/TestClassSample.java b/testng-core/src/test/java/test/beforegroups/issue2229/TestClassSample.java index f5f1134d59..3ce0766b95 100644 --- a/testng-core/src/test/java/test/beforegroups/issue2229/TestClassSample.java +++ b/testng-core/src/test/java/test/beforegroups/issue2229/TestClassSample.java @@ -1,7 +1,6 @@ package test.beforegroups.issue2229; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.List; @@ -52,25 +51,25 @@ public void testC() { @Test(groups = "groupA") public void testGroupA1() { logs.add("testGroupA1"); - assertTrue(valueA, "BeforeGroupA was not executed"); + assertThat(valueA).withFailMessage("BeforeGroupA was not executed").isTrue(); } @Test(groups = "groupA") public void testGroupA2() { logs.add("testGroupA2"); - assertTrue(valueA, "BeforeGroupA was not executed"); + assertThat(valueA).withFailMessage("BeforeGroupA was not executed").isTrue(); } @Test(groups = "groupA") public void testGroupA3() { logs.add("testGroupA3"); - assertTrue(valueA, "BeforeGroupA was not executed"); + assertThat(valueA).withFailMessage("BeforeGroupA was not executed").isTrue(); } @Test(groups = "groupB") public void testGroupB() { logs.add("testGroupB"); - assertTrue(valueB, "BeforeGroupB was not executed"); + assertThat(valueB).withFailMessage("BeforeGroupB was not executed").isTrue(); } @AfterGroups(groups = "groupA") @@ -87,7 +86,7 @@ public void afterGroupB() { @AfterClass public void afterClass() { - assertFalse(valueA, "AfterGroupsA was not executed"); - assertFalse(valueB, "AfterGroupsB was not executed"); + assertThat(valueA).withFailMessage("AfterGroupsA was not executed").isFalse(); + assertThat(valueB).withFailMessage("AfterGroupsB was not executed").isFalse(); } } diff --git a/testng-core/src/test/java/test/bug90/Bug90Test.java b/testng-core/src/test/java/test/bug90/Bug90Test.java index cbcf8b90c2..f2132aec68 100644 --- a/testng-core/src/test/java/test/bug90/Bug90Test.java +++ b/testng-core/src/test/java/test/bug90/Bug90Test.java @@ -1,7 +1,8 @@ package test.bug90; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlClass; @@ -23,6 +24,6 @@ public void afterClassShouldRun() { Sample.m_afterClassWasRun = false; tng.run(); - Assert.assertTrue(Sample.m_afterClassWasRun); + assertThat(Sample.m_afterClassWasRun).isTrue(); } } diff --git a/testng-core/src/test/java/test/bug92/Bug92Test.java b/testng-core/src/test/java/test/bug92/Bug92Test.java index 167c7c6e58..025489bf3d 100644 --- a/testng-core/src/test/java/test/bug92/Bug92Test.java +++ b/testng-core/src/test/java/test/bug92/Bug92Test.java @@ -1,7 +1,8 @@ package test.bug92; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; @@ -21,7 +22,7 @@ public void BeforeTestShouldRunOnce() { TestBase.beforeTestCount = 0; TestBase.beforeTestAlwaysCount = 0; tng.run(); - Assert.assertEquals(TestBase.beforeTestCount, 1); - Assert.assertEquals(TestBase.beforeTestAlwaysCount, 1); + assertThat(TestBase.beforeTestCount).isOne(); + assertThat(TestBase.beforeTestAlwaysCount).isOne(); } } diff --git a/testng-core/src/test/java/test/classgroup/Second.java b/testng-core/src/test/java/test/classgroup/Second.java index a6ffa31f58..f37f1b12ae 100644 --- a/testng-core/src/test/java/test/classgroup/Second.java +++ b/testng-core/src/test/java/test/classgroup/Second.java @@ -1,6 +1,6 @@ package test.classgroup; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -9,6 +9,8 @@ public class Second { @Test public void verify() { - assertTrue(First.allRun(), "Methods for class First should have been invoked first."); + assertThat(First.allRun()) + .withFailMessage("Methods for class First should have been invoked first.") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/cli/CliTest.java b/testng-core/src/test/java/test/cli/CliTest.java index d3f536881b..a470864170 100644 --- a/testng-core/src/test/java/test/cli/CliTest.java +++ b/testng-core/src/test/java/test/cli/CliTest.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.UUID; import java.util.function.Supplier; -import org.testng.Assert; import org.testng.CommandLineArgs; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; @@ -75,7 +74,7 @@ public Object[][] getScenarios() { public void testExitCodeListenerBehavior(Class clazz, int expectedStatus) { TestNG testNG = create(clazz); testNG.run(); - Assert.assertEquals(testNG.getStatus(), expectedStatus); + assertThat(testNG.getStatus()).isEqualTo(expectedStatus); } @DataProvider @@ -106,7 +105,7 @@ public void testToEnsureSuitesInJarAreExecutedViaCli() throws IOException { testng.addListener(logInvocations); testng.setVerbose(2); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); assertThat(logInvocations.logs) .containsExactlyInAnyOrder( "com.kungfu.panda.DragonWarrior.testMethod", "com.kungfu.panda.Tigress.testMethod"); diff --git a/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigFailureSample.java b/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigFailureSample.java index 51f70c8e68..a54b9a6bcf 100644 --- a/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigFailureSample.java +++ b/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigFailureSample.java @@ -1,6 +1,7 @@ package test.cli.github1517; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -12,6 +13,6 @@ public void beforeClass() { @Test public void testMethod() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipAndFailureSample.java b/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipAndFailureSample.java index 7533ff8c32..9775e5ff74 100644 --- a/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipAndFailureSample.java +++ b/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipAndFailureSample.java @@ -1,6 +1,7 @@ package test.cli.github1517; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -18,6 +19,6 @@ public void beforeMethod() { @Test public void testMethod() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipSample.java b/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipSample.java index d32448865d..6dd8c771dc 100644 --- a/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipSample.java +++ b/testng-core/src/test/java/test/cli/github1517/TestClassWithConfigSkipSample.java @@ -1,6 +1,7 @@ package test.cli.github1517; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.SkipException; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public void beforeClass() { @Test public void testMethod() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/cli/github2974/OverrideGroupsCliTest.java b/testng-core/src/test/java/test/cli/github2974/OverrideGroupsCliTest.java index fbb014906e..49c2f6735e 100644 --- a/testng-core/src/test/java/test/cli/github2974/OverrideGroupsCliTest.java +++ b/testng-core/src/test/java/test/cli/github2974/OverrideGroupsCliTest.java @@ -1,8 +1,9 @@ package test.cli.github2974; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; import java.util.List; -import org.testng.Assert; import org.testng.CommandLineArgs; import org.testng.ITestListener; import org.testng.ITestResult; @@ -35,8 +36,7 @@ public void overrideIncludeGroupsFromCliInParentChildXml() { NameCollector collector = new NameCollector(); testNG.addListener(collector); testNG.run(); - Assert.assertTrue(collector.names.contains("overrideTest")); - Assert.assertFalse(collector.names.contains("defaultTest")); + assertThat(collector.names).contains("overrideTest").doesNotContain("defaultTest"); } @Test(description = "GITHUB-2974") @@ -53,7 +53,6 @@ public void overrideExcludeGroupsFromCliInParentChildXml() { NameCollector collector = new NameCollector(); testNG.addListener(collector); testNG.run(); - Assert.assertTrue(collector.names.contains("defaultTest")); - Assert.assertFalse(collector.names.contains("overrideTest")); + assertThat(collector.names).contains("defaultTest").doesNotContain("overrideTest"); } } diff --git a/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java b/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java index 2dee53088f..57c19dc8cb 100644 --- a/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java +++ b/testng-core/src/test/java/test/conffailure/ConfigurationFailure.java @@ -1,7 +1,6 @@ package test.conffailure; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertTrue; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -24,17 +23,17 @@ public class ConfigurationFailure extends SimpleBaseTest { @Test public void beforeTestClassFails() { runTest(ClassWithFailedBeforeTestClass.class, ClassWithFailedBeforeTestClassVerification.class); - assertTrue( - ClassWithFailedBeforeTestClassVerification.success(), - "Not all the @Configuration methods of Run2 were run"); + assertThat(ClassWithFailedBeforeTestClassVerification.success()) + .withFailMessage("Not all the @Configuration methods of Run2 were run") + .isTrue(); } @Test public void beforeTestSuiteFails() { runTest(ClassWithFailedBeforeSuite.class, ClassWithFailedBeforeSuiteVerification.class); - assertTrue( - ClassWithFailedBeforeSuiteVerification.success(), - "No @Configuration methods should have run"); + assertThat(ClassWithFailedBeforeSuiteVerification.success()) + .withFailMessage("No @Configuration methods should have run") + .isTrue(); } private static void runTest(Class... classes) { diff --git a/testng-core/src/test/java/test/configuration/Base3.java b/testng-core/src/test/java/test/configuration/Base3.java index 08c07737be..d3283fba38 100644 --- a/testng-core/src/test/java/test/configuration/Base3.java +++ b/testng-core/src/test/java/test/configuration/Base3.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeGroups; public class Base3 { @@ -14,8 +15,8 @@ public static boolean getBefore() { @BeforeGroups("cg34-1") public void anotherBefore1() { - Assert.assertFalse(m_before); - Assert.assertFalse(ConfigurationGroups3SampleTest.getF1()); + assertThat(m_before).isFalse(); + assertThat(ConfigurationGroups3SampleTest.getF1()).isFalse(); m_before = true; } } diff --git a/testng-core/src/test/java/test/configuration/BeforeMethodTest.java b/testng-core/src/test/java/test/configuration/BeforeMethodTest.java index 8005307d96..0a89a936da 100644 --- a/testng-core/src/test/java/test/configuration/BeforeMethodTest.java +++ b/testng-core/src/test/java/test/configuration/BeforeMethodTest.java @@ -1,7 +1,8 @@ package test.configuration; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.ITestContext; import org.testng.ITestNGMethod; import org.testng.annotations.BeforeMethod; @@ -19,9 +20,9 @@ public void before(Method m, ITestContext ctx) { @Test public void mainTest() { - Assert.assertEquals(m_method.getName(), "mainTest"); + assertThat(m_method.getName()).isEqualTo("mainTest"); ITestNGMethod[] methods = m_context.getAllTestMethods(); - Assert.assertEquals(1, methods.length); - Assert.assertEquals(methods[0].getConstructorOrMethod().getName(), "mainTest"); + assertThat(methods).hasSize(1); + assertThat(methods[0].getConstructorOrMethod().getName()).isEqualTo("mainTest"); } } diff --git a/testng-core/src/test/java/test/configuration/BeforeTestOrderingTest.java b/testng-core/src/test/java/test/configuration/BeforeTestOrderingTest.java index 2dfd4b4d2b..7c48b45940 100644 --- a/testng-core/src/test/java/test/configuration/BeforeTestOrderingTest.java +++ b/testng-core/src/test/java/test/configuration/BeforeTestOrderingTest.java @@ -1,11 +1,12 @@ package test.configuration; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.testng.Assert; import org.testng.Reporter; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -51,6 +52,6 @@ public void verifyBeforeTestOrdering() throws IOException { tng.setXmlSuites(Collections.singletonList(s)); tng.run(); - Assert.assertEquals(m_testNames, expected); + assertThat(m_testNames).containsExactlyElementsOf(expected); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationBaseTest.java b/testng-core/src/test/java/test/configuration/ConfigurationBaseTest.java index c16d885728..1a61824f80 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationBaseTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationBaseTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -14,14 +15,15 @@ protected void testConfiguration(Class... classes) { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals( - tla.getConfigurationFailures().size(), - 0, - getFailedResultMessage(tla.getConfigurationFailures())); - Assert.assertEquals( - tla.getFailedTests().size(), 0, getFailedResultMessage(tla.getFailedTests())); - Assert.assertEquals( - tla.getSkippedTests().size(), 0, getFailedResultMessage(tla.getSkippedTests())); - Assert.assertFalse(tla.getPassedTests().isEmpty(), "All tests should pass"); + assertThat(tla.getConfigurationFailures()) + .withFailMessage(getFailedResultMessage(tla.getConfigurationFailures())) + .isEmpty(); + assertThat(tla.getFailedTests()) + .withFailMessage(getFailedResultMessage(tla.getFailedTests())) + .isEmpty(); + assertThat(tla.getSkippedTests()) + .withFailMessage(getFailedResultMessage(tla.getSkippedTests())) + .isEmpty(); + assertThat(tla.getPassedTests()).withFailMessage("All tests should pass").isNotEmpty(); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups1SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups1SampleTest.java index f9d6b4a6c1..40d14b1e14 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups1SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups1SampleTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -15,8 +16,8 @@ public class ConfigurationGroups1SampleTest { @BeforeGroups("cg1-1") public void before1() { - Assert.assertFalse(m_before); - Assert.assertFalse(m_f1); + assertThat(m_before).isFalse(); + assertThat(m_f1).isFalse(); m_before = true; } @@ -25,13 +26,13 @@ public void fa() {} @Test(groups = "cg1-1") public void f1() { - Assert.assertTrue(m_before); + assertThat(m_before).isTrue(); m_f1 = true; } @Test(dependsOnGroups = {"cg1-a", "cg1-1"}) public void verify() { - Assert.assertTrue(m_before); - Assert.assertTrue(m_f1); + assertThat(m_before).isTrue(); + assertThat(m_f1).isTrue(); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups2SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups2SampleTest.java index 9645a6f619..da68f100c3 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups2SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups2SampleTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -17,9 +18,9 @@ public class ConfigurationGroups2SampleTest { @BeforeGroups("cg2-1") public void before1() { - Assert.assertFalse(m_before); - Assert.assertFalse(m_f1); - Assert.assertFalse(m_g1); + assertThat(m_before).isFalse(); + assertThat(m_f1).isFalse(); + assertThat(m_g1).isFalse(); m_before = true; } @@ -28,20 +29,20 @@ public void fa() {} @Test(groups = "cg2-1") public void f1() { - Assert.assertTrue(m_before); + assertThat(m_before).isTrue(); m_f1 = true; } @Test(groups = "cg2-1") public void g1() { - Assert.assertTrue(m_before); + assertThat(m_before).isTrue(); m_g1 = true; } @Test(dependsOnGroups = {"cg2-a", "cg2-1"}) public void verify() { - Assert.assertTrue(m_before); - Assert.assertTrue(m_f1); - Assert.assertTrue(m_g1); + assertThat(m_before).isTrue(); + assertThat(m_f1).isTrue(); + assertThat(m_g1).isTrue(); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups3SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups3SampleTest.java index 9f0bdfd6ba..a37412460c 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups3SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups3SampleTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -16,8 +17,8 @@ public class ConfigurationGroups3SampleTest extends Base3 { @BeforeGroups("cg34-1") public void before1() { - Assert.assertFalse(m_before); - Assert.assertFalse(m_f1); + assertThat(m_before).isFalse(); + assertThat(m_f1).isFalse(); m_before = true; } @@ -26,16 +27,16 @@ public void fa() {} @Test(groups = "cg34-1") public void f1() { - Assert.assertTrue(m_before); - Assert.assertTrue(Base3.getBefore()); + assertThat(m_before).isTrue(); + assertThat(Base3.getBefore()).isTrue(); m_f1 = true; } @Test(dependsOnGroups = {"cg34-a", "cg34-1"}) public void verify() { - Assert.assertTrue(m_before); - Assert.assertTrue(Base3.getBefore()); - Assert.assertTrue(m_f1); + assertThat(m_before).isTrue(); + assertThat(Base3.getBefore()).isTrue(); + assertThat(m_f1).isTrue(); } public static boolean getF1() { diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups4SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups4SampleTest.java index cc265bccaa..06c15fb170 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups4SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups4SampleTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; @@ -20,20 +21,20 @@ public void f() {} @Test(groups = "cg4-1") public void run() { - Assert.assertFalse(m_after); + assertThat(m_after).isFalse(); m_run = true; } @AfterGroups("cg4-1") public void after1() { - Assert.assertTrue(m_run); - Assert.assertFalse(m_after); + assertThat(m_run).isTrue(); + assertThat(m_after).isFalse(); m_after = true; } @Test(dependsOnGroups = "cg4-1") public void verify() { - Assert.assertTrue(m_run, "run() wasn't run"); - Assert.assertTrue(m_after, "after1() wasn't run"); + assertThat(m_run).withFailMessage("run() wasn't run").isTrue(); + assertThat(m_after).withFailMessage("after1() wasn't run").isTrue(); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups5SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups5SampleTest.java index 3a19c19aec..8484df76fa 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups5SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups5SampleTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; @@ -22,7 +23,7 @@ public void f() {} @Test(groups = "cg5-1") public void run1() { if (m_afterCount == 0) { - Assert.assertFalse(m_after); + assertThat(m_after).isFalse(); } m_run1 = true; } @@ -30,7 +31,7 @@ public void run1() { @Test(groups = "cg5-2") public void run2() { if (m_afterCount == 0) { - Assert.assertFalse(m_after); + assertThat(m_after).isFalse(); } m_run2 = true; } @@ -38,18 +39,18 @@ public void run2() { @AfterGroups({"cg5-1", "cg5-2"}) public void after() { m_afterCount++; - Assert.assertTrue(m_run1 || m_run2); + assertThat(m_run1 || m_run2).isTrue(); if (m_afterCount == 0) { - Assert.assertFalse(m_after); + assertThat(m_after).isFalse(); } m_after = true; } @Test(dependsOnGroups = {"cg5-1", "cg5-2"}) public void verify() { - Assert.assertTrue(m_run1, "run1() wasn't run"); - Assert.assertTrue(m_run2, "run2() wasn't run"); - Assert.assertTrue(m_after, "after1() wasn't run"); - Assert.assertEquals(2, m_afterCount); + assertThat(m_run1).withFailMessage("run1() wasn't run").isTrue(); + assertThat(m_run2).withFailMessage("run2() wasn't run").isTrue(); + assertThat(m_after).withFailMessage("after1() wasn't run").isTrue(); + assertThat(m_afterCount).isEqualTo(2); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups6SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups6SampleTest.java index 67b29e1f7e..63a6858acc 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups6SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups6SampleTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; @@ -20,28 +21,28 @@ public void f() {} @Test(groups = "cg6-1") public void run1() { - Assert.assertFalse(m_after); + assertThat(m_after).isFalse(); m_run1 = true; } @Test(groups = "cg6-1") public void run2() { - Assert.assertFalse(m_after); + assertThat(m_after).isFalse(); m_run2 = true; } @AfterGroups("cg6-1") public void after() { - Assert.assertTrue(m_run1); - Assert.assertTrue(m_run2); - Assert.assertFalse(m_after); + assertThat(m_run1).isTrue(); + assertThat(m_run2).isTrue(); + assertThat(m_after).isFalse(); m_after = true; } @Test(dependsOnGroups = {"cg6-1"}) public void verify() { - Assert.assertTrue(m_run1, "run1() wasn't run"); - Assert.assertTrue(m_run2, "run2() wasn't run"); - Assert.assertTrue(m_after, "after1() wasn't run"); + assertThat(m_run1).withFailMessage("run1() wasn't run").isTrue(); + assertThat(m_run2).withFailMessage("run2() wasn't run").isTrue(); + assertThat(m_after).withFailMessage("after1() wasn't run").isTrue(); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups7SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups7SampleTest.java index cc150defe5..95f7b40dd2 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups7SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups7SampleTest.java @@ -1,9 +1,9 @@ package test.configuration; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import org.testng.Assert; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -33,6 +33,6 @@ private void cleanUpA() { @Test(dependsOnGroups = "A") public void verify() { - Assert.assertEquals(Arrays.asList("1", "2", "2", "3"), m_log); + assertThat(m_log).containsExactly("1", "2", "2", "3"); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroups8SampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroups8SampleTest.java index de9f62814b..e98cde1fbb 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroups8SampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroups8SampleTest.java @@ -1,9 +1,9 @@ package test.configuration; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; @@ -43,6 +43,6 @@ private void cleanUpA() { @Test(dependsOnGroups = "A", groups = "B") public void verify() { - Assert.assertEquals(Arrays.asList("1", "a", "1", "a"), m_log); + assertThat(m_log).containsExactly("1", "a", "1", "a"); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationGroupsTest.java b/testng-core/src/test/java/test/configuration/ConfigurationGroupsTest.java index c05e496ee2..23014e991c 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationGroupsTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationGroupsTest.java @@ -15,7 +15,7 @@ public void multipleBeforeGroupTest() { TestNG testng = create(MultipleBeforeGroupTest.class); testng.setGroups("foo"); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); } @Test(dataProvider = "getTestData") @@ -23,7 +23,7 @@ public void runTest(Class testClass, String groupName) { TestNG testng = create(testClass); testng.setGroups(groupName); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); } @DataProvider diff --git a/testng-core/src/test/java/test/configuration/ConfigurationInheritGroupsSampleTest.java b/testng-core/src/test/java/test/configuration/ConfigurationInheritGroupsSampleTest.java index 69d7ee4960..eeedd96c19 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationInheritGroupsSampleTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationInheritGroupsSampleTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -14,6 +15,6 @@ public void setUp() { } public void test1() { - Assert.assertTrue(m_ok); + assertThat(m_ok).isTrue(); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationListenerTest.java b/testng-core/src/test/java/test/configuration/ConfigurationListenerTest.java index 0274975297..c1cdc74605 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationListenerTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationListenerTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -12,15 +13,15 @@ public class ConfigurationListenerTest extends SimpleBaseTest { @Test public void listenerShouldBeCalled() { TestNG tng = create(ConfigurationListenerSampleTest.class); - Assert.assertFalse(ConfigurationListenerSampleTest.m_passed); + assertThat(ConfigurationListenerSampleTest.m_passed).isFalse(); tng.run(); - Assert.assertTrue(ConfigurationListenerSampleTest.m_passed); + assertThat(ConfigurationListenerSampleTest.m_passed).isTrue(); } @Test(description = "github 2729") public void beforeConfigShouldExecutedForSkippedConfig() { TestNG tng = create(BeforeConfigTestSample.class); tng.run(); - Assert.assertEquals(BeforeConfigSampleListener.count, 2); + assertThat(BeforeConfigSampleListener.count).isEqualTo(2); } } diff --git a/testng-core/src/test/java/test/configuration/ConfigurationTest.java b/testng-core/src/test/java/test/configuration/ConfigurationTest.java index f88b3e27b3..59f04c5bb5 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationTest.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationTest.java @@ -5,7 +5,6 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.testng.Assert; import org.testng.ITestNGMethod; import org.testng.ITestResult; import org.testng.TestNG; @@ -40,7 +39,7 @@ public void testMethodCallOrder() { @Test public void testSuite() { testConfiguration(SuiteTestSample.class); - Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), SuiteTestSample.m_order); + assertThat(SuiteTestSample.m_order).containsExactly(1, 2, 3, 4, 5); } @Test @@ -48,7 +47,7 @@ public void testSuiteRunnerWithDefaultConfiguration() { TestNG testNG = create(SuiteRunnerIssueTestSample.class); testNG.run(); - Assert.assertEquals(testNG.getStatus(), 0); + assertThat(testNG.getStatus()).isZero(); } @Test(description = "GITHUB-2726") diff --git a/testng-core/src/test/java/test/configuration/ConfigurationWithParameters.java b/testng-core/src/test/java/test/configuration/ConfigurationWithParameters.java index 31d907411f..5a24269f4f 100644 --- a/testng-core/src/test/java/test/configuration/ConfigurationWithParameters.java +++ b/testng-core/src/test/java/test/configuration/ConfigurationWithParameters.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -17,6 +18,6 @@ public void testInit(String param) { @Parameters({"param"}) @Test public void testMethod(String param) { - Assert.assertEquals(m_param, param); + assertThat(m_param).isEqualTo(param); } } diff --git a/testng-core/src/test/java/test/configuration/GroupsTest.java b/testng-core/src/test/java/test/configuration/GroupsTest.java index 0ed826e252..21817fabe3 100644 --- a/testng-core/src/test/java/test/configuration/GroupsTest.java +++ b/testng-core/src/test/java/test/configuration/GroupsTest.java @@ -1,8 +1,9 @@ package test.configuration; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -52,6 +53,6 @@ private void runTest(Class cls, List list, List expected) { m_testNg.setTestClasses(new Class[] {cls}); m_testNg.setGroups("twice"); m_testNg.run(); - Assert.assertEquals(list, expected); + assertThat(list).containsExactlyElementsOf(expected); } } diff --git a/testng-core/src/test/java/test/configuration/MultipleBeforeGroupTest.java b/testng-core/src/test/java/test/configuration/MultipleBeforeGroupTest.java index 21e273a2f1..5cb2a22d71 100644 --- a/testng-core/src/test/java/test/configuration/MultipleBeforeGroupTest.java +++ b/testng-core/src/test/java/test/configuration/MultipleBeforeGroupTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -18,6 +19,6 @@ public void test() {} @Test(dependsOnMethods = "test") public void verify() { - Assert.assertEquals(1, m_count); + assertThat(m_count).isOne(); } } diff --git a/testng-core/src/test/java/test/configuration/ReflectMethodParametrizedConfigurationMethodTest.java b/testng-core/src/test/java/test/configuration/ReflectMethodParametrizedConfigurationMethodTest.java index 1143e26850..1e9e23ea5e 100644 --- a/testng-core/src/test/java/test/configuration/ReflectMethodParametrizedConfigurationMethodTest.java +++ b/testng-core/src/test/java/test/configuration/ReflectMethodParametrizedConfigurationMethodTest.java @@ -1,9 +1,10 @@ package test.configuration; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -32,13 +33,17 @@ public void afterMethod(Method invokedTestMethod) { @AfterClass public void assertBeforeAfterMethodsInvocations() { - Assert.assertTrue( - m_before.containsKey("test1"), "@Test method should have been passed to @BeforeMethod"); - Assert.assertTrue( - m_before.containsKey("test2"), "@Test method should have been passed to @BeforeMethod"); - Assert.assertTrue( - m_after.containsKey("test1"), "@Test method should have been passed to @AfterMethod"); - Assert.assertTrue( - m_before.containsKey("test2"), "@Test method should have been passed to @AfterMethod"); + assertThat(m_before) + .withFailMessage("@Test method should have been passed to @BeforeMethod") + .containsKey("test1"); + assertThat(m_before) + .withFailMessage("@Test method should have been passed to @BeforeMethod") + .containsKey("test2"); + assertThat(m_after) + .withFailMessage("@Test method should have been passed to @AfterMethod") + .containsKey("test1"); + assertThat(m_before) + .withFailMessage("@Test method should have been passed to @AfterMethod") + .containsKey("test2"); } } diff --git a/testng-core/src/test/java/test/configuration/SingleConfigurationTest.java b/testng-core/src/test/java/test/configuration/SingleConfigurationTest.java index 2b72160ab4..92d7ea94e8 100644 --- a/testng-core/src/test/java/test/configuration/SingleConfigurationTest.java +++ b/testng-core/src/test/java/test/configuration/SingleConfigurationTest.java @@ -1,6 +1,7 @@ package test.configuration; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; @@ -32,6 +33,6 @@ public void bt() { @Test public void verify() { - Assert.assertEquals(m_before, 1); + assertThat(m_before).isOne(); } } diff --git a/testng-core/src/test/java/test/configuration/SuiteFactoryOnceTest.java b/testng-core/src/test/java/test/configuration/SuiteFactoryOnceTest.java index 4e9686030a..e4d1ac616e 100644 --- a/testng-core/src/test/java/test/configuration/SuiteFactoryOnceTest.java +++ b/testng-core/src/test/java/test/configuration/SuiteFactoryOnceTest.java @@ -15,7 +15,7 @@ public void suiteMethodsShouldOnlyRunOnce() { SuiteFactoryOnceSample1Test.m_after = 0; tng.run(); - assertThat(SuiteFactoryOnceSample1Test.m_before).isEqualTo(1); - assertThat(SuiteFactoryOnceSample1Test.m_after).isEqualTo(1); + assertThat(SuiteFactoryOnceSample1Test.m_before).isOne(); + assertThat(SuiteFactoryOnceSample1Test.m_after).isOne(); } } diff --git a/testng-core/src/test/java/test/configuration/github1625/TestRunnerIssue1625.java b/testng-core/src/test/java/test/configuration/github1625/TestRunnerIssue1625.java index f6883280f6..6e091dc334 100644 --- a/testng-core/src/test/java/test/configuration/github1625/TestRunnerIssue1625.java +++ b/testng-core/src/test/java/test/configuration/github1625/TestRunnerIssue1625.java @@ -15,7 +15,7 @@ public void testMethod(Class clazz) { TestNG testNG = create(clazz); testNG.setParallel(XmlSuite.ParallelMode.METHODS); testNG.run(); - assertThat(testNG.getStatus()).isEqualTo(0); + assertThat(testNG.getStatus()).isZero(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/configuration/github1625/TestclassSampleUsingMocks.java b/testng-core/src/test/java/test/configuration/github1625/TestclassSampleUsingMocks.java index 0203b1b506..09a9f69c4a 100644 --- a/testng-core/src/test/java/test/configuration/github1625/TestclassSampleUsingMocks.java +++ b/testng-core/src/test/java/test/configuration/github1625/TestclassSampleUsingMocks.java @@ -1,9 +1,10 @@ package test.configuration.github1625; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -25,11 +26,11 @@ public void closeMocks() throws Exception { @Test public void first() { - Assert.assertNotNull(list); + assertThat(list).isNotNull(); } @Test public void second() { - Assert.assertNotNull(list); + assertThat(list).isNotNull(); } } diff --git a/testng-core/src/test/java/test/configuration/github1625/TestclassSampleWithoutUsingMocks.java b/testng-core/src/test/java/test/configuration/github1625/TestclassSampleWithoutUsingMocks.java index e8ca173f2c..2f68e89488 100644 --- a/testng-core/src/test/java/test/configuration/github1625/TestclassSampleWithoutUsingMocks.java +++ b/testng-core/src/test/java/test/configuration/github1625/TestclassSampleWithoutUsingMocks.java @@ -1,8 +1,9 @@ package test.configuration.github1625; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; import java.util.List; -import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -17,11 +18,11 @@ public void beforeClass() { @Test public void first() { - Assert.assertNotNull(list); + assertThat(list).isNotNull(); } @Test public void second() { - Assert.assertNotNull(list); + assertThat(list).isNotNull(); } } diff --git a/testng-core/src/test/java/test/configuration/github1700/BaseClassSample.java b/testng-core/src/test/java/test/configuration/github1700/BaseClassSample.java index 6f17839ae9..155e40cb31 100644 --- a/testng-core/src/test/java/test/configuration/github1700/BaseClassSample.java +++ b/testng-core/src/test/java/test/configuration/github1700/BaseClassSample.java @@ -1,8 +1,9 @@ package test.configuration.github1700; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; import java.util.List; -import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.collections.Lists; @@ -13,7 +14,7 @@ public class BaseClassSample { @BeforeMethod(alwaysRun = true) public void setUp(Method method) { if (method.getName().endsWith("test1")) { - Assert.assertEquals(2, 1); + assertThat(2).isOne(); } messages.add(getClass().getCanonicalName() + ".setup()"); } diff --git a/testng-core/src/test/java/test/configuration/issue2254/IssueTest.java b/testng-core/src/test/java/test/configuration/issue2254/IssueTest.java index 2d8d2300c0..6cc3f7b35c 100644 --- a/testng-core/src/test/java/test/configuration/issue2254/IssueTest.java +++ b/testng-core/src/test/java/test/configuration/issue2254/IssueTest.java @@ -1,9 +1,10 @@ package test.configuration.issue2254; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.testng.Assert; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestResult; @@ -41,8 +42,8 @@ public void ensureConfigurationsAreInvokedOnce() { tng.setXmlSuites(Collections.singletonList(xmlSuite)); tng.run(); - Assert.assertEquals(listener.beforeCount, 9); - Assert.assertEquals(listener.afterCount, 9); + assertThat(listener.beforeCount).isEqualTo(9); + assertThat(listener.afterCount).isEqualTo(9); } public static class MyInvokedMethodListener implements IInvokedMethodListener { diff --git a/testng-core/src/test/java/test/configuration/issue2400/IssueTest.java b/testng-core/src/test/java/test/configuration/issue2400/IssueTest.java index d29791bbe6..04b4c6a83a 100644 --- a/testng-core/src/test/java/test/configuration/issue2400/IssueTest.java +++ b/testng-core/src/test/java/test/configuration/issue2400/IssueTest.java @@ -1,8 +1,8 @@ package test.configuration.issue2400; +import org.assertj.core.api.SoftAssertions; import org.testng.TestNG; import org.testng.annotations.Test; -import org.testng.asserts.SoftAssert; import test.SimpleBaseTest; public class IssueTest extends SimpleBaseTest { @@ -11,13 +11,15 @@ public class IssueTest extends SimpleBaseTest { public void ensureDefaultConfigurationsAreSkipped() { TestNG testng = create(TestNGTestClass.class); testng.run(); - SoftAssert softAssert = new SoftAssert(); + SoftAssertions softAssert = new SoftAssertions(); DataStore.INSTANCE .getTracker() .forEach( (key, value) -> - softAssert.assertEquals( - value.get(), 1, "Ensuring " + key + " got invoked only once")); + softAssert + .assertThat(value.get()) + .as("Ensuring " + key + " got invoked only once") + .isEqualTo(1)); softAssert.assertAll(); } } diff --git a/testng-core/src/test/java/test/configuration/issue3000/TestClassSample.java b/testng-core/src/test/java/test/configuration/issue3000/TestClassSample.java index eb15b7e4fd..3ebe826715 100644 --- a/testng-core/src/test/java/test/configuration/issue3000/TestClassSample.java +++ b/testng-core/src/test/java/test/configuration/issue3000/TestClassSample.java @@ -1,6 +1,6 @@ package test.configuration.issue3000; -import static org.testng.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -9,7 +9,7 @@ public class TestClassSample extends MyBaseTestSample { @BeforeClass public void beforeClass() { - assertNotNull(dependency); + assertThat(dependency).isNotNull(); } @Test diff --git a/testng-core/src/test/java/test/configuration/sample/ConfigurationTestSample.java b/testng-core/src/test/java/test/configuration/sample/ConfigurationTestSample.java index 6f84fe0886..509412e733 100644 --- a/testng-core/src/test/java/test/configuration/sample/ConfigurationTestSample.java +++ b/testng-core/src/test/java/test/configuration/sample/ConfigurationTestSample.java @@ -1,7 +1,6 @@ package test.configuration.sample; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; @@ -21,76 +20,76 @@ public class ConfigurationTestSample { @BeforeSuite public void beforeSuite() { - assertFalse(m_afterSuite, "afterSuite shouldn't have run"); - assertFalse(m_beforeClass, "beforeClass shouldn't have run"); - assertFalse(m_afterClass, "afterClass shouldn't have run"); - assertFalse(m_beforeMethod, "beforeMethod shouldn't have run"); - assertFalse(m_afterMethod, "afterMethod shouldn't have run"); + assertThat(m_afterSuite).withFailMessage("afterSuite shouldn't have run").isFalse(); + assertThat(m_beforeClass).withFailMessage("beforeClass shouldn't have run").isFalse(); + assertThat(m_afterClass).withFailMessage("afterClass shouldn't have run").isFalse(); + assertThat(m_beforeMethod).withFailMessage("beforeMethod shouldn't have run").isFalse(); + assertThat(m_afterMethod).withFailMessage("afterMethod shouldn't have run").isFalse(); m_beforeSuite = true; } @BeforeClass public void beforeClass() { - assertTrue(m_beforeSuite, "beforeSuite should have run"); - assertFalse(m_afterSuite, "afterSuite shouldn't have run"); - assertFalse(m_beforeClass, "beforeClass shouldn't have run"); - assertFalse(m_afterClass, "afterClass shouldn't have run"); - assertFalse(m_beforeMethod, "beforeMethod shouldn't have run"); - assertFalse(m_afterMethod, "afterMethod shouldn't have run"); + assertThat(m_beforeSuite).withFailMessage("beforeSuite should have run").isTrue(); + assertThat(m_afterSuite).withFailMessage("afterSuite shouldn't have run").isFalse(); + assertThat(m_beforeClass).withFailMessage("beforeClass shouldn't have run").isFalse(); + assertThat(m_afterClass).withFailMessage("afterClass shouldn't have run").isFalse(); + assertThat(m_beforeMethod).withFailMessage("beforeMethod shouldn't have run").isFalse(); + assertThat(m_afterMethod).withFailMessage("afterMethod shouldn't have run").isFalse(); m_beforeClass = true; } @BeforeMethod public void beforeMethod() { - assertTrue(m_beforeSuite, "beforeSuite should have run"); - assertTrue(m_beforeClass, "beforeClass have run"); - assertFalse(m_afterSuite, "afterSuite shouldn't have run"); - assertFalse(m_afterClass, "afterClass shouldn't have run"); - assertFalse(m_beforeMethod, "beforeMethod shouldn't have run"); - assertFalse(m_afterMethod, "afterMethod shouldn't have run"); + assertThat(m_beforeSuite).withFailMessage("beforeSuite should have run").isTrue(); + assertThat(m_beforeClass).withFailMessage("beforeClass have run").isTrue(); + assertThat(m_afterSuite).withFailMessage("afterSuite shouldn't have run").isFalse(); + assertThat(m_afterClass).withFailMessage("afterClass shouldn't have run").isFalse(); + assertThat(m_beforeMethod).withFailMessage("beforeMethod shouldn't have run").isFalse(); + assertThat(m_afterMethod).withFailMessage("afterMethod shouldn't have run").isFalse(); m_beforeMethod = true; } @AfterMethod public void afterMethod() { - assertTrue(m_beforeSuite, "beforeSuite should have run"); - assertTrue(m_beforeClass, "beforeClass have run"); - assertTrue(m_beforeMethod, "beforeMethod should have run"); - assertFalse(m_afterSuite, "afterSuite shouldn't have run"); - assertFalse(m_afterClass, "afterClass shouldn't have run"); - assertFalse(m_afterMethod, "afterMethod shouldn't have run"); + assertThat(m_beforeSuite).withFailMessage("beforeSuite should have run").isTrue(); + assertThat(m_beforeClass).withFailMessage("beforeClass have run").isTrue(); + assertThat(m_beforeMethod).withFailMessage("beforeMethod should have run").isTrue(); + assertThat(m_afterSuite).withFailMessage("afterSuite shouldn't have run").isFalse(); + assertThat(m_afterClass).withFailMessage("afterClass shouldn't have run").isFalse(); + assertThat(m_afterMethod).withFailMessage("afterMethod shouldn't have run").isFalse(); m_afterMethod = true; } @AfterClass public void afterClass() { - assertTrue(m_beforeSuite, "beforeSuite should have run"); - assertTrue(m_beforeClass, "beforeClass have run"); - assertTrue(m_beforeMethod, "beforeMethod should have run"); - assertTrue(m_afterMethod, "afterMethod should have run"); - assertFalse(m_afterClass, "afterClass shouldn't have run"); - assertFalse(m_afterSuite, "afterSuite shouldn't have run"); + assertThat(m_beforeSuite).withFailMessage("beforeSuite should have run").isTrue(); + assertThat(m_beforeClass).withFailMessage("beforeClass have run").isTrue(); + assertThat(m_beforeMethod).withFailMessage("beforeMethod should have run").isTrue(); + assertThat(m_afterMethod).withFailMessage("afterMethod should have run").isTrue(); + assertThat(m_afterClass).withFailMessage("afterClass shouldn't have run").isFalse(); + assertThat(m_afterSuite).withFailMessage("afterSuite shouldn't have run").isFalse(); m_afterClass = true; } @AfterSuite public void afterSuite() { - assertTrue(m_beforeSuite, "beforeSuite should have run"); - assertTrue(m_beforeClass, "beforeClass have run"); - assertTrue(m_beforeMethod, "beforeMethod should have run"); - assertTrue(m_afterMethod, "afterMethod should have run"); - assertTrue(m_afterClass, "afterClass should have run"); - assertFalse(m_afterSuite, "afterSuite shouldn't have run"); + assertThat(m_beforeSuite).withFailMessage("beforeSuite should have run").isTrue(); + assertThat(m_beforeClass).withFailMessage("beforeClass have run").isTrue(); + assertThat(m_beforeMethod).withFailMessage("beforeMethod should have run").isTrue(); + assertThat(m_afterMethod).withFailMessage("afterMethod should have run").isTrue(); + assertThat(m_afterClass).withFailMessage("afterClass should have run").isTrue(); + assertThat(m_afterSuite).withFailMessage("afterSuite shouldn't have run").isFalse(); m_afterSuite = true; } @Test public void verify() { - assertTrue(m_beforeSuite, "beforeSuite should have run"); - assertTrue(m_beforeClass, "beforeClass have run"); - assertTrue(m_beforeMethod, "beforeMethod should have run"); - assertFalse(m_afterSuite, "afterSuite shouldn't have run"); - assertFalse(m_afterClass, "afterClass shouldn't have run"); - assertFalse(m_afterMethod, "afterMethod shouldn't have run"); + assertThat(m_beforeSuite).withFailMessage("beforeSuite should have run").isTrue(); + assertThat(m_beforeClass).withFailMessage("beforeClass have run").isTrue(); + assertThat(m_beforeMethod).withFailMessage("beforeMethod should have run").isTrue(); + assertThat(m_afterSuite).withFailMessage("afterSuite shouldn't have run").isFalse(); + assertThat(m_afterClass).withFailMessage("afterClass shouldn't have run").isFalse(); + assertThat(m_afterMethod).withFailMessage("afterMethod shouldn't have run").isFalse(); } } diff --git a/testng-core/src/test/java/test/configuration/sample/ExternalConfigurationClassSample.java b/testng-core/src/test/java/test/configuration/sample/ExternalConfigurationClassSample.java index 10389fa305..3af0f6ddf1 100644 --- a/testng-core/src/test/java/test/configuration/sample/ExternalConfigurationClassSample.java +++ b/testng-core/src/test/java/test/configuration/sample/ExternalConfigurationClassSample.java @@ -1,7 +1,6 @@ package test.configuration.sample; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterSuite; import org.testng.annotations.AfterTest; @@ -27,26 +26,26 @@ public void cleanUp() { @BeforeTest public void beforeTest() { - assertTrue(MethodCallOrderTestSample.s_beforeSuite); - assertFalse(MethodCallOrderTestSample.s_beforeTest); - assertFalse(MethodCallOrderTestSample.s_beforeClass); - assertFalse(MethodCallOrderTestSample.s_beforeMethod); + assertThat(MethodCallOrderTestSample.s_beforeSuite).isTrue(); + assertThat(MethodCallOrderTestSample.s_beforeTest).isFalse(); + assertThat(MethodCallOrderTestSample.s_beforeClass).isFalse(); + assertThat(MethodCallOrderTestSample.s_beforeMethod).isFalse(); MethodCallOrderTestSample.s_beforeTest = true; } @AfterTest public void afterTest() { - assertTrue(s_afterMethod, "afterTestMethod should have been run"); - assertTrue(s_afterClass, "afterTestClass should have been run"); - assertFalse(s_afterTest, "afterTest should haven't been run"); + assertThat(s_afterMethod).withFailMessage("afterTestMethod should have been run").isTrue(); + assertThat(s_afterClass).withFailMessage("afterTestClass should have been run").isTrue(); + assertThat(s_afterTest).withFailMessage("afterTest should haven't been run").isFalse(); s_afterTest = true; } @AfterSuite public void afterSuite() { - assertTrue(s_afterMethod, "afterTestMethod should have been run"); - assertTrue(s_afterClass, "afterTestClass should have been run"); - assertTrue(s_afterTest, "afterTest should have been run"); + assertThat(s_afterMethod).withFailMessage("afterTestMethod should have been run").isTrue(); + assertThat(s_afterClass).withFailMessage("afterTestClass should have been run").isTrue(); + assertThat(s_afterTest).withFailMessage("afterTest should have been run").isTrue(); } } diff --git a/testng-core/src/test/java/test/configuration/sample/MethodCallOrderTestSample.java b/testng-core/src/test/java/test/configuration/sample/MethodCallOrderTestSample.java index 03c8a87000..1bc9a1cb9d 100644 --- a/testng-core/src/test/java/test/configuration/sample/MethodCallOrderTestSample.java +++ b/testng-core/src/test/java/test/configuration/sample/MethodCallOrderTestSample.java @@ -1,7 +1,6 @@ package test.configuration.sample; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; @@ -18,10 +17,10 @@ public class MethodCallOrderTestSample { @BeforeClass public void beforeClass() { - assertTrue(s_beforeSuite); - assertTrue(s_beforeTest); - assertFalse(s_beforeClass); - assertFalse(s_beforeMethod); + assertThat(s_beforeSuite).isTrue(); + assertThat(s_beforeTest).isTrue(); + assertThat(s_beforeClass).isFalse(); + assertThat(s_beforeMethod).isFalse(); s_beforeClass = true; } @@ -36,39 +35,47 @@ public void cleanUp() { @BeforeMethod public void beforeMethod() { - assertTrue(s_beforeSuite); - assertTrue(s_beforeTest); - assertTrue(s_beforeClass); - assertFalse(s_beforeMethod); + assertThat(s_beforeSuite).isTrue(); + assertThat(s_beforeTest).isTrue(); + assertThat(s_beforeClass).isTrue(); + assertThat(s_beforeMethod).isFalse(); s_beforeMethod = true; } @Test public void realTest() { - assertTrue(s_beforeSuite); - assertTrue(s_beforeTest); - assertTrue(s_beforeClass); - assertTrue(s_beforeMethod); + assertThat(s_beforeSuite).isTrue(); + assertThat(s_beforeTest).isTrue(); + assertThat(s_beforeClass).isTrue(); + assertThat(s_beforeMethod).isTrue(); } @AfterMethod public void afterMethod() { - assertFalse( - ExternalConfigurationClassSample.s_afterMethod, "afterTestMethod shouldn't have been run"); - assertFalse( - ExternalConfigurationClassSample.s_afterClass, "afterTestClass shouldn't have been run"); - assertFalse(ExternalConfigurationClassSample.s_afterTest, "afterTest should haven't been run"); + assertThat(ExternalConfigurationClassSample.s_afterMethod) + .withFailMessage("afterTestMethod shouldn't have been run") + .isFalse(); + assertThat(ExternalConfigurationClassSample.s_afterClass) + .withFailMessage("afterTestClass shouldn't have been run") + .isFalse(); + assertThat(ExternalConfigurationClassSample.s_afterTest) + .withFailMessage("afterTest should haven't been run") + .isFalse(); ExternalConfigurationClassSample.s_afterMethod = true; } @AfterClass public void afterClass() { - assertTrue( - ExternalConfigurationClassSample.s_afterMethod, "afterTestMethod should have been run"); - assertFalse( - ExternalConfigurationClassSample.s_afterClass, "afterTestClass shouldn't have been run"); - assertFalse(ExternalConfigurationClassSample.s_afterTest, "afterTest should haven't been run"); + assertThat(ExternalConfigurationClassSample.s_afterMethod) + .withFailMessage("afterTestMethod should have been run") + .isTrue(); + assertThat(ExternalConfigurationClassSample.s_afterClass) + .withFailMessage("afterTestClass shouldn't have been run") + .isFalse(); + assertThat(ExternalConfigurationClassSample.s_afterTest) + .withFailMessage("afterTest should haven't been run") + .isFalse(); ExternalConfigurationClassSample.s_afterClass = true; } } diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java b/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java index ff222b22af..9b25f67263 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java @@ -1,7 +1,6 @@ package test.configurationfailurepolicy; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; import java.util.ArrayList; import java.util.Collections; @@ -32,9 +31,8 @@ public class FailurePolicyTest extends SimpleBaseTest { // only if this is run from an xml file that sets this on the suite @BeforeClass(enabled = false) public void setupClass(ITestContext testContext) { - assertEquals( - testContext.getSuite().getXmlSuite().getConfigFailurePolicy(), - XmlSuite.FailurePolicy.CONTINUE); + assertThat(testContext.getSuite().getXmlSuite().getConfigFailurePolicy()) + .isEqualTo(XmlSuite.FailurePolicy.CONTINUE); } @DataProvider(name = "dp") @@ -183,15 +181,15 @@ private void verify( int configurationFailures, int configurationSkips, int skippedTests) { - assertEquals( - tla.getConfigurationFailures().size(), - configurationFailures, - "wrong number of configuration failures"); - assertEquals( - tla.getConfigurationSkips().size(), - configurationSkips, - "wrong number of configuration skips"); - assertEquals(tla.getSkippedTests().size(), skippedTests, "wrong number of skipped tests"); + assertThat(tla.getConfigurationFailures()) + .withFailMessage("wrong number of configuration failures") + .hasSize(configurationFailures); + assertThat(tla.getConfigurationSkips()) + .withFailMessage("wrong number of configuration skips") + .hasSize(configurationSkips); + assertThat(tla.getSkippedTests()) + .withFailMessage("wrong number of skipped tests") + .hasSize(skippedTests); } @Test(description = "GITHUB-2862") diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample.java b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample.java index 36b1901e0f..07eca51317 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample.java @@ -1,6 +1,7 @@ package test.configurationfailurepolicy.issue2862; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -14,7 +15,7 @@ public static class MyBaseClassSample { public void beforeMethod() { if (fail) { fail = false; - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample2.java b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample2.java index 035736dd6d..9178e63ac3 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample2.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample2.java @@ -1,6 +1,7 @@ package test.configurationfailurepolicy.issue2862; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; @@ -11,12 +12,12 @@ public class AnnotationAtParentClassLevelForMethodConfigSample2 { public static class MyBaseClassSample { @BeforeTest(ignoreFailure = true) public void beforeTest() { - Assert.fail(); + fail(); } @BeforeClass public void beforeClassInBaseClass() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample3.java b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample3.java index 6f89640b1c..761b777265 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample3.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationAtParentClassLevelForMethodConfigSample3.java @@ -1,6 +1,7 @@ package test.configurationfailurepolicy.issue2862; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; @@ -14,7 +15,7 @@ public void beforeTest() {} @BeforeClass(ignoreFailure = true) public void beforeClassInBaseClass() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeClassSample.java b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeClassSample.java index 72484e8c27..774eef4ca6 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeClassSample.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeClassSample.java @@ -1,6 +1,7 @@ package test.configurationfailurepolicy.issue2862; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -11,7 +12,7 @@ public static class AnnotatedClassSample { @BeforeClass(ignoreFailure = true) public void beforeClass() { - Assert.fail(); + fail(); } @BeforeMethod diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeMethodSample.java b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeMethodSample.java index 398127487f..3358f0146b 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeMethodSample.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeMethodSample.java @@ -1,6 +1,7 @@ package test.configurationfailurepolicy.issue2862; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -13,7 +14,7 @@ public static class AnnotatedClassSample { public void beforeMethod1() { if (fail) { fail = false; - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestMultipleTestsSample.java b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestMultipleTestsSample.java index fe06ff1371..c61ff60206 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestMultipleTestsSample.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestMultipleTestsSample.java @@ -1,6 +1,7 @@ package test.configurationfailurepolicy.issue2862; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -11,7 +12,7 @@ public static class FirstTestTagAnnotatedClassSample { @BeforeTest(ignoreFailure = true) public void beforeTest() { - Assert.fail(); + fail(); } @BeforeMethod diff --git a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestSample.java b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestSample.java index 6142f56261..2fb9d17880 100644 --- a/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestSample.java +++ b/testng-core/src/test/java/test/configurationfailurepolicy/issue2862/AnnotationBeforeTestSample.java @@ -1,6 +1,7 @@ package test.configurationfailurepolicy.issue2862; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -11,7 +12,7 @@ public static class AnnotatedClassSample { @BeforeTest(ignoreFailure = true) public void beforeTest() { - Assert.fail(); + fail(); } @BeforeMethod diff --git a/testng-core/src/test/java/test/dataprovider/ClassSample.java b/testng-core/src/test/java/test/dataprovider/ClassSample.java index 453f5effbf..25d51b98a0 100644 --- a/testng-core/src/test/java/test/dataprovider/ClassSample.java +++ b/testng-core/src/test/java/test/dataprovider/ClassSample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -16,7 +17,7 @@ public ClassSample(String s) { @DataProvider(name = "dp1") public static Object[][] createData1(Class clazz) { - Assert.assertEquals(clazz, ClassSample.class); + assertThat(clazz).isEqualTo(ClassSample.class); return new Object[][] {{"0"}, {"1"}}; } @@ -25,7 +26,7 @@ public void test1() {} @DataProvider(name = "dp2") public Object[][] createData2(Class clazz) { - Assert.assertEquals(clazz, ClassSample.class); + assertThat(clazz).isEqualTo(ClassSample.class); return new Object[][] {{"Cedric" + s}, {"Alois" + s}}; } diff --git a/testng-core/src/test/java/test/dataprovider/ConfigurationAndDataProvidersSample.java b/testng-core/src/test/java/test/dataprovider/ConfigurationAndDataProvidersSample.java index 741bb2e04d..60ff2fa030 100644 --- a/testng-core/src/test/java/test/dataprovider/ConfigurationAndDataProvidersSample.java +++ b/testng-core/src/test/java/test/dataprovider/ConfigurationAndDataProvidersSample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; @@ -18,10 +19,12 @@ public class ConfigurationAndDataProvidersSample { @DataProvider(name = "test1") public Object[][] createData() { - Assert.assertTrue(m_beforeSuite, "beforeSuite should have been invoked"); - Assert.assertTrue(m_beforeTest, "beforeTest should have been invoked"); - Assert.assertTrue(m_beforeClass, "beforeClass should have been invoked"); - Assert.assertFalse(m_beforeTestMethod, "beforeMethod should not have been invoked"); + assertThat(m_beforeSuite).withFailMessage("beforeSuite should have been invoked").isTrue(); + assertThat(m_beforeTest).withFailMessage("beforeTest should have been invoked").isTrue(); + assertThat(m_beforeClass).withFailMessage("beforeClass should have been invoked").isTrue(); + assertThat(m_beforeTestMethod) + .withFailMessage("beforeMethod should not have been invoked") + .isFalse(); return new Object[][] {{"Test"}}; } diff --git a/testng-core/src/test/java/test/dataprovider/ConstructorOrMethodSample.java b/testng-core/src/test/java/test/dataprovider/ConstructorOrMethodSample.java index c6629e4b7d..7018a2c6c4 100644 --- a/testng-core/src/test/java/test/dataprovider/ConstructorOrMethodSample.java +++ b/testng-core/src/test/java/test/dataprovider/ConstructorOrMethodSample.java @@ -1,8 +1,9 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -19,14 +20,14 @@ public ConstructorOrMethodSample(String s) { @DataProvider(name = "dp1") public static Object[][] createData1(ConstructorOrMethod cOrM) { - Assert.assertEquals(cOrM.getDeclaringClass(), ConstructorOrMethodSample.class); - Assert.assertNull(cOrM.getMethod()); - Assert.assertNotNull(cOrM.getConstructor()); + assertThat(cOrM.getDeclaringClass()).isEqualTo(ConstructorOrMethodSample.class); + assertThat(cOrM.getMethod()).isNull(); + assertThat(cOrM.getConstructor()).isNotNull(); Constructor c = cOrM.getConstructor(); - Assert.assertNotNull(c.getAnnotation(Factory.class)); - Assert.assertEquals(c.getParameterTypes().length, 1); - Assert.assertEquals(c.getParameterTypes()[0], String.class); + assertThat(c.getAnnotation(Factory.class)).isNotNull(); + assertThat(c.getParameterTypes().length).isOne(); + assertThat(c.getParameterTypes()[0]).isEqualTo(String.class); return new Object[][] {{"0"}, {"1"}}; } @@ -36,12 +37,12 @@ public void test1() {} @DataProvider(name = "dp2") public Object[][] createData2(ConstructorOrMethod cOrM) { - Assert.assertEquals(cOrM.getDeclaringClass(), ConstructorOrMethodSample.class); - Assert.assertNotNull(cOrM.getMethod()); - Assert.assertNull(cOrM.getConstructor()); + assertThat(cOrM.getDeclaringClass()).isEqualTo(ConstructorOrMethodSample.class); + assertThat(cOrM.getMethod()).isNotNull(); + assertThat(cOrM.getConstructor()).isNull(); Method m = cOrM.getMethod(); - Assert.assertEquals(m.getName(), "test2"); + assertThat(m.getName()).isEqualTo("test2"); return new Object[][] {{"Cedric" + s}, {"Alois" + s}}; } diff --git a/testng-core/src/test/java/test/dataprovider/ConstructorSample.java b/testng-core/src/test/java/test/dataprovider/ConstructorSample.java index e426cf0869..60c02af820 100644 --- a/testng-core/src/test/java/test/dataprovider/ConstructorSample.java +++ b/testng-core/src/test/java/test/dataprovider/ConstructorSample.java @@ -1,9 +1,10 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -21,10 +22,10 @@ public ConstructorSample(String s) { @DataProvider(name = "dp") public static Object[][] createData(Constructor c) { - Assert.assertEquals(c.getDeclaringClass(), ConstructorSample.class); - Assert.assertNotNull(c.getAnnotation(Factory.class)); - Assert.assertEquals(c.getParameterTypes().length, 1); - Assert.assertEquals(c.getParameterTypes()[0], String.class); + assertThat(c.getDeclaringClass()).isEqualTo(ConstructorSample.class); + assertThat(c.getAnnotation(Factory.class)).isNotNull(); + assertThat(c.getParameterTypes().length).isOne(); + assertThat(c.getParameterTypes()[0]).isEqualTo(String.class); return new Object[][] {{"Cedric"}, {"Alois"}}; } diff --git a/testng-core/src/test/java/test/dataprovider/DataProviderIntegrationSample.java b/testng-core/src/test/java/test/dataprovider/DataProviderIntegrationSample.java index abee64a7b1..cbea34856b 100644 --- a/testng-core/src/test/java/test/dataprovider/DataProviderIntegrationSample.java +++ b/testng-core/src/test/java/test/dataprovider/DataProviderIntegrationSample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -12,6 +13,6 @@ public Object[][] testInts() { @Test(dataProvider = "testInts", expectedExceptions = IllegalArgumentException.class) public void theTest(String aString) { - Assert.assertNotNull(aString); + assertThat(aString).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/DataProviderRetryTest.java b/testng-core/src/test/java/test/dataprovider/DataProviderRetryTest.java index 0e1c55c793..8b409f5f10 100644 --- a/testng-core/src/test/java/test/dataprovider/DataProviderRetryTest.java +++ b/testng-core/src/test/java/test/dataprovider/DataProviderRetryTest.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.SkipException; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -10,7 +11,7 @@ public class DataProviderRetryTest { public void test(String verdict) { switch (verdict) { case "FAIL": - Assert.fail("This time test FAIL!"); + fail("This time test FAIL!"); break; case "SKIP": throw new SkipException("This time test SKIPPED!"); diff --git a/testng-core/src/test/java/test/dataprovider/DataProviderTest.java b/testng-core/src/test/java/test/dataprovider/DataProviderTest.java index de7121c2c6..0fc485f7c4 100644 --- a/testng-core/src/test/java/test/dataprovider/DataProviderTest.java +++ b/testng-core/src/test/java/test/dataprovider/DataProviderTest.java @@ -8,7 +8,6 @@ import java.util.List; import org.assertj.core.api.Condition; import org.assertj.core.api.SoftAssertions; -import org.testng.Assert; import org.testng.IDataProviderMethod; import org.testng.ITestNGMethod; import org.testng.ITestResult; @@ -83,7 +82,7 @@ public void testDataProviderCanBeRetriedOnFailures() { // Without retrying itself we would have already invoked the listener once. assertThat(listener.getBeforeInvocations()).isEqualTo(3); assertThat(listener.getFailureInvocations()).isEqualTo(2); - assertThat(listener.getAfterInvocations()).isEqualTo(1); + assertThat(listener.getAfterInvocations()).isOne(); } @Test(description = "GITHUB-2819") @@ -98,7 +97,7 @@ public void testDataProviderCanBeRetriedViaAnnotationTransformer() { // Without retrying itself we would have already invoked the listener once. assertThat(listener.getBeforeInvocations()).isEqualTo(3); assertThat(listener.getFailureInvocations()).isEqualTo(2); - assertThat(listener.getAfterInvocations()).isEqualTo(1); + assertThat(listener.getAfterInvocations()).isOne(); } @Test(description = "GITHUB-2819") @@ -121,9 +120,9 @@ public void testDataProviderRetryAbortsGracefullyWhenNoRetryAtFirstTime() { DataProviderListenerForRetryAwareTests listener = new DataProviderListenerForRetryAwareTests(); testng.addListener(listener); testng.run(); - assertThat(listener.getBeforeInvocations()).isEqualTo(1); - assertThat(listener.getFailureInvocations()).isEqualTo(1); - assertThat(listener.getAfterInvocations()).isEqualTo(0); + assertThat(listener.getBeforeInvocations()).isOne(); + assertThat(listener.getFailureInvocations()).isOne(); + assertThat(listener.getAfterInvocations()).isZero(); } @Test(description = "GITHUB-2800") @@ -294,8 +293,8 @@ public void methodTest() { assertThat(listener.getSucceedMethodNames()) .containsExactly("test1(Cedric)", "test1(Alois)", "test2(Cedric)", "test3(Cedric)"); - Assert.assertEquals(MethodSample.m_test2, 1); - Assert.assertEquals(MethodSample.m_test3, 1); + assertThat(MethodSample.m_test2).isOne(); + assertThat(MethodSample.m_test3).isOne(); } @Test @@ -354,7 +353,7 @@ public void testForFunctionalInterfacesInLazyLoadingDataProviders( Data.INSTANCE.clear(); run(cls); List actualList = Data.INSTANCE.getData(); - assertThat(actualList).isEqualTo(expected); + assertThat(actualList).containsExactlyElementsOf(expected); } @DataProvider(name = "2565") @@ -500,7 +499,7 @@ public void testDataProvidersThatReturnNull() { TestNG tng = create(Github1509TestClassSample.class); tng.addListener(tla); tng.run(); - assertThat(tla.getFailedTests()).size().isEqualTo(1); + assertThat(tla.getFailedTests()).hasSize(1); ITestResult result = tla.getFailedTests().get(0); String className = Github1509TestClassSample.class.getName() + ".getData()"; String msg = @@ -513,7 +512,7 @@ public void ensureDataProviderNotInvokedMultipleTimesForRetriedTests() { TestNG testng = create(test.dataprovider.issue2884.TestClassSample.class); testng.run(); assertThat(test.dataprovider.issue2884.TestClassSample.dataProviderInvocationCount.get()) - .isEqualTo(1); + .isOne(); } @Test @@ -522,8 +521,8 @@ public void retryWithDataProvider() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - assertThat(tla.getFailedTests()).size().isEqualTo(1); - assertThat(tla.getSkippedTests()).size().isEqualTo(2); + assertThat(tla.getFailedTests()).hasSize(1); + assertThat(tla.getSkippedTests()).hasSize(2); } @Test(description = "GITHUB-217", expectedExceptions = TestNGException.class) @@ -538,14 +537,14 @@ public void ensureTestNGFailsDueToDataProviderFailure() { TestNG testng = create(test.dataprovider.issue217.TestClassSample.class); testng.propagateDataProviderFailureAsTestFailure(); testng.run(); - assertThat(testng.getStatus()).isEqualTo(1); + assertThat(testng.getStatus()).isOne(); } @Test(description = "GITHUB-217") public void ensureTestNGFailsDueToDataProviderFailure2() { TestNG testng = create(test.dataprovider.issue217.AnotherTestClassSample.class); testng.run(); - assertThat(testng.getStatus()).isEqualTo(1); + assertThat(testng.getStatus()).isOne(); } @Test(description = "GITHUB-2888") @@ -595,8 +594,8 @@ public void ensureDynamicRetryAnalyzersAreHonouredForDataDrivenTest() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - assertThat(tla.getFailedTests()).size().isEqualTo(1); - assertThat(tla.getSkippedTests()).size().isEqualTo(1); + assertThat(tla.getFailedTests()).hasSize(1); + assertThat(tla.getSkippedTests()).hasSize(1); } @Test(description = "GITHUB-2327") @@ -606,7 +605,7 @@ public void ensureDataProviderParametersAreAlwaysAvailableForListeners() { testng.addListener(tla); testng.run(); - assertThat(tla.getSkippedTests().size()).isEqualTo(2); + assertThat(tla.getSkippedTests()).hasSize(2); SoftAssertions assertions = new SoftAssertions(); for (ITestResult skippedTest : tla.getSkippedTests()) { @@ -676,7 +675,7 @@ public void ensureNoExceptionsWhenRunningInSharedThreadPoolsWithMethodIntercepto testng.shareThreadPoolForDataProviders(true); testng.setVerbose(2); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); assertThat(test.dataprovider.issue3081.TestClassSample.getLogs()) .withFailMessage( "There should have been 9 threads ONLY used by the data driven test " @@ -696,7 +695,7 @@ public void ensureNoExceptionsWhenRunningInSharedThreadPoolsWithMethodIntercepto testng.setThreadCount(10); testng.setVerbose(2); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); assertThat(TestClassWithPrioritiesSample.getLogs()) .withFailMessage( "There should have been 9 threads ONLY used by the data driven test " @@ -741,7 +740,6 @@ private static void runTest(Class clazz, boolean wireInListener) { testng.setXmlSuites(Collections.singletonList(xmlSuite)); testng.setVerbose(2); testng.run(); - assertThat(DataProviderListener.logs).hasSize(2); assertThat(DataProviderListener.logs) .containsExactly( "[Test2]-beforeDataProviderExecution-dataProvider", diff --git a/testng-core/src/test/java/test/dataprovider/DataProviderWithErrorSample.java b/testng-core/src/test/java/test/dataprovider/DataProviderWithErrorSample.java index bf72aa3ebd..a17efb1aab 100644 --- a/testng-core/src/test/java/test/dataprovider/DataProviderWithErrorSample.java +++ b/testng-core/src/test/java/test/dataprovider/DataProviderWithErrorSample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -8,12 +9,12 @@ public class DataProviderWithErrorSample { @Test(dataProvider = "Data", invocationCount = 2) public void testShouldSkip() { - Assert.fail(); + fail(); } @Test(dataProvider = "Data", invocationCount = 2, successPercentage = 10) public void testShouldSkipEvenIfSuccessPercentage() { - Assert.fail(); + fail(); } @DataProvider(name = "Data") diff --git a/testng-core/src/test/java/test/dataprovider/EmptyDataProviderSample.java b/testng-core/src/test/java/test/dataprovider/EmptyDataProviderSample.java index e4d4afb742..7dfde737b7 100644 --- a/testng-core/src/test/java/test/dataprovider/EmptyDataProviderSample.java +++ b/testng-core/src/test/java/test/dataprovider/EmptyDataProviderSample.java @@ -1,8 +1,9 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.fail; + import java.util.Collections; import java.util.Iterator; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -15,7 +16,7 @@ public Object[][] dp1() { @Test(dataProvider = "dp1") public void test1() { - Assert.fail(); + fail(); } @DataProvider(indices = {2}) @@ -25,6 +26,6 @@ public Iterator dp2() { @Test(dataProvider = "dp2") public void test2() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/dataprovider/FailingDataProviderSample.java b/testng-core/src/test/java/test/dataprovider/FailingDataProviderSample.java index 213af18e70..486e4f164c 100644 --- a/testng-core/src/test/java/test/dataprovider/FailingDataProviderSample.java +++ b/testng-core/src/test/java/test/dataprovider/FailingDataProviderSample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public Object[][] throwsExpectedException() { @Test(dataProvider = "throwsExpectedException") public void dpThrowingException() { - Assert.fail("Method should never get invoked"); + fail("Method should never get invoked"); } } diff --git a/testng-core/src/test/java/test/dataprovider/GitHub513Sample.java b/testng-core/src/test/java/test/dataprovider/GitHub513Sample.java index f977de8770..1889cdccbc 100644 --- a/testng-core/src/test/java/test/dataprovider/GitHub513Sample.java +++ b/testng-core/src/test/java/test/dataprovider/GitHub513Sample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -13,10 +14,10 @@ public static Object[][] testData() { @Test(dataProvider = "testData") public void test(String fixedArg1, Object fixedArg2, String... args) { - Assert.assertEquals(fixedArg1, "a"); - Assert.assertEquals(fixedArg2, "b"); - Assert.assertEquals(args.length, 2); - Assert.assertEquals(args[0], "c"); - Assert.assertEquals(args[1], "d"); + assertThat(fixedArg1).isEqualTo("a"); + assertThat(fixedArg2).isEqualTo("b"); + assertThat(args).hasSize(2); + assertThat(args[0]).isEqualTo("c"); + assertThat(args[1]).isEqualTo("d"); } } diff --git a/testng-core/src/test/java/test/dataprovider/Github1509TestClassSample.java b/testng-core/src/test/java/test/dataprovider/Github1509TestClassSample.java index 91f8c8d2d9..433ea54f06 100644 --- a/testng-core/src/test/java/test/dataprovider/Github1509TestClassSample.java +++ b/testng-core/src/test/java/test/dataprovider/Github1509TestClassSample.java @@ -1,13 +1,14 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class Github1509TestClassSample { @Test(dataProvider = "dp") public void demo(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/dataprovider/ITestNGMethodSample.java b/testng-core/src/test/java/test/dataprovider/ITestNGMethodSample.java index d1caf87faf..885a2549f6 100644 --- a/testng-core/src/test/java/test/dataprovider/ITestNGMethodSample.java +++ b/testng-core/src/test/java/test/dataprovider/ITestNGMethodSample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -9,9 +10,9 @@ public class ITestNGMethodSample { @DataProvider(name = "dp1") public Object[][] createData(ITestNGMethod m) { - Assert.assertEquals(m.getMethodName(), "test1"); - Assert.assertEquals(m.getConstructorOrMethod().getMethod().getName(), "test1"); - Assert.assertEquals(m.getRealClass(), ITestNGMethodSample.class); + assertThat(m.getMethodName()).isEqualTo("test1"); + assertThat(m.getConstructorOrMethod().getMethod().getName()).isEqualTo("test1"); + assertThat(m.getRealClass()).isEqualTo(ITestNGMethodSample.class); return new Object[][] {{"Cedric"}, {"Alois"}}; } diff --git a/testng-core/src/test/java/test/dataprovider/InstanceDataProviderSample.java b/testng-core/src/test/java/test/dataprovider/InstanceDataProviderSample.java index 891f0fca99..a2d4a9b85a 100644 --- a/testng-core/src/test/java/test/dataprovider/InstanceDataProviderSample.java +++ b/testng-core/src/test/java/test/dataprovider/InstanceDataProviderSample.java @@ -1,6 +1,7 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public Object[][] dp() { @Test(dataProvider = "dp") public void f(Integer n) { - Assert.assertEquals(n, Integer.valueOf(hashCode())); + assertThat(n).isEqualTo(Integer.valueOf(hashCode())); } } diff --git a/testng-core/src/test/java/test/dataprovider/MethodSample.java b/testng-core/src/test/java/test/dataprovider/MethodSample.java index c202d1cda2..5ca5b25cb6 100644 --- a/testng-core/src/test/java/test/dataprovider/MethodSample.java +++ b/testng-core/src/test/java/test/dataprovider/MethodSample.java @@ -1,7 +1,8 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -9,8 +10,8 @@ public class MethodSample { @DataProvider(name = "dp1") public Object[][] createData(Method m) { - Assert.assertEquals(m.getName(), "test1"); - Assert.assertEquals(m.getDeclaringClass(), MethodSample.class); + assertThat(m.getName()).isEqualTo("test1"); + assertThat(m.getDeclaringClass()).isEqualTo(MethodSample.class); return new Object[][] {{"Cedric"}, {"Alois"}}; } @@ -33,7 +34,7 @@ public Object[][] createData2(Method m) { default: throw new RuntimeException("Received method " + m + ", expected test2 or test3"); } - Assert.assertEquals(m.getDeclaringClass(), MethodSample.class); + assertThat(m.getDeclaringClass()).isEqualTo(MethodSample.class); return new Object[][] {{"Cedric"}}; } diff --git a/testng-core/src/test/java/test/dataprovider/OneDimDataProviderSample.java b/testng-core/src/test/java/test/dataprovider/OneDimDataProviderSample.java index 13a9a368c8..787d4ad51a 100644 --- a/testng-core/src/test/java/test/dataprovider/OneDimDataProviderSample.java +++ b/testng-core/src/test/java/test/dataprovider/OneDimDataProviderSample.java @@ -1,8 +1,9 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.Iterator; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -15,7 +16,7 @@ public static Object[] staticArray() { @Test(dataProvider = "staticArray") public void testStaticArray(String s) { - Assert.assertNotNull(s); + assertThat(s).isNotNull(); } @DataProvider @@ -25,7 +26,7 @@ public Object[] array() { @Test(dataProvider = "array") public void testArray(String s) { - Assert.assertNotNull(s); + assertThat(s).isNotNull(); } @DataProvider @@ -35,7 +36,7 @@ public static Iterator staticIterator() { @Test(dataProvider = "staticIterator") public void testStaticIterator(String s) { - Assert.assertNotNull(s); + assertThat(s).isNotNull(); } @DataProvider @@ -45,6 +46,6 @@ public Iterator iterator() { @Test(dataProvider = "iterator") public void testIterator(String s) { - Assert.assertNotNull(s); + assertThat(s).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/ParallelDataProvider2Sample.java b/testng-core/src/test/java/test/dataprovider/ParallelDataProvider2Sample.java index 63ff408b1d..d46f7ed676 100644 --- a/testng-core/src/test/java/test/dataprovider/ParallelDataProvider2Sample.java +++ b/testng-core/src/test/java/test/dataprovider/ParallelDataProvider2Sample.java @@ -1,9 +1,10 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -21,6 +22,6 @@ Iterator provide() { @Test(dataProvider = "provide", invocationCount = 2, threadPoolSize = 2) public void checkCME(Integer i) { - Assert.assertNotNull(i); + assertThat(i).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/RawIteratorDataProviderSample.java b/testng-core/src/test/java/test/dataprovider/RawIteratorDataProviderSample.java index cf3d8b14f2..a9bddf0e5c 100644 --- a/testng-core/src/test/java/test/dataprovider/RawIteratorDataProviderSample.java +++ b/testng-core/src/test/java/test/dataprovider/RawIteratorDataProviderSample.java @@ -1,8 +1,9 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.Iterator; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -15,7 +16,7 @@ public static Iterator staticIterator() { @Test(dataProvider = "staticIterator") public void testStaticIterator(String s) { - Assert.assertNotNull(s); + assertThat(s).isNotNull(); } @DataProvider @@ -25,6 +26,6 @@ public Iterator iterator() { @Test(dataProvider = "iterator") public void testIterator(String s) { - Assert.assertNotNull(s); + assertThat(s).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/TestContextSample.java b/testng-core/src/test/java/test/dataprovider/TestContextSample.java index f74cfa657f..c3355f415d 100644 --- a/testng-core/src/test/java/test/dataprovider/TestContextSample.java +++ b/testng-core/src/test/java/test/dataprovider/TestContextSample.java @@ -1,7 +1,8 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; -import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -26,11 +27,11 @@ public Object[] createContext(ITestContext ctx) { @Test(dataProvider = "testContext", groups = "10") public void verifyTen(Object[] objects) { - Assert.assertEquals(objects.length, 10); + assertThat(objects).hasSize(10); } @Test(dataProvider = "testContext", groups = "5") public void verifyFive(Object[] objects) { - Assert.assertEquals(objects.length, 5); + assertThat(objects).hasSize(5); } } diff --git a/testng-core/src/test/java/test/dataprovider/TestInstanceSample.java b/testng-core/src/test/java/test/dataprovider/TestInstanceSample.java index 47bf8b4354..c05ad35d6e 100644 --- a/testng-core/src/test/java/test/dataprovider/TestInstanceSample.java +++ b/testng-core/src/test/java/test/dataprovider/TestInstanceSample.java @@ -1,7 +1,8 @@ package test.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.testng.annotations.TestInstance; @@ -23,7 +24,7 @@ public TestInstanceSample(int n) { @DataProvider public Object[][] dp(Method m, @TestInstance Object instance) { TestInstanceSample o0 = (TestInstanceSample) instance; - Assert.assertTrue(o0.m_n == 1 || o0.m_n == 2); + assertThat(o0.m_n).isIn(1, 2); m_instanceCount++; return new Object[][] {{42}, {43}}; diff --git a/testng-core/src/test/java/test/dataprovider/TestNG411Sample.java b/testng-core/src/test/java/test/dataprovider/TestNG411Sample.java index f8eb83f61c..22add96736 100644 --- a/testng-core/src/test/java/test/dataprovider/TestNG411Sample.java +++ b/testng-core/src/test/java/test/dataprovider/TestNG411Sample.java @@ -1,6 +1,8 @@ package test.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import org.testng.ITestContext; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -20,7 +22,7 @@ public Object[][] dataProviderCheckMax() { "Number of parameters to this test don't match the ones passed by data provider", dataProvider = CHECK_MAX_DATA) public void checkMaxTest(int nr1, int nr2, int expected) { - Assert.fail("This code shouldn't be executed"); + fail("This code shouldn't be executed"); } @DataProvider(name = CHECK_MIN_DATA) @@ -33,7 +35,7 @@ public Object[][] dataProviderCheckMin() { "Number of parameters to this test don't match the ones passed by data provider", dataProvider = CHECK_MIN_DATA) public void checkMinTest(int nr1, int nr2, int expected) { - Assert.fail("This code shouldn't be executed"); + fail("This code shouldn't be executed"); } @Test( @@ -43,7 +45,7 @@ public void checkMinTest(int nr1, int nr2, int expected) { dataProvider = CHECK_MIN_DATA) public void checkMinTest_injection(int nr1, int nr2, ITestContext ctx) { int result = Math.min(nr1, nr2); - Assert.assertEquals(result, nr1); - Assert.assertNotNull(ctx); + assertThat(result).isEqualTo(nr1); + assertThat(ctx).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue128/DataProviderParametersMismatchTest.java b/testng-core/src/test/java/test/dataprovider/issue128/DataProviderParametersMismatchTest.java index 4c5498afab..e1b4568df0 100644 --- a/testng-core/src/test/java/test/dataprovider/issue128/DataProviderParametersMismatchTest.java +++ b/testng-core/src/test/java/test/dataprovider/issue128/DataProviderParametersMismatchTest.java @@ -1,9 +1,10 @@ package test.dataprovider.issue128; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -26,7 +27,9 @@ public void testIfWarningsAreServed() { boolean contains = msg.contains( "Missing one or more parameters that are being injected by the data provider. Please add the below arguments to the method."); - Assert.assertTrue(contains, "Missing parameters warning should have triggered"); + assertThat(contains) + .withFailMessage("Missing parameters warning should have triggered") + .isTrue(); } finally { System.setErr(currentErr); System.setProperty("strictParameterMatch", "false"); @@ -42,9 +45,9 @@ public void testIfExceptionIsRaised() { tng.addListener(listener); tng.run(); for (ITestResult each : listener.getFailedTests()) { - Assert.assertTrue(each.getThrowable() instanceof MethodMatcherException); + assertThat(each.getThrowable()).isInstanceOf(MethodMatcherException.class); } - Assert.assertEquals(listener.getFailedTests().size(), 2); + assertThat(listener.getFailedTests()).hasSize(2); } finally { System.setProperty("strictParameterMatch", "false"); } diff --git a/testng-core/src/test/java/test/dataprovider/issue128/GitHub128Sample.java b/testng-core/src/test/java/test/dataprovider/issue128/GitHub128Sample.java index 12679523b2..331a545f50 100644 --- a/testng-core/src/test/java/test/dataprovider/issue128/GitHub128Sample.java +++ b/testng-core/src/test/java/test/dataprovider/issue128/GitHub128Sample.java @@ -1,7 +1,9 @@ package test.dataprovider.issue128; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -13,7 +15,7 @@ public class GitHub128Sample { @BeforeClass public void beforeClass(ITestContext ctx) { - Assert.assertNotNull(ctx); + assertThat(ctx).isNotNull(); } @BeforeMethod @@ -23,7 +25,7 @@ public void beforeMethod() { @Test public void testMethod(ITestContext ctx) { - Assert.assertNotNull(ctx); + assertThat(ctx).isNotNull(); } @DataProvider(name = "methods") @@ -33,13 +35,13 @@ public Object[][] getMethods() throws NoSuchMethodException { @Test(dataProvider = "methods") public void testInvokeRemote(Method param1, Object[] param2) { - Assert.fail("The test is supposed to fail because the method param is not defined"); + fail("The test is supposed to fail because the method param is not defined"); } @Test(dataProvider = "methods") public void testInvokeRemote2(@NoInjection Method param1, Object[] param2) { - Assert.assertEquals(param1.getName(), "toString"); - Assert.assertEquals(param2.length, 0); + assertThat(param1.getName()).isEqualTo("toString"); + assertThat(param2).isEmpty(); } @DataProvider(name = "methods2") @@ -49,13 +51,13 @@ public Object[][] getMethods2() throws NoSuchMethodException { @Test(dataProvider = "methods2") public void testInvokeRemoteReversed(Object[] param1, Method param2) { - Assert.fail("The test is supposed to fail because the method param is not defined"); + fail("The test is supposed to fail because the method param is not defined"); } @Test(dataProvider = "methods2") public void testInvokeRemoteReversed2(Object[] param1, @NoInjection Method param2) { - Assert.assertEquals(param1.length, 0); - Assert.assertEquals(param2.getName(), "toString"); + assertThat(param1).isEmpty(); + assertThat(param2.getName()).isEqualTo("toString"); } // TODO Add similar test for Before/AfterMethod diff --git a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionAtClassLevelAndNoTestMethodUsage.java b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionAtClassLevelAndNoTestMethodUsage.java index 4669c8751d..cb10ae7153 100644 --- a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionAtClassLevelAndNoTestMethodUsage.java +++ b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionAtClassLevelAndNoTestMethodUsage.java @@ -1,6 +1,7 @@ package test.dataprovider.issue1691; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; @Test(dataProviderClass = SampleDataProvider.class, dataProvider = "hangoutPlaces") @@ -9,7 +10,7 @@ public class DataProviderDefinitionAtClassLevelAndNoTestMethodUsage { public void regularTestMethod() {} public void verifyHangoutPlaces(String place, String city) { - Assert.assertNotNull(place); - Assert.assertNotNull(city); + assertThat(place).isNotNull(); + assertThat(city).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevel.java b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevel.java index 7f4f18372b..4744b6a348 100644 --- a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevel.java +++ b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevel.java @@ -1,6 +1,7 @@ package test.dataprovider.issue1691; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; @Test(dataProviderClass = SampleDataProvider.class, dataProvider = "hangoutPlaces") @@ -8,7 +9,7 @@ public class DataProviderDefinitionCompletelyProvidedAtClassLevel { @Test public void verifyHangoutPlaces(String place, String city) { - Assert.assertNotNull(place); - Assert.assertNotNull(city); + assertThat(place).isNotNull(); + assertThat(city).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevelAndPartiallyAtMethodLevel.java b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevelAndPartiallyAtMethodLevel.java index ad3c45abca..20354e1880 100644 --- a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevelAndPartiallyAtMethodLevel.java +++ b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionCompletelyProvidedAtClassLevelAndPartiallyAtMethodLevel.java @@ -1,6 +1,7 @@ package test.dataprovider.issue1691; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; @Test(dataProviderClass = SampleDataProvider.class, dataProvider = "busyMalls") @@ -8,7 +9,7 @@ public class DataProviderDefinitionCompletelyProvidedAtClassLevelAndPartiallyAtM @Test(dataProvider = "hangoutPlaces") public void verifyHangoutPlaces(String place, String city) { - Assert.assertNotNull(place); - Assert.assertNotNull(city); + assertThat(place).isNotNull(); + assertThat(city).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionProvidedPartiallyAtClassLevel.java b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionProvidedPartiallyAtClassLevel.java index a1b9c34a0c..dccec0a559 100644 --- a/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionProvidedPartiallyAtClassLevel.java +++ b/testng-core/src/test/java/test/dataprovider/issue1691/DataProviderDefinitionProvidedPartiallyAtClassLevel.java @@ -1,6 +1,7 @@ package test.dataprovider.issue1691; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; @Test(dataProviderClass = SampleDataProvider.class, dataProvider = "hangoutPlaces") @@ -8,7 +9,7 @@ public class DataProviderDefinitionProvidedPartiallyAtClassLevel { @Test public void verifyHangoutPlaces(String place, String city) { - Assert.assertNotNull(place); - Assert.assertNotNull(city); + assertThat(place).isNotNull(); + assertThat(city).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithFullDefinitionOfDataProviderInTestMethod.java b/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithFullDefinitionOfDataProviderInTestMethod.java index 5c1cc4d3f6..a6812a68e5 100644 --- a/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithFullDefinitionOfDataProviderInTestMethod.java +++ b/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithFullDefinitionOfDataProviderInTestMethod.java @@ -1,6 +1,7 @@ package test.dataprovider.issue1691.withinheritance; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; import test.dataprovider.issue1691.SampleDataProvider; @@ -8,7 +9,7 @@ public class BaseClassWithFullDefinitionOfDataProviderInTestMethod { @Test(dataProviderClass = SampleDataProvider.class, dataProvider = "hangoutPlaces") public void verifyHangoutPlaces(String place, String city) { - Assert.assertNotNull(place); - Assert.assertNotNull(city); + assertThat(place).isNotNull(); + assertThat(city).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithPartialDefinitionOfDataProviderInTestMethod.java b/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithPartialDefinitionOfDataProviderInTestMethod.java index bdcb6ee168..2e02234bbc 100644 --- a/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithPartialDefinitionOfDataProviderInTestMethod.java +++ b/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/BaseClassWithPartialDefinitionOfDataProviderInTestMethod.java @@ -1,13 +1,14 @@ package test.dataprovider.issue1691.withinheritance; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class BaseClassWithPartialDefinitionOfDataProviderInTestMethod { @Test(dataProvider = "hangoutPlaces") public void verifyHangoutPlaces(String place, String city) { - Assert.assertNotNull(place); - Assert.assertNotNull(city); + assertThat(place).isNotNull(); + assertThat(city).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/ChildClassWithNoDataProviderInformationInTestMethod.java b/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/ChildClassWithNoDataProviderInformationInTestMethod.java index 0bfed792f2..ff096e4a2b 100644 --- a/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/ChildClassWithNoDataProviderInformationInTestMethod.java +++ b/testng-core/src/test/java/test/dataprovider/issue1691/withinheritance/ChildClassWithNoDataProviderInformationInTestMethod.java @@ -1,12 +1,12 @@ package test.dataprovider.issue1691.withinheritance; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; public class ChildClassWithNoDataProviderInformationInTestMethod extends BaseClassWithFullDefinitionOfDataProviderInClassLevel { public void verifyHangoutPlaces(String place, String city) { - Assert.assertNotNull(place); - Assert.assertNotNull(city); + assertThat(place).isNotNull(); + assertThat(city).isNotNull(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue2267/TestClassSample.java b/testng-core/src/test/java/test/dataprovider/issue2267/TestClassSample.java index c1f03117c3..2e4da3209e 100644 --- a/testng-core/src/test/java/test/dataprovider/issue2267/TestClassSample.java +++ b/testng-core/src/test/java/test/dataprovider/issue2267/TestClassSample.java @@ -1,6 +1,7 @@ package test.dataprovider.issue2267; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -18,6 +19,6 @@ public Object[][] dp() { @Test(dataProvider = "dp") public void testWithRetryAndDataProvider(int testNumber) { - Assert.fail("This time test FAIL! with testNumber: " + testNumber); + fail("This time test FAIL! with testNumber: " + testNumber); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue2504/TestClassSample.java b/testng-core/src/test/java/test/dataprovider/issue2504/TestClassSample.java index 1cb5a5e1a2..735f2f5433 100644 --- a/testng-core/src/test/java/test/dataprovider/issue2504/TestClassSample.java +++ b/testng-core/src/test/java/test/dataprovider/issue2504/TestClassSample.java @@ -1,6 +1,7 @@ package test.dataprovider.issue2504; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -21,6 +22,6 @@ public void myBeforeMethod() { @Test(dataProvider = "data") void testSuccess(int i) { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue2884/TestClassSample.java b/testng-core/src/test/java/test/dataprovider/issue2884/TestClassSample.java index 639af7bc27..7ebbbe1fe7 100644 --- a/testng-core/src/test/java/test/dataprovider/issue2884/TestClassSample.java +++ b/testng-core/src/test/java/test/dataprovider/issue2884/TestClassSample.java @@ -1,7 +1,8 @@ package test.dataprovider.issue2884; +import static org.assertj.core.api.Assertions.fail; + import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.IRetryAnalyzer; import org.testng.ITestResult; import org.testng.annotations.DataProvider; @@ -13,7 +14,7 @@ public class TestClassSample { @Test(dataProvider = "dp", retryAnalyzer = TryAgain.class) public void testMethod(Pojo user) { - Assert.fail(); + fail(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/dataprovider/issue2888/SkipDataProviderSample.java b/testng-core/src/test/java/test/dataprovider/issue2888/SkipDataProviderSample.java index 03548570ee..f371b30e5c 100644 --- a/testng-core/src/test/java/test/dataprovider/issue2888/SkipDataProviderSample.java +++ b/testng-core/src/test/java/test/dataprovider/issue2888/SkipDataProviderSample.java @@ -1,6 +1,7 @@ package test.dataprovider.issue2888; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -9,7 +10,7 @@ public class SkipDataProviderSample { @Test(groups = "SkipMe") public void testSkip() { - Assert.fail("This test should not execute, it should be skipped"); + fail("This test should not execute, it should be skipped"); } @DataProvider(name = "dataProvider") @@ -19,6 +20,6 @@ private Object[][] dataProvider() { @Test(dataProvider = "dataProvider", groups = "SkipMe") public void testSkipWithDataProvider(String a) { - Assert.fail("This test should not execute, it should be skipped"); + fail("This test should not execute, it should be skipped"); } } diff --git a/testng-core/src/test/java/test/dataprovider/issue2934/TestCaseSample.java b/testng-core/src/test/java/test/dataprovider/issue2934/TestCaseSample.java index c147563114..810de8ea23 100644 --- a/testng-core/src/test/java/test/dataprovider/issue2934/TestCaseSample.java +++ b/testng-core/src/test/java/test/dataprovider/issue2934/TestCaseSample.java @@ -18,7 +18,7 @@ public class TestCaseSample { @Test(dataProvider = "testData", retryAnalyzer = RetryAnalyzer.class) public void API_dummyTest(int number) { - assertThat(number % 2).isEqualTo(0); + assertThat(number % 2).isZero(); } @DataProvider(name = "testData") diff --git a/testng-core/src/test/java/test/dataprovider/issue3237/SampleCacheTestCase.java b/testng-core/src/test/java/test/dataprovider/issue3237/SampleCacheTestCase.java index b766ca0508..8ded22f0dd 100644 --- a/testng-core/src/test/java/test/dataprovider/issue3237/SampleCacheTestCase.java +++ b/testng-core/src/test/java/test/dataprovider/issue3237/SampleCacheTestCase.java @@ -1,8 +1,9 @@ package test.dataprovider.issue3237; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.IRetryAnalyzer; import org.testng.ITestResult; import org.testng.annotations.DataProvider; @@ -16,7 +17,9 @@ public class SampleCacheTestCase { @Test(dataProvider = "dp", retryAnalyzer = MyRetry.class) public void testMethod(String uuid) { // Verify that fresh UUID is generated on each retry (no caching) - Assert.assertEquals(uuid, currentUuid, "Received stale data from DataProvider!"); + assertThat(uuid) + .withFailMessage("Received stale data from DataProvider!") + .isEqualTo(currentUuid); // Fail on first invocation to trigger retry, pass on second if (invocationCount.getAndIncrement() < 1) { diff --git a/testng-core/src/test/java/test/defaultmethods/DefaultMethodTest.java b/testng-core/src/test/java/test/defaultmethods/DefaultMethodTest.java index 9a235ac7ca..657a4e1d1b 100644 --- a/testng-core/src/test/java/test/defaultmethods/DefaultMethodTest.java +++ b/testng-core/src/test/java/test/defaultmethods/DefaultMethodTest.java @@ -1,6 +1,7 @@ package test.defaultmethods; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestClass; import org.testng.ITestNGMethod; import org.testng.TestNG; @@ -25,8 +26,8 @@ public void testDefaultShouldRun(Class clazz) { ITestClass testClass = runTestWithDefaultMethods(clazz); ITestNGMethod[] testMethods = testClass.getTestMethods(); - Assert.assertEquals(testMethods.length, 1); - Assert.assertEquals(testMethods[0].getMethodName(), "defaultMethodTest"); + assertThat(testMethods.length).isOne(); + assertThat(testMethods[0].getMethodName()).isEqualTo("defaultMethodTest"); } @Test( @@ -36,8 +37,8 @@ public void beforeClassDefaultShouldRun(Class clazz) { ITestClass testClass = runTestWithDefaultMethods(clazz); ITestNGMethod[] beforeClassMethods = testClass.getBeforeClassMethods(); - Assert.assertEquals(beforeClassMethods.length, 1); - Assert.assertEquals(beforeClassMethods[0].getMethodName(), "beforeClassRun"); + assertThat(beforeClassMethods.length).isOne(); + assertThat(beforeClassMethods[0].getMethodName()).isEqualTo("beforeClassRun"); } @Test( @@ -47,8 +48,8 @@ public void afterClassDefaultShouldRun(Class clazz) { ITestClass testClass = runTestWithDefaultMethods(clazz); ITestNGMethod[] afterClassMethods = testClass.getAfterClassMethods(); - Assert.assertEquals(afterClassMethods.length, 1); - Assert.assertEquals(afterClassMethods[0].getMethodName(), "afterClassRun"); + assertThat(afterClassMethods.length).isOne(); + assertThat(afterClassMethods[0].getMethodName()).isEqualTo("afterClassRun"); } @Test( @@ -58,8 +59,8 @@ public void beforeMethodDefaultShouldRun(Class clazz) { final ITestClass testClass = runTestWithDefaultMethods(clazz); ITestNGMethod[] beforeMethods = testClass.getBeforeTestMethods(); - Assert.assertEquals(beforeMethods.length, 1); - Assert.assertEquals(beforeMethods[0].getMethodName(), "beforeMethodRun"); + assertThat(beforeMethods.length).isOne(); + assertThat(beforeMethods[0].getMethodName()).isEqualTo("beforeMethodRun"); } @Test( @@ -69,8 +70,8 @@ public void afterMethodDefaultShouldRun(Class clazz) { final ITestClass testClass = runTestWithDefaultMethods(clazz); ITestNGMethod[] afterMethods = testClass.getAfterTestMethods(); - Assert.assertEquals(afterMethods.length, 1); - Assert.assertEquals(afterMethods[0].getMethodName(), "afterMethodRun"); + assertThat(afterMethods.length).isOne(); + assertThat(afterMethods[0].getMethodName()).isEqualTo("afterMethodRun"); } private ITestClass runTestWithDefaultMethods(Class clazz) { diff --git a/testng-core/src/test/java/test/dependent/BaseOrderMethodTest.java b/testng-core/src/test/java/test/dependent/BaseOrderMethodTest.java index d3b86b5b37..5f1fe5511c 100644 --- a/testng-core/src/test/java/test/dependent/BaseOrderMethodTest.java +++ b/testng-core/src/test/java/test/dependent/BaseOrderMethodTest.java @@ -1,6 +1,6 @@ package test.dependent; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -31,15 +31,8 @@ public void third0() { } protected void verifyGroup(int groupNumber, boolean[] group) { - for (int i = 0; i < group.length; i++) { - assertTrue( - group[i], - "Error while running group " - + groupNumber - + ": " - + " index " - + i - + " of previous group should have been run before."); - } + assertThat(group) + .as("group %d: every method of the previous group should have run before", groupNumber) + .containsOnly(true); } } diff --git a/testng-core/src/test/java/test/dependent/C1.java b/testng-core/src/test/java/test/dependent/C1.java index 7924ad3aac..396bc376ba 100644 --- a/testng-core/src/test/java/test/dependent/C1.java +++ b/testng-core/src/test/java/test/dependent/C1.java @@ -1,6 +1,6 @@ package test.dependent; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.annotations.Test; diff --git a/testng-core/src/test/java/test/dependent/ClassWide2Test.java b/testng-core/src/test/java/test/dependent/ClassWide2Test.java index f8dc714abe..4701cf90ea 100644 --- a/testng-core/src/test/java/test/dependent/ClassWide2Test.java +++ b/testng-core/src/test/java/test/dependent/ClassWide2Test.java @@ -1,12 +1,13 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class ClassWide2Test { @Test(dependsOnMethods = {"test.dependent.ClassWide1Test.m1"}) public void m2() { - Assert.assertTrue(ClassWide1Test.m1WasRun()); + assertThat(ClassWide1Test.m1WasRun()).isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/DepBugVerifyTest.java b/testng-core/src/test/java/test/dependent/DepBugVerifyTest.java index 6677b2e167..a80146f570 100644 --- a/testng-core/src/test/java/test/dependent/DepBugVerifyTest.java +++ b/testng-core/src/test/java/test/dependent/DepBugVerifyTest.java @@ -1,7 +1,8 @@ package test.dependent; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; public class DepBugVerifyTest { @@ -11,7 +12,7 @@ public void verify() { List log = DepBugSampleTest.getLog(); String[] expected = new String[] {"setup", "send", "get", "destroy"}; for (int i = 0; i < log.size(); i++) { - Assert.assertEquals(expected[i], log.get(i)); + assertThat(log.get(i)).isEqualTo(expected[i]); } } } diff --git a/testng-core/src/test/java/test/dependent/DependencyFixTest.java b/testng-core/src/test/java/test/dependent/DependencyFixTest.java index 51d6af0e44..c534827d6d 100644 --- a/testng-core/src/test/java/test/dependent/DependencyFixTest.java +++ b/testng-core/src/test/java/test/dependent/DependencyFixTest.java @@ -1,18 +1,18 @@ package test.dependent; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; public class DependencyFixTest { @Test(dependsOnMethods = "helloWorld", ignoreMissingDependencies = true) public void dependentOnNonExistingMethod() { - assertTrue(true); + assertThat(true).isTrue(); } @Test(dependsOnMethods = "dependentOnNonExistingMethod") public void dependentOnExistingMethod() { - assertTrue(true); + assertThat(true).isTrue(); } @Test( @@ -20,6 +20,6 @@ public void dependentOnExistingMethod() { dependsOnGroups = "nonExistingGroup", ignoreMissingDependencies = true) public void dependentOnNonExistingGroup() { - assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/DependentOnGroup1AlwaysRunSampleTest.java b/testng-core/src/test/java/test/dependent/DependentOnGroup1AlwaysRunSampleTest.java index 81be2931fc..7892a93777 100644 --- a/testng-core/src/test/java/test/dependent/DependentOnGroup1AlwaysRunSampleTest.java +++ b/testng-core/src/test/java/test/dependent/DependentOnGroup1AlwaysRunSampleTest.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; /** @@ -26,6 +27,6 @@ public void b() { @Test(dependsOnMethods = {"b"}) public void verify() { - Assert.assertTrue(m_ok, "method b() should have been invoked"); + assertThat(m_ok).withFailMessage("method b() should have been invoked").isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/DependentOnGroup2AlwaysRunSampleTest.java b/testng-core/src/test/java/test/dependent/DependentOnGroup2AlwaysRunSampleTest.java index 1f60f81cdd..a979309cb2 100644 --- a/testng-core/src/test/java/test/dependent/DependentOnGroup2AlwaysRunSampleTest.java +++ b/testng-core/src/test/java/test/dependent/DependentOnGroup2AlwaysRunSampleTest.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; /** @@ -29,6 +30,6 @@ public void b() { @Test(dependsOnMethods = {"b"}) public void verify() { - Assert.assertTrue(m_ok, "method b() should have been invoked"); + assertThat(m_ok).withFailMessage("method b() should have been invoked").isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/DependentOnMethod1AlwaysRunSampleTest.java b/testng-core/src/test/java/test/dependent/DependentOnMethod1AlwaysRunSampleTest.java index 35deb4fa35..0100fdc03c 100644 --- a/testng-core/src/test/java/test/dependent/DependentOnMethod1AlwaysRunSampleTest.java +++ b/testng-core/src/test/java/test/dependent/DependentOnMethod1AlwaysRunSampleTest.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; /** @@ -26,6 +27,6 @@ public void b() { @Test(dependsOnMethods = {"b"}) public void verify() { - Assert.assertTrue(m_ok, "method b() should have been invoked"); + assertThat(m_ok).withFailMessage("method b() should have been invoked").isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/DependentTest.java b/testng-core/src/test/java/test/dependent/DependentTest.java index a7ae8c13cd..1784b7f6a0 100644 --- a/testng-core/src/test/java/test/dependent/DependentTest.java +++ b/testng-core/src/test/java/test/dependent/DependentTest.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Set; import java.util.function.Function; -import org.testng.Assert; import org.testng.ITestListener; import org.testng.ITestResult; import org.testng.TestNG; @@ -207,10 +206,10 @@ public void dependentWithDataProvider() { for (int i = 0; i < 12; i += 4) { String[] s = log.get(i).split("#"); String instance = s[1]; - Assert.assertEquals(log.get(i), "prepare#" + instance); - Assert.assertEquals(log.get(i + 1), "test1#" + instance); - Assert.assertEquals(log.get(i + 2), "test2#" + instance); - Assert.assertEquals(log.get(i + 3), "clean#" + instance); + assertThat(log.get(i)).isEqualTo("prepare#" + instance); + assertThat(log.get(i + 1)).isEqualTo("test1#" + instance); + assertThat(log.get(i + 2)).isEqualTo("test2#" + instance); + assertThat(log.get(i + 3)).isEqualTo("clean#" + instance); } } diff --git a/testng-core/src/test/java/test/dependent/DependsOnProtectedMethodTest.java b/testng-core/src/test/java/test/dependent/DependsOnProtectedMethodTest.java index 0c4b875a3c..b62bd464b5 100644 --- a/testng-core/src/test/java/test/dependent/DependsOnProtectedMethodTest.java +++ b/testng-core/src/test/java/test/dependent/DependsOnProtectedMethodTest.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -21,7 +22,11 @@ protected void before2() { @Test public void verifyBeforeInvocations() { - Assert.assertTrue( - m_before1 && m_before2, "Protected dependent @BeforeMethods should have been invoked"); + assertThat(m_before2) + .withFailMessage("@BeforeMethod before2() should have been invoked") + .isTrue(); + assertThat(m_before1) + .withFailMessage("Protected dependent @BeforeMethod before() should have been invoked") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/DifferentClassDependsOnGroupsTest1.java b/testng-core/src/test/java/test/dependent/DifferentClassDependsOnGroupsTest1.java index 0d956e4325..9468b8b0f3 100644 --- a/testng-core/src/test/java/test/dependent/DifferentClassDependsOnGroupsTest1.java +++ b/testng-core/src/test/java/test/dependent/DifferentClassDependsOnGroupsTest1.java @@ -1,13 +1,13 @@ package test.dependent; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; public class DifferentClassDependsOnGroupsTest1 { @Test(groups = {"mainGroup"}) public void test0() { - assertTrue(1 == 0); // Force a failure + assertThat(1).isZero(); // Force a failure } @Test(dependsOnGroups = {"mainGroup"}) diff --git a/testng-core/src/test/java/test/dependent/GroupByInstancesTest.java b/testng-core/src/test/java/test/dependent/GroupByInstancesTest.java index fb7e76573c..7aafb8b55f 100644 --- a/testng-core/src/test/java/test/dependent/GroupByInstancesTest.java +++ b/testng-core/src/test/java/test/dependent/GroupByInstancesTest.java @@ -1,7 +1,8 @@ package test.dependent; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.collections.Lists; @@ -28,15 +29,15 @@ private void runTest(boolean group) { List log = GroupByInstancesSampleTest.m_log; int i = 0; if (group) { - Assert.assertTrue(log.get(i++).startsWith("signIn")); - Assert.assertTrue(log.get(i++).startsWith("signOut")); - Assert.assertTrue(log.get(i++).startsWith("signIn")); - Assert.assertTrue(log.get(i++).startsWith("signOut")); + assertThat(log.get(i++)).startsWith("signIn"); + assertThat(log.get(i++)).startsWith("signOut"); + assertThat(log.get(i++)).startsWith("signIn"); + assertThat(log.get(i++)).startsWith("signOut"); } else { - Assert.assertTrue(log.get(i++).startsWith("signIn")); - Assert.assertTrue(log.get(i++).startsWith("signIn")); - Assert.assertTrue(log.get(i++).startsWith("signOut")); - Assert.assertTrue(log.get(i++).startsWith("signOut")); + assertThat(log.get(i++)).startsWith("signIn"); + assertThat(log.get(i++)).startsWith("signIn"); + assertThat(log.get(i++)).startsWith("signOut"); + assertThat(log.get(i++)).startsWith("signOut"); } } } diff --git a/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion2SampleTest.java b/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion2SampleTest.java index d8920fbc4d..d0b1a395d8 100644 --- a/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion2SampleTest.java +++ b/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion2SampleTest.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -32,8 +33,8 @@ public void m3() { @AfterClass(groups = {"g2"}) public void verify() { - Assert.assertFalse(m_m1, "Shouldn't have invoked m1()"); - Assert.assertFalse(m_m2); - Assert.assertTrue(m_m3); + assertThat(m_m1).withFailMessage("Shouldn't have invoked m1()").isFalse(); + assertThat(m_m2).isFalse(); + assertThat(m_m3).isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion4SampleTest.java b/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion4SampleTest.java index 1b3680e3d6..a309bbf861 100644 --- a/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion4SampleTest.java +++ b/testng-core/src/test/java/test/dependent/ImplicitGroupInclusion4SampleTest.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -39,9 +40,9 @@ public void m4() { @AfterClass(groups = {"g2"}) public void verify() { - Assert.assertFalse(m_m1, "Shouldn't have invoked m1()"); - Assert.assertFalse(m_m2); - Assert.assertTrue(m_m3); - Assert.assertTrue(m_m4); + assertThat(m_m1).withFailMessage("Shouldn't have invoked m1()").isFalse(); + assertThat(m_m2).isFalse(); + assertThat(m_m3).isTrue(); + assertThat(m_m4).isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/MultipleDependentSampleTest.java b/testng-core/src/test/java/test/dependent/MultipleDependentSampleTest.java index be4cea03c3..bffb716451 100644 --- a/testng-core/src/test/java/test/dependent/MultipleDependentSampleTest.java +++ b/testng-core/src/test/java/test/dependent/MultipleDependentSampleTest.java @@ -1,6 +1,6 @@ package test.dependent; -import org.testng.Assert; +import org.assertj.core.api.Assertions; import org.testng.annotations.Test; public class MultipleDependentSampleTest { @@ -10,7 +10,7 @@ public void init() {} @Test(dependsOnMethods = "init") public void fail() { - Assert.fail(); + Assertions.fail(); } @Test(dependsOnMethods = "fail") diff --git a/testng-core/src/test/java/test/dependent/SampleDependent1.java b/testng-core/src/test/java/test/dependent/SampleDependent1.java index 4c3ceb55e3..64adae7469 100644 --- a/testng-core/src/test/java/test/dependent/SampleDependent1.java +++ b/testng-core/src/test/java/test/dependent/SampleDependent1.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; /** @@ -12,7 +13,7 @@ public class SampleDependent1 { @Test(groups = {"fail"}) public void fail() { - Assert.assertTrue(false); + assertThat(false).isTrue(); } @Test(dependsOnGroups = {"fail"}) diff --git a/testng-core/src/test/java/test/dependent/SampleDependentConfigurationMethods.java b/testng-core/src/test/java/test/dependent/SampleDependentConfigurationMethods.java index 2855f952d7..890fe76b9b 100644 --- a/testng-core/src/test/java/test/dependent/SampleDependentConfigurationMethods.java +++ b/testng-core/src/test/java/test/dependent/SampleDependentConfigurationMethods.java @@ -1,6 +1,6 @@ package test.dependent; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -16,13 +16,13 @@ public void createInstance() { @BeforeMethod(dependsOnMethods = {"createInstance"}) public void firstInvocation() { - assertTrue(m_create, "createInstance() was never called"); + assertThat(m_create).withFailMessage("createInstance() was never called").isTrue(); m_first = true; } @Test public void verifyDependents() { - assertTrue(m_create, "createInstance() was never called"); - assertTrue(m_first, "firstInvocation() was never called"); + assertThat(m_create).withFailMessage("createInstance() was never called").isTrue(); + assertThat(m_first).withFailMessage("firstInvocation() was never called").isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/SampleDependentMethods.java b/testng-core/src/test/java/test/dependent/SampleDependentMethods.java index f0754a020a..51b3e6f39e 100644 --- a/testng-core/src/test/java/test/dependent/SampleDependentMethods.java +++ b/testng-core/src/test/java/test/dependent/SampleDependentMethods.java @@ -1,7 +1,6 @@ package test.dependent; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -19,7 +18,7 @@ public class SampleDependentMethods { @Test public void oneA() { - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_oneA = true; } @@ -28,32 +27,32 @@ public void canBeRunAnytime() {} @Test(dependsOnMethods = {"oneA", "oneB"}) public void secondA() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_secondA = true; } @Test(dependsOnMethods = {"secondA"}) public void thirdA() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertTrue(m_secondA, "secondA wasn't run"); - assertFalse(m_thirdA, "thirdA shouldn't have been run yet"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA wasn't run").isTrue(); + assertThat(m_thirdA).withFailMessage("thirdA shouldn't have been run yet").isFalse(); m_thirdA = true; } @Test public void oneB() { - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_oneB = true; } @AfterClass public void tearDown() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertTrue(m_secondA, "secondA wasn't run"); - assertTrue(m_thirdA, "thirdA wasn't run"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA wasn't run").isTrue(); + assertThat(m_thirdA).withFailMessage("thirdA wasn't run").isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/SampleDependentMethods2.java b/testng-core/src/test/java/test/dependent/SampleDependentMethods2.java index 5cfaafc215..57ed2fe1b8 100644 --- a/testng-core/src/test/java/test/dependent/SampleDependentMethods2.java +++ b/testng-core/src/test/java/test/dependent/SampleDependentMethods2.java @@ -1,7 +1,6 @@ package test.dependent; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -19,7 +18,7 @@ public class SampleDependentMethods2 { @Test(groups = {"one"}) public void oneA() { - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_oneA = true; } @@ -28,32 +27,32 @@ public void canBeRunAnytime() {} @Test(dependsOnGroups = {"one"}) public void secondA() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_secondA = true; } @Test(dependsOnMethods = {"secondA"}) public void thirdA() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertTrue(m_secondA, "secondA wasn't run"); - assertFalse(m_thirdA, "thirdA shouldn't have been run yet"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA wasn't run").isTrue(); + assertThat(m_thirdA).withFailMessage("thirdA shouldn't have been run yet").isFalse(); m_thirdA = true; } @Test(groups = {"one"}) public void oneB() { - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_oneB = true; } @AfterClass public void tearDown() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertTrue(m_secondA, "secondA wasn't run"); - assertTrue(m_thirdA, "thirdA wasn't run"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA wasn't run").isTrue(); + assertThat(m_thirdA).withFailMessage("thirdA wasn't run").isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/SampleDependentMethods3.java b/testng-core/src/test/java/test/dependent/SampleDependentMethods3.java index 3f141a1e08..0213d03de1 100644 --- a/testng-core/src/test/java/test/dependent/SampleDependentMethods3.java +++ b/testng-core/src/test/java/test/dependent/SampleDependentMethods3.java @@ -1,8 +1,6 @@ package test.dependent; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.Parameters; @@ -20,30 +18,32 @@ public class SampleDependentMethods3 { @Test public void one() { - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_oneA = true; } @Parameters({"foo"}) @Test public void one(String s) { - assertFalse(m_secondA, "secondA shouldn't have been run yet"); - assertEquals(s, "Cedric", "Expected parameter value Cedric but got " + s); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); + assertThat(s) + .withFailMessage("Expected parameter value Cedric but got " + s) + .isEqualTo("Cedric"); m_oneB = true; } @Test(dependsOnMethods = {"one"}) public void secondA() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertFalse(m_secondA, "secondA shouldn't have been run yet"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA shouldn't have been run yet").isFalse(); m_secondA = true; } @AfterClass public void tearDown() { - assertTrue(m_oneA, "oneA wasn't run"); - assertTrue(m_oneB, "oneB wasn't run"); - assertTrue(m_secondA, "secondA wasn't run"); + assertThat(m_oneA).withFailMessage("oneA wasn't run").isTrue(); + assertThat(m_oneB).withFailMessage("oneB wasn't run").isTrue(); + assertThat(m_secondA).withFailMessage("secondA wasn't run").isTrue(); } } diff --git a/testng-core/src/test/java/test/dependent/SampleDependentMethods4.java b/testng-core/src/test/java/test/dependent/SampleDependentMethods4.java index a6c395a6d9..c03f01ae82 100644 --- a/testng-core/src/test/java/test/dependent/SampleDependentMethods4.java +++ b/testng-core/src/test/java/test/dependent/SampleDependentMethods4.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class SampleDependentMethods4 { @@ -10,7 +11,7 @@ public void step1() {} @Test(dependsOnMethods = {"step1"}) public void step2() { - Assert.assertTrue(false, "Problem in step2"); + assertThat(false).withFailMessage("Problem in step2").isTrue(); } @Test(dependsOnMethods = {"step2"}) diff --git a/testng-core/src/test/java/test/dependent/SampleDependentTest.java b/testng-core/src/test/java/test/dependent/SampleDependentTest.java index f04cfd17d8..9ed33fa434 100644 --- a/testng-core/src/test/java/test/dependent/SampleDependentTest.java +++ b/testng-core/src/test/java/test/dependent/SampleDependentTest.java @@ -1,6 +1,7 @@ package test.dependent; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -25,14 +26,14 @@ public void test2() { oneB = true; } if ("secondA".equals(s)) { - Assert.assertTrue(oneA); - Assert.assertTrue(oneB); + assertThat(oneA).isTrue(); + assertThat(oneB).isTrue(); secondA = true; } if ("thirdA".equals(s)) { - Assert.assertTrue(oneA); - Assert.assertTrue(oneB); - Assert.assertTrue(secondA); + assertThat(oneA).isTrue(); + assertThat(oneB).isTrue(); + assertThat(secondA).isTrue(); } } } diff --git a/testng-core/src/test/java/test/dependent/issue141/MultipleMatchesTestClassSample.java b/testng-core/src/test/java/test/dependent/issue141/MultipleMatchesTestClassSample.java index 636393fe34..3769f237e2 100644 --- a/testng-core/src/test/java/test/dependent/issue141/MultipleMatchesTestClassSample.java +++ b/testng-core/src/test/java/test/dependent/issue141/MultipleMatchesTestClassSample.java @@ -1,6 +1,7 @@ package test.dependent.issue141; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class MultipleMatchesTestClassSample { @@ -10,7 +11,7 @@ public void randomTest() {} @Test public void test_C6390323() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test/dependent/issue141/NestedTestClassSample.java b/testng-core/src/test/java/test/dependent/issue141/NestedTestClassSample.java index d361dce1f4..82c633441f 100644 --- a/testng-core/src/test/java/test/dependent/issue141/NestedTestClassSample.java +++ b/testng-core/src/test/java/test/dependent/issue141/NestedTestClassSample.java @@ -1,6 +1,7 @@ package test.dependent.issue141; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class NestedTestClassSample { @@ -19,7 +20,7 @@ public void randomTest() {} @Test public void test_C6390323() { - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/dependent/issue2658/BaseClassSample.java b/testng-core/src/test/java/test/dependent/issue2658/BaseClassSample.java index a7d98d2602..0afa1c954c 100644 --- a/testng-core/src/test/java/test/dependent/issue2658/BaseClassSample.java +++ b/testng-core/src/test/java/test/dependent/issue2658/BaseClassSample.java @@ -1,12 +1,12 @@ package test.dependent.issue2658; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; public class BaseClassSample { @Test public void test() { - assertEquals(getClass(), PassingClassSample.class); + assertThat(getClass()).isEqualTo(PassingClassSample.class); } } diff --git a/testng-core/src/test/java/test/dependent/xml/GroupDependencyTest.java b/testng-core/src/test/java/test/dependent/xml/GroupDependencyTest.java index 214a1e67bd..dc7611f6ba 100644 --- a/testng-core/src/test/java/test/dependent/xml/GroupDependencyTest.java +++ b/testng-core/src/test/java/test/dependent/xml/GroupDependencyTest.java @@ -1,9 +1,10 @@ package test.dependent.xml; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -58,7 +59,7 @@ private void configureGroup(String[] a, boolean multi) { if (multi) { // When we have "a depends on groups b and c", the only certainty is that "a" // will be run last - Assert.assertEquals(method2, a[5]); + assertThat(method2).isEqualTo(a[5]); } else { assertTestResultsEqual(tla.getPassedTests(), Arrays.asList(a[3], a[4], a[5])); } diff --git a/testng-core/src/test/java/test/dependsongroup/DependsOnGroupsTest.java b/testng-core/src/test/java/test/dependsongroup/DependsOnGroupsTest.java index a93191e779..dd7d8722d7 100644 --- a/testng-core/src/test/java/test/dependsongroup/DependsOnGroupsTest.java +++ b/testng-core/src/test/java/test/dependsongroup/DependsOnGroupsTest.java @@ -1,7 +1,7 @@ package test.dependsongroup; -import org.testng.Assert; -import org.testng.ITestResult; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -16,15 +16,8 @@ public void methodsShouldBeGroupedByClasses() { TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener(tla); tng.run(); - String[] expected = - new String[] { - "zeroA", "zeroB", - "firstA", "firstB", - "secondA", "secondB" - }; - for (int i = 0; i < expected.length; i++) { - ITestResult testResult = tla.getPassedTests().get(i); - Assert.assertEquals(testResult.getMethod().getMethodName(), expected[i]); - } + assertThat(tla.getPassedTests()) + .extracting(testResult -> testResult.getMethod().getMethodName()) + .containsExactly("zeroA", "zeroB", "firstA", "firstB", "secondA", "secondB"); } } diff --git a/testng-core/src/test/java/test/expectedexceptions/ExpectedExceptionsTest.java b/testng-core/src/test/java/test/expectedexceptions/ExpectedExceptionsTest.java index 7429a88b50..3129d66c98 100644 --- a/testng-core/src/test/java/test/expectedexceptions/ExpectedExceptionsTest.java +++ b/testng-core/src/test/java/test/expectedexceptions/ExpectedExceptionsTest.java @@ -4,7 +4,6 @@ import java.util.Collection; import java.util.List; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.TestNG; import org.testng.annotations.Test; @@ -48,11 +47,11 @@ public void expectedExceptionsMessage() { addClass(test.expectedexceptions.github1409.TestClassSample.class); run(); Collection> failedTests = getFailedTests().values(); - Assert.assertFalse(failedTests.isEmpty()); + assertThat(failedTests).isNotEmpty(); ITestResult result = failedTests.iterator().next().get(0); String actual = result.getThrowable().getMessage().replaceAll("\\n", ""); String expected = "The exception was thrown with the wrong message: expected \"expected\" but got \"actual\""; - Assert.assertEquals(actual, expected); + assertThat(actual).isEqualTo(expected); } } diff --git a/testng-core/src/test/java/test/expectedexceptions/ParametersExceptionTest.java b/testng-core/src/test/java/test/expectedexceptions/ParametersExceptionTest.java index 31cff3f4af..74e0ed7c12 100644 --- a/testng-core/src/test/java/test/expectedexceptions/ParametersExceptionTest.java +++ b/testng-core/src/test/java/test/expectedexceptions/ParametersExceptionTest.java @@ -1,8 +1,9 @@ package test.expectedexceptions; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.IOException; import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -22,6 +23,6 @@ protected Object[][] dp() { @AfterMethod protected void verify(Method method) { - Assert.assertTrue(false, "forced failure"); + assertThat(false).withFailMessage("forced failure").isTrue(); } } diff --git a/testng-core/src/test/java/test/expectedexceptions/issue2074/FailingInterruptTest.java b/testng-core/src/test/java/test/expectedexceptions/issue2074/FailingInterruptTest.java index a52c91c344..5301d69203 100644 --- a/testng-core/src/test/java/test/expectedexceptions/issue2074/FailingInterruptTest.java +++ b/testng-core/src/test/java/test/expectedexceptions/issue2074/FailingInterruptTest.java @@ -1,6 +1,6 @@ package test.expectedexceptions.issue2074; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; diff --git a/testng-core/src/test/java/test/factory/ArrayEmptyFactorySample.java b/testng-core/src/test/java/test/factory/ArrayEmptyFactorySample.java index cec2ed3d86..d8ce91eae1 100644 --- a/testng-core/src/test/java/test/factory/ArrayEmptyFactorySample.java +++ b/testng-core/src/test/java/test/factory/ArrayEmptyFactorySample.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -17,6 +18,6 @@ public ArrayEmptyFactorySample(int value) {} @Test public void test() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/factory/DisabledFactoryTest.java b/testng-core/src/test/java/test/factory/DisabledFactoryTest.java index dd805f4c57..97cf6510a0 100644 --- a/testng-core/src/test/java/test/factory/DisabledFactoryTest.java +++ b/testng-core/src/test/java/test/factory/DisabledFactoryTest.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -17,8 +18,8 @@ public void disabledFactoryShouldNotRun() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 0); - Assert.assertEquals(tla.getSkippedTests().size(), 0); - Assert.assertEquals(tla.getFailedTests().size(), 0); + assertThat(tla.getPassedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).isEmpty(); + assertThat(tla.getFailedTests()).isEmpty(); } } diff --git a/testng-core/src/test/java/test/factory/EmptyFactoryDataProviderTest.java b/testng-core/src/test/java/test/factory/EmptyFactoryDataProviderTest.java index cc8076d2e1..3154ade958 100644 --- a/testng-core/src/test/java/test/factory/EmptyFactoryDataProviderTest.java +++ b/testng-core/src/test/java/test/factory/EmptyFactoryDataProviderTest.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -18,8 +19,8 @@ public void test() { testng.run(); - Assert.assertTrue(tla.getFailedTests().isEmpty()); - Assert.assertTrue(tla.getSkippedTests().isEmpty()); - Assert.assertTrue(tla.getPassedTests().isEmpty()); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).isEmpty(); + assertThat(tla.getPassedTests()).isEmpty(); } } diff --git a/testng-core/src/test/java/test/factory/FactoryAndTestMethodTest.java b/testng-core/src/test/java/test/factory/FactoryAndTestMethodTest.java index 93a1854ad3..9d8e7ef3a4 100644 --- a/testng-core/src/test/java/test/factory/FactoryAndTestMethodTest.java +++ b/testng-core/src/test/java/test/factory/FactoryAndTestMethodTest.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -22,7 +23,7 @@ public NullArgsTest(String s) { @Test public void test() { - Assert.assertNotNull(s); + assertThat(s).isNotNull(); } } diff --git a/testng-core/src/test/java/test/factory/FactoryInSeparateClassTest.java b/testng-core/src/test/java/test/factory/FactoryInSeparateClassTest.java index 7876b84713..9c94b7dd25 100644 --- a/testng-core/src/test/java/test/factory/FactoryInSeparateClassTest.java +++ b/testng-core/src/test/java/test/factory/FactoryInSeparateClassTest.java @@ -1,6 +1,6 @@ package test.factory; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.BeforeTest; import org.testng.annotations.Factory; @@ -36,11 +36,11 @@ public Object[] createObjects() { dependsOnGroups = {"MySample"}) public void checkSum() { m_wasRun = true; - assertEquals( - m_checkSum, - 6, - "Test instances made by factory did not invoke their test methods correctly. expected 6 but got " - + m_checkSum); + assertThat(m_checkSum) + .withFailMessage( + "Test instances made by factory did not invoke their test methods correctly. expected 6 but got " + + m_checkSum) + .isEqualTo(6); } public static boolean wasRun() { diff --git a/testng-core/src/test/java/test/factory/FactoryInSuperClassTest.java b/testng-core/src/test/java/test/factory/FactoryInSuperClassTest.java index d6ced7000f..decef3a291 100644 --- a/testng-core/src/test/java/test/factory/FactoryInSuperClassTest.java +++ b/testng-core/src/test/java/test/factory/FactoryInSuperClassTest.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -15,6 +16,6 @@ public void factoryInSuperClassShouldWork() { tng.addListener(tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); } } diff --git a/testng-core/src/test/java/test/factory/FactoryIntegrationTest.java b/testng-core/src/test/java/test/factory/FactoryIntegrationTest.java index f18c8289d0..6e2fb50688 100644 --- a/testng-core/src/test/java/test/factory/FactoryIntegrationTest.java +++ b/testng-core/src/test/java/test/factory/FactoryIntegrationTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; -import org.testng.Assert; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.TestNGException; @@ -34,7 +33,7 @@ public void testNonPublicFactoryMethodShouldWork() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 2); + assertThat(tla.getPassedTests()).hasSize(2); } @Test diff --git a/testng-core/src/test/java/test/factory/FactoryOrderMainTest.java b/testng-core/src/test/java/test/factory/FactoryOrderMainTest.java index 27b07fa5a6..7503087cc0 100644 --- a/testng-core/src/test/java/test/factory/FactoryOrderMainTest.java +++ b/testng-core/src/test/java/test/factory/FactoryOrderMainTest.java @@ -1,7 +1,8 @@ package test.factory; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -19,7 +20,7 @@ public void factoriesShouldBeInvokedInTheOrderOfCreation() { List passed = tla.getPassedTests(); for (int i = 0; i < passed.size(); i++) { - Assert.assertEquals(((OrderSample) passed.get(i).getInstance()).getValue(), i); + assertThat(((OrderSample) passed.get(i).getInstance()).getValue()).isEqualTo(i); } } } diff --git a/testng-core/src/test/java/test/factory/FactoryTest.java b/testng-core/src/test/java/test/factory/FactoryTest.java index 71f8bf5596..b974595751 100644 --- a/testng-core/src/test/java/test/factory/FactoryTest.java +++ b/testng-core/src/test/java/test/factory/FactoryTest.java @@ -1,7 +1,6 @@ package test.factory; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterSuite; import org.testng.annotations.Factory; @@ -14,8 +13,8 @@ public class FactoryTest { @Parameters({"factory-param"}) @Factory public Object[] createObjects(String param) { - assertEquals(param, "FactoryParam"); - assertFalse(isInvoked, "Should only be invoked once"); + assertThat(param).isEqualTo("FactoryParam"); + assertThat(isInvoked).withFailMessage("Should only be invoked once").isFalse(); isInvoked = true; return new Object[] {new FactoryTest2(42), new FactoryTest2(43)}; diff --git a/testng-core/src/test/java/test/factory/FactoryWithInstanceInfoTest.java b/testng-core/src/test/java/test/factory/FactoryWithInstanceInfoTest.java index aa7091b2da..961c23c12b 100644 --- a/testng-core/src/test/java/test/factory/FactoryWithInstanceInfoTest.java +++ b/testng-core/src/test/java/test/factory/FactoryWithInstanceInfoTest.java @@ -1,7 +1,6 @@ package test.factory; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.IInstanceInfo; import org.testng.annotations.BeforeSuite; @@ -15,8 +14,8 @@ public class FactoryWithInstanceInfoTest { @Parameters({"factory-param"}) @Factory public IInstanceInfo[] createObjectsWithInstanceInfo(String param) { - assertEquals(param, "FactoryParam", "Incorrect param: " + param); - assertFalse(isInvoked, "Should only be invoked once"); + assertThat(param).withFailMessage("Incorrect param: " + param).isEqualTo("FactoryParam"); + assertThat(isInvoked).withFailMessage("Should only be invoked once").isFalse(); isInvoked = true; return new IInstanceInfo[] { diff --git a/testng-core/src/test/java/test/factory/GitHub876Sample.java b/testng-core/src/test/java/test/factory/GitHub876Sample.java index 86442f99dd..a1f2ef5e92 100644 --- a/testng-core/src/test/java/test/factory/GitHub876Sample.java +++ b/testng-core/src/test/java/test/factory/GitHub876Sample.java @@ -1,6 +1,8 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -24,13 +26,13 @@ public GitHub876Sample(DataTest dataTest) { public void test() { switch (dataTest.s) { case "FOO": - Assert.assertFalse(dataTest.b); + assertThat(dataTest.b).isFalse(); break; case "foo": - Assert.assertTrue(dataTest.b); + assertThat(dataTest.b).isTrue(); break; default: - Assert.fail("Unknown value"); + fail("Unknown value"); } } diff --git a/testng-core/src/test/java/test/factory/IteratorEmptyFactorySample.java b/testng-core/src/test/java/test/factory/IteratorEmptyFactorySample.java index 331869f6b7..4fbf033487 100644 --- a/testng-core/src/test/java/test/factory/IteratorEmptyFactorySample.java +++ b/testng-core/src/test/java/test/factory/IteratorEmptyFactorySample.java @@ -1,8 +1,9 @@ package test.factory; +import static org.assertj.core.api.Assertions.fail; + import java.util.Collections; import java.util.Iterator; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -19,6 +20,6 @@ public IteratorEmptyFactorySample(int value) {} @Test public void test() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/factory/MySample.java b/testng-core/src/test/java/test/factory/MySample.java index 98d4ed96df..f04b786c0f 100644 --- a/testng-core/src/test/java/test/factory/MySample.java +++ b/testng-core/src/test/java/test/factory/MySample.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class MySample { @@ -21,12 +22,13 @@ public MySample(int i) { public void testMethod() { FactoryInSeparateClassTest.addToSum(i); // assert i > 0 : "MySample was not constructed with correct params"; - Assert.assertNotEquals(i, 0, "My test was not created by the factory"); + assertThat(i).withFailMessage("My test was not created by the factory").isNotZero(); } @Test(dependsOnGroups = "testMethodOnFactoryClass") public void verifyThatTestMethodOnFactoryClassWasRun() { - Assert.assertTrue( - FactoryInSeparateClassTest.wasRun(), "Test method on factory class wasn't run"); + assertThat(FactoryInSeparateClassTest.wasRun()) + .withFailMessage("Test method on factory class wasn't run") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/factory/NestedFactorySample.java b/testng-core/src/test/java/test/factory/NestedFactorySample.java index 34932a2985..be270a8006 100644 --- a/testng-core/src/test/java/test/factory/NestedFactorySample.java +++ b/testng-core/src/test/java/test/factory/NestedFactorySample.java @@ -1,7 +1,7 @@ package test.factory; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -36,8 +36,7 @@ public NestedFactorySample(int capacity, float loadFactor) { public void verify() { // Should have three instances: the default one created by TestNG // and two created by the factory - assertEquals(m_instanceCount, 3); - assertTrue( - (m_capacity == 1 && m_loadFactor == 0.1f) || m_capacity == 10 && m_loadFactor == 0.5f); + assertThat(m_instanceCount).isEqualTo(3); + assertThat(tuple(m_capacity, m_loadFactor)).isIn(tuple(1, 0.1f), tuple(10, 0.5f)); } } diff --git a/testng-core/src/test/java/test/factory/NestedStaticFactorySample.java b/testng-core/src/test/java/test/factory/NestedStaticFactorySample.java index 504edd4d5d..fa70095c12 100644 --- a/testng-core/src/test/java/test/factory/NestedStaticFactorySample.java +++ b/testng-core/src/test/java/test/factory/NestedStaticFactorySample.java @@ -1,7 +1,7 @@ package test.factory; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -37,8 +37,7 @@ public NestedStaticFactorySample(int capacity, float loadFactor) { public void verify() { // Should have three instances: the default one created by TestNG // and two created by the factory - assertEquals(m_instanceCount, 2); - assertTrue( - (m_capacity == 1 && m_loadFactor == 0.1f) || m_capacity == 10 && m_loadFactor == 0.5f); + assertThat(m_instanceCount).isEqualTo(2); + assertThat(tuple(m_capacity, m_loadFactor)).isIn(tuple(1, 0.1f), tuple(10, 0.5f)); } } diff --git a/testng-core/src/test/java/test/factory/OddSample.java b/testng-core/src/test/java/test/factory/OddSample.java index 46bda5c107..4013fb0aa5 100644 --- a/testng-core/src/test/java/test/factory/OddSample.java +++ b/testng-core/src/test/java/test/factory/OddSample.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class OddSample { @@ -13,6 +14,6 @@ public OddSample(int n) { @Test public void verify() { - Assert.assertNotEquals(n % 2, 0); + assertThat(n % 2).isNotZero(); } } diff --git a/testng-core/src/test/java/test/factory/TestClassAnnotationTest.java b/testng-core/src/test/java/test/factory/TestClassAnnotationTest.java index d95af8ec14..7a3b62aa67 100644 --- a/testng-core/src/test/java/test/factory/TestClassAnnotationTest.java +++ b/testng-core/src/test/java/test/factory/TestClassAnnotationTest.java @@ -1,6 +1,7 @@ package test.factory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -26,6 +27,6 @@ public void testOne() { @AfterClass public void verify() { - Assert.assertEquals(count, 2); + assertThat(count).isEqualTo(2); } } diff --git a/testng-core/src/test/java/test/factory/VerifyFactoryTest.java b/testng-core/src/test/java/test/factory/VerifyFactoryTest.java index b802a9f159..db008407ee 100644 --- a/testng-core/src/test/java/test/factory/VerifyFactoryTest.java +++ b/testng-core/src/test/java/test/factory/VerifyFactoryTest.java @@ -1,7 +1,8 @@ package test.factory; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; public class VerifyFactoryTest { @@ -9,8 +10,8 @@ public class VerifyFactoryTest { @Test(dependsOnGroups = {"first"}) public void mainCheck() { List numbers = FactoryTest2.getNumbers(); - Assert.assertTrue(numbers.contains(42), "Didn't find 42"); - Assert.assertTrue(numbers.contains(43), "Didn't find 43"); - Assert.assertEquals(numbers.size(), 2); + assertThat(numbers).withFailMessage("Didn't find 42").contains(42); + assertThat(numbers).withFailMessage("Didn't find 43").contains(43); + assertThat(numbers).hasSize(2); } } diff --git a/testng-core/src/test/java/test/factory/VerifyFactoryWithInstanceInfoTest.java b/testng-core/src/test/java/test/factory/VerifyFactoryWithInstanceInfoTest.java index 085acdbc4f..2ed63e6400 100644 --- a/testng-core/src/test/java/test/factory/VerifyFactoryWithInstanceInfoTest.java +++ b/testng-core/src/test/java/test/factory/VerifyFactoryWithInstanceInfoTest.java @@ -1,7 +1,8 @@ package test.factory; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; public class VerifyFactoryWithInstanceInfoTest { @@ -9,8 +10,8 @@ public class VerifyFactoryWithInstanceInfoTest { @Test(dependsOnGroups = {"first"}) public void mainCheck() { List numbers = FactoryWithInstanceInfo2Sample.getNumbers(); - Assert.assertTrue(numbers.contains(42), "Didn't find 42"); - Assert.assertTrue(numbers.contains(43), "Didn't find 43"); - Assert.assertEquals(numbers.size(), 2); + assertThat(numbers).withFailMessage("Didn't find 42").contains(42); + assertThat(numbers).withFailMessage("Didn't find 43").contains(43); + assertThat(numbers).hasSize(2); } } diff --git a/testng-core/src/test/java/test/factory/classconf/XClassOrderWithFactoryTest.java b/testng-core/src/test/java/test/factory/classconf/XClassOrderWithFactoryTest.java index 65c92ec2a7..71e47fefb3 100644 --- a/testng-core/src/test/java/test/factory/classconf/XClassOrderWithFactoryTest.java +++ b/testng-core/src/test/java/test/factory/classconf/XClassOrderWithFactoryTest.java @@ -1,6 +1,7 @@ package test.factory.classconf; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public void testBeforeAfterClassInvocationsWithFactory() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - Assert.assertEquals(XClassOrderWithFactory.LOG.toString(), XClassOrderWithFactory.EXPECTED_LOG); + assertThat(XClassOrderWithFactory.LOG).hasToString(XClassOrderWithFactory.EXPECTED_LOG); } } diff --git a/testng-core/src/test/java/test/factory/github1131/GitHub1131Test.java b/testng-core/src/test/java/test/factory/github1131/GitHub1131Test.java index 9bb46f22a5..c319648c7f 100644 --- a/testng-core/src/test/java/test/factory/github1131/GitHub1131Test.java +++ b/testng-core/src/test/java/test/factory/github1131/GitHub1131Test.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import test.InvokedMethodNameListener; @@ -21,7 +20,7 @@ public void testFactoryOnEmptyConstructor() { tng.run(); assertThat(listener.getSucceedMethodNames()).containsExactly("test", "test"); - Assert.assertEquals(EmptyConstructorSample.count, 2); + assertThat(EmptyConstructorSample.count).isEqualTo(2); } @Test diff --git a/testng-core/src/test/java/test/factory/github1631/GitHub1631Tests.java b/testng-core/src/test/java/test/factory/github1631/GitHub1631Tests.java index a55bf1790c..2167f1efbf 100644 --- a/testng-core/src/test/java/test/factory/github1631/GitHub1631Tests.java +++ b/testng-core/src/test/java/test/factory/github1631/GitHub1631Tests.java @@ -1,6 +1,8 @@ package test.factory.github1631; -import org.testng.*; +import static org.assertj.core.api.Assertions.assertThat; + +import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -10,14 +12,14 @@ public class GitHub1631Tests extends SimpleBaseTest { description = "Test @Factory(dataProvider) should implicitly inject data provider class name") public void factoryWithLocalDataProviderShouldUseHostClassName() { final DataProviderTransformer transformer = runTest(FactoryWithLocalDataProviderTests.class); - Assert.assertEquals( - transformer.getDataProviderClass(), FactoryWithLocalDataProviderTests.class); + assertThat(transformer.getDataProviderClass()) + .isEqualTo(FactoryWithLocalDataProviderTests.class); } @Test(description = "Test @Factory(dataProvider) should explicitly set data provider class name") public void factoryWithExplicitDataProviderShouldUseExternalClassName() { final DataProviderTransformer transformer = runTest(FactoryWithExternalDataProviderTests.class); - Assert.assertEquals(transformer.getDataProviderClass(), ExternalDataProviders.class); + assertThat(transformer.getDataProviderClass()).isEqualTo(ExternalDataProviders.class); } private DataProviderTransformer runTest(final Class cls) { diff --git a/testng-core/src/test/java/test/factory/github2428/IssueTest.java b/testng-core/src/test/java/test/factory/github2428/IssueTest.java index 9523df378c..4bd84277e0 100644 --- a/testng-core/src/test/java/test/factory/github2428/IssueTest.java +++ b/testng-core/src/test/java/test/factory/github2428/IssueTest.java @@ -1,6 +1,7 @@ package test.factory.github2428; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -13,9 +14,9 @@ public void issue2438() { Reporter reporter = new Reporter(); testng.addListener(reporter); testng.run(); - Assert.assertEquals( - reporter.getResults().size(), - 5, - "Data provider generated 5 rows, so expecting 5 distinct test instances to be used"); + assertThat(reporter.getResults()) + .withFailMessage( + "Data provider generated 5 rows, so expecting 5 distinct test instances to be used") + .hasSize(5); } } diff --git a/testng-core/src/test/java/test/factory/github328/GitHub328Test.java b/testng-core/src/test/java/test/factory/github328/GitHub328Test.java index 5dd65a7b06..3ebe7233d4 100644 --- a/testng-core/src/test/java/test/factory/github328/GitHub328Test.java +++ b/testng-core/src/test/java/test/factory/github328/GitHub328Test.java @@ -1,9 +1,9 @@ package test.factory.github328; +import static org.assertj.core.api.Assertions.assertThat; import static test.factory.github328.ExcludedFactory.EXCLUDED_GROUP; import java.util.Collections; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; @@ -21,6 +21,6 @@ public void testFactoryExecutionWhenNoIncludedTests() { tng.run(); - Assert.assertFalse(ExcludedFactory.factoryRan); + assertThat(ExcludedFactory.factoryRan).isFalse(); } } diff --git a/testng-core/src/test/java/test/factory/issue1041/FactoryAnnotatedConstructorExample.java b/testng-core/src/test/java/test/factory/issue1041/FactoryAnnotatedConstructorExample.java index 06d49cd362..99c1b7ce8c 100644 --- a/testng-core/src/test/java/test/factory/issue1041/FactoryAnnotatedConstructorExample.java +++ b/testng-core/src/test/java/test/factory/issue1041/FactoryAnnotatedConstructorExample.java @@ -1,8 +1,9 @@ package test.factory.issue1041; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; import java.util.Objects; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -30,7 +31,7 @@ public static Object[][] getData() { @Test public void testMethod() { - Assert.assertTrue(data > 0); + assertThat(data).isPositive(); } @Override diff --git a/testng-core/src/test/java/test/factory/issue1745/TestClassSample.java b/testng-core/src/test/java/test/factory/issue1745/TestClassSample.java index b4bf6f4782..4be18ced78 100644 --- a/testng-core/src/test/java/test/factory/issue1745/TestClassSample.java +++ b/testng-core/src/test/java/test/factory/issue1745/TestClassSample.java @@ -1,7 +1,6 @@ package test.factory.issue1745; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.ITestContext; import org.testng.annotations.Test; @@ -30,11 +29,11 @@ public TestClassSample(ITestContext ctx, XmlTest currentXmlTest) { @Test public void testMethod() { if ("testcontext".equalsIgnoreCase(whatWasPassed)) { // only testcontext was provided - assertNotNull(ctx); + assertThat(ctx).isNotNull(); currentXmlTest = ctx.getCurrentXmlTest(); } - assertNotNull(currentXmlTest); + assertThat(currentXmlTest).isNotNull(); int number = Integer.parseInt(currentXmlTest.getParameter("number")); - assertTrue(number != 0); + assertThat(number).isNotZero(); } } diff --git a/testng-core/src/test/java/test/factory/nested/AbstractBaseSample.java b/testng-core/src/test/java/test/factory/nested/AbstractBaseSample.java index 56ec9a7917..ef0e8b02de 100644 --- a/testng-core/src/test/java/test/factory/nested/AbstractBaseSample.java +++ b/testng-core/src/test/java/test/factory/nested/AbstractBaseSample.java @@ -1,6 +1,7 @@ package test.factory.nested; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public abstract class AbstractBaseSample { @@ -10,6 +11,6 @@ public abstract class AbstractBaseSample { @Test public void test() { String result = someMethod("hello"); - Assert.assertEquals(result, "hello world"); + assertThat(result).isEqualTo("hello world"); } } diff --git a/testng-core/src/test/java/test/factory/sample/Factory2Sample.java b/testng-core/src/test/java/test/factory/sample/Factory2Sample.java index 825f4c4333..00b23ffa3a 100644 --- a/testng-core/src/test/java/test/factory/sample/Factory2Sample.java +++ b/testng-core/src/test/java/test/factory/sample/Factory2Sample.java @@ -1,6 +1,6 @@ package test.factory.sample; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.Arrays; @@ -51,7 +51,7 @@ public void tearDown() { @AfterSuite public void afterSuite() { - assertEquals(methods, EXPECTED_METHODS); + assertThat(methods).containsExactlyElementsOf(EXPECTED_METHODS); } @Test diff --git a/testng-core/src/test/java/test/failedreporter/FailedReporterLocalTestClass.java b/testng-core/src/test/java/test/failedreporter/FailedReporterLocalTestClass.java index 753b9d9a96..6c8512d438 100644 --- a/testng-core/src/test/java/test/failedreporter/FailedReporterLocalTestClass.java +++ b/testng-core/src/test/java/test/failedreporter/FailedReporterLocalTestClass.java @@ -1,6 +1,8 @@ package test.failedreporter; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; /** @@ -12,14 +14,14 @@ public class FailedReporterLocalTestClass { public static class WithFailure { @Test public void testMethodWithFailure() { - Assert.fail(); + fail(); } } public static class WithoutFailure { @Test public void testMethodWithoutFailure() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } } diff --git a/testng-core/src/test/java/test/failedreporter/FailedReporterParametersTest.java b/testng-core/src/test/java/test/failedreporter/FailedReporterParametersTest.java index 6dc490d6dd..4a4a100e1b 100644 --- a/testng-core/src/test/java/test/failedreporter/FailedReporterParametersTest.java +++ b/testng-core/src/test/java/test/failedreporter/FailedReporterParametersTest.java @@ -1,5 +1,7 @@ package test.failedreporter; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -7,7 +9,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -104,14 +105,14 @@ public void preserveParameters() throws IOException { () -> new IllegalStateException("At-least one value should have been found")); // Cheeck class1 Parameters - Assert.assertEquals("44", failedClass1.getAllParameters().get("sharedParameter")); - Assert.assertEquals("43", failedClass1.getAllParameters().get("class1Parameter")); - Assert.assertNull(failedClass1.getAllParameters().get("class2Parameter")); + assertThat(failedClass1.getAllParameters()).containsEntry("sharedParameter", "44"); + assertThat(failedClass1.getAllParameters()).containsEntry("class1Parameter", "43"); + assertThat(failedClass1.getAllParameters().get("class2Parameter")).isNull(); // Cheeck class2 Parameters - Assert.assertEquals("55", failedClass2.getAllParameters().get("sharedParameter")); - Assert.assertEquals("56", failedClass2.getAllParameters().get("class2Parameter")); - Assert.assertNull(failedClass2.getAllParameters().get("class1Parameter")); + assertThat(failedClass2.getAllParameters()).containsEntry("sharedParameter", "55"); + assertThat(failedClass2.getAllParameters()).containsEntry("class2Parameter", "56"); + assertThat(failedClass2.getAllParameters().get("class1Parameter")).isNull(); } private static Map create(String prefix) { @@ -126,7 +127,9 @@ private static void runAssertions(File outputDir, String expectedFormat, String[ List resultLines = Lists.newArrayList(); grep(failed, String.format(expectedFormat, expectedKey, expectedKey + "Value"), resultLines); int expectedSize = 1; - Assert.assertEquals(resultLines.size(), expectedSize, "Mismatch param:" + expectedKey); + assertThat(resultLines) + .withFailMessage("Mismatch param:" + expectedKey) + .hasSize(expectedSize); } } diff --git a/testng-core/src/test/java/test/failedreporter/FailedReporterScenariosTest.java b/testng-core/src/test/java/test/failedreporter/FailedReporterScenariosTest.java index 78ac15d76c..e9d766d0e3 100644 --- a/testng-core/src/test/java/test/failedreporter/FailedReporterScenariosTest.java +++ b/testng-core/src/test/java/test/failedreporter/FailedReporterScenariosTest.java @@ -1,11 +1,11 @@ package test.failedreporter; +import static org.assertj.core.api.Assertions.assertThat; import static test.failedreporter.FailedReporterLocalTestClass.WithFailure; import static test.failedreporter.FailedReporterLocalTestClass.WithoutFailure; import java.io.File; import java.util.UUID; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.reporters.FailedReporter; @@ -17,7 +17,7 @@ public class FailedReporterScenariosTest extends SimpleBaseTest { public void testFileCreationSkipWhenNoFailuresExist() { File fileLocation = runTests(RUN_TYPES.WITHOUT_FAILURES); try { - Assert.assertFalse(getLocation(fileLocation).exists()); + assertThat(getLocation(fileLocation).exists()).isFalse(); } finally { if (fileLocation.exists()) { deleteDir(fileLocation); @@ -41,7 +41,7 @@ private void runAssertions(File fileLocation) { try { FailedReporterTest.runAssertions( fileLocation, new String[] {"testMethodWithFailure"}, ""); - Assert.assertTrue(getLocation(fileLocation).exists()); + assertThat(getLocation(fileLocation)).exists(); } finally { if (fileLocation.exists()) { deleteDir(fileLocation); diff --git a/testng-core/src/test/java/test/failedreporter/FailedReporterTest.java b/testng-core/src/test/java/test/failedreporter/FailedReporterTest.java index cc1527a81b..7dfbcab613 100644 --- a/testng-core/src/test/java/test/failedreporter/FailedReporterTest.java +++ b/testng-core/src/test/java/test/failedreporter/FailedReporterTest.java @@ -1,8 +1,9 @@ package test.failedreporter; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -195,13 +196,14 @@ private static void runAssertions( File failed = new File(outputDir, "testng-failed.xml"); for (String s : expectedMethods) { List resultLines = Lists.newArrayList(); - Assert.assertTrue(failed.exists(), String.format("File %s not exists", failed.getName())); + assertThat(failed) + .withFailMessage(String.format("File %s not exists", failed.getName())) + .exists(); grep(failed, String.format(expectedLine, s), resultLines); - Assert.assertEquals( - resultLines.size(), - expected, - String.format("Matched lines:\n %s", String.join(",\n", resultLines))); + assertThat(resultLines) + .withFailMessage(String.format("Matched lines:\n %s", String.join(",\n", resultLines))) + .hasSize(expected); } } } diff --git a/testng-core/src/test/java/test/failedreporter/issue1297/depend/PassDependsOnFailureSample.java b/testng-core/src/test/java/test/failedreporter/issue1297/depend/PassDependsOnFailureSample.java index 86b8fd906e..2dc853be68 100644 --- a/testng-core/src/test/java/test/failedreporter/issue1297/depend/PassDependsOnFailureSample.java +++ b/testng-core/src/test/java/test/failedreporter/issue1297/depend/PassDependsOnFailureSample.java @@ -1,6 +1,7 @@ package test.failedreporter.issue1297.depend; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class PassDependsOnFailureSample { @@ -9,6 +10,6 @@ public void newTest1() {} @Test public void newTest2() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_group/GroupDependFailureSample.java b/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_group/GroupDependFailureSample.java index 7db5c13e05..563149b3c8 100644 --- a/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_group/GroupDependFailureSample.java +++ b/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_group/GroupDependFailureSample.java @@ -1,12 +1,13 @@ package test.failedreporter.issue1297.depend_on_group; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; import test.failedreporter.FailedReporterTest; public class GroupDependFailureSample extends GroupDependSampleBase { @Test(groups = FailedReporterTest.DEPENDENCY_GROUP) public void newTest2() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_test/PassDependsOnPassSample.java b/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_test/PassDependsOnPassSample.java index 0a969d6e07..14434f0a3b 100644 --- a/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_test/PassDependsOnPassSample.java +++ b/testng-core/src/test/java/test/failedreporter/issue1297/depend_on_test/PassDependsOnPassSample.java @@ -1,6 +1,7 @@ package test.failedreporter.issue1297.depend_on_test; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class PassDependsOnPassSample { @@ -9,7 +10,7 @@ public void test1() {} @Test(dependsOnMethods = "test1") public void test2() { - Assert.fail(); + fail(); } @Test(dependsOnMethods = "test1") diff --git a/testng-core/src/test/java/test/failedreporter/issue1297/groups/GroupsFailureSample.java b/testng-core/src/test/java/test/failedreporter/issue1297/groups/GroupsFailureSample.java index de28988a1a..4aaceee800 100644 --- a/testng-core/src/test/java/test/failedreporter/issue1297/groups/GroupsFailureSample.java +++ b/testng-core/src/test/java/test/failedreporter/issue1297/groups/GroupsFailureSample.java @@ -1,12 +1,13 @@ package test.failedreporter.issue1297.groups; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; import test.failedreporter.FailedReporterTest; public class GroupsFailureSample extends GroupsSampleBase { @Test(groups = FailedReporterTest.DEPENDENT_GROUP) public void newTest2() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/failedreporter/issue1297/inheritance/InheritanceFailureSample.java b/testng-core/src/test/java/test/failedreporter/issue1297/inheritance/InheritanceFailureSample.java index 092b9eaadc..874f9c8d07 100644 --- a/testng-core/src/test/java/test/failedreporter/issue1297/inheritance/InheritanceFailureSample.java +++ b/testng-core/src/test/java/test/failedreporter/issue1297/inheritance/InheritanceFailureSample.java @@ -1,11 +1,12 @@ package test.failedreporter.issue1297.inheritance; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class InheritanceFailureSample extends SampleBase { @Test public void newTest2() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/failedreporter/issue1297/straightforward/FailureSample.java b/testng-core/src/test/java/test/failedreporter/issue1297/straightforward/FailureSample.java index e530da73e4..2708b41e8b 100644 --- a/testng-core/src/test/java/test/failedreporter/issue1297/straightforward/FailureSample.java +++ b/testng-core/src/test/java/test/failedreporter/issue1297/straightforward/FailureSample.java @@ -1,6 +1,7 @@ package test.failedreporter.issue1297.straightforward; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -11,7 +12,7 @@ public void beforeClassFailureSample() {} @Test public void newTest2() { - Assert.fail(); + fail(); } @AfterClass diff --git a/testng-core/src/test/java/test/failedreporter/issue2517/DataProviderWithFactoryFailedReporterTest.java b/testng-core/src/test/java/test/failedreporter/issue2517/DataProviderWithFactoryFailedReporterTest.java index 319f5d6ef1..d6b26b32d7 100644 --- a/testng-core/src/test/java/test/failedreporter/issue2517/DataProviderWithFactoryFailedReporterTest.java +++ b/testng-core/src/test/java/test/failedreporter/issue2517/DataProviderWithFactoryFailedReporterTest.java @@ -1,8 +1,9 @@ package test.failedreporter.issue2517; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -48,7 +49,7 @@ private static void runAssertions( for (String s : expectedMethods) { List resultLines = Lists.newArrayList(); grep(failed, String.format(expectedLine, s), resultLines); - Assert.assertEquals(resultLines.size(), expected); + assertThat(resultLines).hasSize(expected); } } } diff --git a/testng-core/src/test/java/test/failedreporter/issue2521/DataProviderWithFactoryMultiFailedReporterTest.java b/testng-core/src/test/java/test/failedreporter/issue2521/DataProviderWithFactoryMultiFailedReporterTest.java index 6eda518950..317ad86cb8 100644 --- a/testng-core/src/test/java/test/failedreporter/issue2521/DataProviderWithFactoryMultiFailedReporterTest.java +++ b/testng-core/src/test/java/test/failedreporter/issue2521/DataProviderWithFactoryMultiFailedReporterTest.java @@ -1,8 +1,9 @@ package test.failedreporter.issue2521; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -48,7 +49,7 @@ private static void runAssertions( for (String s : expectedMethods) { List resultLines = Lists.newArrayList(); grep(failed, String.format(expectedLine, s), resultLines); - Assert.assertEquals(resultLines.size(), expected); + assertThat(resultLines).hasSize(expected); } } } diff --git a/testng-core/src/test/java/test/failures/BaseFailuresTest.java b/testng-core/src/test/java/test/failures/BaseFailuresTest.java index 2496b44803..dda1be2ba5 100644 --- a/testng-core/src/test/java/test/failures/BaseFailuresTest.java +++ b/testng-core/src/test/java/test/failures/BaseFailuresTest.java @@ -1,5 +1,7 @@ package test.failures; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.Charset; @@ -9,7 +11,6 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.regex.Pattern; -import org.testng.Assert; import org.testng.TestNG; import org.testng.reporters.FailedReporter; import test.SimpleBaseTest; @@ -59,7 +60,7 @@ protected static boolean containsRegularExpressions(Path f, String[] strRegexps) protected static void verify(Path outputDir, String suiteName, String[] expected) throws IOException { Path f = outputDir.resolve(suiteName).resolve(FailedReporter.TESTNG_FAILED_XML); - Assert.assertTrue(containsRegularExpressions(f, expected)); + assertThat(containsRegularExpressions(f, expected)).isTrue(); Files.walkFileTree( outputDir, diff --git a/testng-core/src/test/java/test/failures/issue1930/TestBase.java b/testng-core/src/test/java/test/failures/issue1930/TestBase.java index cdb4a19a79..9fcd7962d0 100644 --- a/testng-core/src/test/java/test/failures/issue1930/TestBase.java +++ b/testng-core/src/test/java/test/failures/issue1930/TestBase.java @@ -1,6 +1,7 @@ package test.failures.issue1930; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class TestBase { @Test(dataProvider = "test2") public void testNumberEquality(Integer i1, Integer i2) { - Assert.assertEquals(i1, i2); + assertThat(i1).isEqualTo(i2); } @DataProvider(name = "test2") diff --git a/testng-core/src/test/java/test/failures/issue1930/TestClassSample.java b/testng-core/src/test/java/test/failures/issue1930/TestClassSample.java index 8f6f595a04..cb90eef860 100644 --- a/testng-core/src/test/java/test/failures/issue1930/TestClassSample.java +++ b/testng-core/src/test/java/test/failures/issue1930/TestClassSample.java @@ -1,6 +1,7 @@ package test.failures.issue1930; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -21,6 +22,6 @@ public static Object[][] primeNumbers() { @Test(dataProvider = "test1") public void testPrimeNumberChecker(int inputNumber, boolean expectedResult) { - Assert.assertEquals(expectedResult, primeNumberChecker.validate(inputNumber)); + assertThat(expectedResult).isEqualTo(primeNumberChecker.validate(inputNumber)); } } diff --git a/testng-core/src/test/java/test/github1336/BaseClass.java b/testng-core/src/test/java/test/github1336/BaseClass.java index 898a403ada..2e5dea0b3d 100644 --- a/testng-core/src/test/java/test/github1336/BaseClass.java +++ b/testng-core/src/test/java/test/github1336/BaseClass.java @@ -1,8 +1,9 @@ package test.github1336; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Random; import java.util.concurrent.TimeUnit; -import org.testng.Assert; import org.testng.annotations.BeforeClass; public class BaseClass { @@ -36,6 +37,6 @@ String getCurrentUrl() { void runTest(String url) { getDriver().get(url); - Assert.assertEquals(getDriver().getCurrentUrl(), url); + assertThat(getDriver().getCurrentUrl()).isEqualTo(url); } } diff --git a/testng-core/src/test/java/test/github1362/AfterGroupsTestInvolvingInterceptors.java b/testng-core/src/test/java/test/github1362/AfterGroupsTestInvolvingInterceptors.java index 6c755ce656..0f44ed6f37 100644 --- a/testng-core/src/test/java/test/github1362/AfterGroupsTestInvolvingInterceptors.java +++ b/testng-core/src/test/java/test/github1362/AfterGroupsTestInvolvingInterceptors.java @@ -1,6 +1,6 @@ package test.github1362; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.Collections; @@ -35,9 +35,6 @@ private void runTests(ITestNGListener interceptor, String... names) { testng.addListener(interceptor); } testng.run(); - for (String each : listener.getInvokedMethodNames()) { - assertTrue( - expected.contains(each), each + " not found in expected invocation methods " + expected); - } + assertThat(listener.getInvokedMethodNames()).isSubsetOf(expected); } } diff --git a/testng-core/src/test/java/test/github1362/TestSample.java b/testng-core/src/test/java/test/github1362/TestSample.java index d147c34532..bf15b72569 100644 --- a/testng-core/src/test/java/test/github1362/TestSample.java +++ b/testng-core/src/test/java/test/github1362/TestSample.java @@ -1,6 +1,7 @@ package test.github1362; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -12,17 +13,17 @@ public void setup() {} @Test(groups = {"exTests"}) public void test1() { - Assert.assertTrue(true, "test1"); + assertThat(true).withFailMessage("test1").isTrue(); } @Test(groups = {"exTests"}) public void test2() { - Assert.assertTrue(true, "test2"); + assertThat(true).withFailMessage("test2").isTrue(); } @Test(groups = {"exTests"}) public void test3() { - Assert.assertTrue(true, "test3"); + assertThat(true).withFailMessage("test3").isTrue(); } @AfterGroups(groups = {"exTests"}) diff --git a/testng-core/src/test/java/test/github1417/AnotherTestClassSample.java b/testng-core/src/test/java/test/github1417/AnotherTestClassSample.java index 61d4874a1a..312b8063eb 100644 --- a/testng-core/src/test/java/test/github1417/AnotherTestClassSample.java +++ b/testng-core/src/test/java/test/github1417/AnotherTestClassSample.java @@ -1,6 +1,7 @@ package test.github1417; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; @@ -41,6 +42,6 @@ public void afterClass(String browsername) { @Test public void testMethod() { - Assert.assertEquals("chrome", browsername); + assertThat(browsername).isEqualTo("chrome"); } } diff --git a/testng-core/src/test/java/test/github1417/TestClassSample.java b/testng-core/src/test/java/test/github1417/TestClassSample.java index e9017d65aa..381d789ccc 100644 --- a/testng-core/src/test/java/test/github1417/TestClassSample.java +++ b/testng-core/src/test/java/test/github1417/TestClassSample.java @@ -1,6 +1,7 @@ package test.github1417; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -16,6 +17,6 @@ public void beforeClass(String browsername) { @Test public void testMethod() { - Assert.assertEquals("firefox", browsername); + assertThat(browsername).isEqualTo("firefox"); } } diff --git a/testng-core/src/test/java/test/github1417/TestParamsInjectionInBeforeClass.java b/testng-core/src/test/java/test/github1417/TestParamsInjectionInBeforeClass.java index ef52f429ea..4af82323df 100644 --- a/testng-core/src/test/java/test/github1417/TestParamsInjectionInBeforeClass.java +++ b/testng-core/src/test/java/test/github1417/TestParamsInjectionInBeforeClass.java @@ -1,9 +1,10 @@ package test.github1417; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; @@ -14,11 +15,10 @@ public void testMethod() { TestNG testNG = new TestNG(); testNG.setTestSuites(Collections.singletonList(suite)); testNG.run(); - Assert.assertFalse(testNG.hasFailure()); - Assert.assertFalse(testNG.hasSkip()); - Assert.assertEquals(AnotherTestClassSample.getInstance().getBrowsername(), "chrome"); + assertThat(testNG.hasFailure()).isFalse(); + assertThat(testNG.hasSkip()).isFalse(); + assertThat(AnotherTestClassSample.getInstance().getBrowsername()).isEqualTo("chrome"); List actual = YetAnotherTestClassSample.getInstance().getBrowsers(); - Assert.assertEquals(actual.size(), 2); - Assert.assertEquals(actual, Arrays.asList("safari", "safari")); + assertThat(actual).containsExactlyElementsOf(Arrays.asList("safari", "safari")); } } diff --git a/testng-core/src/test/java/test/github1417/YetAnotherTestClassSample.java b/testng-core/src/test/java/test/github1417/YetAnotherTestClassSample.java index 81def3d872..16546cfe37 100644 --- a/testng-core/src/test/java/test/github1417/YetAnotherTestClassSample.java +++ b/testng-core/src/test/java/test/github1417/YetAnotherTestClassSample.java @@ -1,8 +1,9 @@ package test.github1417; +import static org.assertj.core.api.Assertions.assertThat; + import com.beust.jcommander.internal.Lists; import java.util.List; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; @@ -33,7 +34,7 @@ public void beforeClass(String browser) { @Test public void testMethod() { - Assert.assertFalse(browsers.isEmpty()); + assertThat(browsers).isNotEmpty(); } @Parameters({"browsername"}) diff --git a/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithListenerAnnotationSample.java b/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithListenerAnnotationSample.java index a67912fba1..6987f70012 100644 --- a/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithListenerAnnotationSample.java +++ b/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithListenerAnnotationSample.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Listeners; @@ -18,7 +19,7 @@ public FactoryPoweredDataProviderWithListenerAnnotationSample(int i) { @Test public void testMethod() { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithoutListenerAnnotationSample.java b/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithoutListenerAnnotationSample.java index 672e73bfad..18a9c674c5 100644 --- a/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithoutListenerAnnotationSample.java +++ b/testng-core/src/test/java/test/github1490/FactoryPoweredDataProviderWithoutListenerAnnotationSample.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -15,7 +16,7 @@ public FactoryPoweredDataProviderWithoutListenerAnnotationSample(int i) { @Test public void testMethod() { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/github1490/InstanceBasedDataProviderWithListenerAnnotationSample.java b/testng-core/src/test/java/test/github1490/InstanceBasedDataProviderWithListenerAnnotationSample.java index 9ac720ba80..cab42c8095 100644 --- a/testng-core/src/test/java/test/github1490/InstanceBasedDataProviderWithListenerAnnotationSample.java +++ b/testng-core/src/test/java/test/github1490/InstanceBasedDataProviderWithListenerAnnotationSample.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -10,7 +11,7 @@ public class InstanceBasedDataProviderWithListenerAnnotationSample { @Test(dataProvider = "getData") public void testMethod(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider diff --git a/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample.java b/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample.java index 50ae502ccc..7fea07a04d 100644 --- a/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample.java +++ b/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -10,7 +11,7 @@ public class SimpleDataProviderWithListenerAnnotationSample { @Test(dataProvider = "getData") public void testMethod(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider diff --git a/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample1.java b/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample1.java index 77f1d1e65e..26437efb71 100644 --- a/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample1.java +++ b/testng-core/src/test/java/test/github1490/SimpleDataProviderWithListenerAnnotationSample1.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -10,7 +11,7 @@ public class SimpleDataProviderWithListenerAnnotationSample1 extends LocalDataProviderListener { @Test(dataProvider = "getData") public void testMethod(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider diff --git a/testng-core/src/test/java/test/github1490/SimpleDataProviderWithoutListenerAnnotationSample.java b/testng-core/src/test/java/test/github1490/SimpleDataProviderWithoutListenerAnnotationSample.java index cdd7dd29fa..475c6aef9f 100644 --- a/testng-core/src/test/java/test/github1490/SimpleDataProviderWithoutListenerAnnotationSample.java +++ b/testng-core/src/test/java/test/github1490/SimpleDataProviderWithoutListenerAnnotationSample.java @@ -1,13 +1,14 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class SimpleDataProviderWithoutListenerAnnotationSample { @Test(dataProvider = "getData") public void testMethod(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider diff --git a/testng-core/src/test/java/test/github1490/StaticDataProviderWithListenerAnnotationSample.java b/testng-core/src/test/java/test/github1490/StaticDataProviderWithListenerAnnotationSample.java index d7ae7bc038..32b39a5243 100644 --- a/testng-core/src/test/java/test/github1490/StaticDataProviderWithListenerAnnotationSample.java +++ b/testng-core/src/test/java/test/github1490/StaticDataProviderWithListenerAnnotationSample.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Listeners; @@ -18,7 +19,7 @@ public StaticDataProviderWithListenerAnnotationSample(int i) { @Test public void testMethod() { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider diff --git a/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleOne.java b/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleOne.java index 33575dd7e9..55f0b89acb 100644 --- a/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleOne.java +++ b/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleOne.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -17,7 +18,7 @@ public TwoFactoriesShareSameDataProviderSampleOne(String cookieName, int count) @Test public void testHowMuchMasterShifuAte() { - Assert.assertEquals("oreo", cookieName); - Assert.assertTrue(count > 100); + assertThat("oreo").isEqualTo(cookieName); + assertThat(count).isGreaterThan(100); } } diff --git a/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleTwo.java b/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleTwo.java index 4b7247ac88..0644536605 100644 --- a/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleTwo.java +++ b/testng-core/src/test/java/test/github1490/TwoFactoriesShareSameDataProviderSampleTwo.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -17,7 +18,7 @@ public TwoFactoriesShareSameDataProviderSampleTwo(String cookieName, int count) @Test public void testHowMuchMasterShifuAte() { - Assert.assertEquals("marie-gold", cookieName); - Assert.assertTrue(count < 100); + assertThat("marie-gold").isEqualTo(cookieName); + assertThat(count).isLessThan(100); } } diff --git a/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSample.java b/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSample.java index d1c0d6a7f6..cb8cd41734 100644 --- a/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSample.java +++ b/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSample.java @@ -1,6 +1,7 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.testng.internal.ConstructorOrMethod; @@ -9,15 +10,15 @@ public class TwoTestMethodsShareSameDataProviderSample { @TestInfo(name = "glutton") @Test(dataProvider = "cookie-master") public void testHowMuchPoAte(String cookieName, int count) { - Assert.assertEquals("oreo", cookieName); - Assert.assertTrue(count > 100); + assertThat("oreo").isEqualTo(cookieName); + assertThat(count).isGreaterThan(100); } @TestInfo(name = "nibbler") @Test(dataProvider = "cookie-master") public void testHowMuchMasterShifuAte(String cookieName, int count) { - Assert.assertEquals("marie-gold", cookieName); - Assert.assertTrue(count < 100); + assertThat("marie-gold").isEqualTo(cookieName); + assertThat(count).isLessThan(100); } @DataProvider(name = "cookie-master") diff --git a/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSampleTwo.java b/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSampleTwo.java index b9435798c9..a51fb915a4 100644 --- a/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSampleTwo.java +++ b/testng-core/src/test/java/test/github1490/TwoTestMethodsShareSameDataProviderSampleTwo.java @@ -1,20 +1,21 @@ package test.github1490; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class TwoTestMethodsShareSameDataProviderSampleTwo { @TestInfo(name = "glutton") @Test(dataProvider = "cookie-master", dataProviderClass = DataProviderHouse.class) public void testHowMuchPoAte(String cookieName, int count) { - Assert.assertEquals("oreo", cookieName); - Assert.assertTrue(count > 100); + assertThat("oreo").isEqualTo(cookieName); + assertThat(count).isGreaterThan(100); } @TestInfo(name = "nibbler") @Test(dataProvider = "cookie-master", dataProviderClass = DataProviderHouse.class) public void testHowMuchMasterShifuAte(String cookieName, int count) { - Assert.assertEquals("marie-gold", cookieName); - Assert.assertTrue(count < 100); + assertThat("marie-gold").isEqualTo(cookieName); + assertThat(count).isLessThan(100); } } diff --git a/testng-core/src/test/java/test/github1490/VerifyDataProviderListener.java b/testng-core/src/test/java/test/github1490/VerifyDataProviderListener.java index 4addd0a28d..3370207ffc 100644 --- a/testng-core/src/test/java/test/github1490/VerifyDataProviderListener.java +++ b/testng-core/src/test/java/test/github1490/VerifyDataProviderListener.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.testng.Assert; import org.testng.IDataProviderMethod; import org.testng.TestNG; import org.testng.annotations.AfterMethod; @@ -25,9 +24,9 @@ public void testInstanceBasedDataProviderInformation() { tng.run(); IDataProviderMethod before = DataProviderInfoProvider.before; IDataProviderMethod after = DataProviderInfoProvider.after; - Assert.assertEquals(before, after); - Assert.assertEquals(before.getInstance(), after.getInstance()); - Assert.assertEquals(before.getMethod().getName(), "getData"); + assertThat(before).isEqualTo(after); + assertThat(before.getInstance()).isEqualTo(after.getInstance()); + assertThat(before.getMethod().getName()).isEqualTo("getData"); } @Test @@ -36,9 +35,9 @@ public void testStaticDataProviderInformation() { tng.run(); IDataProviderMethod before = DataProviderInfoProvider.before; IDataProviderMethod after = DataProviderInfoProvider.after; - Assert.assertEquals(before, after); - Assert.assertNull(before.getInstance()); - Assert.assertEquals(before.getMethod().getName(), "getStaticData"); + assertThat(before).isEqualTo(after); + assertThat(before.getInstance()).isNull(); + assertThat(before.getMethod().getName()).isEqualTo("getStaticData"); } @Test diff --git a/testng-core/src/test/java/test/github765/DuplicateCallsSample.java b/testng-core/src/test/java/test/github765/DuplicateCallsSample.java index e2e53a8a24..d7a385724a 100644 --- a/testng-core/src/test/java/test/github765/DuplicateCallsSample.java +++ b/testng-core/src/test/java/test/github765/DuplicateCallsSample.java @@ -1,6 +1,7 @@ package test.github765; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class DuplicateCallsSample extends TestTemplate { @Test(dataProvider = "testParameters") public void callExecuteTest(Integer testParameters) { - Assert.assertTrue(testParameters > 0); + assertThat(testParameters).isPositive(); } @DataProvider(name = "testParameters") diff --git a/testng-core/src/test/java/test/github765/ExcludeSyntheticMethodsFromTemplateCallsTest.java b/testng-core/src/test/java/test/github765/ExcludeSyntheticMethodsFromTemplateCallsTest.java index e6c9711042..d4e51e09bb 100644 --- a/testng-core/src/test/java/test/github765/ExcludeSyntheticMethodsFromTemplateCallsTest.java +++ b/testng-core/src/test/java/test/github765/ExcludeSyntheticMethodsFromTemplateCallsTest.java @@ -1,7 +1,8 @@ package test.github765; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import test.InvokedMethodNameListener; @@ -16,7 +17,7 @@ public void testMethod() { testng.addListener(listener); testng.run(); List methods = listener.getMethodsForTestClass(DuplicateCallsSample.class); - Assert.assertEquals(methods.size(), 1); - Assert.assertEquals(methods.get(0), "callExecuteTest"); + assertThat(methods).hasSize(1); + assertThat(methods.get(0)).isEqualTo("callExecuteTest"); } } diff --git a/testng-core/src/test/java/test/github799/EnsureInstancesAreOrderedViaFactories.java b/testng-core/src/test/java/test/github799/EnsureInstancesAreOrderedViaFactories.java index 350bbe420b..653bff66ff 100644 --- a/testng-core/src/test/java/test/github799/EnsureInstancesAreOrderedViaFactories.java +++ b/testng-core/src/test/java/test/github799/EnsureInstancesAreOrderedViaFactories.java @@ -1,7 +1,8 @@ package test.github799; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestResult; @@ -45,7 +46,7 @@ private void runTest(Class clazz, String... expected) { for (int i = 0; i < expected.length; i++) { String actual = listener.messages.get(i); - Assert.assertEquals(actual, expected[i]); + assertThat(actual).isEqualTo(expected[i]); } } diff --git a/testng-core/src/test/java/test/github799/InstanceTestSample.java b/testng-core/src/test/java/test/github799/InstanceTestSample.java index e3e1341467..78ce37828b 100644 --- a/testng-core/src/test/java/test/github799/InstanceTestSample.java +++ b/testng-core/src/test/java/test/github799/InstanceTestSample.java @@ -1,6 +1,7 @@ package test.github799; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.Reporter; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; @@ -27,7 +28,7 @@ public static Object[][] getData() { @Test public void testMethod() { Reporter.log(toString()); - Assert.assertNotNull(this.name); + assertThat(this.name).isNotNull(); } @Override diff --git a/testng-core/src/test/java/test/github799/MethodsTestSample.java b/testng-core/src/test/java/test/github799/MethodsTestSample.java index 7128326d97..81a93e57f8 100644 --- a/testng-core/src/test/java/test/github799/MethodsTestSample.java +++ b/testng-core/src/test/java/test/github799/MethodsTestSample.java @@ -1,6 +1,7 @@ package test.github799; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.Reporter; import org.testng.annotations.Test; @@ -9,20 +10,20 @@ public class MethodsTestSample { public void angry() { String methodName = Reporter.getCurrentTestResult().getMethod().getMethodName(); Reporter.log(methodName); - Assert.assertNotNull(methodName); + assertThat(methodName).isNotNull(); } @Test public void birds() { String methodName = Reporter.getCurrentTestResult().getMethod().getMethodName(); Reporter.log(methodName); - Assert.assertNotNull(methodName); + assertThat(methodName).isNotNull(); } @Test public void android() { String methodName = Reporter.getCurrentTestResult().getMethod().getMethodName(); Reporter.log(methodName); - Assert.assertNotNull(methodName); + assertThat(methodName).isNotNull(); } } diff --git a/testng-core/src/test/java/test/github799/ReverseOrderTestSample.java b/testng-core/src/test/java/test/github799/ReverseOrderTestSample.java index ed366b1076..4d6fe400a4 100644 --- a/testng-core/src/test/java/test/github799/ReverseOrderTestSample.java +++ b/testng-core/src/test/java/test/github799/ReverseOrderTestSample.java @@ -1,6 +1,7 @@ package test.github799; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.Reporter; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; @@ -22,6 +23,6 @@ public static Object[][] data() { @Test public void test() { Reporter.log(Integer.toString(num)); - Assert.assertTrue(num > 0); + assertThat(num).isPositive(); } } diff --git a/testng-core/src/test/java/test/github799/TestSample.java b/testng-core/src/test/java/test/github799/TestSample.java index 5177ceedb2..277535f1e0 100644 --- a/testng-core/src/test/java/test/github799/TestSample.java +++ b/testng-core/src/test/java/test/github799/TestSample.java @@ -1,6 +1,7 @@ package test.github799; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.Reporter; import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; @@ -22,6 +23,6 @@ public static Object[][] data() { @Test public void test() { Reporter.log(Integer.toString(num)); - Assert.assertTrue(num > 0); + assertThat(num).isPositive(); } } diff --git a/testng-core/src/test/java/test/groupinvocation/DummyTest.java b/testng-core/src/test/java/test/groupinvocation/DummyTest.java index 595c1389eb..2b113a5ec0 100644 --- a/testng-core/src/test/java/test/groupinvocation/DummyTest.java +++ b/testng-core/src/test/java/test/groupinvocation/DummyTest.java @@ -1,8 +1,9 @@ package test.groupinvocation; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.HashMap; import java.util.Map; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -21,13 +22,14 @@ public void testAB() {} @AfterClass(alwaysRun = true) public void checkInvocations() { Integer hashCode1 = s_externalClassGroups.get("beforeGroups"); - Assert.assertNotNull(hashCode1, "External @BeforeGroups not invoked"); + assertThat(hashCode1).withFailMessage("External @BeforeGroups not invoked").isNotNull(); Integer hashCode2 = s_externalClassGroups.get("afterGroups"); - Assert.assertNotNull(hashCode2, "External @AfterGroups not invoked"); - Assert.assertEquals( - hashCode1, - hashCode2, - "External @BeforeGroups and @AfterGroups were not invoked on the" + " same class instance"); + assertThat(hashCode2).withFailMessage("External @AfterGroups not invoked").isNotNull(); + assertThat(hashCode1) + .withFailMessage( + "External @BeforeGroups and @AfterGroups were not invoked on the" + + " same class instance") + .isEqualTo(hashCode2); } public static void recordInvocation(String string, int i) { diff --git a/testng-core/src/test/java/test/groupinvocation/DummyTest2.java b/testng-core/src/test/java/test/groupinvocation/DummyTest2.java index 49506c851f..640989fd1a 100644 --- a/testng-core/src/test/java/test/groupinvocation/DummyTest2.java +++ b/testng-core/src/test/java/test/groupinvocation/DummyTest2.java @@ -1,6 +1,7 @@ package test.groupinvocation; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -14,6 +15,8 @@ public void dummyTest() { @AfterClass(alwaysRun = true) public void checkInvocations() { - Assert.assertFalse(m_invoked, "@Test method invoked even if @BeforeGroups failed"); + assertThat(m_invoked) + .withFailMessage("@Test method invoked even if @BeforeGroups failed") + .isFalse(); } } diff --git a/testng-core/src/test/java/test/groupinvocation/InvokerTest.java b/testng-core/src/test/java/test/groupinvocation/InvokerTest.java index 86a45e556b..168933cea6 100644 --- a/testng-core/src/test/java/test/groupinvocation/InvokerTest.java +++ b/testng-core/src/test/java/test/groupinvocation/InvokerTest.java @@ -1,6 +1,7 @@ package test.groupinvocation; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -15,12 +16,12 @@ public class InvokerTest extends SimpleBaseTest { @Test public void testClassWithRedundantGroups() { - Assert.assertEquals(2, privateRun(RedundantGroupNamesSample.class, SMOKE, FUNCTIONAL_TESTS)); + assertThat(privateRun(RedundantGroupNamesSample.class, SMOKE, FUNCTIONAL_TESTS)).isEqualTo(2); } @Test public void testClassWithUniqueGroups() { - Assert.assertEquals(2, privateRun(UniqueGroupNamesSample.class, SMOKE)); + assertThat(privateRun(UniqueGroupNamesSample.class, SMOKE)).isEqualTo(2); } private int privateRun(final Class className, String... groupNames) { diff --git a/testng-core/src/test/java/test/groups/issue2232/IssueTest.java b/testng-core/src/test/java/test/groups/issue2232/IssueTest.java index e4c1f026b5..5e8dffc95c 100644 --- a/testng-core/src/test/java/test/groups/issue2232/IssueTest.java +++ b/testng-core/src/test/java/test/groups/issue2232/IssueTest.java @@ -28,7 +28,7 @@ public class IssueTest extends SimpleBaseTest { public void ensureNoNPEThrownWhenRunningGroups() throws InterruptedException { TestNG testng = create(constructSuite()); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); } private XmlSuite constructSuite() { @@ -58,7 +58,7 @@ public void commandlineTest() throws IOException, InterruptedException { constructSuite().toXml().getBytes(Charset.defaultCharset())); List args = Collections.singletonList(suitefile.toFile().getAbsolutePath()); int status = exec(Collections.emptyList(), args); - assertThat(status).isEqualTo(0); + assertThat(status).isZero(); } private int exec(List jvmArgs, List args) diff --git a/testng-core/src/test/java/test/guice/GuiceParentModuleTest.java b/testng-core/src/test/java/test/guice/GuiceParentModuleTest.java index 3f4ddc67b3..8bbf35e82c 100644 --- a/testng-core/src/test/java/test/guice/GuiceParentModuleTest.java +++ b/testng-core/src/test/java/test/guice/GuiceParentModuleTest.java @@ -1,7 +1,8 @@ package test.guice; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.inject.Inject; -import org.testng.Assert; import org.testng.ITestContext; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -14,11 +15,11 @@ public class GuiceParentModuleTest { @Inject ITestContext context; public void testService() { - Assert.assertNotNull(myService); - Assert.assertNotNull(mySession); + assertThat(myService).isNotNull(); + assertThat(mySession).isNotNull(); myService.serve(mySession); - Assert.assertNotNull(context); - Assert.assertEquals(context.getName(), "Guice"); - Assert.assertEquals(context.getSuite().getName(), "parent-module-suite"); + assertThat(context).isNotNull(); + assertThat(context.getName()).isEqualTo("Guice"); + assertThat(context.getSuite().getName()).isEqualTo("parent-module-suite"); } } diff --git a/testng-core/src/test/java/test/guice/GuiceTest.java b/testng-core/src/test/java/test/guice/GuiceTest.java index 2cbe47dae4..8119632430 100644 --- a/testng-core/src/test/java/test/guice/GuiceTest.java +++ b/testng-core/src/test/java/test/guice/GuiceTest.java @@ -1,7 +1,6 @@ package test.guice; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; import com.google.inject.Injector; import com.google.inject.Module; @@ -71,7 +70,7 @@ public void ensureInjectorsAreReUsed() { suite.setParentModule(ParentModule.class.getCanonicalName()); TestNG testng = create(suite); testng.run(); - assertThat(Person.counter).isEqualTo(1); + assertThat(Person.counter).isOne(); } @Test(description = "GITHUB-2355") @@ -81,8 +80,8 @@ public void ensureMultipleInjectorsAreNotCreated() { suite.setParentModule(AnotherParentModule.class.getCanonicalName()); TestNG testng = create(suite); testng.run(); - assertThat(AnotherParentModule.getCounter()).isEqualTo(1); - assertThat(Person.counter).isEqualTo(1); + assertThat(AnotherParentModule.getCounter()).isOne(); + assertThat(Person.counter).isOne(); } @Test(description = "GITHUB-2427") @@ -91,10 +90,15 @@ public void ensureConfigureMethodCalledOnceForModule() { suite.setParentModule(TestParentConfigModule.class.getCanonicalName()); TestNG testng = create(suite); testng.run(); - assertEquals( - TestParentConfigModule.counter.get(), 1, "TestParentModule configuration called times"); - assertEquals(TestModuleOne.counter.get(), 1, "TestModuleOne configuration called times"); - assertEquals(TestModuleTwo.counter.get(), 1, "TestModuleTwo configuration called times"); + assertThat(TestParentConfigModule.counter.get()) + .withFailMessage("TestParentModule configuration called times") + .isOne(); + assertThat(TestModuleOne.counter.get()) + .withFailMessage("TestModuleOne configuration called times") + .isOne(); + assertThat(TestModuleTwo.counter.get()) + .withFailMessage("TestModuleTwo configuration called times") + .isOne(); } @Test(description = "GITHUB-2570") diff --git a/testng-core/src/test/java/test/guice/issue2570/SampleTestClass.java b/testng-core/src/test/java/test/guice/issue2570/SampleTestClass.java index 2f7c7c6c1b..9d7f3dc65f 100644 --- a/testng-core/src/test/java/test/guice/issue2570/SampleTestClass.java +++ b/testng-core/src/test/java/test/guice/issue2570/SampleTestClass.java @@ -1,6 +1,7 @@ package test.guice.issue2570; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -8,17 +9,17 @@ public class SampleTestClass { @Test(retryAnalyzer = GuicePoweredConstructorInjectedRetry.class) public void test() { - Assert.fail(); + fail(); } @Test(retryAnalyzer = GuicePoweredSetterInjectedRetry.class) public void anotherTest() { - Assert.fail(); + fail(); } @Test(dataProvider = "dp", retryAnalyzer = GuicePoweredConstructorInjectedRetryForDPTest.class) public void dataDrivenTest(int i) { - Assert.fail(); + fail(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/guice/issue3050/EvidenceTestOneSample.java b/testng-core/src/test/java/test/guice/issue3050/EvidenceTestOneSample.java index 15a76e41f0..287e839af5 100644 --- a/testng-core/src/test/java/test/guice/issue3050/EvidenceTestOneSample.java +++ b/testng-core/src/test/java/test/guice/issue3050/EvidenceTestOneSample.java @@ -1,6 +1,6 @@ package test.guice.issue3050; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.ITestContext; import org.testng.ITestNGMethod; diff --git a/testng-core/src/test/java/test/guice/issue3050/EvidenceTestThreeSample.java b/testng-core/src/test/java/test/guice/issue3050/EvidenceTestThreeSample.java index ebcdf5e8d9..8998ddd367 100644 --- a/testng-core/src/test/java/test/guice/issue3050/EvidenceTestThreeSample.java +++ b/testng-core/src/test/java/test/guice/issue3050/EvidenceTestThreeSample.java @@ -1,6 +1,6 @@ package test.guice.issue3050; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.ITestContext; import org.testng.ITestNGMethod; diff --git a/testng-core/src/test/java/test/guice/issue3050/EvidenceTestTwoSample.java b/testng-core/src/test/java/test/guice/issue3050/EvidenceTestTwoSample.java index 6ae9522d6f..2b34c64e73 100644 --- a/testng-core/src/test/java/test/guice/issue3050/EvidenceTestTwoSample.java +++ b/testng-core/src/test/java/test/guice/issue3050/EvidenceTestTwoSample.java @@ -1,6 +1,6 @@ package test.guice.issue3050; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.ITestContext; import org.testng.ITestNGMethod; diff --git a/testng-core/src/test/java/test/guice/jitbinding/FirstModuleSample.java b/testng-core/src/test/java/test/guice/jitbinding/FirstModuleSample.java index 1c093a4b79..00c5e797f0 100644 --- a/testng-core/src/test/java/test/guice/jitbinding/FirstModuleSample.java +++ b/testng-core/src/test/java/test/guice/jitbinding/FirstModuleSample.java @@ -20,6 +20,6 @@ protected void configure() { @Test public void testInject() { - assertThat(value).isEqualTo(""); + assertThat(value).isEmpty(); } } diff --git a/testng-core/src/test/java/test/guice/jitbinding/JitBindingTest.java b/testng-core/src/test/java/test/guice/jitbinding/JitBindingTest.java index 00b1acce4b..9ccf077908 100644 --- a/testng-core/src/test/java/test/guice/jitbinding/JitBindingTest.java +++ b/testng-core/src/test/java/test/guice/jitbinding/JitBindingTest.java @@ -1,6 +1,7 @@ package test.guice.jitbinding; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -14,8 +15,8 @@ public void testConflictingJitBinding() { TestListenerAdapter adapter = new TestListenerAdapter(); tng.addListener(adapter); tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 2); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(2); } } diff --git a/testng-core/src/test/java/test/hook/issue2251/IssueTest.java b/testng-core/src/test/java/test/hook/issue2251/IssueTest.java index 837dc610a4..158d1a1e95 100644 --- a/testng-core/src/test/java/test/hook/issue2251/IssueTest.java +++ b/testng-core/src/test/java/test/hook/issue2251/IssueTest.java @@ -1,6 +1,7 @@ package test.hook.issue2251; -import org.assertj.core.api.Assertions; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -15,6 +16,6 @@ public void runTest() { testng.addListener(l); testng.run(); Throwable t = l.getFailedTests().get(0).getThrowable(); - Assertions.assertThat(t).isInstanceOf(NullPointerException.class); + assertThat(t).isInstanceOf(NullPointerException.class); } } diff --git a/testng-core/src/test/java/test/hook/issue2257/IssueTest.java b/testng-core/src/test/java/test/hook/issue2257/IssueTest.java index 25de3d5340..8bde7216cc 100644 --- a/testng-core/src/test/java/test/hook/issue2257/IssueTest.java +++ b/testng-core/src/test/java/test/hook/issue2257/IssueTest.java @@ -16,6 +16,6 @@ public void ensureConfigurationsCanBeRetriedViaCallBacks() { testng.run(); assertThat(listener.getConfigurationSkips()).isEmpty(); assertThat(listener.getConfigurationFailures()).isEmpty(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); } } diff --git a/testng-core/src/test/java/test/hook/issue2257/TestClassSample.java b/testng-core/src/test/java/test/hook/issue2257/TestClassSample.java index 31e2f5a053..5a8d1efc75 100644 --- a/testng-core/src/test/java/test/hook/issue2257/TestClassSample.java +++ b/testng-core/src/test/java/test/hook/issue2257/TestClassSample.java @@ -1,6 +1,7 @@ package test.hook.issue2257; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.IConfigurable; import org.testng.IConfigureCallBack; import org.testng.ITestResult; @@ -54,7 +55,7 @@ private void runConfiguration() { if (counter++ == 2) { counter = 1; } else { - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/hook/issue2266/TestClassSample.java b/testng-core/src/test/java/test/hook/issue2266/TestClassSample.java index be7ea321b4..9494eebdae 100644 --- a/testng-core/src/test/java/test/hook/issue2266/TestClassSample.java +++ b/testng-core/src/test/java/test/hook/issue2266/TestClassSample.java @@ -1,6 +1,7 @@ package test.hook.issue2266; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.IHookCallBack; import org.testng.IHookable; import org.testng.ITestResult; @@ -26,7 +27,7 @@ public void run(IHookCallBack callBack, ITestResult testResult) { @Test(description = "GITHUB-2266") public void runTest() { if (counter++ != 2) { - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/hook/samples/HookSuccessDynamicParametersSample.java b/testng-core/src/test/java/test/hook/samples/HookSuccessDynamicParametersSample.java index 74499a694a..18ee93b284 100644 --- a/testng-core/src/test/java/test/hook/samples/HookSuccessDynamicParametersSample.java +++ b/testng-core/src/test/java/test/hook/samples/HookSuccessDynamicParametersSample.java @@ -1,9 +1,10 @@ package test.hook.samples; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.annotation.Annotation; import java.lang.reflect.Method; import javax.inject.Named; -import org.testng.Assert; import org.testng.IHookCallBack; import org.testng.IHookable; import org.testng.ITestResult; @@ -34,7 +35,7 @@ public Object[][] dp() { @Test(dataProvider = "dp") public void verify(@Named("bar") String bar, String test) { - Assert.assertEquals(bar, "foobar"); - Assert.assertEquals(test, "test"); + assertThat(bar).isEqualTo("foobar"); + assertThat(test).isEqualTo("test"); } } diff --git a/testng-core/src/test/java/test/hook/samples/HookSuccessWithListenerSample.java b/testng-core/src/test/java/test/hook/samples/HookSuccessWithListenerSample.java index 168ead15e4..a68db5d4d5 100644 --- a/testng-core/src/test/java/test/hook/samples/HookSuccessWithListenerSample.java +++ b/testng-core/src/test/java/test/hook/samples/HookSuccessWithListenerSample.java @@ -1,8 +1,8 @@ package test.hook.samples; +import static org.assertj.core.api.Assertions.assertThat; import static test.hook.HookableTest.*; -import org.testng.Assert; import org.testng.IHookCallBack; import org.testng.IHookable; import org.testng.ITestResult; @@ -17,7 +17,7 @@ public class HookSuccessWithListenerSample { public void verify() { ITestResult itr = Reporter.getCurrentTestResult(); boolean attribute = Boolean.parseBoolean(itr.getAttribute(HOOK_INVOKED_ATTRIBUTE).toString()); - Assert.assertTrue(attribute); + assertThat(attribute).isTrue(); } public static class HookListener implements IHookable { diff --git a/testng-core/src/test/java/test/inheritance/ClassScopeTest.java b/testng-core/src/test/java/test/inheritance/ClassScopeTest.java index 5a026953be..8c7feff839 100644 --- a/testng-core/src/test/java/test/inheritance/ClassScopeTest.java +++ b/testng-core/src/test/java/test/inheritance/ClassScopeTest.java @@ -1,6 +1,7 @@ package test.inheritance; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class ClassScopeTest extends BaseClassScope { @@ -13,6 +14,6 @@ public void setVerify() { @Test(dependsOnMethods = "setVerify") public void verify() { - Assert.assertTrue(m_verify); + assertThat(m_verify).isTrue(); } } diff --git a/testng-core/src/test/java/test/inheritance/InheritanceConfigTest.java b/testng-core/src/test/java/test/inheritance/InheritanceConfigTest.java index c0679146e1..2cca5e29f0 100644 --- a/testng-core/src/test/java/test/inheritance/InheritanceConfigTest.java +++ b/testng-core/src/test/java/test/inheritance/InheritanceConfigTest.java @@ -22,6 +22,6 @@ public void testMethod() { xmlTest.addIncludedGroup("final"); TestNG tng = create(xmlTest.getSuite()); tng.run(); - assertThat(tng.getStatus()).isEqualTo(0); + assertThat(tng.getStatus()).isZero(); } } diff --git a/testng-core/src/test/java/test/inheritance/github980/ChildClassSample.java b/testng-core/src/test/java/test/inheritance/github980/ChildClassSample.java index c91fc930f8..d0e32d8e20 100644 --- a/testng-core/src/test/java/test/inheritance/github980/ChildClassSample.java +++ b/testng-core/src/test/java/test/inheritance/github980/ChildClassSample.java @@ -1,16 +1,17 @@ package test.inheritance.github980; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class ChildClassSample extends ParentClassSample { @Test public void c() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void d() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/inheritance/github980/ParentClassSample.java b/testng-core/src/test/java/test/inheritance/github980/ParentClassSample.java index 94c845cff1..970b5dc87b 100644 --- a/testng-core/src/test/java/test/inheritance/github980/ParentClassSample.java +++ b/testng-core/src/test/java/test/inheritance/github980/ParentClassSample.java @@ -1,16 +1,17 @@ package test.inheritance.github980; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class ParentClassSample { @Test public void a() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void b() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/inheritance/testng234/ChildTest.java b/testng-core/src/test/java/test/inheritance/testng234/ChildTest.java index 977884d715..3e59bf79d2 100644 --- a/testng-core/src/test/java/test/inheritance/testng234/ChildTest.java +++ b/testng-core/src/test/java/test/inheritance/testng234/ChildTest.java @@ -1,6 +1,7 @@ package test.inheritance.testng234; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class ChildTest extends ParentTest { @BeforeClass public void beforeClassMethod() { - Assert.assertTrue(false, "This is so sad... I must skip all my tests ..."); + assertThat(false).withFailMessage("This is so sad... I must skip all my tests ...").isTrue(); } @Override diff --git a/testng-core/src/test/java/test/inheritance/testng234/PolymorphicFailureTest.java b/testng-core/src/test/java/test/inheritance/testng234/PolymorphicFailureTest.java index 8597130537..fee26f6a43 100644 --- a/testng-core/src/test/java/test/inheritance/testng234/PolymorphicFailureTest.java +++ b/testng-core/src/test/java/test/inheritance/testng234/PolymorphicFailureTest.java @@ -1,7 +1,8 @@ package test.inheritance.testng234; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; -import org.testng.Assert; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -18,7 +19,7 @@ public void superclassFailureShouldCauseFailure() { assertTestResultsEqual( tla.getSkippedTests(), Arrays.asList("polymorphicMethod", "executePolymorphicMethod")); - Assert.assertEquals(0, tla.getPassedTests().size()); - Assert.assertEquals(0, tla.getFailedTests().size()); + assertThat(tla.getPassedTests()).isEmpty(); + assertThat(tla.getFailedTests()).isEmpty(); } } diff --git a/testng-core/src/test/java/test/inheritance/testng739/A.java b/testng-core/src/test/java/test/inheritance/testng739/A.java index f4dc8cd496..f55f99cbe4 100644 --- a/testng-core/src/test/java/test/inheritance/testng739/A.java +++ b/testng-core/src/test/java/test/inheritance/testng739/A.java @@ -1,6 +1,7 @@ package test.inheritance.testng739; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class A extends BaseClass { @BeforeClass public void beforeClassA() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test/inject/Github1298Test.java b/testng-core/src/test/java/test/inject/Github1298Test.java index 07141a51c5..2f5f446e0c 100644 --- a/testng-core/src/test/java/test/inject/Github1298Test.java +++ b/testng-core/src/test/java/test/inject/Github1298Test.java @@ -1,6 +1,7 @@ package test.inject; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestResult; import org.testng.Reporter; import org.testng.annotations.BeforeMethod; @@ -16,7 +17,7 @@ public void setUp(ITestResult tr) { @Test public void testPlugin() { ITestResult result = Reporter.getCurrentTestResult(); - Assert.assertEquals(result.getAttribute("class").toString(), getClass().getName()); - Assert.assertNotNull(result.getAttribute("toString")); + assertThat(result.getAttribute("class")).hasToString(getClass().getName()); + assertThat(result.getAttribute("toString")).isNotNull(); } } diff --git a/testng-core/src/test/java/test/inject/InjectAfterMethodWithTestResultTest.java b/testng-core/src/test/java/test/inject/InjectAfterMethodWithTestResultTest.java index 077145da10..e7d6c63209 100644 --- a/testng-core/src/test/java/test/inject/InjectAfterMethodWithTestResultTest.java +++ b/testng-core/src/test/java/test/inject/InjectAfterMethodWithTestResultTest.java @@ -1,6 +1,7 @@ package test.inject; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -12,6 +13,6 @@ public void verifyTestResultInjection() { TestNG tng = create(InjectAfterMethodWithTestResultSampleTest.class); tng.run(); - Assert.assertEquals(0, InjectAfterMethodWithTestResultSampleTest.m_success); + assertThat(InjectAfterMethodWithTestResultSampleTest.m_success).isZero(); } } diff --git a/testng-core/src/test/java/test/inject/InjectBeforeAndAfterMethodsWithTestResultSampleTest.java b/testng-core/src/test/java/test/inject/InjectBeforeAndAfterMethodsWithTestResultSampleTest.java index c9e70a02da..a53a2948bf 100644 --- a/testng-core/src/test/java/test/inject/InjectBeforeAndAfterMethodsWithTestResultSampleTest.java +++ b/testng-core/src/test/java/test/inject/InjectBeforeAndAfterMethodsWithTestResultSampleTest.java @@ -4,7 +4,6 @@ import java.lang.reflect.Method; import java.util.Map; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.Reporter; import org.testng.SkipException; @@ -20,8 +19,8 @@ public class InjectBeforeAndAfterMethodsWithTestResultSampleTest { @Test public void pass() { - Assert.assertEquals(Reporter.getCurrentTestResult().getAttribute("before"), 10); - Assert.assertEquals(m_testResult.getAttribute("before"), 10); + assertThat(Reporter.getCurrentTestResult().getAttribute("before")).isEqualTo(10); + assertThat(m_testResult.getAttribute("before")).isEqualTo(10); } @Test @@ -49,7 +48,7 @@ public void before(Method m, ITestResult r) { public void after(Method m, ITestResult r) { String name = m.getName(); assertThat(m_testResult.getMethod()).isEqualTo(r.getMethod()); - assertThat(attributesFrom(m_testResult)).isEqualTo(attributesFrom(r)); + assertThat(attributesFrom(m_testResult)).containsExactlyInAnyOrderEntriesOf(attributesFrom(r)); if (("pass".equals(name) && r.getStatus() == ITestResult.SUCCESS) || ("fail".equals(name) && r.getStatus() == ITestResult.FAILURE) || ("skip".equals(name) && r.getStatus() == ITestResult.SKIP)) { diff --git a/testng-core/src/test/java/test/inject/InjectBeforeMethodTest.java b/testng-core/src/test/java/test/inject/InjectBeforeMethodTest.java index aaf0079671..624a4f9598 100644 --- a/testng-core/src/test/java/test/inject/InjectBeforeMethodTest.java +++ b/testng-core/src/test/java/test/inject/InjectBeforeMethodTest.java @@ -1,7 +1,8 @@ package test.inject; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; @@ -16,7 +17,7 @@ public class InjectBeforeMethodTest { @BeforeMethod public void before(Object[] parameters) { - Assert.assertEquals(DATA[m_beforeIndex], parameters); + assertThat(DATA[m_beforeIndex]).isEqualTo(parameters); m_beforeIndex++; } @@ -33,7 +34,7 @@ public Object[][] dp() { @AfterMethod public void after(Object[] parameters) { - Assert.assertEquals(DATA[m_afterIndex], parameters); + assertThat(DATA[m_afterIndex]).isEqualTo(parameters); m_afterIndex++; } diff --git a/testng-core/src/test/java/test/inject/InjectTestContextTest.java b/testng-core/src/test/java/test/inject/InjectTestContextTest.java index 11e351b0fc..25b114c4f3 100644 --- a/testng-core/src/test/java/test/inject/InjectTestContextTest.java +++ b/testng-core/src/test/java/test/inject/InjectTestContextTest.java @@ -1,6 +1,7 @@ package test.inject; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestContext; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -19,9 +20,9 @@ public void verifyTestContextInjection(ITestContext tc, XmlTest xmlTest) { tng.addListener(tla); tng.run(); - Assert.assertEquals(xmlTest.getName(), "Injection"); - Assert.assertEquals(tla.getPassedTests().size(), 1); - Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getMethodName(), "f"); + assertThat(xmlTest.getName()).isEqualTo("Injection"); + assertThat(tla.getPassedTests()).hasSize(1); + assertThat(tla.getPassedTests().get(0).getMethod().getMethodName()).isEqualTo("f"); } @Parameters("string") diff --git a/testng-core/src/test/java/test/inject/InjectTestResultTest.java b/testng-core/src/test/java/test/inject/InjectTestResultTest.java index d5e723d943..f63477bc3c 100644 --- a/testng-core/src/test/java/test/inject/InjectTestResultTest.java +++ b/testng-core/src/test/java/test/inject/InjectTestResultTest.java @@ -1,6 +1,7 @@ package test.inject; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -12,6 +13,6 @@ public void verifyTestResultInjection() { TestNG tng = create(InjectBeforeAndAfterMethodsWithTestResultSampleTest.class); tng.run(); - Assert.assertEquals(InjectBeforeAndAfterMethodsWithTestResultSampleTest.m_success, 0); + assertThat(InjectBeforeAndAfterMethodsWithTestResultSampleTest.m_success).isZero(); } } diff --git a/testng-core/src/test/java/test/inject/NoInjectionTest.java b/testng-core/src/test/java/test/inject/NoInjectionTest.java index ec11f40480..5bfb36df64 100644 --- a/testng-core/src/test/java/test/inject/NoInjectionTest.java +++ b/testng-core/src/test/java/test/inject/NoInjectionTest.java @@ -1,7 +1,8 @@ package test.inject; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.NoInjection; import org.testng.annotations.Test; @@ -20,12 +21,12 @@ public Object[][] provide() throws Exception { @Test(dataProvider = "provider") public void withoutInjection(@NoInjection Method m) { - Assert.assertEquals(m.getName(), "f"); + assertThat(m.getName()).isEqualTo("f"); } @Test(dataProvider = "provider") public void withInjection(Method m) { - Assert.assertEquals(m.getName(), "withInjection"); + assertThat(m.getName()).isEqualTo("withInjection"); } } diff --git a/testng-core/src/test/java/test/inject/Sample.java b/testng-core/src/test/java/test/inject/Sample.java index 7c87d262c7..8030a5d94d 100644 --- a/testng-core/src/test/java/test/inject/Sample.java +++ b/testng-core/src/test/java/test/inject/Sample.java @@ -1,6 +1,7 @@ package test.inject; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestContext; import org.testng.ITestNGMethod; import org.testng.annotations.Test; @@ -9,9 +10,9 @@ public class Sample { @Test public void f(ITestContext tc) { - Assert.assertNotNull(tc); + assertThat(tc).isNotNull(); ITestNGMethod[] allMethods = tc.getAllTestMethods(); - Assert.assertEquals(allMethods.length, 1); - Assert.assertEquals(allMethods[0].getConstructorOrMethod().getName(), "f"); + assertThat(allMethods.length).isOne(); + assertThat(allMethods[0].getConstructorOrMethod().getName()).isEqualTo("f"); } } diff --git a/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java b/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java index bc306b8c98..ce5fa591b8 100644 --- a/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java +++ b/testng-core/src/test/java/test/interleavedorder/InterleavedInvocationTest.java @@ -1,8 +1,9 @@ package test.interleavedorder; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; import java.util.List; -import org.testng.Assert; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.BeforeTest; @@ -19,12 +20,11 @@ public void beforeTest() { } private void verifyInvocation(int number, List log, int index) { - Assert.assertEquals(log.get(index), "beforeTestChild" + number + "Class"); - Assert.assertTrue( - ("test1".equals(log.get(index + 1)) && "test2".equals(LOG.get(index + 2))) - || ("test2".equals(LOG.get(index + 1)) && "test1".equals(LOG.get(index + 2))), - "test methods were not invoked correctly"); - Assert.assertEquals(log.get(index + 3), "afterTestChild" + number + "Class"); + assertThat(log.get(index)).isEqualTo("beforeTestChild" + number + "Class"); + assertThat(log.subList(index + 1, index + 3)) + .as("test methods were not invoked correctly") + .containsExactlyInAnyOrder("test1", "test2"); + assertThat(log.get(index + 3)).isEqualTo("afterTestChild" + number + "Class"); } @Test @@ -36,7 +36,7 @@ public void invocationOrder() { testng.addListener(tla); testng.run(); - Assert.assertEquals(LOG.size(), 8, LOG.toString()); + assertThat(LOG).withFailMessage(LOG.toString()).hasSize(8); int number1 = "beforeTestChild1Class".equals(LOG.get(0)) ? 1 : 2; int number2 = number1 == 1 ? 2 : 1; verifyInvocation(number1, LOG, 0); diff --git a/testng-core/src/test/java/test/invocationcount/FailedInvocationCountTest.java b/testng-core/src/test/java/test/invocationcount/FailedInvocationCountTest.java index 6181cba65d..b1f7c41581 100644 --- a/testng-core/src/test/java/test/invocationcount/FailedInvocationCountTest.java +++ b/testng-core/src/test/java/test/invocationcount/FailedInvocationCountTest.java @@ -13,7 +13,6 @@ import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; import org.assertj.core.api.SoftAssertions; -import org.testng.Assert; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestResult; @@ -43,9 +42,9 @@ private void runTest(boolean skip, int passed, int failed, int skipped) { testng.addListener(tla); testng.run(); - Assert.assertEquals(tla.getPassedTests().size(), passed); - Assert.assertEquals(tla.getFailedTests().size(), failed); - Assert.assertEquals(tla.getSkippedTests().size(), skipped); + assertThat(tla.getPassedTests()).hasSize(passed); + assertThat(tla.getFailedTests()).hasSize(failed); + assertThat(tla.getSkippedTests()).hasSize(skipped); } @Test @@ -65,9 +64,9 @@ public void verifyAttributeShouldStop() { testng.addListener(tla); testng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 8); - Assert.assertEquals(tla.getFailedTests().size(), 7); - Assert.assertEquals(tla.getSkippedTests().size(), 5); + assertThat(tla.getPassedTests()).hasSize(8); + assertThat(tla.getFailedTests()).hasSize(7); + assertThat(tla.getSkippedTests()).hasSize(5); } @Test(dataProvider = "dp") diff --git a/testng-core/src/test/java/test/invocationcount/issue1719/TestclassSample.java b/testng-core/src/test/java/test/invocationcount/issue1719/TestclassSample.java index efd981b286..6b6ec5ca81 100644 --- a/testng-core/src/test/java/test/invocationcount/issue1719/TestclassSample.java +++ b/testng-core/src/test/java/test/invocationcount/issue1719/TestclassSample.java @@ -1,9 +1,10 @@ package test.invocationcount.issue1719; +import static org.assertj.core.api.Assertions.fail; + import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -17,7 +18,7 @@ public static Object[][] getData() { public static class DataDrivenTestHavingZeroSuccessPercentageAndNoInvocationCount { @Test(successPercentage = 0, dataProvider = "dp", dataProviderClass = TestclassSample.class) public void dataDrivenTestMethod(int i) { - Assert.fail("Failing iteration:" + i); + fail("Failing iteration:" + i); } } @@ -35,11 +36,11 @@ public void dataDrivenTestMethodWithInvocationCount(int i) { int current = tracker.computeIfAbsent(i, k -> new AtomicInteger()).incrementAndGet(); String msg = String.format("Parameter [%d], Invocation [%d]", i, current); if (i != 1) { // If the parameter is NOT 1, then just fail - Assert.fail("Failing test " + msg); + fail("Failing test " + msg); } if (shouldFail) { // If the parameter is 1, then simulate a flaky test that passes and fails shouldFail = false; - Assert.fail("Failing test " + msg); + fail("Failing test " + msg); } } } @@ -47,14 +48,14 @@ public void dataDrivenTestMethodWithInvocationCount(int i) { public static class RegularTestWithZeroSuccessPercentage { @Test(successPercentage = 0) public void simpleTestMethod() { - Assert.fail(); + fail(); } } public static class RegularTestWithZeroSuccessPercentageAndInvocationCount { @Test(successPercentage = 0, invocationCount = 2) public void testMethodWithMultipleInvocations() { - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageAndInvocationCountDefinedSample.java b/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageAndInvocationCountDefinedSample.java index fbdce2525c..6fe2c1791c 100644 --- a/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageAndInvocationCountDefinedSample.java +++ b/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageAndInvocationCountDefinedSample.java @@ -1,6 +1,6 @@ package test.invocationcount.issue3170; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -8,7 +8,7 @@ public class DataDrivenWithSuccessPercentageAndInvocationCountDefinedSample { @Test(dataProvider = "test", invocationCount = 10, successPercentage = 90) public void sampleTestCase(String string) { - assertEquals(string, "1"); + assertThat(string).isEqualTo("1"); } @DataProvider(name = "test") diff --git a/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageDefinedSample.java b/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageDefinedSample.java index 7d3e8fa39e..23ac1adaf5 100644 --- a/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageDefinedSample.java +++ b/testng-core/src/test/java/test/invocationcount/issue3170/DataDrivenWithSuccessPercentageDefinedSample.java @@ -1,6 +1,6 @@ package test.invocationcount.issue3170; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -8,7 +8,7 @@ public class DataDrivenWithSuccessPercentageDefinedSample { @Test(dataProvider = "test", successPercentage = 99) public void sampleTestCase(String string) { - assertEquals(string, "1"); + assertThat(string).isEqualTo("1"); } @DataProvider(name = "test") diff --git a/testng-core/src/test/java/test/invocationcount/issue3180/SampleTestContainer.java b/testng-core/src/test/java/test/invocationcount/issue3180/SampleTestContainer.java index 92040dd8cd..bce499d641 100644 --- a/testng-core/src/test/java/test/invocationcount/issue3180/SampleTestContainer.java +++ b/testng-core/src/test/java/test/invocationcount/issue3180/SampleTestContainer.java @@ -1,9 +1,9 @@ package test.invocationcount.issue3180; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -25,14 +25,14 @@ public static class TestContainsFlakyDataDrivenTest { dataProviderClass = SampleTestContainer.class, retryAnalyzer = RetryAnalyzer.class) public void testDataProvider(AtomicInteger counter) { - assertEquals(counter.incrementAndGet(), 3); + assertThat(counter.incrementAndGet()).isEqualTo(3); } } public static class TestWithNormalFailingTest { @Test(retryAnalyzer = RetryAnalyzer.class) public void alwaysFailingRegularTest() { - Assert.fail(); + fail(); } } @@ -43,7 +43,7 @@ public static class TestWithSomeFailingIterations { dataProviderClass = SampleTestContainer.class, retryAnalyzer = RetryAnalyzer.class) public void failsForOddNumbersOnly(int i) { - assertEquals(i % 2, 0); + assertThat(i % 2).isZero(); } } @@ -53,7 +53,7 @@ public static class TestContainsAlwaysFailingDataDrivenTest { dataProviderClass = SampleTestContainer.class, retryAnalyzer = RetryAnalyzer.class) public void alwaysFailingDataDrivenTest(AtomicInteger ignored) { - Assert.fail(); + fail(); } } @@ -62,7 +62,7 @@ public static class TestContainsPercentageDrivenTest { @Test(invocationCount = 10, successPercentage = 90, retryAnalyzer = RetryAnalyzer.class) public void invocationCountTestWhichEventuallyPassesDueToSuccessFactors() { - Assert.assertTrue(switcher.getAndIncrement() < 9); + assertThat(switcher.getAndIncrement()).isLessThan(9); } } @@ -74,12 +74,12 @@ public static class TestContainsAllCombinations { dataProviderClass = SampleTestContainer.class, retryAnalyzer = RetryAnalyzer.class) public void testDataProvider(AtomicInteger counter) { - assertEquals(counter.incrementAndGet(), 3); + assertThat(counter.incrementAndGet()).isEqualTo(3); } @Test(retryAnalyzer = RetryAnalyzer.class) public void alwaysFailingRegularTest() { - Assert.fail(); + fail(); } @Test( @@ -87,7 +87,7 @@ public void alwaysFailingRegularTest() { dataProviderClass = SampleTestContainer.class, retryAnalyzer = RetryAnalyzer.class) public void failsForOddNumbersOnly(int i) { - assertEquals(i % 2, 0); + assertThat(i % 2).isZero(); } @Test( @@ -95,12 +95,12 @@ public void failsForOddNumbersOnly(int i) { dataProviderClass = SampleTestContainer.class, retryAnalyzer = RetryAnalyzer.class) public void alwaysFailingDataDrivenTest(AtomicInteger ignored) { - Assert.fail(); + fail(); } @Test(invocationCount = 10, successPercentage = 90) public void invocationCountTestWhichEventuallyPassesDueToSuccessFactors() { - Assert.assertTrue(switcher.getAndIncrement() < 9); + assertThat(switcher.getAndIncrement()).isLessThan(9); } } } diff --git a/testng-core/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java b/testng-core/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java index 50c7613ea7..ffd3be4856 100644 --- a/testng-core/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java +++ b/testng-core/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java @@ -1,7 +1,8 @@ package test.invokedmethodlistener; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestNGListener; @@ -22,8 +23,8 @@ private static void run(Class[] classes, IInvokedMethodListener l) { } private static void assertMethodCount(MyListener l) { - Assert.assertEquals(l.getBeforeCount(), 9); - Assert.assertEquals(l.getAfterCount(), 9); + assertThat(l.getBeforeCount()).isEqualTo(9); + assertThat(l.getAfterCount()).isEqualTo(9); } @Test @@ -38,13 +39,13 @@ public void withFailure() { MyListener l = new MyListener(); run(new Class[] {Failure.class}, l); assertMethodCount(l); - Assert.assertEquals(l.getSuiteStatus(), ITestResult.FAILURE); - Assert.assertTrue(null != l.getSuiteThrowable()); - Assert.assertTrue(l.getSuiteThrowable().getClass() == RuntimeException.class); + assertThat(l.getSuiteStatus()).isEqualTo(ITestResult.FAILURE); + assertThat(l.getSuiteThrowable()).isNotNull(); + assertThat(l.getSuiteThrowable().getClass()).isSameAs(RuntimeException.class); - Assert.assertEquals(l.getMethodStatus(), ITestResult.FAILURE); - Assert.assertTrue(null != l.getMethodThrowable()); - Assert.assertTrue(l.getMethodThrowable().getClass() == IllegalArgumentException.class); + assertThat(l.getMethodStatus()).isEqualTo(ITestResult.FAILURE); + assertThat(l.getMethodThrowable()).isNotNull(); + assertThat(l.getMethodThrowable().getClass()).isSameAs(IllegalArgumentException.class); } /** @@ -60,15 +61,15 @@ public void sameMethodInvokedMultipleTimesShouldHaveDifferentTimeStamps() { tng.run(); List m = listener.getInvokedMethods(); IInvokedMethod beforeSuite = m.get(0); - Assert.assertFalse(beforeSuite.getTestMethod().isAfterMethodConfiguration()); - Assert.assertTrue(beforeSuite.isConfigurationMethod()); + assertThat(beforeSuite.getTestMethod().isAfterMethodConfiguration()).isFalse(); + assertThat(beforeSuite.isConfigurationMethod()).isTrue(); IInvokedMethod after1 = m.get(2); - Assert.assertTrue(after1.getTestMethod().isAfterMethodConfiguration()); - Assert.assertTrue(after1.isConfigurationMethod()); + assertThat(after1.getTestMethod().isAfterMethodConfiguration()).isTrue(); + assertThat(after1.isConfigurationMethod()).isTrue(); IInvokedMethod after2 = m.get(4); - Assert.assertTrue(after2.getTestMethod().isAfterMethodConfiguration()); - Assert.assertTrue(after2.isConfigurationMethod()); - Assert.assertTrue(after1.getDate() != after2.getDate()); + assertThat(after2.getTestMethod().isAfterMethodConfiguration()).isTrue(); + assertThat(after2.isConfigurationMethod()).isTrue(); + assertThat(after1.getDate()).isNotSameAs(after2.getDate()); } @Test( @@ -81,7 +82,7 @@ public void testMethodsWithExpectedExceptionsShouldShowUpAsPass() { tng.addListener((ITestNGListener) l); tng.run(); - Assert.assertTrue(l.isSuccess); + assertThat(l.isSuccess).isTrue(); } @Test(description = "Invoked method does not recognize configuration method") @@ -89,31 +90,31 @@ public void issue629_InvokedMethodDoesNotRecognizeConfigurationMethod() { InvokedMethodNameListener l = new InvokedMethodNameListener(); run(new Class[] {Success.class}, l); - Assert.assertEquals(l.testMethods.size(), 1); - Assert.assertTrue(l.testMethods.contains("a")); - - Assert.assertEquals(l.testMethodsFromTM.size(), 1); - Assert.assertTrue(l.testMethodsFromTM.contains("a")); - - Assert.assertEquals(l.configurationMethods.size(), 8); - Assert.assertTrue(l.configurationMethods.contains("beforeMethod")); - Assert.assertTrue(l.configurationMethods.contains("afterMethod")); - Assert.assertTrue(l.configurationMethods.contains("beforeTest")); - Assert.assertTrue(l.configurationMethods.contains("afterTest")); - Assert.assertTrue(l.configurationMethods.contains("beforeClass")); - Assert.assertTrue(l.configurationMethods.contains("afterClass")); - Assert.assertTrue(l.configurationMethods.contains("beforeSuite")); - Assert.assertTrue(l.configurationMethods.contains("afterSuite")); - - Assert.assertEquals(l.configurationMethodsFromTM.size(), 8); - Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeMethod")); - Assert.assertTrue(l.configurationMethodsFromTM.contains("afterMethod")); - Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeTest")); - Assert.assertTrue(l.configurationMethodsFromTM.contains("afterTest")); - Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeClass")); - Assert.assertTrue(l.configurationMethodsFromTM.contains("afterClass")); - Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeSuite")); - Assert.assertTrue(l.configurationMethodsFromTM.contains("afterSuite")); + assertThat(l.testMethods).hasSize(1).contains("a"); + + assertThat(l.testMethodsFromTM).hasSize(1).contains("a"); + + assertThat(l.configurationMethods) + .hasSize(8) + .contains("beforeMethod") + .contains("afterMethod") + .contains("beforeTest") + .contains("afterTest") + .contains("beforeClass") + .contains("afterClass") + .contains("beforeSuite") + .contains("afterSuite"); + + assertThat(l.configurationMethodsFromTM) + .hasSize(8) + .contains("beforeMethod") + .contains("afterMethod") + .contains("beforeTest") + .contains("afterTest") + .contains("beforeClass") + .contains("afterClass") + .contains("beforeSuite") + .contains("afterSuite"); } @Test @@ -131,9 +132,9 @@ private void assertIssue87(Class... tests) { tng.addListener((ITestNGListener) listener); tng.run(); List m = listener.getInvokedMethods(); - Assert.assertEquals(m.get(0).getTestMethod().getMethodName(), "someMethod1"); - Assert.assertEquals(m.get(1).getTestMethod().getMethodName(), "someMethod3"); - Assert.assertEquals(m.get(2).getTestMethod().getMethodName(), "someTest"); - Assert.assertEquals(m.size(), 3); + assertThat(m.get(0).getTestMethod().getMethodName()).isEqualTo("someMethod1"); + assertThat(m.get(1).getTestMethod().getMethodName()).isEqualTo("someMethod3"); + assertThat(m.get(2).getTestMethod().getMethodName()).isEqualTo("someTest"); + assertThat(m).hasSize(3); } } diff --git a/testng-core/src/test/java/test/issue107/Issue107Test.java b/testng-core/src/test/java/test/issue107/Issue107Test.java index 9aac92d1a8..4146447acf 100644 --- a/testng-core/src/test/java/test/issue107/Issue107Test.java +++ b/testng-core/src/test/java/test/issue107/Issue107Test.java @@ -1,8 +1,9 @@ package test.issue107; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; import java.util.Map; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -46,7 +47,7 @@ private void runTest(XmlSuite suite) { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getFailedTests().size(), 0); - Assert.assertEquals(tla.getPassedTests().size(), 2); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getPassedTests()).hasSize(2); } } diff --git a/testng-core/src/test/java/test/issue107/TestTestngCounter.java b/testng-core/src/test/java/test/issue107/TestTestngCounter.java index f926c93472..762363b352 100644 --- a/testng-core/src/test/java/test/issue107/TestTestngCounter.java +++ b/testng-core/src/test/java/test/issue107/TestTestngCounter.java @@ -1,6 +1,7 @@ package test.issue107; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Listeners; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; @@ -15,12 +16,12 @@ public class TestTestngCounter { @Parameters({PARAMETER_NAME}) @Test public void testParameter(String key) { - Assert.assertEquals(key, EXPECTED_VALUE); + assertThat(key).isEqualTo(EXPECTED_VALUE); } @Parameters({PARAMETER_NAME}) @Test public void testParameterAsOptional(@Optional("Unknown") String key) { - Assert.assertEquals(key, EXPECTED_VALUE); + assertThat(key).isEqualTo(EXPECTED_VALUE); } } diff --git a/testng-core/src/test/java/test/issue1430/TestFileToClass.java b/testng-core/src/test/java/test/issue1430/TestFileToClass.java index 1411a005d0..70653713b2 100644 --- a/testng-core/src/test/java/test/issue1430/TestFileToClass.java +++ b/testng-core/src/test/java/test/issue1430/TestFileToClass.java @@ -1,6 +1,7 @@ package test.issue1430; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; import org.testng.internal.ClassHelper; @@ -11,7 +12,7 @@ public void testFileToClass() { Class c1 = this.getClass(); String p = c1.getResource("TestFileToClass.class").getPath(); Class c2 = ClassHelper.fileToClass(p); - Assert.assertNotNull(c2); - Assert.assertEquals(c1.getName(), c2.getName()); + assertThat(c2).isNotNull(); + assertThat(c1.getName()).isEqualTo(c2.getName()); } } diff --git a/testng-core/src/test/java/test/issue565/Issue565Test.java b/testng-core/src/test/java/test/issue565/Issue565Test.java index 97bc3f1c91..857a4a62c6 100644 --- a/testng-core/src/test/java/test/issue565/Issue565Test.java +++ b/testng-core/src/test/java/test/issue565/Issue565Test.java @@ -1,6 +1,7 @@ package test.issue565; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -33,8 +34,8 @@ public void ThereShouldNotBeDeadlockWhenGroupByInstanceAndGroupDependencyUsed() tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getFailedTests().size(), 0); - Assert.assertEquals(tla.getSkippedTests().size(), 0); - Assert.assertEquals(tla.getPassedTests().size(), 2 + 4 * GeneratedClassFactory.SIZE); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).isEmpty(); + assertThat(tla.getPassedTests()).hasSize(2 + 4 * GeneratedClassFactory.SIZE); } } diff --git a/testng-core/src/test/java/test/jarpackages/JarPackagesTest.java b/testng-core/src/test/java/test/jarpackages/JarPackagesTest.java index 997d37110f..e80d0841b4 100644 --- a/testng-core/src/test/java/test/jarpackages/JarPackagesTest.java +++ b/testng-core/src/test/java/test/jarpackages/JarPackagesTest.java @@ -1,7 +1,8 @@ package test.jarpackages; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -27,22 +28,16 @@ private TestListenerAdapter init(String jarFile) { @Test public void jarWithTestngXml() { TestListenerAdapter tla = init("withtestngxml.jar"); - Assert.assertEquals(tla.getPassedTests().size(), 2); - String first = tla.getPassedTests().get(0).getName(); - String second = tla.getPassedTests().get(1).getName(); - boolean fThenG = "f".equals(first) && "g".equals(second); - boolean gThenF = "g".equals(first) && "f".equals(second); - Assert.assertTrue(fThenG || gThenF); + assertThat(tla.getPassedTests()) + .extracting(result -> result.getName()) + .containsExactlyInAnyOrder("f", "g"); } @Test public void jarWithoutTestngXml() { TestListenerAdapter tla = init("withouttestngxml.jar"); - Assert.assertEquals(tla.getPassedTests().size(), 2); - String first = tla.getPassedTests().get(0).getName(); - String second = tla.getPassedTests().get(1).getName(); - boolean fThenG = "f".equals(first) && "g".equals(second); - boolean gThenF = "g".equals(first) && "f".equals(second); - Assert.assertTrue(fThenG || gThenF); + assertThat(tla.getPassedTests()) + .extracting(result -> result.getName()) + .containsExactlyInAnyOrder("f", "g"); } } diff --git a/testng-core/src/test/java/test/jason/MainTest.java b/testng-core/src/test/java/test/jason/MainTest.java index 1149f46ec9..864d174937 100644 --- a/testng-core/src/test/java/test/jason/MainTest.java +++ b/testng-core/src/test/java/test/jason/MainTest.java @@ -1,7 +1,8 @@ package test.jason; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlClass; @@ -23,6 +24,6 @@ public void afterClassShouldRun() { tng.setXmlSuites(List.of(s)); Main.m_passed = false; tng.run(); - Assert.assertTrue(Main.m_passed); + assertThat(Main.m_passed).isTrue(); } } diff --git a/testng-core/src/test/java/test/junitreports/JUnitReportsTest.java b/testng-core/src/test/java/test/junitreports/JUnitReportsTest.java index d56e2ba25e..10ae713c19 100644 --- a/testng-core/src/test/java/test/junitreports/JUnitReportsTest.java +++ b/testng-core/src/test/java/test/junitreports/JUnitReportsTest.java @@ -2,7 +2,7 @@ import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.*; +import static org.assertj.core.api.Assertions.fail; import static test.junitreports.TestClassContainerForGithubIssue1265.*; import com.beust.jcommander.internal.Lists; @@ -83,16 +83,24 @@ public void testJUnitReportReporterWithMultipleClasses() throws IOException { for (Class clazz : classes) { Testsuite suite = reportReporter.getTestsuite(clazz.getName()); Map attributes = mapping.get(clazz); - assertEquals(suite.getName(), clazz.getName(), "Suite Name validation."); - assertEquals(suite.getTests(), attributes.get(TESTS).intValue(), " count validation."); - assertEquals( - suite.getErrors(), attributes.get(ERRORS).intValue(), "errored count validation."); - assertEquals( - suite.getIgnored(), attributes.get(IGNORED).intValue(), "ignored count validation."); - assertEquals( - suite.getFailures(), attributes.get(FAILURES).intValue(), "failure count validation."); - assertEquals( - suite.getSkipped(), attributes.get(SKIPPED).intValue(), "skipped count validation."); + assertThat(suite.getName()) + .withFailMessage("Suite Name validation.") + .isEqualTo(clazz.getName()); + assertThat(suite.getTests()) + .withFailMessage(" count validation.") + .isEqualTo(attributes.get(TESTS).intValue()); + assertThat(suite.getErrors()) + .withFailMessage("errored count validation.") + .isEqualTo(attributes.get(ERRORS).intValue()); + assertThat(suite.getIgnored()) + .withFailMessage("ignored count validation.") + .isEqualTo(attributes.get(IGNORED).intValue()); + assertThat(suite.getFailures()) + .withFailMessage("failure count validation.") + .isEqualTo(attributes.get(FAILURES).intValue()); + assertThat(suite.getSkipped()) + .withFailMessage("skipped count validation.") + .isEqualTo(attributes.get(SKIPPED).intValue()); } } @@ -110,7 +118,7 @@ public void testTestCaseOrderingInJUnitReportReporterWhenPrioritiesDefined() thr for (Testcase testcase : suite.getTestcase()) { actual.add(testcase.getName().trim()); } - assertEquals(actual, expected); + assertThat(actual).containsExactlyElementsOf(expected); } @Test @@ -123,7 +131,7 @@ public void testEnsureTestnameDoesnotAcceptNullValues() throws IOException { Testsuite suite = reportReporter.getTestsuite(SampleTestClass.class.getName()); Testcase testcase = suite.getTestcase().get(0); String actual = testcase.getName(); - assertEquals(actual, "Test_001"); + assertThat(actual).isEqualTo("Test_001"); } @Test @@ -233,7 +241,7 @@ public String toString() { String.format( "Could not find an expected result for actual test case result %s", actualTestCaseResult)) - .isEqualTo(1); + .isOne(); } // Verify the actual full system-out for the testsuite which includes output lines from @@ -256,7 +264,7 @@ public String toString() { // Verify that the count of actual xml testsuite system-out lines matches the count of expected // output lines. - assertThat(actualFullOutputList.size()).isEqualTo(expectedFullOutputCount); + assertThat(actualFullOutputList).hasSize(expectedFullOutputCount); // Verify that before and after messages are at the beginning and end of the testsuite // system-out. @@ -280,7 +288,7 @@ public void ensureTestReportContainsNoSysOutContent() throws Exception { Reporter.clear(); tng.run(); Document doc = getJunitReport(outputDir, testClass); - assertThat(doc.getElementsByTagName("system-out").getLength()).isEqualTo(0); + assertThat(doc.getElementsByTagName("system-out").getLength()).isZero(); } private Document getJunitReport(Path outputDir, Class testClass) @@ -347,18 +355,20 @@ private void runTest( suitename = xmlTest.getName(); } Testsuite suite = reportReporter.getTestsuite(suitename); - assertEquals(suite.getName(), suitename, "Suite Name validation."); - assertEquals(suite.getTests(), tests, " count validation."); - assertEquals(suite.getErrors(), errors, "errored count validation."); - assertEquals(suite.getIgnored(), ignored, "ignored count validation."); - assertEquals(suite.getFailures(), failures, "failure count validation."); - assertEquals(suite.getSkipped(), skipped, "skipped count validation."); - assertEquals(suite.getTestcase().size(), 3, "test case count validation."); + assertThat(suite.getName()).withFailMessage("Suite Name validation.").isEqualTo(suitename); + assertThat(suite.getTests()).withFailMessage(" count validation.").isEqualTo(tests); + assertThat(suite.getErrors()).withFailMessage("errored count validation.").isEqualTo(errors); + assertThat(suite.getIgnored()).withFailMessage("ignored count validation.").isEqualTo(ignored); + assertThat(suite.getFailures()) + .withFailMessage("failure count validation.") + .isEqualTo(failures); + assertThat(suite.getSkipped()).withFailMessage("skipped count validation.").isEqualTo(skipped); + assertThat(suite.getTestcase()).withFailMessage("test case count validation.").hasSize(3); List actualTestcases = suite.getTestcase(); for (Testcase actualTestcase : actualTestcases) { - assertTrue( - testcaseList.contains(actualTestcase), - "Validation of " + actualTestcase.getName() + " " + "presence."); + assertThat(testcaseList) + .withFailMessage("Validation of " + actualTestcase.getName() + " " + "presence.") + .contains(actualTestcase); } } } diff --git a/testng-core/src/test/java/test/junitreports/TestClassContainerForGithubIssue1265.java b/testng-core/src/test/java/test/junitreports/TestClassContainerForGithubIssue1265.java index becce0a4d8..f766ccef99 100644 --- a/testng-core/src/test/java/test/junitreports/TestClassContainerForGithubIssue1265.java +++ b/testng-core/src/test/java/test/junitreports/TestClassContainerForGithubIssue1265.java @@ -1,6 +1,6 @@ package test.junitreports; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; @@ -20,12 +20,12 @@ public static class FirstTest extends ParentTest { @Test public void should_pass() { - assertEquals("abc", "abc"); + assertThat("abc").isEqualTo("abc"); } @Test(enabled = false) public void should_be_ignored() { - assertEquals("abcd", "abc"); + assertThat("abcd").isEqualTo("abc"); } } @@ -33,7 +33,7 @@ public static class SecondTest extends ParentTest { @Test public void should_pass_second() { - assertEquals("abc", "abc"); + assertThat("abc").isEqualTo("abc"); } } @@ -41,7 +41,7 @@ public static class ThirdTest extends ParentTest { @Test public void should_pass_third() { - assertEquals("abc", "abc"); + assertThat("abc").isEqualTo("abc"); } } } diff --git a/testng-core/src/test/java/test/junitreports/issue2124/TestClassSample.java b/testng-core/src/test/java/test/junitreports/issue2124/TestClassSample.java index 8219fb0449..dd35806db8 100644 --- a/testng-core/src/test/java/test/junitreports/issue2124/TestClassSample.java +++ b/testng-core/src/test/java/test/junitreports/issue2124/TestClassSample.java @@ -1,6 +1,7 @@ package test.junitreports.issue2124; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.Reporter; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; @@ -56,12 +57,12 @@ public void testReporterWithDataProvider(String message) { @Test public void testFailWithReporter() { Reporter.log(MESSAGE_5, true); - Assert.fail(MESSAGE_FAIL); + fail(MESSAGE_FAIL); } @Test public void testFailNoReporter() { - Assert.fail(MESSAGE_FAIL); + fail(MESSAGE_FAIL); } @Test diff --git a/testng-core/src/test/java/test/listeners/AlterSuiteListenerTest.java b/testng-core/src/test/java/test/listeners/AlterSuiteListenerTest.java index c27ad6d2ce..4a40a05926 100644 --- a/testng-core/src/test/java/test/listeners/AlterSuiteListenerTest.java +++ b/testng-core/src/test/java/test/listeners/AlterSuiteListenerTest.java @@ -1,9 +1,14 @@ package test.listeners; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.testng.*; +import org.testng.IAlterSuiteListener; +import org.testng.ISuite; +import org.testng.ISuiteListener; +import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.internal.collections.Pair; import org.testng.xml.XmlSuite; @@ -19,13 +24,13 @@ public void executionListenerWithXml() { XmlSuite suite = runTest(AlterSuiteListener1SampleTest.class, AlterSuiteNameListener.class.getName()) .second(); - Assert.assertEquals(suite.getName(), AlterSuiteNameListener.class.getSimpleName()); + assertThat(suite.getName()).isEqualTo(AlterSuiteNameListener.class.getSimpleName()); } @Test public void executionListenerWithoutListener() { XmlSuite suite = runTest(AlterSuiteListener1SampleTest.class).second(); - Assert.assertEquals(suite.getName(), ALTER_SUITE_LISTENER); + assertThat(suite.getName()).isEqualTo(ALTER_SUITE_LISTENER); } @Test @@ -33,7 +38,7 @@ public void executionListenerWithXml2() { XmlSuite suite = runTest(AlterSuiteListener1SampleTest.class, AlterXmlTestsInSuiteListener.class.getName()) .second(); - Assert.assertEquals(suite.getTests().size(), 2); + assertThat(suite.getTests()).hasSize(2); } @Test(description = "GITHUB-2469") @@ -45,10 +50,10 @@ public void executionListenerWithXml3() { AlteredXmlSuiteReadListener.class.getName()); TestNG tng = retObjects.first(); XmlSuite suite = retObjects.second(); - Assert.assertEquals(suite.getTests().size(), 2); + assertThat(suite.getTests()).hasSize(2); List listeners = Optional.ofNullable(tng.getSuiteListeners()).orElse(new ArrayList<>()); - Assert.assertFalse(listeners.isEmpty()); + assertThat(listeners).isNotEmpty(); for (ISuiteListener iSuiteListener : listeners) { if (iSuiteListener instanceof AlteredXmlSuiteReadListener) { AlteredXmlSuiteReadListener alteredXmlSuiteReadListener = @@ -57,7 +62,7 @@ public void executionListenerWithXml3() { List tests = xmlSuite.getTests(); int i = 1; for (XmlTest xmlTest : tests) { - Assert.assertEquals(xmlTest.getParameter("param"), String.valueOf(i)); + assertThat(xmlTest.getParameter("param")).isEqualTo(String.valueOf(i)); i++; } } diff --git a/testng-core/src/test/java/test/listeners/ConfigurationListenerTest.java b/testng-core/src/test/java/test/listeners/ConfigurationListenerTest.java index 957bd2594e..b4147e8279 100644 --- a/testng-core/src/test/java/test/listeners/ConfigurationListenerTest.java +++ b/testng-core/src/test/java/test/listeners/ConfigurationListenerTest.java @@ -1,6 +1,7 @@ package test.listeners; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.IConfigurationListener; import org.testng.ITestResult; import org.testng.SkipException; @@ -61,7 +62,7 @@ private void runTest(Class cls, int expected) { tng.addListener(listener); tng.run(); - Assert.assertEquals(CL.m_status, expected); + assertThat(CL.m_status).isEqualTo(expected); } @Test @@ -86,8 +87,7 @@ public void skippedConfigurationShouldHaveThrowable() { tng.addListener(listener); tng.run(); - Assert.assertNotNull(listener.throwable); - Assert.assertTrue(listener.throwable instanceof SkipException); - Assert.assertEquals(listener.throwable.getMessage(), "Skip"); + assertThat(listener.throwable).isInstanceOf(SkipException.class); + assertThat(listener.throwable.getMessage()).isEqualTo("Skip"); } } diff --git a/testng-core/src/test/java/test/listeners/EndMillisShouldNotBeZeroTest.java b/testng-core/src/test/java/test/listeners/EndMillisShouldNotBeZeroTest.java index d78c9d5f9e..31dd1050d6 100644 --- a/testng-core/src/test/java/test/listeners/EndMillisShouldNotBeZeroTest.java +++ b/testng-core/src/test/java/test/listeners/EndMillisShouldNotBeZeroTest.java @@ -1,6 +1,7 @@ package test.listeners; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestResult; @@ -39,6 +40,6 @@ public void f1() { description = "Make sure that ITestResult#getEndMillis is properly set", dependsOnMethods = "f1") public void f2() { - Assert.assertTrue(m_end > 0); + assertThat(m_end).isPositive(); } } diff --git a/testng-core/src/test/java/test/listeners/ExecutionListenerAndSuiteListenerTest.java b/testng-core/src/test/java/test/listeners/ExecutionListenerAndSuiteListenerTest.java index ae78446ff8..25fa591614 100644 --- a/testng-core/src/test/java/test/listeners/ExecutionListenerAndSuiteListenerTest.java +++ b/testng-core/src/test/java/test/listeners/ExecutionListenerAndSuiteListenerTest.java @@ -1,6 +1,6 @@ package test.listeners; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; import org.testng.TestNG; @@ -17,6 +17,6 @@ public void executionListenerAndSuiteListenerTest() { TestNG testng = new TestNG(); testng.setXmlSuites(suites); testng.run(); - assertEquals(ExecutionListenerAndSuiteListener.getTmpString(), "INITIALIZED"); + assertThat(ExecutionListenerAndSuiteListener.getTmpString()).isEqualTo("INITIALIZED"); } } diff --git a/testng-core/src/test/java/test/listeners/ExecutionListenerTest.java b/testng-core/src/test/java/test/listeners/ExecutionListenerTest.java index 66533427ca..9852f8500e 100644 --- a/testng-core/src/test/java/test/listeners/ExecutionListenerTest.java +++ b/testng-core/src/test/java/test/listeners/ExecutionListenerTest.java @@ -1,7 +1,8 @@ package test.listeners; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.IExecutionListener; import org.testng.TestNG; import org.testng.annotations.Test; @@ -57,7 +58,7 @@ private void runTest(Class listenerClass, boolean addListener, boolean expect ExecutionListener.m_finish = false; tng.run(); - Assert.assertEquals(ExecutionListener.m_start, expected); - Assert.assertEquals(ExecutionListener.m_finish, expected); + assertThat(ExecutionListener.m_start).isEqualTo(expected); + assertThat(ExecutionListener.m_finish).isEqualTo(expected); } } diff --git a/testng-core/src/test/java/test/listeners/GitHub911Sample.java b/testng-core/src/test/java/test/listeners/GitHub911Sample.java index 25c63e8fea..9187f0d447 100644 --- a/testng-core/src/test/java/test/listeners/GitHub911Sample.java +++ b/testng-core/src/test/java/test/listeners/GitHub911Sample.java @@ -1,6 +1,7 @@ package test.listeners; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class GitHub911Sample { @BeforeSuite(alwaysRun = true) public void setUp() { - Assert.fail(); + fail(); } // TODO check before invocation diff --git a/testng-core/src/test/java/test/listeners/ListenerAssert.java b/testng-core/src/test/java/test/listeners/ListenerAssert.java index 147df57527..8f6d0391f4 100644 --- a/testng-core/src/test/java/test/listeners/ListenerAssert.java +++ b/testng-core/src/test/java/test/listeners/ListenerAssert.java @@ -1,7 +1,8 @@ package test.listeners; +import static org.assertj.core.api.Assertions.fail; + import java.util.List; -import org.testng.Assert; import org.testng.ITestNGListener; public final class ListenerAssert { @@ -15,6 +16,6 @@ public static void assertListenerType( return; } } - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/listeners/ListenerInXmlTest.java b/testng-core/src/test/java/test/listeners/ListenerInXmlTest.java index 32d208895b..62419ed0dd 100644 --- a/testng-core/src/test/java/test/listeners/ListenerInXmlTest.java +++ b/testng-core/src/test/java/test/listeners/ListenerInXmlTest.java @@ -1,7 +1,8 @@ package test.listeners; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -14,6 +15,6 @@ public void listenerInXmlShouldBeInvoked() { tng.setTestSuites(List.of(getPathToResource("listener-in-xml.xml"))); LListener.invoked = false; tng.run(); - Assert.assertTrue(LListener.invoked); + assertThat(LListener.invoked).isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/ListenerTest.java b/testng-core/src/test/java/test/listeners/ListenerTest.java index 9827735111..2ea31f7582 100644 --- a/testng-core/src/test/java/test/listeners/ListenerTest.java +++ b/testng-core/src/test/java/test/listeners/ListenerTest.java @@ -6,7 +6,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.testng.*; +import org.testng.ITestNGListener; +import org.testng.TestListenerAdapter; +import org.testng.TestNG; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -49,14 +51,14 @@ public void bm() { public void listenerShouldBeCalledBeforeConfiguration() { TestNG tng = create(OrderedListenerSampleTest.class); tng.run(); - Assert.assertEquals(SimpleListener.m_list, Arrays.asList(1, 2, 3, 4)); + assertThat(SimpleListener.m_list).containsExactly(1, 2, 3, 4); } @Test(description = "TESTNG-400: onTestFailure should be called before @AfterMethod") public void failureBeforeAfterMethod() { TestNG tng = create(FailingSampleTest.class); tng.run(); - Assert.assertEquals(SimpleListener.m_list, Arrays.asList(4, 5, 6)); + assertThat(SimpleListener.m_list).containsExactly(4, 5, 6); } @Test(description = "Inherited @Listeners annotations should aggregate") @@ -64,7 +66,7 @@ public void aggregateListeners() { TestNG tng = create(AggregateSampleTest.class); AggregateSampleTest.m_count = 0; tng.run(); - Assert.assertEquals(AggregateSampleTest.m_count, 2); + assertThat(AggregateSampleTest.m_count).isEqualTo(2); } @Test(description = "Should attach only one instance of the same @Listener class per test") @@ -72,7 +74,7 @@ public void shouldAttachOnlyOneInstanceOfTheSameListenerClassPerTest() { TestNG tng = create(Derived1.class, Derived2.class); BaseWithListener.m_count = 0; tng.run(); - Assert.assertEquals(BaseWithListener.m_count, 2); + assertThat(BaseWithListener.m_count).isEqualTo(2); } @Test(description = "@Listeners with an ISuiteListener") @@ -81,8 +83,8 @@ public void suiteListenersShouldWork() { SuiteListener.start = 0; SuiteListener.finish = 0; tng.run(); - Assert.assertEquals(SuiteListener.start, 1); - Assert.assertEquals(SuiteListener.finish, 1); + assertThat(SuiteListener.start).isOne(); + assertThat(SuiteListener.finish).isOne(); } @Test(description = "GITHUB-767: ISuiteListener called twice when @Listeners") @@ -91,8 +93,8 @@ public void suiteListenerInListernersAnnotationShouldBeRunOnce() { SuiteListener2.start = 0; SuiteListener2.finish = 0; tng.run(); - Assert.assertEquals(SuiteListener2.start, 1); - Assert.assertEquals(SuiteListener2.finish, 1); + assertThat(SuiteListener2.start).isOne(); + assertThat(SuiteListener2.finish).isOne(); } @Test(description = "GITHUB-171") @@ -101,8 +103,8 @@ public void suiteListenersShouldBeOnlyRunOnceWithManyTests() { SuiteListener.start = 0; SuiteListener.finish = 0; tng.run(); - Assert.assertEquals(SuiteListener.start, 1); - Assert.assertEquals(SuiteListener.finish, 1); + assertThat(SuiteListener.start).isOne(); + assertThat(SuiteListener.finish).isOne(); } @Test(description = "GITHUB-795") @@ -111,8 +113,8 @@ public void suiteListenersShouldBeOnlyRunOnceWithManyIdenticalTests() { SuiteListener.start = 0; SuiteListener.finish = 0; tng.run(); - Assert.assertEquals(SuiteListener.start, 1); - Assert.assertEquals(SuiteListener.finish, 1); + assertThat(SuiteListener.start).isOne(); + assertThat(SuiteListener.finish).isOne(); } @Test(description = "GITHUB-169") @@ -131,7 +133,7 @@ public void methodInterceptorShouldBeRunOnce() { MyMethodInterceptor interceptor = new MyMethodInterceptor(); tng.addListener(interceptor); tng.run(); - Assert.assertEquals(interceptor.getCount(), 1); + assertThat(interceptor.getCount()).isOne(); } @Test( @@ -144,7 +146,7 @@ public void methodInterceptorShouldBeRunOnce() { new InterceptorInvokeTwiceSimulateListener(); tng.addListener(interceptor); tng.run(); - Assert.assertEquals(interceptor.getCount(), 1); + assertThat(interceptor.getCount()).isOne(); } @Test(description = "GITHUB-356: Add listeners for @BeforeClass/@AfterClass") @@ -223,8 +225,8 @@ public void classListenerShouldBeOnlyRunOnce() { tng.run(); assertThat(adapter.getFailedTests()).isEmpty(); assertThat(adapter.getSkippedTests()).isEmpty(); - assertThat(tacl.getBeforeClassCount()).isEqualTo(1); - assertThat(tacl.getAfterClassCount()).isEqualTo(1); + assertThat(tacl.getBeforeClassCount()).isOne(); + assertThat(tacl.getAfterClassCount()).isOne(); } @Test(description = "GITHUB-911: Should not call method listeners for skipped methods") @@ -233,13 +235,13 @@ public void methodListenersShouldNotBeCalledForSkippedMethods() { TestNG tng = create(GitHub911Sample.class); tng.addListener(listener); tng.run(); - Assert.assertEquals(listener.onStart, 1); - Assert.assertEquals(listener.onFinish, 1); - Assert.assertEquals(listener.onTestStart, 2); - Assert.assertEquals(listener.onTestSuccess, 0); - Assert.assertEquals(listener.onTestFailure, 0); - Assert.assertEquals(listener.onTestFailedButWithinSuccessPercentage, 0); - Assert.assertEquals(listener.onTestSkipped, 2); + assertThat(listener.onStart).isOne(); + assertThat(listener.onFinish).isOne(); + assertThat(listener.onTestStart).isEqualTo(2); + assertThat(listener.onTestSuccess).isZero(); + assertThat(listener.onTestFailure).isZero(); + assertThat(listener.onTestFailedButWithinSuccessPercentage).isZero(); + assertThat(listener.onTestSkipped).isEqualTo(2); } @Test(description = "GITHUB-895: Changing status of test by setStatus of ITestResult") @@ -248,10 +250,10 @@ public void setStatusShouldWorkInListener() { TestNG tng = create(SetStatusSample.class); tng.addListener(listener); tng.run(); - Assert.assertEquals(listener.getContext().getFailedTests().size(), 0); - Assert.assertEquals(listener.getContext().getFailedButWithinSuccessPercentageTests().size(), 0); - Assert.assertEquals(listener.getContext().getSkippedTests().size(), 0); - Assert.assertEquals(listener.getContext().getPassedTests().size(), 1); + assertThat(listener.getContext().getFailedTests().size()).isZero(); + assertThat(listener.getContext().getFailedButWithinSuccessPercentageTests().size()).isZero(); + assertThat(listener.getContext().getSkippedTests().size()).isZero(); + assertThat(listener.getContext().getPassedTests().size()).isOne(); } @Test( @@ -265,14 +267,14 @@ public void listenerRegistration() { tng.addListener((ITestNGListener) listener); tng.addListener((ITestNGListener) listener); tng.run(); - Assert.assertEquals(listener.getOnSuiteStartCount(), 1); - Assert.assertEquals(listener.getOnSuiteFinishCount(), 1); - Assert.assertEquals(listener.getOnTestStartCount(), 1); - Assert.assertEquals(listener.getOnTestFinishCount(), 1); - Assert.assertEquals(listener.getBeforeInvocationCount(), 1); - Assert.assertEquals(listener.getAfterInvocationCount(), 1); - Assert.assertEquals(listener.getOnMethodTestStartCount(), 1); - Assert.assertEquals(listener.getOnMethodTestSuccessCount(), 1); + assertThat(listener.getOnSuiteStartCount()).isOne(); + assertThat(listener.getOnSuiteFinishCount()).isOne(); + assertThat(listener.getOnTestStartCount()).isOne(); + assertThat(listener.getOnTestFinishCount()).isOne(); + assertThat(listener.getBeforeInvocationCount()).isOne(); + assertThat(listener.getAfterInvocationCount()).isOne(); + assertThat(listener.getOnMethodTestStartCount()).isOne(); + assertThat(listener.getOnMethodTestSuccessCount()).isOne(); } @Test @@ -288,8 +290,8 @@ public void testListenerCallInvocation() { tng.addListener(listener); tng.run(); List messages = ListenerFor956.getMessages(); - Assert.assertEquals(messages.size(), 1); - Assert.assertEquals(messages.get(0), "Executing test956"); + assertThat(messages).hasSize(1); + assertThat(messages.get(0)).isEqualTo("Executing test956"); } @Test(description = "GITHUB-1393: fail a test from onTestStart method") @@ -299,8 +301,8 @@ public void testFailATestFromOnTestStart() { tng.addListener(adapter); tng.addListener(new Listener1393()); tng.run(); - Assert.assertEquals(adapter.getPassedTests().size(), 0); - Assert.assertEquals(adapter.getFailedTests().size(), 1); + assertThat(adapter.getPassedTests()).isEmpty(); + assertThat(adapter.getFailedTests()).hasSize(1); } @Test(dataProvider = "dp", description = "GITHUB-1029") @@ -360,7 +362,7 @@ public void ensureDynamicTestListenerInjection() { public void ensureDynamicListenerAdditionsDontTriggerConcurrentModificationExceptions() { TestNG testng = create(test.listeners.issue2061.TestClassSample.class); testng.run(); - assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); } @Test(description = "GITHUB-2558") diff --git a/testng-core/src/test/java/test/listeners/ListenersTest.java b/testng-core/src/test/java/test/listeners/ListenersTest.java index ff347b8de9..9afae8ced8 100644 --- a/testng-core/src/test/java/test/listeners/ListenersTest.java +++ b/testng-core/src/test/java/test/listeners/ListenersTest.java @@ -12,7 +12,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.assertj.core.api.Assertions; import org.assertj.core.api.SoftAssertions; import org.testng.CommandLineArgs; import org.testng.ITestNGListener; @@ -568,7 +567,7 @@ public void testThreadIsNotInterruptedInListener() { testng.addListener(listener); testng.run(); - Assertions.assertThat(listener.getInterruptedMethods()).isEmpty(); + assertThat(listener.getInterruptedMethods()).isEmpty(); } @DataProvider(name = "suiteProvider") diff --git a/testng-core/src/test/java/test/listeners/ResultContextTest.java b/testng-core/src/test/java/test/listeners/ResultContextTest.java index ec96d2f88d..65253cbaf7 100644 --- a/testng-core/src/test/java/test/listeners/ResultContextTest.java +++ b/testng-core/src/test/java/test/listeners/ResultContextTest.java @@ -1,6 +1,7 @@ package test.listeners; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -11,7 +12,8 @@ public class ResultContextTest extends SimpleBaseTest { public void testResultContext() { TestNG tng = create(ResultContextListenerSample.class); tng.run(); - Assert.assertTrue( - ResultContextListener.contextProvided, "Test context was not provided to the listener"); + assertThat(ResultContextListener.contextProvided) + .withFailMessage("Test context was not provided to the listener") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/ResultEndMillisTest.java b/testng-core/src/test/java/test/listeners/ResultEndMillisTest.java index df8d69e9bd..bae817cfbb 100644 --- a/testng-core/src/test/java/test/listeners/ResultEndMillisTest.java +++ b/testng-core/src/test/java/test/listeners/ResultEndMillisTest.java @@ -16,6 +16,6 @@ public void endMillisShouldBeNonNull() { tng.addListener((ITestNGListener) new ResultListener()); tng.run(); - assertThat(ResultListener.m_end > 0).isTrue(); + assertThat(ResultListener.m_end).isPositive(); } } diff --git a/testng-core/src/test/java/test/listeners/SetStatusSample.java b/testng-core/src/test/java/test/listeners/SetStatusSample.java index dbd86be0f5..e2aba629bf 100644 --- a/testng-core/src/test/java/test/listeners/SetStatusSample.java +++ b/testng-core/src/test/java/test/listeners/SetStatusSample.java @@ -1,12 +1,13 @@ package test.listeners; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class SetStatusSample { @Test public void aFailingTest() { - Assert.fail("Failing deliberately"); + fail("Failing deliberately"); } } diff --git a/testng-core/src/test/java/test/listeners/SuiteAndConfigurationListenerTest.java b/testng-core/src/test/java/test/listeners/SuiteAndConfigurationListenerTest.java index 7e8e1df79d..577ca7d2ec 100644 --- a/testng-core/src/test/java/test/listeners/SuiteAndConfigurationListenerTest.java +++ b/testng-core/src/test/java/test/listeners/SuiteAndConfigurationListenerTest.java @@ -1,7 +1,8 @@ package test.listeners; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.IConfigurationListener; import org.testng.ISuite; import org.testng.ISuiteListener; @@ -29,7 +30,8 @@ public void onStart(ISuite suite) { @Test public void bothListenersShouldRun() { - Assert.assertEquals( - MyListener.started.get(), 1, "ISuiteListener was not invoked exactly once:"); + assertThat(MyListener.started.get()) + .withFailMessage("ISuiteListener was not invoked exactly once:") + .isOne(); } } diff --git a/testng-core/src/test/java/test/listeners/SuiteAndInvokedMethodListenerTest.java b/testng-core/src/test/java/test/listeners/SuiteAndInvokedMethodListenerTest.java index c8978f6366..cc45fb72f4 100644 --- a/testng-core/src/test/java/test/listeners/SuiteAndInvokedMethodListenerTest.java +++ b/testng-core/src/test/java/test/listeners/SuiteAndInvokedMethodListenerTest.java @@ -1,6 +1,7 @@ package test.listeners; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ISuite; @@ -36,7 +37,9 @@ public void onStart(ISuite suite) { @Test public void bothListenersShouldRun() { - Assert.assertTrue(MyListener.m_before, "IInvokedMethodListener was not invoked"); - Assert.assertTrue(MyListener.m_start, "ISuiteListener was not invoked"); + assertThat(MyListener.m_before) + .withFailMessage("IInvokedMethodListener was not invoked") + .isTrue(); + assertThat(MyListener.m_start).withFailMessage("ISuiteListener was not invoked").isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/factory/TestNGFactoryTest.java b/testng-core/src/test/java/test/listeners/factory/TestNGFactoryTest.java index e810364d08..ad5d90d4ce 100644 --- a/testng-core/src/test/java/test/listeners/factory/TestNGFactoryTest.java +++ b/testng-core/src/test/java/test/listeners/factory/TestNGFactoryTest.java @@ -1,6 +1,6 @@ package test.listeners.factory; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -58,7 +58,7 @@ public void onTestFailure(ITestResult result) { }); testng.run(); assertThat(testng.getStatus()).isZero(); - assertThat(counter.get()).withFailMessage("No test should have failed").isEqualTo(0); + assertThat(counter.get()).withFailMessage("No test should have failed").isZero(); } @DataProvider(name = "dp-3120") diff --git a/testng-core/src/test/java/test/listeners/factory/issue3120/FactoryListenerTestClassCombinedSample.java b/testng-core/src/test/java/test/listeners/factory/issue3120/FactoryListenerTestClassCombinedSample.java index 62c13437da..649bf97f10 100644 --- a/testng-core/src/test/java/test/listeners/factory/issue3120/FactoryListenerTestClassCombinedSample.java +++ b/testng-core/src/test/java/test/listeners/factory/issue3120/FactoryListenerTestClassCombinedSample.java @@ -1,6 +1,7 @@ package test.listeners.factory.issue3120; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.IExecutionListener; import org.testng.ITestNGListener; import org.testng.ITestNGListenerFactory; @@ -27,7 +28,7 @@ public void onExecutionStart() { @Test public void sampleTestMethod() { - Assert.assertTrue(factoryInvoked, "Factory should have been invoked"); - Assert.assertTrue(listenerInvoked, "Listener should have been invoked"); + assertThat(factoryInvoked).withFailMessage("Factory should have been invoked").isTrue(); + assertThat(listenerInvoked).withFailMessage("Listener should have been invoked").isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/factory/issue3120/TestClassSample.java b/testng-core/src/test/java/test/listeners/factory/issue3120/TestClassSample.java index d1ded8b0f0..cf40dd3d13 100644 --- a/testng-core/src/test/java/test/listeners/factory/issue3120/TestClassSample.java +++ b/testng-core/src/test/java/test/listeners/factory/issue3120/TestClassSample.java @@ -1,6 +1,7 @@ package test.listeners.factory.issue3120; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -9,7 +10,11 @@ public class TestClassSample { @Test public void sampleTestMethod() { - Assert.assertTrue(CustomFactory.factoryInvoked, "Factory should have been invoked"); - Assert.assertTrue(CustomFactory.listenerInvoked, "Listener should have been invoked"); + assertThat(CustomFactory.factoryInvoked) + .withFailMessage("Factory should have been invoked") + .isTrue(); + assertThat(CustomFactory.listenerInvoked) + .withFailMessage("Listener should have been invoked") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithDataDrivenMethod.java b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithDataDrivenMethod.java index b68f2ace2a..8852becfe7 100644 --- a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithDataDrivenMethod.java +++ b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithDataDrivenMethod.java @@ -1,13 +1,14 @@ package test.listeners.github1029; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class Issue1029SampleTestClassWithDataDrivenMethod { @Test(dataProvider = "dp") public void a(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider(name = "dp", parallel = true) diff --git a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveInstances.java b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveInstances.java index 1682a8771b..03b0623eb9 100644 --- a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveInstances.java +++ b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveInstances.java @@ -1,6 +1,7 @@ package test.listeners.github1029; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -16,7 +17,7 @@ public Issue1029SampleTestClassWithFiveInstances(int i) { @Test public void a() { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveMethods.java b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveMethods.java index 5867fbd74e..5d7f149710 100644 --- a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveMethods.java +++ b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithFiveMethods.java @@ -1,31 +1,32 @@ package test.listeners.github1029; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class Issue1029SampleTestClassWithFiveMethods { @Test public void a() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void b() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void c() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void d() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void e() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithOneMethod.java b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithOneMethod.java index 51c9b997f8..ac93c54163 100644 --- a/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithOneMethod.java +++ b/testng-core/src/test/java/test/listeners/github1029/Issue1029SampleTestClassWithOneMethod.java @@ -1,11 +1,12 @@ package test.listeners.github1029; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class Issue1029SampleTestClassWithOneMethod { @Test(invocationCount = 5, threadPoolSize = 10) public void a() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/github1130/GitHub1130Test.java b/testng-core/src/test/java/test/listeners/github1130/GitHub1130Test.java index 47e7edd1cb..27c86089a5 100644 --- a/testng-core/src/test/java/test/listeners/github1130/GitHub1130Test.java +++ b/testng-core/src/test/java/test/listeners/github1130/GitHub1130Test.java @@ -31,8 +31,8 @@ private void checkGithub1130(TestNG tng) { // So the assertion should basically be able to check that ONLY 1 instance of the listener // is being used, even though TestNG created multiple instances of it. assertThat(MyListener.instance).isNotNull(); - assertThat(MyListener.instance.beforeSuiteCount.size()).isEqualTo(1); - assertThat(MyListener.instance.beforeClassCount.size()).isEqualTo(2); + assertThat(MyListener.instance.beforeSuiteCount).hasSize(1); + assertThat(MyListener.instance.beforeClassCount).hasSize(2); assertThat(MyListener.instance.beforeSuiteCount.get(0)) .isEqualTo(MyListener.instance.beforeClassCount.get(0)) .isEqualTo(MyListener.instance.beforeClassCount.get(1)); diff --git a/testng-core/src/test/java/test/listeners/github1284/Sample1284.java b/testng-core/src/test/java/test/listeners/github1284/Sample1284.java index 196cbe4085..bff487cc94 100644 --- a/testng-core/src/test/java/test/listeners/github1284/Sample1284.java +++ b/testng-core/src/test/java/test/listeners/github1284/Sample1284.java @@ -1,35 +1,36 @@ package test.listeners.github1284; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; import org.testng.collections.Lists; public class Sample1284 { @Test public void testWithNoListener() { - Assert.assertNull(Listener1284.getInstance()); - Assert.assertEquals(Listener1284.testList.size(), 0); + assertThat(Listener1284.getInstance()).isNull(); + assertThat(Listener1284.testList).isEmpty(); } @Test public void testWithListener() { - Assert.assertNotNull(Listener1284.getInstance()); - Assert.assertEquals(Listener1284.testList.size(), 1); - Assert.assertEquals( - Listener1284.testList.get(0), Sample1284.class.getName() + " - Before Invocation"); + assertThat(Listener1284.getInstance()).isNotNull(); + assertThat(Listener1284.testList).hasSize(1); + assertThat(Listener1284.testList.get(0)) + .isEqualTo(Sample1284.class.getName() + " - Before Invocation"); } @Test public void testWithChildListener() { - Assert.assertNotNull(Listener1284.getInstance()); - Assert.assertEquals(Listener1284.testList.size(), 3); + assertThat(Listener1284.getInstance()).isNotNull(); + assertThat(Listener1284.testList).hasSize(3); String beforeInvocation = Sample1284.class.getName() + " - Before Invocation"; String afterInvocation = Sample1284.class.getName() + " - After Invocation"; List expectedList = Lists.newArrayList(beforeInvocation, afterInvocation, beforeInvocation); - Assert.assertEquals(Listener1284.testList, expectedList); + assertThat(Listener1284.testList).containsExactlyElementsOf(expectedList); } } diff --git a/testng-core/src/test/java/test/listeners/github1284/Sample1284B.java b/testng-core/src/test/java/test/listeners/github1284/Sample1284B.java index d4ca1324c1..597d3b6c4d 100644 --- a/testng-core/src/test/java/test/listeners/github1284/Sample1284B.java +++ b/testng-core/src/test/java/test/listeners/github1284/Sample1284B.java @@ -1,21 +1,22 @@ package test.listeners.github1284; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; import org.testng.collections.Lists; public class Sample1284B { @Test public void testTheOrderOfInvokedMethods() { - Assert.assertNotNull(Listener1284.getInstance()); - Assert.assertEquals(Listener1284.testList.size(), 5); + assertThat(Listener1284.getInstance()).isNotNull(); + assertThat(Listener1284.testList).hasSize(5); String b1 = Sample1284.class.getName() + " - Before Invocation"; String a1 = Sample1284.class.getName() + " - After Invocation"; String b2 = Sample1284B.class.getName() + " - Before Invocation"; List expectedList = Lists.newArrayList(b1, a1, b1, a1, b2); - Assert.assertEquals(Listener1284.testList, expectedList); + assertThat(Listener1284.testList).containsExactlyElementsOf(expectedList); } } diff --git a/testng-core/src/test/java/test/listeners/github1284/TestListeners.java b/testng-core/src/test/java/test/listeners/github1284/TestListeners.java index ae4c420b7b..a44d9599d8 100644 --- a/testng-core/src/test/java/test/listeners/github1284/TestListeners.java +++ b/testng-core/src/test/java/test/listeners/github1284/TestListeners.java @@ -1,7 +1,8 @@ package test.listeners.github1284; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -15,7 +16,7 @@ public void verifyWithoutListener() { Collections.singletonList( getPathToResource("test/listeners/github1284/github1284_nolistener.xml"))); testNG.run(); - Assert.assertEquals(testNG.getStatus(), 0); + assertThat(testNG.getStatus()).isZero(); } @Test(priority = 2) @@ -25,7 +26,7 @@ public void verifyWithListener() { Collections.singletonList( getPathToResource("test/listeners/github1284/github1284_withlistener.xml"))); testNG.run(); - Assert.assertEquals(testNG.getStatus(), 0); + assertThat(testNG.getStatus()).isZero(); } @Test(priority = 3) @@ -34,6 +35,6 @@ public void verifyWithChildSuite() { testNG.setTestSuites( Collections.singletonList(getPathToResource("test/listeners/github1284/github1284.xml"))); testNG.run(); - Assert.assertEquals(testNG.getStatus(), 0); + assertThat(testNG.getStatus()).isZero(); } } diff --git a/testng-core/src/test/java/test/listeners/github1296/MyTest.java b/testng-core/src/test/java/test/listeners/github1296/MyTest.java index e9163d44d8..b2c468fab7 100644 --- a/testng-core/src/test/java/test/listeners/github1296/MyTest.java +++ b/testng-core/src/test/java/test/listeners/github1296/MyTest.java @@ -1,6 +1,6 @@ package test.listeners.github1296; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; @@ -15,7 +15,7 @@ public void setUp() {} @Test public void test() { - assertTrue(true); + assertThat(true).isTrue(); } @AfterTest diff --git a/testng-core/src/test/java/test/listeners/github1319/TestResultInstanceCheckTest.java b/testng-core/src/test/java/test/listeners/github1319/TestResultInstanceCheckTest.java index 7a35d86bbd..a6fa29fded 100644 --- a/testng-core/src/test/java/test/listeners/github1319/TestResultInstanceCheckTest.java +++ b/testng-core/src/test/java/test/listeners/github1319/TestResultInstanceCheckTest.java @@ -1,6 +1,7 @@ package test.listeners.github1319; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -11,10 +12,12 @@ public void testInstances() { TestNG tng = create(TestSample.class); tng.run(); int hashCode = TestSample.hashcode; - Assert.assertEquals(TestSample.Listener.maps.size(), 6, "Validating the number of instances"); + assertThat(TestSample.Listener.maps) + .withFailMessage("Validating the number of instances") + .hasSize(6); for (Object object : TestSample.Listener.maps.values()) { - Assert.assertNotNull(object); - Assert.assertEquals(object.hashCode(), hashCode); + assertThat(object).isNotNull(); + assertThat(object.hashCode()).isEqualTo(hashCode); } } } diff --git a/testng-core/src/test/java/test/listeners/github1319/TestSample.java b/testng-core/src/test/java/test/listeners/github1319/TestSample.java index 26b09fec0b..ca214369a9 100644 --- a/testng-core/src/test/java/test/listeners/github1319/TestSample.java +++ b/testng-core/src/test/java/test/listeners/github1319/TestSample.java @@ -1,8 +1,14 @@ package test.listeners.github1319; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import com.google.common.collect.Maps; import java.util.Map; -import org.testng.*; +import org.testng.IConfigurationListener; +import org.testng.ITestListener; +import org.testng.ITestResult; +import org.testng.SkipException; import org.testng.annotations.*; @Listeners(TestSample.Listener.class) @@ -15,12 +21,12 @@ public TestSample() { @Test public void test1() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void test2() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test/listeners/github1465/ExampleClassSample.java b/testng-core/src/test/java/test/listeners/github1465/ExampleClassSample.java index 420b24fe23..2e6204d3d7 100644 --- a/testng-core/src/test/java/test/listeners/github1465/ExampleClassSample.java +++ b/testng-core/src/test/java/test/listeners/github1465/ExampleClassSample.java @@ -1,6 +1,6 @@ package test.listeners.github1465; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.lang.reflect.Method; import org.testng.SkipException; @@ -18,12 +18,12 @@ public void beforeMethod(Method method) { @Test public void test1() { - assertTrue(true); + assertThat(true).isTrue(); } @Test public void test2() { - assertTrue(true); + assertThat(true).isTrue(); } @AfterMethod diff --git a/testng-core/src/test/java/test/listeners/github2385/IssueTest.java b/testng-core/src/test/java/test/listeners/github2385/IssueTest.java index e3079cb5cd..e6878ee1e9 100644 --- a/testng-core/src/test/java/test/listeners/github2385/IssueTest.java +++ b/testng-core/src/test/java/test/listeners/github2385/IssueTest.java @@ -1,7 +1,6 @@ package test.listeners.github2385; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.Collections; @@ -19,65 +18,65 @@ public class IssueTest extends SimpleBaseTest { public void testExtendClass() { TestNG testNG = create(SonTestClassSample.class); testNG.run(); - assertTrue(TestListener.listenerExecuted); - assertTrue(TestListener.listenerMethodInvoked); + assertThat(TestListener.listenerExecuted).isTrue(); + assertThat(TestListener.listenerMethodInvoked).isTrue(); } @Test public void testClassAndInterface() { TestNG testNG = create(TestClassAndInterfaceInheritSample.class); testNG.run(); - assertTrue(TestListener.listenerExecuted); - assertTrue(TestListener.listenerMethodInvoked); - assertTrue(TestClassListener.listenerMethodInvoked); + assertThat(TestListener.listenerExecuted).isTrue(); + assertThat(TestListener.listenerMethodInvoked).isTrue(); + assertThat(TestClassListener.listenerMethodInvoked).isTrue(); } @Test public void testClassListeners() { TestNG testNG = create(TestClassListenersInheritSample.class); testNG.run(); - assertTrue(TestListener.listenerExecuted); - assertTrue(TestListener.listenerMethodInvoked); + assertThat(TestListener.listenerExecuted).isTrue(); + assertThat(TestListener.listenerMethodInvoked).isTrue(); } @Test public void testInterface() { TestNG testNG = create(TestInterfaceListenersInheritSample.class); testNG.run(); - assertTrue(TestListener.listenerExecuted); - assertTrue(TestListener.listenerMethodInvoked); + assertThat(TestListener.listenerExecuted).isTrue(); + assertThat(TestListener.listenerMethodInvoked).isTrue(); } @Test public void testMultiInherit() { TestNG testNG = create(TestMultiInheritSample.class); testNG.run(); - assertTrue(TestListener.listenerMethodInvoked); - assertTrue(TestClassListener.listenerMethodInvoked); + assertThat(TestListener.listenerMethodInvoked).isTrue(); + assertThat(TestClassListener.listenerMethodInvoked).isTrue(); } @Test public void testMultiInheritSameAnnotation() { TestNG testNG = create(TestMultiInheritSameAnnotationSample.class); testNG.run(); - assertTrue(TestListener.listenerMethodInvoked); + assertThat(TestListener.listenerMethodInvoked).isTrue(); } @Test public void testMultiLevel() { TestNG testNG = create(TestMultiLevelInheritSample.class); testNG.run(); - assertTrue(TestListener.listenerExecuted); - assertTrue(TestListener.listenerMethodInvoked); - assertTrue(TestClassListener.listenerMethodInvoked); + assertThat(TestListener.listenerExecuted).isTrue(); + assertThat(TestListener.listenerMethodInvoked).isTrue(); + assertThat(TestClassListener.listenerMethodInvoked).isTrue(); } @Test public void testMultiLevelSameAnnotation() { TestNG testNG = create(TestMultiLevelInheritSameAnnotationSample.class); testNG.run(); - assertTrue(TestListener.listenerExecuted); - assertTrue(TestListener.listenerMethodInvoked); + assertThat(TestListener.listenerExecuted).isTrue(); + assertThat(TestListener.listenerMethodInvoked).isTrue(); } @Test @@ -99,7 +98,7 @@ public void testPackages() { tng.setXmlSuites(Collections.singletonList(xmlSuite)); tng.run(); - assertFalse(TestListener.listenerMethodInvoked); + assertThat(TestListener.listenerMethodInvoked).isFalse(); } @AfterMethod diff --git a/testng-core/src/test/java/test/listeners/github2522/FirstTestSample.java b/testng-core/src/test/java/test/listeners/github2522/FirstTestSample.java index 5e05544f3c..a59725641d 100644 --- a/testng-core/src/test/java/test/listeners/github2522/FirstTestSample.java +++ b/testng-core/src/test/java/test/listeners/github2522/FirstTestSample.java @@ -1,6 +1,7 @@ package test.listeners.github2522; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class FirstTestSample { @@ -9,7 +10,7 @@ public void firstMethod() {} @Test(description = "Second test step", dependsOnMethods = "firstMethod") public void secondMethod() { - Assert.fail(); + fail(); } @Test(description = "Third test step", dependsOnMethods = "secondMethod") diff --git a/testng-core/src/test/java/test/listeners/github2522/IssueTest.java b/testng-core/src/test/java/test/listeners/github2522/IssueTest.java index cd40858561..869af6b992 100644 --- a/testng-core/src/test/java/test/listeners/github2522/IssueTest.java +++ b/testng-core/src/test/java/test/listeners/github2522/IssueTest.java @@ -1,6 +1,7 @@ package test.listeners.github2522; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestResult; import org.testng.TestNG; import org.testng.annotations.Test; @@ -14,67 +15,21 @@ public void issueTest() { testNG.addListener(new TestListener()); testNG.run(); - Assert.assertEquals( - ITestResult.STARTED, - TestListener.beforeInvocation - .get("test.listeners.github2522.FirstTestSamplefirstMethod") - .intValue()); - Assert.assertEquals( - ITestResult.STARTED, - TestListener.beforeInvocation - .get("test.listeners.github2522.FirstTestSamplesecondMethod") - .intValue()); - Assert.assertEquals( - ITestResult.SKIP, - TestListener.beforeInvocation - .get("test.listeners.github2522.FirstTestSamplethirdMethod") - .intValue()); - Assert.assertEquals( - ITestResult.STARTED, - TestListener.beforeInvocation - .get("test.listeners.github2522.SecondTestSamplefirstMethod") - .intValue()); - Assert.assertEquals( - ITestResult.SKIP, - TestListener.beforeInvocation - .get("test.listeners.github2522.SecondTestSamplesecondMethod") - .intValue()); - Assert.assertEquals( - ITestResult.SKIP, - TestListener.beforeInvocation - .get("test.listeners.github2522.SecondTestSamplethirdMethod") - .intValue()); + assertThat(TestListener.beforeInvocation) + .containsEntry("test.listeners.github2522.FirstTestSamplefirstMethod", ITestResult.STARTED) + .containsEntry("test.listeners.github2522.FirstTestSamplesecondMethod", ITestResult.STARTED) + .containsEntry("test.listeners.github2522.FirstTestSamplethirdMethod", ITestResult.SKIP) + .containsEntry("test.listeners.github2522.SecondTestSamplefirstMethod", ITestResult.STARTED) + .containsEntry("test.listeners.github2522.SecondTestSamplesecondMethod", ITestResult.SKIP) + .containsEntry("test.listeners.github2522.SecondTestSamplethirdMethod", ITestResult.SKIP); - Assert.assertEquals( - ITestResult.SUCCESS, - TestListener.afterInvocation - .get("test.listeners.github2522.FirstTestSamplefirstMethod") - .intValue()); - Assert.assertEquals( - ITestResult.FAILURE, - TestListener.afterInvocation - .get("test.listeners.github2522.FirstTestSamplesecondMethod") - .intValue()); - Assert.assertEquals( - ITestResult.SKIP, - TestListener.afterInvocation - .get("test.listeners.github2522.FirstTestSamplethirdMethod") - .intValue()); - Assert.assertEquals( - ITestResult.SKIP, - TestListener.afterInvocation - .get("test.listeners.github2522.SecondTestSamplefirstMethod") - .intValue()); - Assert.assertEquals( - ITestResult.SKIP, - TestListener.afterInvocation - .get("test.listeners.github2522.SecondTestSamplesecondMethod") - .intValue()); - Assert.assertEquals( - ITestResult.SKIP, - TestListener.afterInvocation - .get("test.listeners.github2522.SecondTestSamplethirdMethod") - .intValue()); + assertThat(TestListener.afterInvocation) + .containsEntry("test.listeners.github2522.FirstTestSamplefirstMethod", ITestResult.SUCCESS) + .containsEntry("test.listeners.github2522.FirstTestSamplesecondMethod", ITestResult.FAILURE) + .containsEntry("test.listeners.github2522.FirstTestSamplethirdMethod", ITestResult.SKIP) + .containsEntry("test.listeners.github2522.SecondTestSamplefirstMethod", ITestResult.SKIP) + .containsEntry("test.listeners.github2522.SecondTestSamplesecondMethod", ITestResult.SKIP) + .containsEntry("test.listeners.github2522.SecondTestSamplethirdMethod", ITestResult.SKIP); } @Test @@ -83,6 +38,6 @@ public void testSkip() { testNG.addListener(new SkipTestListener()); testNG.run(); - Assert.assertTrue(SkipTestSample.getFlag()); + assertThat(SkipTestSample.getFlag()).isTrue(); } } diff --git a/testng-core/src/test/java/test/listeners/github551/Test551.java b/testng-core/src/test/java/test/listeners/github551/Test551.java index a2d1aad634..9f92a63952 100644 --- a/testng-core/src/test/java/test/listeners/github551/Test551.java +++ b/testng-core/src/test/java/test/listeners/github551/Test551.java @@ -1,6 +1,7 @@ package test.listeners.github551; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -14,6 +15,7 @@ public void testExecutionTimeOfFailedConfig() { TestNG testNG = create(TestWithFailingConfig.class); testNG.addListener(listener); testNG.run(); - Assert.assertTrue(ConfigListener.executionTime >= TestWithFailingConfig.EXEC_TIME); + assertThat(ConfigListener.executionTime) + .isGreaterThanOrEqualTo(TestWithFailingConfig.EXEC_TIME); } } diff --git a/testng-core/src/test/java/test/listeners/github956/TestClassContainer.java b/testng-core/src/test/java/test/listeners/github956/TestClassContainer.java index 4a7327e842..631fe481f1 100644 --- a/testng-core/src/test/java/test/listeners/github956/TestClassContainer.java +++ b/testng-core/src/test/java/test/listeners/github956/TestClassContainer.java @@ -1,6 +1,7 @@ package test.listeners.github956; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -9,7 +10,7 @@ public class TestClassContainer { public static class FirstTestClass { @Test public void testMethod() { - Assert.assertEquals(true, true); + assertThat(true).isTrue(); } } @@ -17,7 +18,7 @@ public void testMethod() { public static class SecondTestClass { @Test public void testMethod() { - Assert.assertEquals(true, true); + assertThat(true).isTrue(); } } } diff --git a/testng-core/src/test/java/test/listeners/issue1777/TestClassSample.java b/testng-core/src/test/java/test/listeners/issue1777/TestClassSample.java index b11edd6aab..62e28da900 100644 --- a/testng-core/src/test/java/test/listeners/issue1777/TestClassSample.java +++ b/testng-core/src/test/java/test/listeners/issue1777/TestClassSample.java @@ -1,6 +1,6 @@ package test.listeners.issue1777; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.lang.reflect.Method; import org.testng.annotations.AfterMethod; @@ -17,12 +17,12 @@ public void beforeMethod(Method method) { @Test public void test1() { - assertTrue(true); + assertThat(true).isTrue(); } @Test public void test2() { - assertTrue(true); + assertThat(true).isTrue(); } @AfterMethod diff --git a/testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java b/testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java index ef0b4c9e7e..4a5164227c 100644 --- a/testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java +++ b/testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java @@ -1,14 +1,15 @@ package test.listeners.issue2916; +import static org.assertj.core.api.Assertions.fail; + import java.util.concurrent.TimeUnit; -import org.testng.Assert; import org.testng.annotations.Test; public class ElaborateSampleTestCase extends NormalSampleTestCase { @Test(priority = 2) public void failingTest() { - Assert.fail(); + fail(); } @Test(dependsOnMethods = "failingTest") @@ -19,13 +20,13 @@ public void skippingTest() {} @Test(successPercentage = 40, invocationCount = 4, priority = 3) public void flakyTest() { if (counter != 3) { - Assert.fail(); + fail(); } } @Test(timeOut = 25, priority = 4) public void timingOutTest() throws InterruptedException { TimeUnit.SECONDS.sleep(10); - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/listeners/issue2916/SimpleConfigTestCase.java b/testng-core/src/test/java/test/listeners/issue2916/SimpleConfigTestCase.java index c6643e5434..dcacdb2b0c 100644 --- a/testng-core/src/test/java/test/listeners/issue2916/SimpleConfigTestCase.java +++ b/testng-core/src/test/java/test/listeners/issue2916/SimpleConfigTestCase.java @@ -1,6 +1,7 @@ package test.listeners.issue2916; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.*; public class SimpleConfigTestCase { @@ -15,7 +16,7 @@ public void beforeClass() {} @BeforeMethod public void beforeMethod() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test/listeners/issue3064/SampleTestCase.java b/testng-core/src/test/java/test/listeners/issue3064/SampleTestCase.java index 2a8c190c1b..f30cca7ce9 100644 --- a/testng-core/src/test/java/test/listeners/issue3064/SampleTestCase.java +++ b/testng-core/src/test/java/test/listeners/issue3064/SampleTestCase.java @@ -1,6 +1,6 @@ package test.listeners.issue3064; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.ITestContext; import org.testng.ITestNGMethod; diff --git a/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationDefaultBehaviorTest.java b/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationDefaultBehaviorTest.java index d0db8e5b5d..761a3f1574 100644 --- a/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationDefaultBehaviorTest.java +++ b/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationDefaultBehaviorTest.java @@ -1,10 +1,10 @@ package test.listeners.ordering; +import static org.assertj.core.api.Assertions.assertThat; import static test.listeners.ordering.Constants.*; import java.util.Arrays; import java.util.List; -import org.assertj.core.api.Assertions; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.internal.RuntimeBehavior; @@ -570,6 +570,6 @@ private static void runTest(List expected, Class clazz, boolean skipI testng.addListener(listener); testng.alwaysRunListeners(true); testng.run(); - Assertions.assertThat(listener.getMessages()).containsExactlyElementsOf(expected); + assertThat(listener.getMessages()).containsExactlyElementsOf(expected); } } diff --git a/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationListenerInvocationDisabledBehaviorTest.java b/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationListenerInvocationDisabledBehaviorTest.java index 73c9b0c171..3182297145 100644 --- a/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationListenerInvocationDisabledBehaviorTest.java +++ b/testng-core/src/test/java/test/listeners/ordering/ListenerInvocationListenerInvocationDisabledBehaviorTest.java @@ -1,5 +1,6 @@ package test.listeners.ordering; +import static org.assertj.core.api.Assertions.assertThat; import static test.listeners.ordering.Constants.IALTERSUITELISTENER_ALTER; import static test.listeners.ordering.Constants.IANNOTATIONTRANSFORMER_DATAPROVIDER; import static test.listeners.ordering.Constants.IANNOTATIONTRANSFORMER_FACTORY; @@ -33,7 +34,6 @@ import java.util.Arrays; import java.util.List; -import org.assertj.core.api.Assertions; import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -458,6 +458,6 @@ private static void runTest(List expected, Class clazz, boolean skipI testng.addListener(listener); testng.alwaysRunListeners(false); testng.run(); - Assertions.assertThat(listener.getMessages()).containsExactlyElementsOf(expected); + assertThat(listener.getMessages()).containsExactlyElementsOf(expected); } } diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassPoweredByFactoryWithFailedMethod.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassPoweredByFactoryWithFailedMethod.java index 781e9af8e1..235ee0a40f 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassPoweredByFactoryWithFailedMethod.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassPoweredByFactoryWithFailedMethod.java @@ -1,6 +1,7 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -16,6 +17,6 @@ public static Object[] create() { @Test public void testWillFail() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithDataDrivenMethodPassAndFailedIterations.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithDataDrivenMethodPassAndFailedIterations.java index 51ad7dc8a1..724c44ad29 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithDataDrivenMethodPassAndFailedIterations.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithDataDrivenMethodPassAndFailedIterations.java @@ -1,6 +1,7 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -9,7 +10,7 @@ public class SimpleTestClassWithDataDrivenMethodPassAndFailedIterations { @Test(dataProvider = "dp") public void testWillPass(int i) { if (i == 1) { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedAndSkippedConfigAndSkippedTestMethod.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedAndSkippedConfigAndSkippedTestMethod.java index 09e7b10903..a81d403148 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedAndSkippedConfigAndSkippedTestMethod.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedAndSkippedConfigAndSkippedTestMethod.java @@ -1,6 +1,7 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class SimpleTestClassWithFailedAndSkippedConfigAndSkippedTestMethod { @BeforeClass public void beforeClass() { - Assert.fail(); + fail(); } @BeforeMethod diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedConfigAndSkippedTestMethod.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedConfigAndSkippedTestMethod.java index 6a3ac1fe92..7c12ac7072 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedConfigAndSkippedTestMethod.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedConfigAndSkippedTestMethod.java @@ -1,13 +1,14 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class SimpleTestClassWithFailedConfigAndSkippedTestMethod { @BeforeClass public void beforeClass() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethod.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethod.java index 8574b33db9..9c3ecd05a8 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethod.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethod.java @@ -1,12 +1,13 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class SimpleTestClassWithFailedMethod { @Test public void testWillFail() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodHasRetryAnalyzer.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodHasRetryAnalyzer.java index 6f7e404785..6513e29a9d 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodHasRetryAnalyzer.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodHasRetryAnalyzer.java @@ -1,6 +1,7 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.IRetryAnalyzer; import org.testng.ITestResult; import org.testng.annotations.Test; @@ -9,7 +10,7 @@ public class SimpleTestClassWithFailedMethodHasRetryAnalyzer { @Test(retryAnalyzer = OnceMore.class) public void testWillFail() { - Assert.fail(); + fail(); } public static class OnceMore implements IRetryAnalyzer { diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodMultipleInvocations.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodMultipleInvocations.java index e9ab029d33..9913d82123 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodMultipleInvocations.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithFailedMethodMultipleInvocations.java @@ -1,12 +1,13 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class SimpleTestClassWithFailedMethodMultipleInvocations { @Test(invocationCount = 2) public void testWillFail() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithPassFailMethods.java b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithPassFailMethods.java index 1c6c0d7203..5862777726 100644 --- a/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithPassFailMethods.java +++ b/testng-core/src/test/java/test/listeners/ordering/SimpleTestClassWithPassFailMethods.java @@ -1,6 +1,7 @@ package test.listeners.ordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class SimpleTestClassWithPassFailMethods { @@ -10,7 +11,7 @@ public void testWillPass() {} @Test public void testWillFail() { - Assert.fail(); + fail(); } @Test(dependsOnMethods = "testWillFail") diff --git a/testng-core/src/test/java/test/mannotation/MAnnotation2SampleTest.java b/testng-core/src/test/java/test/mannotation/MAnnotation2SampleTest.java index 615d2d51c0..514c8eea4a 100644 --- a/testng-core/src/test/java/test/mannotation/MAnnotation2SampleTest.java +++ b/testng-core/src/test/java/test/mannotation/MAnnotation2SampleTest.java @@ -1,11 +1,12 @@ package test.mannotation; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.IConfigurationAnnotation; import org.testng.annotations.ITestAnnotation; @@ -33,7 +34,7 @@ public void verifyTestGroupsInheritance() throws SecurityException, NoSuchMethod Method method = MTest3.class.getMethod(data.getKey()); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); List expected = data.getValue(); - Assert.assertEqualsNoOrder(expected.toArray(new String[0]), test1.getGroups()); + assertThat(test1.getGroups()).containsExactlyInAnyOrderElementsOf(expected); } } @@ -48,7 +49,7 @@ public void verifyTestDependsOnGroupsInheritance() Method method = MTest3.class.getMethod(data.getKey()); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); List expected = data.getValue(); - Assert.assertEqualsNoOrder(expected.toArray(new String[0]), test1.getDependsOnGroups()); + assertThat(test1.getDependsOnGroups()).containsExactlyInAnyOrderElementsOf(expected); } } @@ -62,7 +63,7 @@ public void verifyTestDependsOnMethodsInheritance() Method method = MTest3.class.getMethod(data.getKey()); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); List expected = data.getValue(); - Assert.assertEqualsNoOrder(expected.toArray(new String[0]), test1.getDependsOnMethods()); + assertThat(test1.getDependsOnMethods()).containsExactlyInAnyOrderElementsOf(expected); } } @@ -72,7 +73,7 @@ public void verifyConfigurationGroupsInheritance() Method method = MTest3.class.getMethod("beforeSuite"); IConfigurationAnnotation test1 = (IConfigurationAnnotation) m_finder.findAnnotation(method, IBeforeSuite.class); - Assert.assertEqualsNoOrder(new String[] {"method-test3"}, test1.getGroups()); + assertThat(test1.getGroups()).containsExactlyInAnyOrder("method-test3"); } @Test(groups = "current") @@ -82,7 +83,7 @@ public void verifyTestEnabledInheritance() throws SecurityException, NoSuchMetho for (int i = 0; i < methods.length; i++) { Method method = MTest3.class.getMethod(methods[i]); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); - Assert.assertEquals(test1.getEnabled(), expected[i].booleanValue()); + assertThat(test1.getEnabled()).isEqualTo(expected[i].booleanValue()); } } } diff --git a/testng-core/src/test/java/test/mannotation/MAnnotationSampleTest.java b/testng-core/src/test/java/test/mannotation/MAnnotationSampleTest.java index c4006ef420..0044869284 100644 --- a/testng-core/src/test/java/test/mannotation/MAnnotationSampleTest.java +++ b/testng-core/src/test/java/test/mannotation/MAnnotationSampleTest.java @@ -1,7 +1,8 @@ package test.mannotation; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.IConfigurationAnnotation; import org.testng.annotations.IDataProviderAnnotation; @@ -29,30 +30,31 @@ public void verifyTestClassLevel() { // Tests on MTest1SampleTest // ITestAnnotation test1 = m_finder.findAnnotation(MTest1.class, ITestAnnotation.class); - Assert.assertTrue(test1.getEnabled()); - Assert.assertEquals(test1.getGroups(), new String[] {"group1", "group2"}); - Assert.assertTrue(test1.getAlwaysRun()); - Assert.assertEqualsNoOrder( - test1.getDependsOnGroups(), new String[] {"dg1", "dg2"}, "depends on groups"); - Assert.assertEqualsNoOrder(test1.getDependsOnMethods(), new String[] {"dm1", "dm2"}); - Assert.assertEquals(test1.getTimeOut(), 42); - Assert.assertEquals(test1.getInvocationCount(), 43); - Assert.assertEquals(test1.getSuccessPercentage(), 44); - Assert.assertEquals(test1.getThreadPoolSize(), 3); - Assert.assertEquals(test1.getDataProvider(), "dp"); - Assert.assertEquals(test1.getDescription(), "Class level description"); + assertThat(test1.getEnabled()).isTrue(); + assertThat(test1.getGroups()).isEqualTo(new String[] {"group1", "group2"}); + assertThat(test1.getAlwaysRun()).isTrue(); + assertThat(test1.getDependsOnGroups()) + .withFailMessage("depends on groups") + .containsExactlyInAnyOrder(new String[] {"dg1", "dg2"}); + assertThat(test1.getDependsOnMethods()).containsExactlyInAnyOrder(new String[] {"dm1", "dm2"}); + assertThat(test1.getTimeOut()).isEqualTo(42); + assertThat(test1.getInvocationCount()).isEqualTo(43); + assertThat(test1.getSuccessPercentage()).isEqualTo(44); + assertThat(test1.getThreadPoolSize()).isEqualTo(3); + assertThat(test1.getDataProvider()).isEqualTo("dp"); + assertThat(test1.getDescription()).isEqualTo("Class level description"); // // Tests on MTest1SampleTest (test defaults) // ITestAnnotation test2 = m_finder.findAnnotation(MTest2.class, ITestAnnotation.class); // test default for enabled - Assert.assertTrue(test2.getEnabled()); - Assert.assertFalse(test2.getAlwaysRun()); - Assert.assertEquals(test2.getTimeOut(), 0); - Assert.assertEquals(test2.getInvocationCount(), 1); - Assert.assertEquals(test2.getSuccessPercentage(), 100); - Assert.assertEquals(test2.getDataProvider(), ""); + assertThat(test2.getEnabled()).isTrue(); + assertThat(test2.getAlwaysRun()).isFalse(); + assertThat(test2.getTimeOut()).isZero(); + assertThat(test2.getInvocationCount()).isOne(); + assertThat(test2.getSuccessPercentage()).isEqualTo(100); + assertThat(test2.getDataProvider()).isEmpty(); } public void verifyTestMethodLevel() throws SecurityException, NoSuchMethodException { @@ -61,70 +63,70 @@ public void verifyTestMethodLevel() throws SecurityException, NoSuchMethodExcept // Method method = MTest1.class.getMethod("f"); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); - Assert.assertTrue(test1.getEnabled()); - Assert.assertEqualsNoOrder( - test1.getGroups(), new String[] {"group1", "group3", "group4", "group2"}); - Assert.assertTrue(test1.getAlwaysRun()); - Assert.assertEqualsNoOrder( - test1.getDependsOnGroups(), new String[] {"dg1", "dg2", "dg3", "dg4"}); - Assert.assertEqualsNoOrder( - test1.getDependsOnMethods(), new String[] {"dm1", "dm2", "dm3", "dm4"}); - Assert.assertEquals(test1.getTimeOut(), 142); - Assert.assertEquals(test1.getInvocationCount(), 143); - Assert.assertEquals(test1.getSuccessPercentage(), 61); - Assert.assertEquals(test1.getDataProvider(), "dp2"); - Assert.assertEquals(test1.getDescription(), "Method description"); + assertThat(test1.getEnabled()).isTrue(); + assertThat(test1.getGroups()) + .containsExactlyInAnyOrder(new String[] {"group1", "group3", "group4", "group2"}); + assertThat(test1.getAlwaysRun()).isTrue(); + assertThat(test1.getDependsOnGroups()) + .containsExactlyInAnyOrder(new String[] {"dg1", "dg2", "dg3", "dg4"}); + assertThat(test1.getDependsOnMethods()) + .containsExactlyInAnyOrder(new String[] {"dm1", "dm2", "dm3", "dm4"}); + assertThat(test1.getTimeOut()).isEqualTo(142); + assertThat(test1.getInvocationCount()).isEqualTo(143); + assertThat(test1.getSuccessPercentage()).isEqualTo(61); + assertThat(test1.getDataProvider()).isEqualTo("dp2"); + assertThat(test1.getDescription()).isEqualTo("Method description"); Class[] exceptions = test1.getExpectedExceptions(); - Assert.assertEquals(exceptions.length, 1); - Assert.assertEquals(exceptions[0], NullPointerException.class); + assertThat(exceptions.length).isOne(); + assertThat(exceptions[0]).isEqualTo(NullPointerException.class); } public void verifyDataProvider() throws SecurityException, NoSuchMethodException { Method method = MTest1.class.getMethod("otherConfigurations"); IDataProviderAnnotation dataProvider = m_finder.findAnnotation(method, IDataProviderAnnotation.class); - Assert.assertNotNull(dataProvider); - Assert.assertEquals(dataProvider.getName(), "dp4"); + assertThat(dataProvider).isNotNull(); + assertThat(dataProvider.getName()).isEqualTo("dp4"); } public void verifyFactory() throws SecurityException, NoSuchMethodException { Method method = MTest1.class.getMethod("factory"); IFactoryAnnotation factory = m_finder.findAnnotation(method, IFactoryAnnotation.class); - Assert.assertNotNull(factory); + assertThat(factory).isNotNull(); } public void verifyParameters() throws SecurityException, NoSuchMethodException { Method method = MTest1.class.getMethod("parameters"); IParametersAnnotation parameters = m_finder.findAnnotation(method, IParametersAnnotation.class); - Assert.assertNotNull(parameters); - Assert.assertEquals(parameters.getValue(), new String[] {"pp1", "pp2", "pp3"}); + assertThat(parameters).isNotNull(); + assertThat(parameters.getValue()).isEqualTo(new String[] {"pp1", "pp2", "pp3"}); } public void verifyNewConfigurationBefore() throws SecurityException, NoSuchMethodException { Method method = MTest1.class.getMethod("newBefore"); IConfigurationAnnotation configuration = (IConfigurationAnnotation) m_finder.findAnnotation(method, IBeforeSuite.class); - Assert.assertNotNull(configuration); - Assert.assertTrue(configuration.getBeforeSuite()); + assertThat(configuration).isNotNull(); + assertThat(configuration.getBeforeSuite()).isTrue(); // Default values - Assert.assertTrue(configuration.getEnabled()); - Assert.assertTrue(configuration.getInheritGroups()); - Assert.assertFalse(configuration.getAlwaysRun()); + assertThat(configuration.getEnabled()).isTrue(); + assertThat(configuration.getInheritGroups()).isTrue(); + assertThat(configuration.getAlwaysRun()).isFalse(); } public void verifyNewConfigurationAfter() throws SecurityException, NoSuchMethodException { Method method = MTest1.class.getMethod("newAfter"); IConfigurationAnnotation configuration = (IConfigurationAnnotation) m_finder.findAnnotation(method, IAfterSuite.class); - Assert.assertNotNull(configuration); - Assert.assertTrue(configuration.getAfterSuite()); + assertThat(configuration).isNotNull(); + assertThat(configuration.getAfterSuite()).isTrue(); // Default values - Assert.assertTrue(configuration.getEnabled()); - Assert.assertTrue(configuration.getInheritGroups()); - Assert.assertFalse(configuration.getAlwaysRun()); + assertThat(configuration.getEnabled()).isTrue(); + assertThat(configuration.getInheritGroups()).isTrue(); + assertThat(configuration.getAlwaysRun()).isFalse(); } } diff --git a/testng-core/src/test/java/test/methodinterceptors/MethodInterceptorTest.java b/testng-core/src/test/java/test/methodinterceptors/MethodInterceptorTest.java index 31a4a7be34..383745db8b 100644 --- a/testng-core/src/test/java/test/methodinterceptors/MethodInterceptorTest.java +++ b/testng-core/src/test/java/test/methodinterceptors/MethodInterceptorTest.java @@ -1,11 +1,12 @@ package test.methodinterceptors; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.List; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.ITestResult; import org.testng.TestListenerAdapter; @@ -44,9 +45,9 @@ private void testNullInterceptor(TestNG tng) { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 0); - Assert.assertEquals(tla.getFailedTests().size(), 0); - Assert.assertEquals(tla.getSkippedTests().size(), 0); + assertThat(tla.getPassedTests()).isEmpty(); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).isEmpty(); } private void testFast(boolean useInterceptor) { @@ -60,14 +61,14 @@ private void testFast(boolean useInterceptor) { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 3); + assertThat(tla.getPassedTests()).hasSize(3); ITestResult first = tla.getPassedTests().get(0); String method = "zzzfast"; if (useInterceptor) { - Assert.assertEquals(first.getMethod().getMethodName(), method); + assertThat(first.getMethod().getMethodName()).isEqualTo(method); } else { - Assert.assertNotSame(first.getMethod().getMethodName(), method); + assertThat(first.getMethod().getMethodName()).isNotSameAs(method); } } diff --git a/testng-core/src/test/java/test/methodinterceptors/multipleinterceptors/MultipleInterceptorsTest.java b/testng-core/src/test/java/test/methodinterceptors/multipleinterceptors/MultipleInterceptorsTest.java index 9a25ba738f..41504aa907 100644 --- a/testng-core/src/test/java/test/methodinterceptors/multipleinterceptors/MultipleInterceptorsTest.java +++ b/testng-core/src/test/java/test/methodinterceptors/multipleinterceptors/MultipleInterceptorsTest.java @@ -1,7 +1,8 @@ package test.methodinterceptors.multipleinterceptors; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -19,8 +20,8 @@ public void testMultipleInterceptors() { TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); - Assert.assertEquals(tla.getPassedTests().get(0).getName(), "d"); + assertThat(tla.getPassedTests()).hasSize(1); + assertThat(tla.getPassedTests().get(0).getName()).isEqualTo("d"); } @Test @@ -33,6 +34,6 @@ public void testMultipleInterceptorsWithPreserveOrder() { TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().get(0).getMethod().getDescription(), "abc"); + assertThat(tla.getPassedTests().get(0).getMethod().getDescription()).isEqualTo("abc"); } } diff --git a/testng-core/src/test/java/test/methods/SampleMethod1.java b/testng-core/src/test/java/test/methods/SampleMethod1.java index e7e020902c..3aafdd1a7a 100644 --- a/testng-core/src/test/java/test/methods/SampleMethod1.java +++ b/testng-core/src/test/java/test/methods/SampleMethod1.java @@ -1,6 +1,6 @@ package test.methods; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -43,8 +43,9 @@ public void shouldNotRun2() { } public static void verify() { - assertTrue( - m_ok1 && m_ok2 && m_ok3 && m_ok4, - "All booleans should be true: " + m_ok1 + " " + m_ok2 + " " + m_ok3 + " " + m_ok4); + assertThat(m_ok1).withFailMessage("m_ok1 should be true").isTrue(); + assertThat(m_ok2).withFailMessage("m_ok2 should be true").isTrue(); + assertThat(m_ok3).withFailMessage("m_ok3 should be true").isTrue(); + assertThat(m_ok4).withFailMessage("m_ok4 should be true").isTrue(); } } diff --git a/testng-core/src/test/java/test/methodselectors/ClassWithManyMethodsSample.java b/testng-core/src/test/java/test/methodselectors/ClassWithManyMethodsSample.java index 47c48eae94..10e049e61d 100644 --- a/testng-core/src/test/java/test/methodselectors/ClassWithManyMethodsSample.java +++ b/testng-core/src/test/java/test/methodselectors/ClassWithManyMethodsSample.java @@ -1,24 +1,25 @@ package test.methodselectors; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; @Test(description = "GITHUB-1507") public class ClassWithManyMethodsSample { public void testa() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } public void testb() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } public void testc() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } public void testd() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/methodselectors/CommandLineTest.java b/testng-core/src/test/java/test/methodselectors/CommandLineTest.java index e6dee8263f..bbe97e1929 100644 --- a/testng-core/src/test/java/test/methodselectors/CommandLineTest.java +++ b/testng-core/src/test/java/test/methodselectors/CommandLineTest.java @@ -1,7 +1,8 @@ package test.methodselectors; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.assertj.core.api.Assertions; import org.testng.ITestResult; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -193,7 +194,7 @@ public void testSpecificTestNamesWithRegexCommandLineExclusions() { private void verifyTests(String title, String[] expected, List found) { - Assertions.assertThat(found.stream().map(ITestResult::getName).toArray(String[]::new)) + assertThat(found.stream().map(ITestResult::getName).toArray(String[]::new)) .describedAs(title) .isEqualTo(expected); } diff --git a/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java b/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java index a953bf4f42..3f7f6e378f 100644 --- a/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java +++ b/testng-core/src/test/java/test/methodselectors/MethodSelectorInSuiteTest.java @@ -1,8 +1,9 @@ package test.methodselectors; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; import java.util.List; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.ITestResult; import org.testng.TestListenerAdapter; @@ -71,10 +72,10 @@ public void fileOnCommandLine() { private void validate(String[] expectPassed) { List passed = m_tla.getPassedTests(); - Assert.assertEquals(passed.size(), expectPassed.length); + assertThat(passed).hasSameSizeAs(expectPassed); // doing this index based is probably not the best for (int i = 0; i < expectPassed.length; i++) { - Assert.assertEquals(passed.get(i).getName(), expectPassed[i]); + assertThat(passed.get(i).getName()).isEqualTo(expectPassed[i]); } } } diff --git a/testng-core/src/test/java/test/methodselectors/MethodSelectorTest.java b/testng-core/src/test/java/test/methodselectors/MethodSelectorTest.java index 6b0be2e3dc..e054e12411 100644 --- a/testng-core/src/test/java/test/methodselectors/MethodSelectorTest.java +++ b/testng-core/src/test/java/test/methodselectors/MethodSelectorTest.java @@ -1,6 +1,7 @@ package test.methodselectors; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; import test.BaseTest; import test.methodselectors.issue1985.FilteringMethodSelector; @@ -82,9 +83,9 @@ public void testNoMethodsAreExecutedWithNoMatchFound() { addIncludedMethod(className, "train_Local"); addIncludedMethod(className, "flight_Domestic"); run(); - Assert.assertTrue(getPassedTests().isEmpty()); - Assert.assertTrue(getFailedTests().isEmpty()); - Assert.assertTrue(getSkippedTests().isEmpty()); + assertThat(getPassedTests()).isEmpty(); + assertThat(getFailedTests()).isEmpty(); + assertThat(getSkippedTests()).isEmpty(); } @Test(description = "GITHUB-1985") diff --git a/testng-core/src/test/java/test/methodselectors/PriorityTest.java b/testng-core/src/test/java/test/methodselectors/PriorityTest.java index ff3d498ef3..50987402c4 100644 --- a/testng-core/src/test/java/test/methodselectors/PriorityTest.java +++ b/testng-core/src/test/java/test/methodselectors/PriorityTest.java @@ -1,7 +1,8 @@ package test.methodselectors; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.ITestResult; import org.testng.TestListenerAdapter; @@ -19,16 +20,16 @@ private void runTest(int priority, String[] passedTests) { tng.run(); List passed = tla.getPassedTests(); - Assert.assertEquals(passedTests.length, passed.size()); + assertThat(passedTests).hasSameSizeAs(passed); if (passedTests.length == 1) { String passed0 = passed.get(0).getName(); - Assert.assertEquals(passed0, passedTests[0]); + assertThat(passed0).isEqualTo(passedTests[0]); } if (passedTests.length == 2) { String passed0 = passed.get(0).getName(); String passed1 = passed.get(1).getName(); - Assert.assertTrue(passed0.equals(passedTests[0]) || passed0.equals(passedTests[1])); - Assert.assertTrue(passed1.equals(passedTests[0]) || passed1.equals(passedTests[1])); + assertThat(passed0).isIn(passedTests[0], passedTests[1]); + assertThat(passed1).isIn(passedTests[0], passedTests[1]); } } diff --git a/testng-core/src/test/java/test/multiple/Test1.java b/testng-core/src/test/java/test/multiple/Test1.java index f349b8c127..8d1e5ed049 100644 --- a/testng-core/src/test/java/test/multiple/Test1.java +++ b/testng-core/src/test/java/test/multiple/Test1.java @@ -1,6 +1,6 @@ package test.multiple; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; @@ -10,7 +10,7 @@ public class Test1 { @Test public void f1() { - assertTrue(m_count < 1, "FAILING"); + assertThat(m_count).withFailMessage("FAILING").isLessThan(1); m_count++; } diff --git a/testng-core/src/test/java/test/name/BlankNameSample.java b/testng-core/src/test/java/test/name/BlankNameSample.java index aec0bcc5e0..4080bbd15b 100644 --- a/testng-core/src/test/java/test/name/BlankNameSample.java +++ b/testng-core/src/test/java/test/name/BlankNameSample.java @@ -1,6 +1,7 @@ package test.name; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITest; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class BlankNameSample implements ITest { @Test public void test() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Override diff --git a/testng-core/src/test/java/test/name/ITestSample.java b/testng-core/src/test/java/test/name/ITestSample.java index 79c4a78776..83a385a1ca 100644 --- a/testng-core/src/test/java/test/name/ITestSample.java +++ b/testng-core/src/test/java/test/name/ITestSample.java @@ -1,6 +1,7 @@ package test.name; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITest; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -25,7 +26,7 @@ public Object[][] getTests() { @Test(dataProvider = "dp") public void run(String testName) { - Assert.assertEquals(testName, this.testName.get()); + assertThat(this.testName.get()).isEqualTo(testName); } @BeforeMethod @@ -35,7 +36,7 @@ public void init(Object[] testArgs) { @AfterMethod public void tearDown(Object[] testArgs) { - Assert.assertEquals((String) testArgs[0], this.testName.get()); + assertThat(this.testName.get()).isEqualTo((String) testArgs[0]); } @Override diff --git a/testng-core/src/test/java/test/name/NameSample.java b/testng-core/src/test/java/test/name/NameSample.java index 5bc0f34310..74ebaea192 100644 --- a/testng-core/src/test/java/test/name/NameSample.java +++ b/testng-core/src/test/java/test/name/NameSample.java @@ -1,6 +1,7 @@ package test.name; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; @Test(testName = "NAME") @@ -8,6 +9,6 @@ public class NameSample { @Test public void test() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/name/NameTest.java b/testng-core/src/test/java/test/name/NameTest.java index 829b9439b8..e1899f79bd 100644 --- a/testng-core/src/test/java/test/name/NameTest.java +++ b/testng-core/src/test/java/test/name/NameTest.java @@ -1,10 +1,10 @@ package test.name; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -21,13 +21,13 @@ public void itestTest() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), "NAME"); - Assert.assertEquals(result.getTestName(), "NAME"); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEqualTo("NAME"); + assertThat(result.getTestName()).isEqualTo("NAME"); } @Test @@ -38,13 +38,13 @@ public void itestTestWithXml() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), "NAME"); - Assert.assertEquals(result.getTestName(), "NAME"); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEqualTo("NAME"); + assertThat(result.getTestName()).isEqualTo("NAME"); } @Test @@ -55,13 +55,13 @@ public void testNameTest() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), "NAME"); - Assert.assertEquals(result.getTestName(), "NAME"); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEqualTo("NAME"); + assertThat(result.getTestName()).isEqualTo("NAME"); } @Test @@ -72,13 +72,13 @@ public void testNameTestWithXml() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), "NAME"); - Assert.assertEquals(result.getTestName(), "NAME"); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEqualTo("NAME"); + assertThat(result.getTestName()).isEqualTo("NAME"); } @Test @@ -89,13 +89,13 @@ public void noNameTest() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), "test"); - Assert.assertNull(result.getTestName()); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEqualTo("test"); + assertThat(result.getTestName()).isNull(); } @Test @@ -106,13 +106,13 @@ public void noNameTestWithXml() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), "test"); - Assert.assertNull(result.getTestName()); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEqualTo("test"); + assertThat(result.getTestName()).isNull(); } @Test @@ -123,17 +123,17 @@ public void complexITestTest() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 5); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(5); List testNames = new ArrayList<>(Arrays.asList("test1", "test2", "test3", "test4", "test5")); for (ITestResult testResult : adapter.getPassedTests()) { - Assert.assertTrue( - testNames.remove(testResult.getName()), - "Duplicate test names " + getNames(adapter.getPassedTests())); + assertThat(testNames.remove(testResult.getName())) + .withFailMessage("Duplicate test names " + getNames(adapter.getPassedTests())) + .isTrue(); } - Assert.assertEquals(testNames, Collections.emptyList()); + assertThat(testNames).isEmpty(); } private static List getNames(List results) { @@ -152,12 +152,12 @@ public void testOnClassFromReporter() { tng.run(); - Assert.assertEquals(listener.getNames().size(), 1); - Assert.assertEquals(listener.getNames().get(0), "test"); + assertThat(listener.getNames()).hasSize(1); + assertThat(listener.getNames().get(0)).isEqualTo("test"); // testName should be ignored if not specified - Assert.assertEquals(listener.getTestNames().size(), 1); - Assert.assertNull(listener.getTestNames().get(0)); + assertThat(listener.getTestNames()).hasSize(1); + assertThat(listener.getTestNames().get(0)).isNull(); } @Test @@ -168,13 +168,13 @@ public void blankNameTest() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), ""); - Assert.assertEquals(result.getTestName(), ""); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEmpty(); + assertThat(result.getTestName()).isEmpty(); } @Test @@ -185,12 +185,12 @@ public void blankNameTestWithXml() { tng.run(); - Assert.assertTrue(adapter.getFailedTests().isEmpty()); - Assert.assertTrue(adapter.getSkippedTests().isEmpty()); - Assert.assertEquals(adapter.getPassedTests().size(), 1); + assertThat(adapter.getFailedTests()).isEmpty(); + assertThat(adapter.getSkippedTests()).isEmpty(); + assertThat(adapter.getPassedTests()).hasSize(1); ITestResult result = adapter.getPassedTests().get(0); - Assert.assertEquals(result.getMethod().getMethodName(), "test"); - Assert.assertEquals(result.getName(), ""); - Assert.assertEquals(result.getTestName(), ""); + assertThat(result.getMethod().getMethodName()).isEqualTo("test"); + assertThat(result.getName()).isEmpty(); + assertThat(result.getTestName()).isEmpty(); } } diff --git a/testng-core/src/test/java/test/name/NoNameSample.java b/testng-core/src/test/java/test/name/NoNameSample.java index 66d397ee61..3c610270a6 100644 --- a/testng-core/src/test/java/test/name/NoNameSample.java +++ b/testng-core/src/test/java/test/name/NoNameSample.java @@ -1,12 +1,13 @@ package test.name; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class NoNameSample { @Test public void test() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/name/SimpleITestSample.java b/testng-core/src/test/java/test/name/SimpleITestSample.java index 14edf13d5e..14646c5658 100644 --- a/testng-core/src/test/java/test/name/SimpleITestSample.java +++ b/testng-core/src/test/java/test/name/SimpleITestSample.java @@ -1,6 +1,7 @@ package test.name; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITest; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class SimpleITestSample implements ITest { @Test public void test() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Override diff --git a/testng-core/src/test/java/test/name/github1046/TestClassSample.java b/testng-core/src/test/java/test/name/github1046/TestClassSample.java index 75325d36c6..bf33839fb3 100644 --- a/testng-core/src/test/java/test/name/github1046/TestClassSample.java +++ b/testng-core/src/test/java/test/name/github1046/TestClassSample.java @@ -1,6 +1,6 @@ package test.name.github1046; -import static org.testng.Assert.assertNotEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.IHookCallBack; import org.testng.IHookable; @@ -17,12 +17,12 @@ public Object[][] getTestData() { @Test(dataProvider = "dp") public void testSample1(int num) { - assertNotEquals(num, 0); + assertThat(num).isNotZero(); } @Test(dataProvider = "dp") public void testSample2(int num) { - assertNotEquals(num, 0); + assertThat(num).isNotZero(); } @Test diff --git a/testng-core/src/test/java/test/name/github1046/TestCustomNamesForTests.java b/testng-core/src/test/java/test/name/github1046/TestCustomNamesForTests.java index 8d13873891..8f1cabd989 100644 --- a/testng-core/src/test/java/test/name/github1046/TestCustomNamesForTests.java +++ b/testng-core/src/test/java/test/name/github1046/TestCustomNamesForTests.java @@ -1,8 +1,9 @@ package test.name.github1046; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.Set; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.collections.Sets; @@ -25,6 +26,6 @@ public void testCustomTestNames() { } expectedNames.add("ordinaryTestMethod_TestNG_TestCase_999"); expectedNames.add("dontChangeName"); - Assert.assertEqualsNoOrder(reporter.getTestnames(), expectedNames); + assertThat(reporter.getTestnames()).hasSameElementsAs(expectedNames); } } diff --git a/testng-core/src/test/java/test/nested/GarfTest.java b/testng-core/src/test/java/test/nested/GarfTest.java index 8005050ae2..70ffbb3ad2 100644 --- a/testng-core/src/test/java/test/nested/GarfTest.java +++ b/testng-core/src/test/java/test/nested/GarfTest.java @@ -1,6 +1,7 @@ package test.nested; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; import test.nested.foo.AccountTypeEnum; @@ -10,6 +11,6 @@ public class GarfTest { @Test() public void testGarf() { AccountTypeEnum foo = AccountTypeEnum.ClearingMember; - Assert.assertEquals(foo, AccountTypeEnum.ClearingMember); + assertThat(foo).isEqualTo(AccountTypeEnum.ClearingMember); } } diff --git a/testng-core/src/test/java/test/objectfactory/ClassObjectFactorySampleTest.java b/testng-core/src/test/java/test/objectfactory/ClassObjectFactorySampleTest.java index 0682494614..ae713fad29 100644 --- a/testng-core/src/test/java/test/objectfactory/ClassObjectFactorySampleTest.java +++ b/testng-core/src/test/java/test/objectfactory/ClassObjectFactorySampleTest.java @@ -1,6 +1,7 @@ package test.objectfactory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class ClassObjectFactorySampleTest implements ISetValue { @@ -9,7 +10,7 @@ public class ClassObjectFactorySampleTest implements ISetValue { @Test public void f() { - Assert.assertEquals(m_n, 42); + assertThat(m_n).isEqualTo(42); } @Override diff --git a/testng-core/src/test/java/test/objectfactory/CombinedTestAndObjectFactorySample.java b/testng-core/src/test/java/test/objectfactory/CombinedTestAndObjectFactorySample.java index a86a9cd040..f51066b72a 100644 --- a/testng-core/src/test/java/test/objectfactory/CombinedTestAndObjectFactorySample.java +++ b/testng-core/src/test/java/test/objectfactory/CombinedTestAndObjectFactorySample.java @@ -1,7 +1,8 @@ package test.objectfactory; +import static org.assertj.core.api.Assertions.assertThat; + import java.lang.reflect.Constructor; -import org.testng.Assert; import org.testng.ITestObjectFactory; import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; @@ -18,7 +19,9 @@ public ITestObjectFactory create() { @Test public void isConfigured() { - Assert.assertTrue(configured, "Should have been configured by object factory"); + assertThat(configured) + .withFailMessage("Should have been configured by object factory") + .isTrue(); } @Override diff --git a/testng-core/src/test/java/test/objectfactory/ContextAwareObjectFactoryFactory.java b/testng-core/src/test/java/test/objectfactory/ContextAwareObjectFactoryFactory.java index 4e4136b860..b0603740a2 100644 --- a/testng-core/src/test/java/test/objectfactory/ContextAwareObjectFactoryFactory.java +++ b/testng-core/src/test/java/test/objectfactory/ContextAwareObjectFactoryFactory.java @@ -1,6 +1,6 @@ package test.objectfactory; -import static org.testng.Assert.assertNotNull; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.ITestContext; import org.testng.ITestObjectFactory; @@ -13,7 +13,7 @@ public class ContextAwareObjectFactoryFactory { @ObjectFactory public ITestObjectFactory create(ITestContext context) { - assertNotNull(context); + assertThat(context).isNotNull(); invoked++; return new ObjectFactoryImpl(); } diff --git a/testng-core/src/test/java/test/objectfactory/CustomFactoryTest.java b/testng-core/src/test/java/test/objectfactory/CustomFactoryTest.java index 2422c2fc1a..a1346a3618 100644 --- a/testng-core/src/test/java/test/objectfactory/CustomFactoryTest.java +++ b/testng-core/src/test/java/test/objectfactory/CustomFactoryTest.java @@ -1,6 +1,7 @@ package test.objectfactory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.TestNGException; import org.testng.annotations.BeforeMethod; @@ -21,7 +22,7 @@ public void setFactoryOnTestNG() { tng.setObjectFactory(LoggingObjectFactory.class); tng.run(); - Assert.assertEquals(LoggingObjectFactory.invoked, 1); + assertThat(LoggingObjectFactory.invoked).isOne(); } @Test @@ -31,7 +32,7 @@ public void setFactoryOnSuite() { TestNG tng = create(suite); tng.run(); - Assert.assertEquals(LoggingObjectFactory.invoked, 1); + assertThat(LoggingObjectFactory.invoked).isOne(); } @Test(description = "This broke after I made the change to enable AbstractTest") @@ -42,7 +43,7 @@ public void setFactoryByAnnotation() { TestNG tng = create(suite); tng.run(); - Assert.assertEquals(LoggingObjectFactory.invoked, 1); + assertThat(LoggingObjectFactory.invoked).isOne(); } @Test @@ -54,7 +55,7 @@ public void factoryReceivesContext() { TestNG tng = create(suite); tng.run(); - Assert.assertEquals(ContextAwareObjectFactoryFactory.invoked, 1); + assertThat(ContextAwareObjectFactoryFactory.invoked).isOne(); } @Test(expectedExceptions = TestNGException.class) diff --git a/testng-core/src/test/java/test/objectfactory/ObjectFactory2Test.java b/testng-core/src/test/java/test/objectfactory/ObjectFactory2Test.java index 32e7720c4c..d3615bc2fc 100644 --- a/testng-core/src/test/java/test/objectfactory/ObjectFactory2Test.java +++ b/testng-core/src/test/java/test/objectfactory/ObjectFactory2Test.java @@ -1,6 +1,7 @@ package test.objectfactory; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; @@ -24,7 +25,7 @@ private void testFactory(boolean onSuite) { tng.run(); - Assert.assertEquals(ClassObjectFactorySampleTest.m_n, 42); + assertThat(ClassObjectFactorySampleTest.m_n).isEqualTo(42); } @Test diff --git a/testng-core/src/test/java/test/objectfactory/github1827/GitHub1827Sample.java b/testng-core/src/test/java/test/objectfactory/github1827/GitHub1827Sample.java index 7d5aaec3fd..2f52be7cb0 100644 --- a/testng-core/src/test/java/test/objectfactory/github1827/GitHub1827Sample.java +++ b/testng-core/src/test/java/test/objectfactory/github1827/GitHub1827Sample.java @@ -1,6 +1,6 @@ package test.objectfactory.github1827; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -14,6 +14,6 @@ public GitHub1827Sample(int value) { @Test public void test() { - assertEquals(value, 1); + assertThat(value).isOne(); } } diff --git a/testng-core/src/test/java/test/override/OverrideTest.java b/testng-core/src/test/java/test/override/OverrideTest.java index 8b6b3670e6..469e0c3a4a 100644 --- a/testng-core/src/test/java/test/override/OverrideTest.java +++ b/testng-core/src/test/java/test/override/OverrideTest.java @@ -1,11 +1,12 @@ package test.override; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Collections; -import org.testng.Assert; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.TestNGException; @@ -54,7 +55,7 @@ private void runTest(String include, String exclude) { tng.setTestSuites(Collections.singletonList(f.getAbsolutePath())); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); } @Test(description = "Override -groups") diff --git a/testng-core/src/test/java/test/parameters/BeforeWithParameterSample.java b/testng-core/src/test/java/test/parameters/BeforeWithParameterSample.java index e5c503f303..865952c97e 100644 --- a/testng-core/src/test/java/test/parameters/BeforeWithParameterSample.java +++ b/testng-core/src/test/java/test/parameters/BeforeWithParameterSample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Parameters; @@ -11,7 +12,7 @@ public class BeforeWithParameterSample { @BeforeMethod @Parameters("parameter") public static void beforeMethod(String parameter) { - Assert.assertEquals(parameter, "parameter value"); + assertThat(parameter).isEqualTo("parameter value"); } @DataProvider(name = "dataProvider") @@ -21,7 +22,7 @@ public static Object[][] dataProvider() { @Test(dataProvider = "dataProvider") public static void testExample(String a, String b) { - Assert.assertEquals(a, "abc"); - Assert.assertEquals(b, "def"); + assertThat(a).isEqualTo("abc"); + assertThat(b).isEqualTo("def"); } } diff --git a/testng-core/src/test/java/test/parameters/EnumParameterSample.java b/testng-core/src/test/java/test/parameters/EnumParameterSample.java index 662fb97576..61cc6934ae 100644 --- a/testng-core/src/test/java/test/parameters/EnumParameterSample.java +++ b/testng-core/src/test/java/test/parameters/EnumParameterSample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -14,6 +15,6 @@ public enum MyEnum { @Test @Parameters("parameter") public void testMethod(MyEnum parameter) { - Assert.assertNotNull(parameter); + assertThat(parameter).isNotNull(); } } diff --git a/testng-core/src/test/java/test/parameters/InheritFromSuiteChild1.java b/testng-core/src/test/java/test/parameters/InheritFromSuiteChild1.java index c4d8d0a8fe..4c384ba1f8 100644 --- a/testng-core/src/test/java/test/parameters/InheritFromSuiteChild1.java +++ b/testng-core/src/test/java/test/parameters/InheritFromSuiteChild1.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -14,9 +15,9 @@ public class InheritFromSuiteChild1 { @Test @Parameters({"parameter1", "parameter2", "parameter3", "parameter4"}) public void inheritedParameter(String p1, String p2, @Optional("foobar") String p3, String p4) { - Assert.assertEquals(p1, "p1"); - Assert.assertEquals(p2, "c1p2"); - Assert.assertEquals(p3, "foobar"); - Assert.assertEquals(p4, "c1p4"); + assertThat(p1).isEqualTo("p1"); + assertThat(p2).isEqualTo("c1p2"); + assertThat(p3).isEqualTo("foobar"); + assertThat(p4).isEqualTo("c1p4"); } } diff --git a/testng-core/src/test/java/test/parameters/InheritFromSuiteChild2.java b/testng-core/src/test/java/test/parameters/InheritFromSuiteChild2.java index 7e73276f4a..6b16b463d5 100644 --- a/testng-core/src/test/java/test/parameters/InheritFromSuiteChild2.java +++ b/testng-core/src/test/java/test/parameters/InheritFromSuiteChild2.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -13,9 +14,9 @@ public class InheritFromSuiteChild2 { @Test @Parameters({"parameter1", "parameter2", "parameter3", "parameter4"}) public void inheritedParameter(String p1, String p2, String p3, @Optional("abc") String p4) { - Assert.assertEquals(p1, "p1"); - Assert.assertEquals(p2, "c2p2"); - Assert.assertEquals(p3, "c2p3"); - Assert.assertEquals(p4, "abc"); + assertThat(p1).isEqualTo("p1"); + assertThat(p2).isEqualTo("c2p2"); + assertThat(p3).isEqualTo("c2p3"); + assertThat(p4).isEqualTo("abc"); } } diff --git a/testng-core/src/test/java/test/parameters/InheritFromSuiteChild3.java b/testng-core/src/test/java/test/parameters/InheritFromSuiteChild3.java index 9319bd815b..273c30ca1d 100644 --- a/testng-core/src/test/java/test/parameters/InheritFromSuiteChild3.java +++ b/testng-core/src/test/java/test/parameters/InheritFromSuiteChild3.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -12,9 +13,9 @@ public class InheritFromSuiteChild3 { @Test @Parameters({"parameter1", "parameter2", "parameter3", "parameter4"}) public void inheritedParameter(String p1, String p2, String p3, String p4) { - Assert.assertEquals(p1, "p1"); - Assert.assertEquals(p2, "c3p2"); - Assert.assertEquals(p3, "c2p3"); - Assert.assertEquals(p4, "c3p4"); + assertThat(p1).isEqualTo("p1"); + assertThat(p2).isEqualTo("c3p2"); + assertThat(p3).isEqualTo("c2p3"); + assertThat(p4).isEqualTo("c3p4"); } } diff --git a/testng-core/src/test/java/test/parameters/Issue1554TestClassSample.java b/testng-core/src/test/java/test/parameters/Issue1554TestClassSample.java index cb4dc11aab..4bcba30588 100644 --- a/testng-core/src/test/java/test/parameters/Issue1554TestClassSample.java +++ b/testng-core/src/test/java/test/parameters/Issue1554TestClassSample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestContext; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; @@ -19,7 +20,7 @@ public void setUpTest(String browser, ITestContext context) { @Test() public void aTest() { - Assert.assertNotNull(browser); - Assert.assertNotNull(context); + assertThat(browser).isNotNull(); + assertThat(context).isNotNull(); } } diff --git a/testng-core/src/test/java/test/parameters/Override1Sample.java b/testng-core/src/test/java/test/parameters/Override1Sample.java index 1a37000acc..163124f425 100644 --- a/testng-core/src/test/java/test/parameters/Override1Sample.java +++ b/testng-core/src/test/java/test/parameters/Override1Sample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -9,15 +10,15 @@ public class Override1Sample { @Parameters({"InheritedFromSuite", "InheritedFromTest", "InheritedFromClass"}) public void g(String suite, String test, String cls) { - Assert.assertEquals(suite, "InheritedFromSuite"); - Assert.assertEquals(test, "InheritedFromTest"); - Assert.assertEquals(cls, "InheritedFromClass"); + assertThat(suite).isEqualTo("InheritedFromSuite"); + assertThat(test).isEqualTo("InheritedFromTest"); + assertThat(cls).isEqualTo("InheritedFromClass"); } public void h() {} @Parameters("a") public void f(String p) { - Assert.assertEquals(p, "Correct"); + assertThat(p).isEqualTo("Correct"); } } diff --git a/testng-core/src/test/java/test/parameters/ParamInheritanceTest.java b/testng-core/src/test/java/test/parameters/ParamInheritanceTest.java index a8e7c061db..06f8aa9f2e 100644 --- a/testng-core/src/test/java/test/parameters/ParamInheritanceTest.java +++ b/testng-core/src/test/java/test/parameters/ParamInheritanceTest.java @@ -1,11 +1,12 @@ package test.parameters; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.List; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -41,7 +42,7 @@ public void noNPEInCountingResults() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); } finally { try { os.close(); @@ -63,6 +64,6 @@ public void parameterInheritanceAndOverriding() { tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 3); + assertThat(tla.getPassedTests()).hasSize(3); } } diff --git a/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionSample.java b/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionSample.java index 2c00e47e89..045ab1b74a 100644 --- a/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionSample.java +++ b/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionSample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestContext; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Optional; @@ -14,12 +15,12 @@ public class ParameterInjectAndOptionSample { @Parameters({"beforesuitedata"}) public void beforeSuite( ITestContext context, @Optional("optionalbeforesuitedata") String beforesuitedata) { - Assert.assertEquals(beforesuitedata, "optionalbeforesuitedata"); + assertThat(beforesuitedata).isEqualTo("optionalbeforesuitedata"); } @Test @Parameters({"testdata"}) public void test(XmlTest xmlTest, @Optional("optionaltestdata") String testdata) { - Assert.assertEquals(testdata, "optionaltestdata"); + assertThat(testdata).isEqualTo("optionaltestdata"); } } diff --git a/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionTest.java b/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionTest.java index 1d8b00d111..6665a78f37 100644 --- a/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionTest.java +++ b/testng-core/src/test/java/test/parameters/ParameterInjectAndOptionTest.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -15,6 +16,6 @@ public void test() { TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); } } diff --git a/testng-core/src/test/java/test/parameters/ParameterSample.java b/testng-core/src/test/java/test/parameters/ParameterSample.java index 172b998766..b1f8e191bd 100644 --- a/testng-core/src/test/java/test/parameters/ParameterSample.java +++ b/testng-core/src/test/java/test/parameters/ParameterSample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; @@ -11,13 +12,13 @@ public class ParameterSample { @Parameters({"first-name"}) @BeforeMethod public void beforeTest(String firstName) { - Assert.assertEquals(firstName, "Cedric"); + assertThat(firstName).isEqualTo("Cedric"); } @Parameters({"first-name"}) @Test(groups = {"singleString"}) public void testSingleString(String firstName) { - Assert.assertEquals(firstName, "Cedric"); + assertThat(firstName).isEqualTo("Cedric"); } @Parameters({"this parameter doesn't exist"}) diff --git a/testng-core/src/test/java/test/parameters/ParameterTest.java b/testng-core/src/test/java/test/parameters/ParameterTest.java index 8f43d40036..b4b9a5f00e 100644 --- a/testng-core/src/test/java/test/parameters/ParameterTest.java +++ b/testng-core/src/test/java/test/parameters/ParameterTest.java @@ -108,7 +108,7 @@ public void testNativeInjection() { TestListenerAdapter listener = new TestListenerAdapter(); testng.addListener(listener); testng.run(); - assertThat(listener.getFailedTests().size()).isEqualTo(2); + assertThat(listener.getFailedTests()).hasSize(2); String[] expectedMsgs = new String[] { "Method test.parameters.Issue1061Sample.test() didn't finish within the time-out 1000", @@ -132,7 +132,7 @@ public void testNativeInjectionAndParamsInjection() { TestListenerAdapter listener = new TestListenerAdapter(); testng.addListener(listener); testng.run(); - assertThat(listener.getPassedTests().isEmpty()).isFalse(); + assertThat(listener.getPassedTests()).isNotEmpty(); } @Test(description = "GITHUB-581") diff --git a/testng-core/src/test/java/test/parameters/ParametersPackageLevelMethodTest.java b/testng-core/src/test/java/test/parameters/ParametersPackageLevelMethodTest.java index a5af769343..a8e8f2e623 100644 --- a/testng-core/src/test/java/test/parameters/ParametersPackageLevelMethodTest.java +++ b/testng-core/src/test/java/test/parameters/ParametersPackageLevelMethodTest.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -16,6 +17,6 @@ public void test() { TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 1); + assertThat(tla.getPassedTests()).hasSize(1); } } diff --git a/testng-core/src/test/java/test/parameters/Shadow1Sample.java b/testng-core/src/test/java/test/parameters/Shadow1Sample.java index 7ce91b8f23..5a809730d1 100644 --- a/testng-core/src/test/java/test/parameters/Shadow1Sample.java +++ b/testng-core/src/test/java/test/parameters/Shadow1Sample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -9,6 +10,6 @@ public class Shadow1Sample { @Parameters("a") @Test public void test1(String a) { - Assert.assertEquals(a, "First"); + assertThat(a).isEqualTo("First"); } } diff --git a/testng-core/src/test/java/test/parameters/Shadow2Sample.java b/testng-core/src/test/java/test/parameters/Shadow2Sample.java index cca3322b44..bfa18ae1fc 100644 --- a/testng-core/src/test/java/test/parameters/Shadow2Sample.java +++ b/testng-core/src/test/java/test/parameters/Shadow2Sample.java @@ -1,6 +1,7 @@ package test.parameters; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -9,6 +10,6 @@ public class Shadow2Sample { @Parameters("a") @Test public void test2(String a) { - Assert.assertEquals(a, "Second"); + assertThat(a).isEqualTo("Second"); } } diff --git a/testng-core/src/test/java/test/parameters/issue2238/ExampleTestCase.java b/testng-core/src/test/java/test/parameters/issue2238/ExampleTestCase.java index c38e38ae92..3cd614dae5 100644 --- a/testng-core/src/test/java/test/parameters/issue2238/ExampleTestCase.java +++ b/testng-core/src/test/java/test/parameters/issue2238/ExampleTestCase.java @@ -1,6 +1,7 @@ package test.parameters.issue2238; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -10,6 +11,6 @@ public class ExampleTestCase { @Parameters("value") public void testMethod(int value) { int expected = Integer.parseInt(System.getProperty("value")); - Assert.assertEquals(value, expected); + assertThat(value).isEqualTo(expected); } } diff --git a/testng-core/src/test/java/test/pkg/PackageTest.java b/testng-core/src/test/java/test/pkg/PackageTest.java index 04d9bb626a..c965064cc9 100644 --- a/testng-core/src/test/java/test/pkg/PackageTest.java +++ b/testng-core/src/test/java/test/pkg/PackageTest.java @@ -1,6 +1,6 @@ package test.pkg; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; import test.BaseTest; @@ -32,7 +32,9 @@ public void stringSingle() { public void packageWithNonTestClasses() { addPackage("test.pkg2", new String[0], new String[0]); run(); - assertTrue(!NON_TEST_CONSTRUCTOR, Test2.class.getName() + " should not be considered"); + assertThat(!NON_TEST_CONSTRUCTOR) + .withFailMessage(Test2.class.getName() + " should not be considered") + .isTrue(); } @Test diff --git a/testng-core/src/test/java/test/preserveorder/ClassSample.java b/testng-core/src/test/java/test/preserveorder/ClassSample.java index f46ff1b014..5553bc596c 100644 --- a/testng-core/src/test/java/test/preserveorder/ClassSample.java +++ b/testng-core/src/test/java/test/preserveorder/ClassSample.java @@ -8,7 +8,8 @@ */ package test.preserveorder; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class ClassSample { @@ -21,6 +22,6 @@ public ClassSample(int val) { @Test public void checkVal() { - Assert.assertTrue(this.val != 0); + assertThat(this.val).isNotZero(); } } diff --git a/testng-core/src/test/java/test/preserveorder/Issue1122Sample.java b/testng-core/src/test/java/test/preserveorder/Issue1122Sample.java index 13431185ab..a3d3e96ebe 100644 --- a/testng-core/src/test/java/test/preserveorder/Issue1122Sample.java +++ b/testng-core/src/test/java/test/preserveorder/Issue1122Sample.java @@ -1,6 +1,7 @@ package test.preserveorder; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestContext; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; @@ -9,7 +10,7 @@ public class Issue1122Sample { @Test public void test(ITestContext context) { - Assert.assertEquals( - context.getCurrentXmlTest().getPreserveOrder(), XmlSuite.DEFAULT_PRESERVE_ORDER); + assertThat(context.getCurrentXmlTest().getPreserveOrder()) + .isEqualTo(XmlSuite.DEFAULT_PRESERVE_ORDER); } } diff --git a/testng-core/src/test/java/test/preserveorder/PreserveOrderTest.java b/testng-core/src/test/java/test/preserveorder/PreserveOrderTest.java index dec3343afc..bb5c13b60e 100644 --- a/testng-core/src/test/java/test/preserveorder/PreserveOrderTest.java +++ b/testng-core/src/test/java/test/preserveorder/PreserveOrderTest.java @@ -4,7 +4,6 @@ import java.util.Iterator; import java.util.List; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestNG; import org.testng.annotations.DataProvider; @@ -46,7 +45,7 @@ public void preserveClassOrder(Class[] tests) { for (Class testClass : tests) { for (int i = 1; i <= 3; i++) { String methodName = methods.next(); - Assert.assertEquals(methodName, testClass.getSimpleName().toLowerCase() + i); + assertThat(methodName).isEqualTo(testClass.getSimpleName().toLowerCase() + i); } } } diff --git a/testng-core/src/test/java/test/priority/SampleTest01.java b/testng-core/src/test/java/test/priority/SampleTest01.java index 6bcb93b2fe..8ef79a173a 100644 --- a/testng-core/src/test/java/test/priority/SampleTest01.java +++ b/testng-core/src/test/java/test/priority/SampleTest01.java @@ -1,6 +1,7 @@ package test.priority; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class SampleTest01 extends SampleTestBase { @@ -13,30 +14,30 @@ public void test0010_createAction() { priority = 2, dependsOnMethods = {"test0010_createAction"}) public void test0020_simpleSearch() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 3) public void test0030_advancedSearch() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test( priority = 4, dependsOnMethods = {"test0010_createAction"}) public void test0040_viewAction() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test( priority = 5, dependsOnMethods = {"test0010_createAction"}) public void test0050_modifyAction() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 6) public void test0060_deleteAction() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/priority/SampleTest02.java b/testng-core/src/test/java/test/priority/SampleTest02.java index 75fd54f1ed..aa2aaade3e 100644 --- a/testng-core/src/test/java/test/priority/SampleTest02.java +++ b/testng-core/src/test/java/test/priority/SampleTest02.java @@ -1,43 +1,44 @@ package test.priority; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class SampleTest02 extends SampleTestBase { @Test(priority = 1) public void test0210_createAction() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test( priority = 2, dependsOnMethods = {"test0210_createAction"}) public void test0220_simpleSearch() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 3) public void test0230_advancedSearch() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test( priority = 4, dependsOnMethods = {"test0210_createAction"}) public void test0240_viewAction() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test( priority = 5, dependsOnMethods = {"test0210_createAction"}) public void test0250_modifyAction() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test(priority = 6) public void test0260_deleteAction() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest.java b/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest.java index 2b31420a44..c5d98a151f 100644 --- a/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest.java +++ b/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest.java @@ -1,6 +1,6 @@ package test.priority.parallel; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.*; import java.util.HashMap; @@ -136,45 +136,48 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " + SUITE_A + ": " + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " + SUITE_A + ": " + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 12, - "There should 12 test method level events logged for " - + SUITE_A - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 12, - "There should be 12 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteLevelEventLogs) + .hasSize(2); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + SUITE_A + ": " + testLevelEventLogs) + .hasSize(4); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 12 test method level events logged for " + + SUITE_A + + ": " + + testMethodLevelEventLogs) + .hasSize(12); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(4); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 12 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(12); } // Verify that the suites run in parallel by checking that the suite and test level events for diff --git a/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest2.java b/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest2.java index 4521125644..13c1aab050 100644 --- a/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest2.java +++ b/testng-core/src/test/java/test/priority/parallel/EfficientPriorityParallelizationTest2.java @@ -1,7 +1,6 @@ package test.priority.parallel; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; import static test.thread.parallelization.TestNgRunStateTracker.*; import java.util.HashMap; @@ -117,45 +116,48 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " + SUITE_A + ": " + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " + SUITE_A + ": " + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 12, - "There should 12 test method level events logged for " - + SUITE_A - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 12, - "There should be 12 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteLevelEventLogs) + .hasSize(2); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + SUITE_A + ": " + testLevelEventLogs) + .hasSize(2); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 12 test method level events logged for " + + SUITE_A + + ": " + + testMethodLevelEventLogs) + .hasSize(12); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 12 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(12); } // Verify that the suites run in parallel by checking that the suite and test level events for diff --git a/testng-core/src/test/java/test/privatemethod/PrivateMethodTest.java b/testng-core/src/test/java/test/privatemethod/PrivateMethodTest.java index 71a3fdfc8e..0696709bca 100644 --- a/testng-core/src/test/java/test/privatemethod/PrivateMethodTest.java +++ b/testng-core/src/test/java/test/privatemethod/PrivateMethodTest.java @@ -1,6 +1,7 @@ package test.privatemethod; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class PrivateMethodTest { @@ -16,7 +17,7 @@ public void testPrivateMethod() { PrivateMethodTest pmt = new PrivateMethodTest("aname", 1); int returnValue = pmt.privateMethod(); - Assert.assertEquals(returnValue, 1); + assertThat(returnValue).isOne(); } } } diff --git a/testng-core/src/test/java/test/reflect/ReflectionRecipesTest.java b/testng-core/src/test/java/test/reflect/ReflectionRecipesTest.java index 320284dfc0..6f8ec3d811 100644 --- a/testng-core/src/test/java/test/reflect/ReflectionRecipesTest.java +++ b/testng-core/src/test/java/test/reflect/ReflectionRecipesTest.java @@ -2,6 +2,7 @@ import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static org.assertj.core.api.Assertions.assertThat; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -12,7 +13,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.testng.Assert; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.TestRunner; @@ -76,10 +76,10 @@ public Object[][] exactMatchDP() if (annotation != null) { final String provider = annotation.expectationProvider(); final int flag = annotation.flag(); - Assert.assertNotNull(provider); + assertThat(provider).isNotNull(); final Method providerMethod = ExactMatchTest.class.getMethod(provider, int.class); final Object out = providerMethod.invoke(ExactMatchTest.class, flag); - Assert.assertTrue(out instanceof Object[][]); + assertThat(out).isInstanceOf(Object[][].class); log.debug(method.getName() + ", " + out); objects.add(new Object[] {out, method}); } @@ -100,10 +100,10 @@ public Object[][] matchArrayEndingDP() if (annotation != null) { final String provider = annotation.expectationProvider(); final int flag = annotation.flag(); - Assert.assertNotNull(provider); + assertThat(provider).isNotNull(); final Method providerMethod = MatchArrayEndingTest.class.getMethod(provider, int.class); final Object out = providerMethod.invoke(MatchArrayEndingTest.class, flag); - Assert.assertTrue(out instanceof Object[][]); + assertThat(out).isInstanceOf(Object[][].class); log.debug(method.getName() + ", " + out); objects.add(new Object[] {out, method}); } @@ -127,21 +127,17 @@ public Object[][] notTestContexts() { public void matchArrayEndingTest(final Object[][] expected, @NoInjection final Method method) { if (expected != null) { final Parameter[] methodParameters = ReflectionRecipes.getMethodParameters(method); - Assert.assertNotNull(methodParameters); + assertThat(methodParameters).isNotNull(); final Parameter[] filteredParameters = ReflectionRecipes.filter(methodParameters, InjectableParameter.Assistant.ALL_INJECTS); - Assert.assertNotNull(filteredParameters); + assertThat(filteredParameters).isNotNull(); for (final Object[] expect : expected) { - Assert.assertNotNull(expect); - Assert.assertEquals(expect.length, 2); - Assert.assertNotNull(expect[0]); - Assert.assertTrue(expect[0] instanceof Object[]); - Assert.assertNotNull(expect[1]); - Assert.assertTrue(expect[1] instanceof Boolean); - Assert.assertEquals( - ReflectionRecipes.matchArrayEnding(filteredParameters, (Object[]) expect[0]), - expect[1]); + assertThat(expect).hasSize(2); + assertThat(expect[0]).isInstanceOf(Object[].class); + assertThat(expect[1]).isInstanceOf(Boolean.class); + assertThat(ReflectionRecipes.matchArrayEnding(filteredParameters, (Object[]) expect[0])) + .isEqualTo(expect[1]); } } } @@ -150,20 +146,17 @@ public void matchArrayEndingTest(final Object[][] expected, @NoInjection final M public void exactMatchTest(final Object[][] expected, @NoInjection final Method method) { if (expected != null) { final Parameter[] methodParameters = ReflectionRecipes.getMethodParameters(method); - Assert.assertNotNull(methodParameters); + assertThat(methodParameters).isNotNull(); final Parameter[] filteredParameters = ReflectionRecipes.filter(methodParameters, InjectableParameter.Assistant.ALL_INJECTS); - Assert.assertNotNull(filteredParameters); + assertThat(filteredParameters).isNotNull(); for (final Object[] expect : expected) { - Assert.assertNotNull(expect); - Assert.assertEquals(expect.length, 2); - Assert.assertNotNull(expect[0]); - Assert.assertTrue(expect[0] instanceof Object[]); - Assert.assertNotNull(expect[1]); - Assert.assertTrue(expect[1] instanceof Boolean); - Assert.assertEquals( - ReflectionRecipes.exactMatch(filteredParameters, (Object[]) expect[0]), expect[1]); + assertThat(expect).hasSize(2); + assertThat(expect[0]).isInstanceOf(Object[].class); + assertThat(expect[1]).isInstanceOf(Boolean.class); + assertThat(ReflectionRecipes.exactMatch(filteredParameters, (Object[]) expect[0])) + .isEqualTo(expect[1]); } } } @@ -174,9 +167,9 @@ public void testFilters(final Parameter[] parameters) { final Parameter[] parameters1 = ReflectionRecipes.filter(parameters, InjectableParameter.Assistant.ALL_INJECTS); log.debug("Out: " + Arrays.asList(parameters1)); - Assert.assertEquals(parameters1.length, 2); - Assert.assertEquals(parameters1[0].getType(), int.class); - Assert.assertEquals(parameters1[1].getType(), Boolean.class); + assertThat(parameters1).hasSize(2); + assertThat(parameters1[0].getType()).isEqualTo(int.class); + assertThat(parameters1[1].getType()).isEqualTo(Boolean.class); } @Test(dataProvider = "methodInputParamArgsPair") @@ -187,17 +180,17 @@ public void testInject(final Parameter[] parameters, final Object[] args) { ReflectionRecipes.inject( parameters, InjectableParameter.Assistant.ALL_INJECTS, args, (Method) null, null, null); log.debug("injectedArgs: " + Arrays.asList(injectedArgs)); - Assert.assertEquals(injectedArgs.length, parameters.length); + assertThat(injectedArgs).hasSameSizeAs(parameters); } @Test(dataProvider = "testContexts") public void testIsOrImplementsInterface(final Class clazz) { - Assert.assertTrue(ReflectionRecipes.isOrImplementsInterface(ITestContext.class, clazz)); + assertThat(ReflectionRecipes.isOrImplementsInterface(ITestContext.class, clazz)).isTrue(); } @Test(dataProvider = "notTestContexts") public void testNegativeCaseIsOrImplementsInterface(final Class clazz) { - Assert.assertFalse(ReflectionRecipes.isOrImplementsInterface(ITestContext.class, clazz)); + assertThat(ReflectionRecipes.isOrImplementsInterface(ITestContext.class, clazz)).isFalse(); } private interface T { diff --git a/testng-core/src/test/java/test/reflect/TestMethodMatcher.java b/testng-core/src/test/java/test/reflect/TestMethodMatcher.java index 744fc59949..ee2f8359df 100644 --- a/testng-core/src/test/java/test/reflect/TestMethodMatcher.java +++ b/testng-core/src/test/java/test/reflect/TestMethodMatcher.java @@ -1,9 +1,9 @@ package test.reflect; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.lang.reflect.Method; -import org.testng.Assert; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.annotations.DataProvider; @@ -109,7 +109,7 @@ public void testNegativeCaseMatcher( final MethodMatcher matcher = new DataProviderMethodMatcher( new MethodMatcherContext(method, params, iTestContext, iTestResult)); - Assert.assertFalse(matcher.conforms()); + assertThat(matcher.conforms()).isFalse(); assertThatThrownBy( () -> { method.invoke(new TestMethodMatcher(), matcher.getConformingArguments()); @@ -126,29 +126,28 @@ public void goodTestIssue122(String s, String[] strings) { for (String item : strings) { log.debug("An item is \"" + item + "\""); } - Assert.assertEquals(s, "3"); + assertThat(s).isEqualTo("3"); } public void badTestIssue122(String s, String... strings) { for (String item : strings) { log.debug("An item is \"" + item + "\""); } - Assert.assertEquals(s, "3"); + assertThat(s).isEqualTo("3"); } public void mixedArgs(final int i, final Boolean b, final String[] s1, final String... strings) { for (String item : strings) { log.debug("An item is \"" + item + "\""); } - Assert.assertEquals(i, 3); - Assert.assertNotNull(b); - Assert.assertTrue(b); - Assert.assertNotNull(s1); - Assert.assertEquals(s1.length, 1); - Assert.assertEquals(s1[0], "three"); - Assert.assertNotNull(strings); - Assert.assertEquals(strings.length, 1); - Assert.assertEquals(strings[0], "four"); + assertThat(i).isEqualTo(3); + assertThat(b).isTrue(); + assertThat(s1).isNotNull(); + assertThat(s1.length).isOne(); + assertThat(s1[0]).isEqualTo("three"); + assertThat(strings).isNotNull(); + assertThat(strings.length).isOne(); + assertThat(strings[0]).isEqualTo("four"); } public void potpourri0( @@ -177,27 +176,23 @@ public void potpourri0( for (String item : strings) { log.debug("An item is \"" + item + "\""); } - Assert.assertNotNull(myTestContext); - Assert.assertTrue(myTestContext instanceof TestContextJustForTesting); - Assert.assertNotNull(myTestResult); - Assert.assertTrue(myTestResult instanceof TestResultJustForTesting); - Assert.assertNotNull(myXmlTest); - Assert.assertTrue(myXmlTest instanceof XmlTestJustForTesting); - Assert.assertNotNull(currentTestMethod); - Assert.assertEquals("potpourri0", currentTestMethod.getName()); - Assert.assertNotNull(myMethod1); - Assert.assertEquals("mixedArgs", myMethod1.getName()); - Assert.assertNotNull(myMethod2); - Assert.assertEquals("badTestIssue122", myMethod2.getName()); - Assert.assertEquals(i, 3); - Assert.assertNotNull(b); - Assert.assertTrue(b); - Assert.assertNotNull(s1); - Assert.assertEquals(s1.length, 1); - Assert.assertEquals(s1[0], "three"); - Assert.assertNotNull(strings); - Assert.assertEquals(strings.length, 1); - Assert.assertEquals(strings[0], "four"); + assertThat(myTestContext).isInstanceOf(TestContextJustForTesting.class); + assertThat(myTestResult).isInstanceOf(TestResultJustForTesting.class); + assertThat(myXmlTest).isInstanceOf(XmlTestJustForTesting.class); + assertThat(currentTestMethod).isNotNull(); + assertThat(currentTestMethod.getName()).isEqualTo("potpourri0"); + assertThat(myMethod1).isNotNull(); + assertThat(myMethod1.getName()).isEqualTo("mixedArgs"); + assertThat(myMethod2).isNotNull(); + assertThat(myMethod2.getName()).isEqualTo("badTestIssue122"); + assertThat(i).isEqualTo(3); + assertThat(b).isTrue(); + assertThat(s1).isNotNull(); + assertThat(s1.length).isOne(); + assertThat(s1[0]).isEqualTo("three"); + assertThat(strings).isNotNull(); + assertThat(strings.length).isOne(); + assertThat(strings[0]).isEqualTo("four"); } public void potpourri1( @@ -226,26 +221,22 @@ public void potpourri1( for (String item : strings) { log.debug("An item is \"" + item + "\""); } - Assert.assertNotNull(myTestContext); - Assert.assertTrue(myTestContext instanceof TestContextJustForTesting); - Assert.assertNotNull(myTestResult); - Assert.assertTrue(myTestResult instanceof TestResultJustForTesting); - Assert.assertNotNull(myXmlTest); - Assert.assertTrue(myXmlTest instanceof XmlTestJustForTesting); - Assert.assertNotNull(currentTestMethod); - Assert.assertEquals("potpourri1", currentTestMethod.getName()); - Assert.assertNotNull(myMethod1); - Assert.assertEquals("mixedArgs", myMethod1.getName()); - Assert.assertNotNull(myMethod2); - Assert.assertEquals("badTestIssue122", myMethod2.getName()); - Assert.assertEquals(i, 3); - Assert.assertNotNull(b); - Assert.assertTrue(b); - Assert.assertNotNull(s1); - Assert.assertEquals(s1.length, 1); - Assert.assertEquals(s1[0], "three"); - Assert.assertNotNull(strings); - Assert.assertEquals(strings.length, 1); - Assert.assertEquals(strings[0], "four"); + assertThat(myTestContext).isInstanceOf(TestContextJustForTesting.class); + assertThat(myTestResult).isInstanceOf(TestResultJustForTesting.class); + assertThat(myXmlTest).isInstanceOf(XmlTestJustForTesting.class); + assertThat(currentTestMethod).isNotNull(); + assertThat(currentTestMethod.getName()).isEqualTo("potpourri1"); + assertThat(myMethod1).isNotNull(); + assertThat(myMethod1.getName()).isEqualTo("mixedArgs"); + assertThat(myMethod2).isNotNull(); + assertThat(myMethod2.getName()).isEqualTo("badTestIssue122"); + assertThat(i).isEqualTo(3); + assertThat(b).isTrue(); + assertThat(s1).isNotNull(); + assertThat(s1.length).isOne(); + assertThat(s1[0]).isEqualTo("three"); + assertThat(strings).isNotNull(); + assertThat(strings.length).isOne(); + assertThat(strings[0]).isEqualTo("four"); } } diff --git a/testng-core/src/test/java/test/regression/BeforeTestFailingTest.java b/testng-core/src/test/java/test/regression/BeforeTestFailingTest.java index 8daf13a3d7..740cbcf80d 100644 --- a/testng-core/src/test/java/test/regression/BeforeTestFailingTest.java +++ b/testng-core/src/test/java/test/regression/BeforeTestFailingTest.java @@ -1,6 +1,7 @@ package test.regression; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -16,7 +17,7 @@ public void beforeTestFailingShouldCauseSkips() { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getSkippedTests().size(), 1); - Assert.assertEquals(tla.getPassedTests().size(), 0); + assertThat(tla.getSkippedTests()).hasSize(1); + assertThat(tla.getPassedTests()).isEmpty(); } } diff --git a/testng-core/src/test/java/test/regression/groupsordering/Base.java b/testng-core/src/test/java/test/regression/groupsordering/Base.java index 2c3fb9c756..81ef3b9787 100644 --- a/testng-core/src/test/java/test/regression/groupsordering/Base.java +++ b/testng-core/src/test/java/test/regression/groupsordering/Base.java @@ -1,6 +1,7 @@ package test.regression.groupsordering; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; @@ -10,15 +11,18 @@ public abstract class Base { @BeforeGroups(value = "a", groups = "a") public void setUp() { - Assert.assertFalse( - s_childAWasRun || s_childBWasRun, - "Static field was not reset: @AfterGroup method not invoked"); + assertThat(s_childAWasRun) + .withFailMessage("Static field was not reset: @AfterGroup method not invoked") + .isFalse(); + assertThat(s_childBWasRun) + .withFailMessage("Static field was not reset: @AfterGroup method not invoked") + .isFalse(); } @AfterGroups(value = "a", groups = "a") public void tearDown() { - Assert.assertTrue(s_childAWasRun, "Child A was not run"); - Assert.assertTrue(s_childBWasRun, "Child B was not run"); + assertThat(s_childAWasRun).withFailMessage("Child A was not run").isTrue(); + assertThat(s_childBWasRun).withFailMessage("Child B was not run").isTrue(); s_childAWasRun = false; s_childBWasRun = false; } diff --git a/testng-core/src/test/java/test/reports/FailedReporterTest.java b/testng-core/src/test/java/test/reports/FailedReporterTest.java index 32fc29b410..012d5021be 100644 --- a/testng-core/src/test/java/test/reports/FailedReporterTest.java +++ b/testng-core/src/test/java/test/reports/FailedReporterTest.java @@ -11,7 +11,6 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -107,13 +106,13 @@ public void failedFile() throws IOException { new Parser(temp.resolve(FailedReporter.TESTNG_FAILED_XML).toAbsolutePath().toString()) .parse(); XmlSuite failedSuite = failedSuites.iterator().next(); - Assert.assertEquals("42", failedSuite.getParameter("n")); + assertThat(failedSuite.getParameter("n")).isEqualTo("42"); XmlTest failedTest = failedSuite.getTests().get(0); - Assert.assertEquals("43", failedTest.getParameter("o")); + assertThat(failedTest.getParameter("o")).isEqualTo("43"); XmlClass failedClass = failedTest.getClasses().get(0); - Assert.assertEquals("44", failedClass.getAllParameters().get("p")); + assertThat(failedClass.getAllParameters()).containsEntry("p", "44"); } @Test(description = "ISSUE-2445") diff --git a/testng-core/src/test/java/test/reports/GitHub1148Sample.java b/testng-core/src/test/java/test/reports/GitHub1148Sample.java index e921e0cd8b..d879486913 100644 --- a/testng-core/src/test/java/test/reports/GitHub1148Sample.java +++ b/testng-core/src/test/java/test/reports/GitHub1148Sample.java @@ -1,6 +1,7 @@ package test.reports; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public Object[][] dp() { @Test(dataProvider = "dp") public void verifyData(String n1) { - Assert.assertEquals(n1, "Cedric"); + assertThat(n1).isEqualTo("Cedric"); } } diff --git a/testng-core/src/test/java/test/reports/GitHub447Sample.java b/testng-core/src/test/java/test/reports/GitHub447Sample.java index 15a18ba709..55ac0a561b 100644 --- a/testng-core/src/test/java/test/reports/GitHub447Sample.java +++ b/testng-core/src/test/java/test/reports/GitHub447Sample.java @@ -1,7 +1,6 @@ package test.reports; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.List; @@ -12,8 +11,8 @@ public class GitHub447Sample { @Test(dataProvider = "add") public void add(List list, Object e, String expected) { - assertTrue(list.add(e)); - assertEquals(list.toString(), expected); + assertThat(list.add(e)).isTrue(); + assertThat(list).hasToString(expected); } @DataProvider(name = "add") diff --git a/testng-core/src/test/java/test/reports/PerSuiteXMLReporterTest.java b/testng-core/src/test/java/test/reports/PerSuiteXMLReporterTest.java index 9b53ef24be..d79d5785dd 100644 --- a/testng-core/src/test/java/test/reports/PerSuiteXMLReporterTest.java +++ b/testng-core/src/test/java/test/reports/PerSuiteXMLReporterTest.java @@ -78,8 +78,8 @@ private static void runVerificationsForSuite(File parentDir, XmlSuite xmlSuite, int failed = Integer.parseInt(node.getAttributes().getNamedItem("failed").getNodeValue()); assertThat(ignored).isZero(); assertThat(total).isEqualTo(2); - assertThat(passed).isEqualTo(1); - assertThat(failed).isEqualTo(1); + assertThat(passed).isOne(); + assertThat(failed).isOne(); String text = (String) xPath diff --git a/testng-core/src/test/java/test/reports/ReportTest.java b/testng-core/src/test/java/test/reports/ReportTest.java index ea87ce8fd1..259a528c09 100644 --- a/testng-core/src/test/java/test/reports/ReportTest.java +++ b/testng-core/src/test/java/test/reports/ReportTest.java @@ -41,7 +41,7 @@ public void verifyIndex() throws IOException { tng.run(); - Assert.assertTrue(Files.exists(f), f.toString()); + assertThat(Files.exists(f)).withFailMessage(f.toString()).isTrue(); } @Test @@ -63,8 +63,8 @@ public void directoryShouldBeSuiteName() throws IOException { tng.run(); - Assert.assertTrue(Files.exists(f)); - Assert.assertTrue(Files.exists(f2)); + assertThat(f).exists(); + assertThat(f2).exists(); } @Test @@ -85,8 +85,8 @@ public void oneDirectoryPerSuite() throws IOException { tng.run(); - Assert.assertTrue(Files.exists(f1)); - Assert.assertTrue(Files.exists(f2)); + assertThat(f1).exists(); + assertThat(f2).exists(); } private static Path getHtmlReportFile(Path outputDir, String suiteName, String testName) @@ -105,13 +105,13 @@ public void shouldHonorSuiteName() throws IOException { Path fileA = outputDirectory.resolve("SuiteA-JDK5"); Path fileB = outputDirectory.resolve("SuiteB-JDK5"); - Assert.assertTrue(Files.notExists(fileA)); - Assert.assertTrue(Files.notExists(fileB)); + assertThat(Files.notExists(fileA)).isTrue(); + assertThat(Files.notExists(fileB)).isTrue(); tng.run(); - Assert.assertTrue(Files.exists(fileA)); - Assert.assertTrue(Files.exists(fileB)); + assertThat(fileA).exists(); + assertThat(fileB).exists(); } private static boolean m_success; @@ -133,7 +133,7 @@ public void onTestSuccess(ITestResult tr) { tng.addListener(listener); tng.run(); - Assert.assertTrue(m_success); + assertThat(m_success).isTrue(); } @Test @@ -160,22 +160,22 @@ public void github1090() { tng.run(); List parameters = reporter.getParameters(); - Assert.assertEquals(parameters.size(), 5); - Assert.assertEquals(parameters.get(0)[0].toString(), "[]"); - Assert.assertNull(parameters.get(0)[1]); - Assert.assertEquals(parameters.get(0)[2].toString(), "[null]"); - Assert.assertEquals(parameters.get(1)[0].toString(), "[null]"); - Assert.assertEquals(parameters.get(1)[1], "dup"); - Assert.assertEquals(parameters.get(1)[2].toString(), "[null, dup]"); - Assert.assertEquals(parameters.get(2)[0].toString(), "[null, dup]"); - Assert.assertEquals(parameters.get(2)[1], "dup"); - Assert.assertEquals(parameters.get(2)[2].toString(), "[null, dup, dup]"); - Assert.assertEquals(parameters.get(3)[0].toString(), "[null, dup, dup]"); - Assert.assertEquals(parameters.get(3)[1], "str"); - Assert.assertEquals(parameters.get(3)[2].toString(), "[null, dup, dup, str]"); - Assert.assertEquals(parameters.get(4)[0].toString(), "[null, dup, dup, str]"); - Assert.assertNull(parameters.get(4)[1]); - Assert.assertEquals(parameters.get(4)[2].toString(), "[null, dup, dup, str, null]"); + assertThat(parameters).hasSize(5); + assertThat(parameters.get(0)[0]).hasToString("[]"); + assertThat(parameters.get(0)[1]).isNull(); + assertThat(parameters.get(0)[2]).hasToString("[null]"); + assertThat(parameters.get(1)[0]).hasToString("[null]"); + assertThat(parameters.get(1)[1]).isEqualTo("dup"); + assertThat(parameters.get(1)[2]).hasToString("[null, dup]"); + assertThat(parameters.get(2)[0]).hasToString("[null, dup]"); + assertThat(parameters.get(2)[1]).isEqualTo("dup"); + assertThat(parameters.get(2)[2]).hasToString("[null, dup, dup]"); + assertThat(parameters.get(3)[0]).hasToString("[null, dup, dup]"); + assertThat(parameters.get(3)[1]).isEqualTo("str"); + assertThat(parameters.get(3)[2]).hasToString("[null, dup, dup, str]"); + assertThat(parameters.get(4)[0]).hasToString("[null, dup, dup, str]"); + assertThat(parameters.get(4)[1]).isNull(); + assertThat(parameters.get(4)[2]).hasToString("[null, dup, dup, str, null]"); } @DataProvider @@ -246,9 +246,7 @@ private static Path checkFailed(Path testngFailedXml, String... failedMethods) assertThat(listener.getFailedMethodNames()).containsExactly(failedMethods); Path testngFailedXml2 = outputDirectory.resolve(FailedReporter.TESTNG_FAILED_XML); - assertThat(testngFailedXml2).exists(); - - return testngFailedXml2; + return assertThat(testngFailedXml2).exists().actual(); } public static class DpArrays { @@ -287,8 +285,8 @@ public void reportArraysToString() { tng.run(); System.setOut(previousOut); - Assert.assertTrue(systemOutCapture.toString().contains("testMethod([ITEM1])")); - Assert.assertTrue(systemOutCapture.toString().contains("testMethod([ITEM1, ITEM2])")); + assertThat(systemOutCapture.toString()).contains("testMethod([ITEM1])"); + assertThat(systemOutCapture.toString()).contains("testMethod([ITEM1, ITEM2])"); } @Test @@ -303,8 +301,7 @@ public void reportCreatedWithNullParameter() { System.setOut(previousOut); String actual = systemOutCapture.toString(); - Assert.assertTrue( - actual.contains( - "PASSED: test.reports.ReportTest$NullParameter.testMethod(null, \"Bazinga!\")")); + assertThat(actual) + .contains("PASSED: test.reports.ReportTest$NullParameter.testMethod(null, \"Bazinga!\")"); } } diff --git a/testng-core/src/test/java/test/reports/ReporterLogTest.java b/testng-core/src/test/java/test/reports/ReporterLogTest.java index a8d090d6a3..d1a3a3c7d0 100644 --- a/testng-core/src/test/java/test/reports/ReporterLogTest.java +++ b/testng-core/src/test/java/test/reports/ReporterLogTest.java @@ -1,7 +1,8 @@ package test.reports; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.Reporter; import org.testng.TestNG; import org.testng.annotations.DataProvider; @@ -25,7 +26,7 @@ public void shouldLogFromListener(Class testClass, String value) { TestNG tng = create(testClass); tng.run(); List output = Reporter.getOutput(); - Assert.assertTrue(contains(output, value)); + assertThat(contains(output, value)).isTrue(); } private static boolean contains(List output, String logMessage) { diff --git a/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample1.java b/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample1.java index eb35b52861..4e66b849bc 100644 --- a/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample1.java +++ b/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample1.java @@ -1,6 +1,7 @@ package test.reports; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -8,6 +9,6 @@ public class UniqueReporterInjectionSample1 { @Test public void testMethod() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample2.java b/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample2.java index f463d54c6d..314284991e 100644 --- a/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample2.java +++ b/testng-core/src/test/java/test/reports/UniqueReporterInjectionSample2.java @@ -1,6 +1,7 @@ package test.reports; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -8,6 +9,6 @@ public class UniqueReporterInjectionSample2 { @Test public void testMethod() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/reports/UniqueReporterInjectionTest.java b/testng-core/src/test/java/test/reports/UniqueReporterInjectionTest.java index dd664c7b72..c3c8e05750 100644 --- a/testng-core/src/test/java/test/reports/UniqueReporterInjectionTest.java +++ b/testng-core/src/test/java/test/reports/UniqueReporterInjectionTest.java @@ -1,7 +1,12 @@ package test.reports; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.*; +import org.testng.IReporter; +import org.testng.ISuite; +import org.testng.ITestNGListener; +import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; import org.testng.xml.XmlTest; @@ -20,8 +25,8 @@ public void testPruningOfDuplicateReporter() { tng.run(); // Since we have another reporting listener that is injected via the service loader file // reporting listeners size will now have to be two - Assert.assertEquals(tng.getReporters().size(), 2); - Assert.assertEquals(ReporterListenerForIssue1227.counter, 1); + assertThat(tng.getReporters()).hasSize(2); + assertThat(ReporterListenerForIssue1227.counter).isOne(); } public static class ReporterListenerForIssue1227 implements IReporter { diff --git a/testng-core/src/test/java/test/reports/XmlReporterTest.java b/testng-core/src/test/java/test/reports/XmlReporterTest.java index 7744c27636..2ef22321fb 100644 --- a/testng-core/src/test/java/test/reports/XmlReporterTest.java +++ b/testng-core/src/test/java/test/reports/XmlReporterTest.java @@ -87,7 +87,7 @@ public void ensureReportGenerationWhenTestMethodIsWrappedWithWrappedTestNGMethod t, new MethodInstance(new WrappedTestNGMethod(t.getMethod())))) .collect(Collectors.toList()))); - assertThat(file.exists()).isTrue(); + assertThat(file).exists(); } @Test(description = "GITHUB-2886") @@ -108,7 +108,7 @@ public void ensureConfigurationMethodsAreNotCountedAsSkippedInXmlReports() throw int total = Integer.parseInt(node.getAttributes().getNamedItem("total").getNodeValue()); int passed = Integer.parseInt(node.getAttributes().getNamedItem("passed").getNodeValue()); int failed = Integer.parseInt(node.getAttributes().getNamedItem("failed").getNodeValue()); - assertThat(ignored).isEqualTo(1); + assertThat(ignored).isOne(); assertThat(total).isEqualTo(3); assertThat(passed).isEqualTo(2); assertThat(failed).isZero(); diff --git a/testng-core/src/test/java/test/reports/issue2445/Test1.java b/testng-core/src/test/java/test/reports/issue2445/Test1.java index f92d5d0b7f..a3c6bf8de5 100644 --- a/testng-core/src/test/java/test/reports/issue2445/Test1.java +++ b/testng-core/src/test/java/test/reports/issue2445/Test1.java @@ -1,11 +1,12 @@ package test.reports.issue2445; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class Test1 { @Test public void test1() { - Assert.fail("Simulate failure"); + fail("Simulate failure"); } } diff --git a/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeGroupsWithBeforeGroupsSuiteTestSample.java b/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeGroupsWithBeforeGroupsSuiteTestSample.java index 343ef4eddd..a1a5d968f1 100644 --- a/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeGroupsWithBeforeGroupsSuiteTestSample.java +++ b/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeGroupsWithBeforeGroupsSuiteTestSample.java @@ -1,6 +1,7 @@ package test.reports.issue2611; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterSuite; import org.testng.annotations.AfterTest; @@ -12,7 +13,7 @@ public class TestClassFailsAtBeforeGroupsWithBeforeGroupsSuiteTestSample { @BeforeGroups(groups = {"dragon-warrior"}) public void beforeGroups() { - Assert.fail(); + fail(); } @AfterGroups(groups = {"dragon-warrior"}) diff --git a/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeSuiteWithBeforeGroupsSuiteTestSample.java b/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeSuiteWithBeforeGroupsSuiteTestSample.java index b62fe9b968..8038281a6a 100644 --- a/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeSuiteWithBeforeGroupsSuiteTestSample.java +++ b/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeSuiteWithBeforeGroupsSuiteTestSample.java @@ -1,6 +1,7 @@ package test.reports.issue2611; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterSuite; import org.testng.annotations.AfterTest; @@ -18,7 +19,7 @@ public void afterGroups() {} @BeforeSuite(groups = {"dragon-warrior"}) public void beforeSuite() { - Assert.fail(); + fail(); } @AfterSuite(groups = {"dragon-warrior"}) diff --git a/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeTestWithBeforeGroupsSuiteTestSample.java b/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeTestWithBeforeGroupsSuiteTestSample.java index c39279dda7..e2d0242399 100644 --- a/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeTestWithBeforeGroupsSuiteTestSample.java +++ b/testng-core/src/test/java/test/reports/issue2611/TestClassFailsAtBeforeTestWithBeforeGroupsSuiteTestSample.java @@ -1,6 +1,7 @@ package test.reports.issue2611; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterSuite; import org.testng.annotations.AfterTest; @@ -24,7 +25,7 @@ public void afterSuite() {} @BeforeTest(groups = {"dragon-warrior"}) public void beforeTest() { - Assert.fail(); + fail(); } @AfterTest(groups = {"dragon-warrior"}) diff --git a/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeGroupsSample.java b/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeGroupsSample.java index cb5cf7065b..1c2bc1fafd 100644 --- a/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeGroupsSample.java +++ b/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeGroupsSample.java @@ -1,6 +1,7 @@ package test.reports.issue2611; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; @@ -8,7 +9,7 @@ public class TestClassWithBeforeGroupsSample { @BeforeGroups(groups = {"dragon-warrior"}) public void beforeGroups() { - Assert.fail(); + fail(); } @AfterGroups(groups = {"dragon-warrior"}) diff --git a/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeSuiteSample.java b/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeSuiteSample.java index 6de7b98fb6..67a9d8f75b 100644 --- a/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeSuiteSample.java +++ b/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeSuiteSample.java @@ -1,6 +1,7 @@ package test.reports.issue2611; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; @@ -8,7 +9,7 @@ public class TestClassWithBeforeSuiteSample { @BeforeSuite(groups = {"dragon-warrior"}) public void beforeSuite() { - Assert.fail(); + fail(); } @AfterSuite(groups = {"dragon-warrior"}) diff --git a/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeTestSample.java b/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeTestSample.java index dc2237fdfb..f1b9c5c01c 100644 --- a/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeTestSample.java +++ b/testng-core/src/test/java/test/reports/issue2611/TestClassWithBeforeTestSample.java @@ -1,6 +1,7 @@ package test.reports.issue2611; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; @@ -8,7 +9,7 @@ public class TestClassWithBeforeTestSample { @BeforeTest(groups = {"dragon-warrior"}) public void beforeTest() { - Assert.fail(); + fail(); } @AfterTest(groups = {"dragon-warrior"}) diff --git a/testng-core/src/test/java/test/reports/issue2879/TestClassSample.java b/testng-core/src/test/java/test/reports/issue2879/TestClassSample.java index d30405a4fd..0ff5a612d3 100644 --- a/testng-core/src/test/java/test/reports/issue2879/TestClassSample.java +++ b/testng-core/src/test/java/test/reports/issue2879/TestClassSample.java @@ -1,6 +1,7 @@ package test.reports.issue2879; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class TestClassSample { @@ -13,11 +14,11 @@ public void passingTwo() {} @Test public void failingOne() { - Assert.fail(); + fail(); } @Test public void failingTwo() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/reports/issue2906/SampleOneTestCase.java b/testng-core/src/test/java/test/reports/issue2906/SampleOneTestCase.java index 819d23027f..4f6f6f682c 100644 --- a/testng-core/src/test/java/test/reports/issue2906/SampleOneTestCase.java +++ b/testng-core/src/test/java/test/reports/issue2906/SampleOneTestCase.java @@ -1,6 +1,7 @@ package test.reports.issue2906; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.Reporter; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public void firstPassingTestCase() { @Test public void firstFailingTestCase() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/reports/issue2906/SampleThreeTestCase.java b/testng-core/src/test/java/test/reports/issue2906/SampleThreeTestCase.java index 900a3759cb..f23e956a99 100644 --- a/testng-core/src/test/java/test/reports/issue2906/SampleThreeTestCase.java +++ b/testng-core/src/test/java/test/reports/issue2906/SampleThreeTestCase.java @@ -1,6 +1,7 @@ package test.reports.issue2906; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.Reporter; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public void thirdPassingTestCase() { @Test public void thirdFailingTestCase() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/reports/issue2906/SampleTwoTestCase.java b/testng-core/src/test/java/test/reports/issue2906/SampleTwoTestCase.java index 3cb8ed384a..16c69bf3bb 100644 --- a/testng-core/src/test/java/test/reports/issue2906/SampleTwoTestCase.java +++ b/testng-core/src/test/java/test/reports/issue2906/SampleTwoTestCase.java @@ -1,6 +1,7 @@ package test.reports.issue2906; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.Reporter; import org.testng.annotations.Test; @@ -13,6 +14,6 @@ public void secondPassingTestCase() { @Test public void secondFailingTestCase() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/EventualSuccess.java b/testng-core/src/test/java/test/retryAnalyzer/EventualSuccess.java index 7bafc90dcd..75d3ef39d8 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/EventualSuccess.java +++ b/testng-core/src/test/java/test/retryAnalyzer/EventualSuccess.java @@ -1,7 +1,8 @@ package test.retryAnalyzer; +import static org.assertj.core.api.Assertions.fail; + import java.util.concurrent.atomic.AtomicBoolean; -import org.testng.Assert; import org.testng.annotations.Test; public class EventualSuccess { @@ -10,7 +11,7 @@ public class EventualSuccess { @Test(retryAnalyzer = MyRetry.class) public void test() { if (!ranYet.getAndSet(true)) { - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/ExitCodeTest.java b/testng-core/src/test/java/test/retryAnalyzer/ExitCodeTest.java index 74c52ef414..362fd1786d 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/ExitCodeTest.java +++ b/testng-core/src/test/java/test/retryAnalyzer/ExitCodeTest.java @@ -1,7 +1,6 @@ package test.retryAnalyzer; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.ITestNGListener; import org.testng.TestNG; @@ -13,14 +12,14 @@ public class ExitCodeTest extends SimpleBaseTest { public void exitsWithZeroOnSuccess() { TestNG tng = create(ImmediateSuccess.class); tng.run(); - assertEquals(tng.getStatus(), 0); + assertThat(tng.getStatus()).isZero(); } @Test public void exitsWithNonzeroOnFailure() { TestNG tng = create(PersistentFailure.class); tng.run(); - assertTrue(tng.getStatus() != 0); + assertThat(tng.getStatus()).isNotZero(); } @Test @@ -28,20 +27,20 @@ public void exitsWithZeroAfterSuccessfulRetry() { TestNG tng = create(EventualSuccess.class); tng.addListener((ITestNGListener) new TestResultPruner()); tng.run(); - assertEquals(tng.getStatus(), 0); + assertThat(tng.getStatus()).isZero(); } @Test(description = "GITHUB-217") public void exitWithNonzeroOnSkips() { TestNG tng = create(Issue217TestClassSample.class); tng.run(); - assertEquals(tng.getStatus(), 2); + assertThat(tng.getStatus()).isEqualTo(2); } @Test(description = "GITHUB-217") public void exitWithNonzeroOnSkips1() { TestNG tng = create(Issue217TestClassSampleWithOneDataProvider.class); tng.run(); - assertEquals(tng.getStatus(), 2); + assertThat(tng.getStatus()).isEqualTo(2); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/FactoryTest.java b/testng-core/src/test/java/test/retryAnalyzer/FactoryTest.java index d4aadaf65e..aca1e4c517 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/FactoryTest.java +++ b/testng-core/src/test/java/test/retryAnalyzer/FactoryTest.java @@ -1,6 +1,6 @@ package test.retryAnalyzer; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.ITest; import org.testng.annotations.Test; diff --git a/testng-core/src/test/java/test/retryAnalyzer/InvocationCountTest.java b/testng-core/src/test/java/test/retryAnalyzer/InvocationCountTest.java index a268463758..ae74574d93 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/InvocationCountTest.java +++ b/testng-core/src/test/java/test/retryAnalyzer/InvocationCountTest.java @@ -1,7 +1,7 @@ package test.retryAnalyzer; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import com.google.common.collect.ConcurrentHashMultiset; import com.google.common.collect.Multiset; @@ -64,10 +64,10 @@ public void failAfterThreeRetries() { }, alwaysRun = true) public void checkInvocationCounts() { - assertEquals(invocations.count("testAnnotationWithNoRetries"), 0); - assertEquals(invocations.count("testAnnotationWithOneRetry"), 1); - assertEquals(invocations.count("testAnnotationWithSevenRetries"), 7); - assertEquals(invocations.count("failAfterThreeRetries"), 4); + assertThat(invocations.count("testAnnotationWithNoRetries")).isZero(); + assertThat(invocations.count("testAnnotationWithOneRetry")).isOne(); + assertThat(invocations.count("testAnnotationWithSevenRetries")).isEqualTo(7); + assertThat(invocations.count("failAfterThreeRetries")).isEqualTo(4); } @Test(retryAnalyzer = InvocationCountTest.class, dataProvider = "dataProvider3") @@ -94,9 +94,9 @@ public void retryWithDataProvider(String tc) { dependsOnMethods = {"retryWithDataProvider"}, alwaysRun = true) public void checkRetryCounts() { - assertEquals(tcid1, 3); - assertEquals(tcid2, 3); - assertEquals(tcid3, 3); + assertThat(tcid1).isEqualTo(3); + assertThat(tcid2).isEqualTo(3); + assertThat(tcid3).isEqualTo(3); } @DataProvider(name = "dataProvider") @@ -126,7 +126,7 @@ public void testAnnotationWithDataProvider(int paf, boolean test) { } } if (paf == 4) { - assertEquals(executionNumber, 5); + assertThat(executionNumber).isEqualTo(5); } } @@ -137,7 +137,7 @@ public void testAnnotationWithDataProviderAndRecreateParameters(boolean ignored) r3--; fail(); } else if (r3 == 0) { - assertEquals(value, 42); + assertThat(value).isEqualTo(42); } } @@ -149,7 +149,7 @@ public void withFactory() { tng.run(); - assertEquals(FactoryTest.m_count, 4); + assertThat(FactoryTest.m_count).isEqualTo(4); } @Override diff --git a/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSample.java b/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSample.java index adae51f3db..acbdfd208d 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSample.java @@ -1,6 +1,7 @@ package test.retryAnalyzer; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -10,7 +11,7 @@ public void a() {} @Test(dataProvider = "dp") public void testMethod(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSampleWithOneDataProvider.java b/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSampleWithOneDataProvider.java index 6ad30c566d..2b3a535368 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSampleWithOneDataProvider.java +++ b/testng-core/src/test/java/test/retryAnalyzer/Issue217TestClassSampleWithOneDataProvider.java @@ -1,13 +1,14 @@ package test.retryAnalyzer; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class Issue217TestClassSampleWithOneDataProvider { @Test(dataProvider = "dp") public void testMethod(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/retryAnalyzer/PersistentFailure.java b/testng-core/src/test/java/test/retryAnalyzer/PersistentFailure.java index 62e4fbba26..ec426bd6c5 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/PersistentFailure.java +++ b/testng-core/src/test/java/test/retryAnalyzer/PersistentFailure.java @@ -1,11 +1,12 @@ package test.retryAnalyzer; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class PersistentFailure { @Test(retryAnalyzer = MyRetry.class) public void test() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/RetryAnalyzerTest.java b/testng-core/src/test/java/test/retryAnalyzer/RetryAnalyzerTest.java index d9f0658403..331f53b736 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/RetryAnalyzerTest.java +++ b/testng-core/src/test/java/test/retryAnalyzer/RetryAnalyzerTest.java @@ -11,7 +11,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.stream.Collectors; -import org.testng.Assert; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestResult; @@ -160,7 +159,7 @@ public void testIfRetryIsInvokedWhenTestMethodHas( InvokedMethodNameListener listener = new InvokedMethodNameListener(); tng.addListener(listener); tng.run(); - assertThat(listener.getSkippedMethodNames().size()).isEqualTo(size); + assertThat(listener.getSkippedMethodNames()).hasSize(size); } @DataProvider(name = "1706") @@ -178,16 +177,12 @@ public void testIfDependentMethodsAreInvokedWhenRetrySucceeds() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - assertThat( - tla.getPassedTests().stream() - .map(RetryAnalyzerTest::methodName) - .collect(Collectors.toList())) + assertThat(tla.getPassedTests()) + .extracting(RetryAnalyzerTest::methodName) .containsExactly("a", "b"); assertThat(tla.getFailedTests()).isEmpty(); - assertThat( - tla.getSkippedTests().stream() - .map(RetryAnalyzerTest::methodName) - .collect(Collectors.toList())) + assertThat(tla.getSkippedTests()) + .extracting(RetryAnalyzerTest::methodName) .containsExactly("a"); } @@ -322,7 +317,7 @@ public void testFailedRetryWithParameters() { createXmlTest(suite, "2669_Test", RetryTestSample.class); TestNG testng = create(suite); testng.run(); - Assert.assertEquals(RetryTestSample.count, 3); + assertThat(RetryTestSample.count).isEqualTo(3); } @Test(description = "GITHUB-2684") diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/ComplexDataProviderWithObjectAndArraySample.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/ComplexDataProviderWithObjectAndArraySample.java index f2d96b9077..cfcffc6ff3 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/ComplexDataProviderWithObjectAndArraySample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/ComplexDataProviderWithObjectAndArraySample.java @@ -1,7 +1,8 @@ package test.retryAnalyzer.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -17,13 +18,13 @@ public Object[][] getObjectData() { // attempts @Test(dataProvider = "getObjectData", retryAnalyzer = DataProviderRetryAnalyzer.class) public void test(boolean flag, String... values) { - Assert.assertEquals( - countWithObjectAndStringArrayForSuccess--, - 0, - "Test execution is not" - + "successful after 3 retry attempts configured in retryAnalyzer for this data " - + Arrays.toString(values) - + "with boolean flag as " - + flag); + assertThat(countWithObjectAndStringArrayForSuccess--) + .withFailMessage( + "Test execution is not" + + "successful after 3 retry attempts configured in retryAnalyzer for this data " + + Arrays.toString(values) + + "with boolean flag as " + + flag) + .isZero(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithRetryAttemptsFailure.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithRetryAttemptsFailure.java index 5dbbfa8c37..0f80f09b26 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithRetryAttemptsFailure.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithRetryAttemptsFailure.java @@ -1,7 +1,8 @@ package test.retryAnalyzer.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -14,12 +15,13 @@ public Object[][] getObjectData() { // Test retry-analyzer with end result as failed after 3 successful retry attempts @Test(dataProvider = "getObjectData", retryAnalyzer = DataProviderRetryAnalyzer.class) public void test(boolean flag, String... values) { - Assert.assertTrue( - flag, - "Test execution is not" - + "successful after 3 retry attempts configured in retryAnalyzer for this data " - + Arrays.toString(values) - + "with boolean flag as " - + flag); + assertThat(flag) + .withFailMessage( + "Test execution is not" + + "successful after 3 retry attempts configured in retryAnalyzer for this data " + + Arrays.toString(values) + + "with boolean flag as " + + flag) + .isTrue(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithSingleParam.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithSingleParam.java index 017bd74727..65d43a571b 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithSingleParam.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithSingleParam.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -23,21 +24,23 @@ public void test(int param) { // If the param is 1 then decrement the counter countWithSingleParam1 and assert true to check // if it is 0. if (param == 1) { - Assert.assertTrue( - countWithSingleParam1-- == 0, - "Test execution is not" - + "successful after 3 retry attempts configured in retryAnalyzer for this data " - + param); + assertThat(countWithSingleParam1--) + .withFailMessage( + "Test execution is not" + + "successful after 3 retry attempts configured in retryAnalyzer for this data " + + param) + .isZero(); } // If the param is 2 then decrement the counter countWithSingleParam2 and assert true to check // if it is 0. if (param == 2) { - Assert.assertTrue( - countWithSingleParam2-- == 0, - "Test execution is not" - + "successful after 3 retry attempts configured in retryAnalyzer for this data " - + param); + assertThat(countWithSingleParam2--) + .withFailMessage( + "Test execution is not" + + "successful after 3 retry attempts configured in retryAnalyzer for this data " + + param) + .isZero(); } } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithStringArraySample.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithStringArraySample.java index 4f674bd742..8f1e5bc7cf 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithStringArraySample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/DataProviderWithStringArraySample.java @@ -1,7 +1,8 @@ package test.retryAnalyzer.dataprovider; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -17,11 +18,11 @@ public Object[][] getTestData() { // retry attempts @Test(dataProvider = "getTestData", retryAnalyzer = DataProviderRetryAnalyzer.class) public void test(String... values) { - Assert.assertEquals( - countWithStringArray--, - 0, - "Test execution is not" - + "successful after 3 retry attempts configured in retryAnalyzer for this data " - + Arrays.toString(values)); + assertThat(countWithStringArray--) + .withFailMessage( + "Test execution is not" + + "successful after 3 retry attempts configured in retryAnalyzer for this data " + + Arrays.toString(values)) + .isZero(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithComplexDataProviderTest.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithComplexDataProviderTest.java index d853ee2f8c..98102f6f77 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithComplexDataProviderTest.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithComplexDataProviderTest.java @@ -1,6 +1,6 @@ package test.retryAnalyzer.dataprovider; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -16,9 +16,9 @@ public void testWithoutDataProvider() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - assertEquals(tla.getPassedTests().size(), 1); - assertEquals(tla.getFailedTests().size(), 0); - assertEquals(tla.getSkippedTests().size(), 3); + assertThat(tla.getPassedTests()).hasSize(1); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).hasSize(3); } // Test with string array of objects in data-provider with end result as success after 3 retry @@ -29,9 +29,9 @@ public void testWithDataProviderStringArray() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - assertEquals(tla.getPassedTests().size(), 1); - assertEquals(tla.getFailedTests().size(), 0); - assertEquals(tla.getSkippedTests().size(), 3); + assertThat(tla.getPassedTests()).hasSize(1); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).hasSize(3); } // Test with multiple integer arrays in data-provider when parallel mode on and end result as @@ -44,11 +44,10 @@ public void testWithSingleParam() { testng.addListener(tla); testng.run(); // Since 2 integer arrays are passing inside data-provider, number of test cases should be 2 - assertEquals(tla.getPassedTests().size(), 2); - assertEquals(tla.getFailedTests().size(), 0); - assertEquals( - tla.getSkippedTests().size(), - 6); // Number of total skipped count should be 6, each for a test + assertThat(tla.getPassedTests()).hasSize(2); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()) + .hasSize(6); // Number of total skipped count should be 6, each for a test } // Test with objects in data-provider with result as success after 3 retry attempts @@ -58,9 +57,9 @@ public void testWithDataProviderWithObjectAndArraySample() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - assertEquals(tla.getPassedTests().size(), 1); - assertEquals(tla.getFailedTests().size(), 0); - assertEquals(tla.getSkippedTests().size(), 3); + assertThat(tla.getPassedTests()).hasSize(1); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).hasSize(3); } // Test with objects in data-provider with result as failed after 3 retry attempts @@ -70,8 +69,8 @@ public void testDataProviderWithRetryAttemptsFailure() { TestListenerAdapter tla = new TestListenerAdapter(); testng.addListener(tla); testng.run(); - assertEquals(tla.getFailedTests().size(), 1); - assertEquals(tla.getPassedTests().size(), 0); - assertEquals(tla.getSkippedTests().size(), 3); + assertThat(tla.getFailedTests()).hasSize(1); + assertThat(tla.getPassedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).hasSize(3); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithDataProviderTest.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithDataProviderTest.java index 3f11b847f3..6f850f823e 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithDataProviderTest.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithDataProviderTest.java @@ -1,6 +1,6 @@ package test.retryAnalyzer.dataprovider; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; @@ -18,10 +18,10 @@ public void testRetryCounts() { tng.run(); - assertEquals(tla.getPassedTests().size(), 1); - assertEquals(tla.getPassedTests().get(0).getParameters(), new String[] {"c"}); + assertThat(tla.getPassedTests()).hasSize(1); + assertThat(tla.getPassedTests().get(0).getParameters()).isEqualTo(new String[] {"c"}); - assertEquals(tla.getFailedTests().size(), 3); - assertEquals(tla.getSkippedTests().size(), 9); + assertThat(tla.getFailedTests()).hasSize(3); + assertThat(tla.getSkippedTests()).hasSize(9); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithoutDataProvider.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithoutDataProvider.java index 60b86ee300..bfbb100141 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithoutDataProvider.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryAnalyzerWithoutDataProvider.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.dataprovider; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class RetryAnalyzerWithoutDataProvider { @@ -10,6 +11,6 @@ public class RetryAnalyzerWithoutDataProvider { // attempts @Test(retryAnalyzer = DataProviderRetryAnalyzer.class) public void test() { - Assert.assertTrue(countWithoutDataProvider-- == 0); + assertThat(countWithoutDataProvider--).isZero(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryCountTest.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryCountTest.java index c25a015ce5..95f4b1f5b3 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryCountTest.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/RetryCountTest.java @@ -1,6 +1,6 @@ package test.retryAnalyzer.dataprovider; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -14,6 +14,6 @@ public Object[][] provider() { @Test(dataProvider = "provider", retryAnalyzer = DataProviderRetryAnalyzer.class) public void test1(String param) { - assertEquals(param, "c"); + assertThat(param).isEqualTo("c"); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/issue2163/TestClassPoweredByDataProviderSample.java b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/issue2163/TestClassPoweredByDataProviderSample.java index 82b1f7a8bc..113263ddbf 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/dataprovider/issue2163/TestClassPoweredByDataProviderSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/dataprovider/issue2163/TestClassPoweredByDataProviderSample.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.dataprovider.issue2163; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -8,7 +9,7 @@ public class TestClassPoweredByDataProviderSample { @Test(retryAnalyzer = RetryAnalyzer.class, dataProvider = "dpNewObject") public void willNotStopAfter3Failures(Object... newObject) { - Assert.fail("Kaboom!"); + fail("Kaboom!"); } @DataProvider diff --git a/testng-core/src/test/java/test/retryAnalyzer/github1519/TestClassSample.java b/testng-core/src/test/java/test/retryAnalyzer/github1519/TestClassSample.java old mode 100755 new mode 100644 index d34da0a144..e1623a17fc --- a/testng-core/src/test/java/test/retryAnalyzer/github1519/TestClassSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/github1519/TestClassSample.java @@ -1,7 +1,8 @@ package test.retryAnalyzer.github1519; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; import org.testng.collections.Lists; @@ -11,6 +12,6 @@ public class TestClassSample { @Test(retryAnalyzer = MyAnalyzer.class) public void testMethod() { - Assert.assertTrue(retry); + assertThat(retry).isTrue(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/github1600/Github1600TestSample.java b/testng-core/src/test/java/test/retryAnalyzer/github1600/Github1600TestSample.java old mode 100755 new mode 100644 index d4670067ad..afbf4d8a28 --- a/testng-core/src/test/java/test/retryAnalyzer/github1600/Github1600TestSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/github1600/Github1600TestSample.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.github1600; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class Github1600TestSample { @@ -8,7 +9,7 @@ public class Github1600TestSample { @Test public void test1() { - Assert.assertEquals(a, 2); + assertThat(a).isEqualTo(2); a++; } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/github1706/DataDrivenSample.java b/testng-core/src/test/java/test/retryAnalyzer/github1706/DataDrivenSample.java index a0f9682b1e..b20bfa4ba9 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/github1706/DataDrivenSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/github1706/DataDrivenSample.java @@ -1,7 +1,9 @@ package test.retryAnalyzer.github1706; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -10,9 +12,9 @@ public class DataDrivenSample { @Test(retryAnalyzer = LocalRetry.class, dataProvider = "getdata") public void testMethod(int i) { - Assert.assertTrue(i > 0); + assertThat(i).isPositive(); if (counter.incrementAndGet() != 3) { - Assert.fail(); + fail(); } counter = new AtomicInteger(0); } diff --git a/testng-core/src/test/java/test/retryAnalyzer/github1706/NativeInjectionSample.java b/testng-core/src/test/java/test/retryAnalyzer/github1706/NativeInjectionSample.java index 579b140b4f..bc2afdae77 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/github1706/NativeInjectionSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/github1706/NativeInjectionSample.java @@ -1,8 +1,10 @@ package test.retryAnalyzer.github1706; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.annotations.Test; public class NativeInjectionSample { @@ -10,9 +12,9 @@ public class NativeInjectionSample { @Test(retryAnalyzer = LocalRetry.class) public void testMethod(Method method) { - Assert.assertNotNull(method); + assertThat(method).isNotNull(); if (counter.incrementAndGet() != 3) { - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/github1706/ParameterInjectionSample.java b/testng-core/src/test/java/test/retryAnalyzer/github1706/ParameterInjectionSample.java index 62141c4188..e7af30df67 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/github1706/ParameterInjectionSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/github1706/ParameterInjectionSample.java @@ -1,7 +1,9 @@ package test.retryAnalyzer.github1706; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -11,9 +13,9 @@ public class ParameterInjectionSample { @Test(retryAnalyzer = LocalRetry.class) @Parameters({"counter"}) public void testMethod(int paramCounter) { - Assert.assertTrue(paramCounter > 0); + assertThat(paramCounter).isPositive(); if (counter.incrementAndGet() != 3) { - Assert.fail(); + fail(); } } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/github2669/RetryTestSample.java b/testng-core/src/test/java/test/retryAnalyzer/github2669/RetryTestSample.java index 4e3a8a625e..cc6e1a7d1b 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/github2669/RetryTestSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/github2669/RetryTestSample.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.github2669; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.ITestContext; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -12,6 +13,6 @@ public class RetryTestSample { @Test(retryAnalyzer = FailedRetry.class) public void create(String id, String name, String age, ITestContext context) { count++; - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue1241/GitHub1241Sample.java b/testng-core/src/test/java/test/retryAnalyzer/issue1241/GitHub1241Sample.java index 79c4832fde..5daa843c01 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue1241/GitHub1241Sample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue1241/GitHub1241Sample.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.issue1241; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class GitHub1241Sample { @@ -9,6 +10,6 @@ public void test1() {} @Test(retryAnalyzer = MyRetry.class) public void test2() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue1538/TestClassSampleWithTestMethodDependencies.java b/testng-core/src/test/java/test/retryAnalyzer/issue1538/TestClassSampleWithTestMethodDependencies.java index f3912b2f29..ac1393f937 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue1538/TestClassSampleWithTestMethodDependencies.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue1538/TestClassSampleWithTestMethodDependencies.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.issue1538; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class TestClassSampleWithTestMethodDependencies { @@ -8,11 +9,11 @@ public class TestClassSampleWithTestMethodDependencies { @Test(retryAnalyzer = RetryForIssue1538.class) public void a() { - Assert.assertEquals(i++, 1); + assertThat(i++).isOne(); } @Test(dependsOnMethods = "a", retryAnalyzer = RetryForIssue1538.class) public void b() { - Assert.assertEquals(i++, 2); + assertThat(i++).isEqualTo(2); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue1697/DatadrivenSample.java b/testng-core/src/test/java/test/retryAnalyzer/issue1697/DatadrivenSample.java index 512ba7d280..10e2f70e01 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue1697/DatadrivenSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue1697/DatadrivenSample.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.issue1697; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -11,7 +12,7 @@ public class DatadrivenSample { public void testMethod(int data) { if (data == 1 && flag) { flag = false; - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue1697/SampleTestclass.java b/testng-core/src/test/java/test/retryAnalyzer/issue1697/SampleTestclass.java index 68d4a903bb..57116f5b30 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue1697/SampleTestclass.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue1697/SampleTestclass.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.issue1697; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class SampleTestclass { @@ -9,13 +10,13 @@ public class SampleTestclass { @Test(retryAnalyzer = SimpleRetrier.class) public void dataDrivenTest() { if (counter++ != 1) { - Assert.fail(); + fail(); } } @Test public void parent() { - Assert.fail(); + fail(); } @Test(dependsOnMethods = "parent") diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue1946/TestclassBase.java b/testng-core/src/test/java/test/retryAnalyzer/issue1946/TestclassBase.java index e16ffe5363..4f7672e765 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue1946/TestclassBase.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue1946/TestclassBase.java @@ -1,6 +1,6 @@ package test.retryAnalyzer.issue1946; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import org.testng.Reporter; import org.testng.annotations.DataProvider; diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue2148/ExceptionAfterMethodTestSample.java b/testng-core/src/test/java/test/retryAnalyzer/issue2148/ExceptionAfterMethodTestSample.java index e1446ccb4e..0b39c8da60 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue2148/ExceptionAfterMethodTestSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue2148/ExceptionAfterMethodTestSample.java @@ -1,9 +1,10 @@ package test.retryAnalyzer.issue2148; +import static org.assertj.core.api.Assertions.fail; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.Reporter; import org.testng.annotations.AfterMethod; @@ -24,7 +25,7 @@ public void beforeMethod(ITestResult method) { public void testMethod() { ITestResult method = Reporter.getCurrentTestResult(); logs.add("Test Method [" + method.getMethod().getMethodName() + "] #" + counter.get()); - Assert.fail(); + fail(); } @AfterMethod(alwaysRun = true) diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue2684/SampleTestClassWithGroupConfigs.java b/testng-core/src/test/java/test/retryAnalyzer/issue2684/SampleTestClassWithGroupConfigs.java index ebd51cfc29..730e257158 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue2684/SampleTestClassWithGroupConfigs.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue2684/SampleTestClassWithGroupConfigs.java @@ -1,6 +1,6 @@ package test.retryAnalyzer.issue2684; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterGroups; @@ -34,7 +34,7 @@ public void beforeMethod() {} @Test(groups = "2684_group", retryAnalyzer = RerunAnalyzer.class) public void testMethod() { RerunAnalyzer.secondTestRetryCount++; - assertTrue(RerunAnalyzer.secondTestRetryCount > RerunAnalyzer.maxRetryCount); + assertThat(RerunAnalyzer.secondTestRetryCount).isGreaterThan(RerunAnalyzer.maxRetryCount); } @AfterMethod(alwaysRun = true) diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue3231/InvocationCountRetrySample.java b/testng-core/src/test/java/test/retryAnalyzer/issue3231/InvocationCountRetrySample.java index 64337133f5..82683f3d73 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue3231/InvocationCountRetrySample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue3231/InvocationCountRetrySample.java @@ -1,7 +1,8 @@ package test.retryAnalyzer.issue3231; +import static org.assertj.core.api.Assertions.fail; + import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.IRetryAnalyzer; import org.testng.ITestResult; import org.testng.annotations.Test; @@ -22,6 +23,6 @@ public boolean retry(ITestResult result) { @Test(invocationCount = 2, retryAnalyzer = MyRetry.class) public void test() { invocationCount.incrementAndGet(); - Assert.fail("fail"); + fail("fail"); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue3231/MutationSample.java b/testng-core/src/test/java/test/retryAnalyzer/issue3231/MutationSample.java index 38e2f3cb03..b59bc45494 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue3231/MutationSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue3231/MutationSample.java @@ -1,9 +1,10 @@ package test.retryAnalyzer.issue3231; +import static org.assertj.core.api.Assertions.fail; + import java.util.Objects; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; -import org.testng.Assert; import org.testng.IRetryAnalyzer; import org.testng.ITestResult; import org.testng.annotations.DataProvider; @@ -67,6 +68,6 @@ public void willNotStopAfter3FailuresCustom(Custom newObject) { return; } newObject.setId(UUID.randomUUID()); // Mutate! - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/retryAnalyzer/issue3231/RetryLimitSample.java b/testng-core/src/test/java/test/retryAnalyzer/issue3231/RetryLimitSample.java index bcbc7cf08e..458171578c 100644 --- a/testng-core/src/test/java/test/retryAnalyzer/issue3231/RetryLimitSample.java +++ b/testng-core/src/test/java/test/retryAnalyzer/issue3231/RetryLimitSample.java @@ -1,6 +1,7 @@ package test.retryAnalyzer.issue3231; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.IRetryAnalyzer; import org.testng.ITestResult; import org.testng.annotations.DataProvider; @@ -25,6 +26,6 @@ public Object[][] dp() { @Test(dataProvider = "dp", retryAnalyzer = MyRetry.class) public void test(String s) { - Assert.fail("fail"); + fail("fail"); } } diff --git a/testng-core/src/test/java/test/sample/AfterClassCalledAtEnd.java b/testng-core/src/test/java/test/sample/AfterClassCalledAtEnd.java index e42c170936..170996c148 100644 --- a/testng-core/src/test/java/test/sample/AfterClassCalledAtEnd.java +++ b/testng-core/src/test/java/test/sample/AfterClassCalledAtEnd.java @@ -1,7 +1,6 @@ package test.sample; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -25,29 +24,42 @@ public void before1Class() { @AfterClass(groups = {"someGroup"}) public void afterClass() { m_afterClass = true; - assertTrue( - m_test1 && m_test2 && m_test3, - "One of the test methods was not invoked: " + m_test1 + " " + m_test2 + " " + m_test3); + assertThat(m_test1 && m_test2 && m_test3) + .withFailMessage( + "One of the test methods was not invoked: " + m_test1 + " " + m_test2 + " " + m_test3) + .isTrue(); } @Test(description = "Verify that beforeClass and afterClass are called correctly") public void test1() { m_test1 = true; - assertTrue(m_before1Class, "beforeClass configuration must be called before method"); - assertFalse(m_afterClass, "afterClass configuration must not be called before test method"); + assertThat(m_before1Class) + .withFailMessage("beforeClass configuration must be called before method") + .isTrue(); + assertThat(m_afterClass) + .withFailMessage("afterClass configuration must not be called before test method") + .isFalse(); } @Test public void test2() { m_test2 = true; - assertTrue(m_before1Class, "beforeClass configuration must be called before method"); - assertFalse(m_afterClass, "afterClass configuration must not be called before test method"); + assertThat(m_before1Class) + .withFailMessage("beforeClass configuration must be called before method") + .isTrue(); + assertThat(m_afterClass) + .withFailMessage("afterClass configuration must not be called before test method") + .isFalse(); } @Test public void test3() { m_test3 = true; - assertTrue(m_before1Class, "beforeClass configuration must be called before method"); - assertFalse(m_afterClass, "afterClass configuration must not be called before test method"); + assertThat(m_before1Class) + .withFailMessage("beforeClass configuration must be called before method") + .isTrue(); + assertThat(m_afterClass) + .withFailMessage("afterClass configuration must not be called before test method") + .isFalse(); } } diff --git a/testng-core/src/test/java/test/sample/BaseAfterClassCalledAtEnd.java b/testng-core/src/test/java/test/sample/BaseAfterClassCalledAtEnd.java index 17dbe70dc0..c8df705358 100644 --- a/testng-core/src/test/java/test/sample/BaseAfterClassCalledAtEnd.java +++ b/testng-core/src/test/java/test/sample/BaseAfterClassCalledAtEnd.java @@ -1,6 +1,6 @@ package test.sample; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; @@ -9,6 +9,8 @@ public class BaseAfterClassCalledAtEnd { @AfterClass(dependsOnGroups = {".*"}) public void baseAfterClass() { - assertTrue(m_afterClass, "This afterClass method should have been called last"); + assertThat(m_afterClass) + .withFailMessage("This afterClass method should have been called last") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/sample/BaseSampleInheritance.java b/testng-core/src/test/java/test/sample/BaseSampleInheritance.java index 420b4adfea..4a8d588384 100644 --- a/testng-core/src/test/java/test/sample/BaseSampleInheritance.java +++ b/testng-core/src/test/java/test/sample/BaseSampleInheritance.java @@ -1,6 +1,6 @@ package test.sample; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; import java.util.List; @@ -40,7 +40,11 @@ public void configuration1() { @Test(dependsOnGroups = {"inheritedTestMethod"}) public void testBooleans() { - assertTrue(m_invokedBaseMethod, "Didn't invoke test method in base class"); - assertTrue(m_invokedBaseConfiguration, "Didn't invoke configuration method in base class"); + assertThat(m_invokedBaseMethod) + .withFailMessage("Didn't invoke test method in base class") + .isTrue(); + assertThat(m_invokedBaseConfiguration) + .withFailMessage("Didn't invoke configuration method in base class") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/sample/Basic1.java b/testng-core/src/test/java/test/sample/Basic1.java index 3834974ef4..ac154a24e0 100644 --- a/testng-core/src/test/java/test/sample/Basic1.java +++ b/testng-core/src/test/java/test/sample/Basic1.java @@ -1,6 +1,6 @@ package test.sample; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -23,6 +23,6 @@ public void beforeTestMethod() { @Test(groups = {"basic1"}) public void basic1() { - assertTrue(getCount() > 0, "COUNT WAS NOT INCREMENTED"); + assertThat(getCount()).withFailMessage("COUNT WAS NOT INCREMENTED").isPositive(); } } diff --git a/testng-core/src/test/java/test/sample/Basic2.java b/testng-core/src/test/java/test/sample/Basic2.java index b2bb688906..66889385b2 100644 --- a/testng-core/src/test/java/test/sample/Basic2.java +++ b/testng-core/src/test/java/test/sample/Basic2.java @@ -1,7 +1,6 @@ package test.sample; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterTest; @@ -14,7 +13,7 @@ public class Basic2 { @Test(dependsOnGroups = {"basic1"}) public void basic2() { m_basic2WasRun = true; - assertTrue(Basic1.getCount() > 0, "COUNT WAS NOT INCREMENTED"); + assertThat(Basic1.getCount()).withFailMessage("COUNT WAS NOT INCREMENTED").isPositive(); } @AfterTest @@ -26,8 +25,11 @@ public void cleanUp() { @AfterClass public void checkTestAtClassLevelWasRun() { m_afterClass++; - assertTrue(m_basic2WasRun, "Class annotated with @Test didn't have its methods run."); - assertEquals( - m_afterClass, 1, "After class should have been called exactly once, not " + m_afterClass); + assertThat(m_basic2WasRun) + .withFailMessage("Class annotated with @Test didn't have its methods run.") + .isTrue(); + assertThat(m_afterClass) + .withFailMessage("After class should have been called exactly once, not " + m_afterClass) + .isOne(); } } diff --git a/testng-core/src/test/java/test/sample/InvocationCountTest.java b/testng-core/src/test/java/test/sample/InvocationCountTest.java index c61609a57d..4565cb630e 100644 --- a/testng-core/src/test/java/test/sample/InvocationCountTest.java +++ b/testng-core/src/test/java/test/sample/InvocationCountTest.java @@ -1,6 +1,6 @@ package test.sample; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterSuite; @@ -71,9 +71,9 @@ public void successPercentageShouldFail() { @AfterClass(groups = {"invocationOnly"}) public void verify() { - assertEquals( - m_count, - 10, - "Method should have been invoked 10 times but was invoked " + m_count + " times"); + assertThat(m_count) + .withFailMessage( + "Method should have been invoked 10 times but was invoked " + m_count + " times") + .isEqualTo(10); } } diff --git a/testng-core/src/test/java/test/sample/JUnitSample3.java b/testng-core/src/test/java/test/sample/JUnitSample3.java index 6cf7af067a..cfeb54e15b 100644 --- a/testng-core/src/test/java/test/sample/JUnitSample3.java +++ b/testng-core/src/test/java/test/sample/JUnitSample3.java @@ -1,7 +1,8 @@ package test.sample; +import static org.assertj.core.api.Assertions.assertThat; + import junit.framework.TestCase; -import org.testng.Assert; /** * This class verifies that a new instance is used every time @@ -12,12 +13,12 @@ public class JUnitSample3 extends TestCase { private int m_count = 0; public void test1() { - Assert.assertEquals(m_count, 0); + assertThat(m_count).isZero(); m_count++; } public void test2() { - Assert.assertEquals(m_count, 0); + assertThat(m_count).isZero(); m_count++; } } diff --git a/testng-core/src/test/java/test/sample/PartialGroupTest.java b/testng-core/src/test/java/test/sample/PartialGroupTest.java index e676f08cf1..fbf7863544 100644 --- a/testng-core/src/test/java/test/sample/PartialGroupTest.java +++ b/testng-core/src/test/java/test/sample/PartialGroupTest.java @@ -1,6 +1,7 @@ package test.sample; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -28,12 +29,12 @@ public void testMethodGroup() { @Test public void testClassGroupShouldFail() { - Assert.assertTrue(false); + assertThat(false).isTrue(); } @Test(groups = {"methodGroup"}) public void testMethodGroupShouldFail() { - Assert.assertTrue(false); + assertThat(false).isTrue(); } @Test diff --git a/testng-core/src/test/java/test/sample/PartialGroupVerification.java b/testng-core/src/test/java/test/sample/PartialGroupVerification.java index 0aeb6cfdf7..15dc2c3e47 100644 --- a/testng-core/src/test/java/test/sample/PartialGroupVerification.java +++ b/testng-core/src/test/java/test/sample/PartialGroupVerification.java @@ -1,6 +1,6 @@ package test.sample; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -12,8 +12,11 @@ public class PartialGroupVerification { @Test public void verify() { - assertTrue( - PartialGroupTest.m_successMethod && PartialGroupTest.m_successClass, - "test1 and test2 should have been invoked both"); + assertThat(PartialGroupTest.m_successMethod) + .withFailMessage("test1 (method) should have been invoked") + .isTrue(); + assertThat(PartialGroupTest.m_successClass) + .withFailMessage("test2 (class) should have been invoked") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/sample/Sample1.java b/testng-core/src/test/java/test/sample/Sample1.java index cb9dd65141..061b96131f 100644 --- a/testng-core/src/test/java/test/sample/Sample1.java +++ b/testng-core/src/test/java/test/sample/Sample1.java @@ -1,6 +1,7 @@ package test.sample; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -59,6 +60,6 @@ public void throwExceptionShouldFail() { @Test(groups = {"assert"}) public void verifyLastNameShouldFail() { - Assert.assertEquals("Beust", "", "Expected name Beust, found blah"); + assertThat("Beust").withFailMessage("Expected name Beust, found blah").isEmpty(); } } diff --git a/testng-core/src/test/java/test/sample/Scope.java b/testng-core/src/test/java/test/sample/Scope.java index e725f2947d..17ad30be19 100644 --- a/testng-core/src/test/java/test/sample/Scope.java +++ b/testng-core/src/test/java/test/sample/Scope.java @@ -1,6 +1,6 @@ package test.sample; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -11,12 +11,12 @@ public class Scope { @Parameters({"parameter"}) @Test(groups = {"outer-group"}) public void outerDeprecated(String s) { - assertEquals(s, "out", "Expected out got " + s); + assertThat(s).withFailMessage("Expected out got " + s).isEqualTo("out"); } @Parameters({"parameter"}) @Test(groups = {"inner-group"}) public void innerDeprecated(String s) { - assertEquals(s, "in", "Expected in got " + s); + assertThat(s).withFailMessage("Expected in got " + s).isEqualTo("in"); } } diff --git a/testng-core/src/test/java/test/sanitycheck/CheckSuiteNamesTest.java b/testng-core/src/test/java/test/sanitycheck/CheckSuiteNamesTest.java index d1fb784d2e..d352cfb281 100644 --- a/testng-core/src/test/java/test/sanitycheck/CheckSuiteNamesTest.java +++ b/testng-core/src/test/java/test/sanitycheck/CheckSuiteNamesTest.java @@ -1,9 +1,10 @@ package test.sanitycheck; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.IOException; import java.util.Arrays; import java.util.Collections; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -25,7 +26,7 @@ public void checkChildSuites() { tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 4); + assertThat(tla.getPassedTests()).hasSize(4); } /** Child suites have same names */ @@ -37,12 +38,12 @@ public void checkChildSuitesFails() { tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getTestContexts().get(0).getSuite().getName(), "SanityCheck suites"); - Assert.assertEquals(tla.getTestContexts().get(1).getSuite().getName(), "SanityCheck suites"); - Assert.assertEquals( - tla.getTestContexts().get(2).getSuite().getName(), "SanityCheck suites (0)"); - Assert.assertEquals( - tla.getTestContexts().get(3).getSuite().getName(), "SanityCheck suites (0)"); + assertThat(tla.getTestContexts().get(0).getSuite().getName()).isEqualTo("SanityCheck suites"); + assertThat(tla.getTestContexts().get(1).getSuite().getName()).isEqualTo("SanityCheck suites"); + assertThat(tla.getTestContexts().get(2).getSuite().getName()) + .isEqualTo("SanityCheck suites (0)"); + assertThat(tla.getTestContexts().get(3).getSuite().getName()) + .isEqualTo("SanityCheck suites (0)"); } /** Checks that suites created programmatically also works as expected */ @@ -65,8 +66,8 @@ public void checkProgrammaticSuitesFails() { TestNG tng = create(); tng.setXmlSuites(Arrays.asList(xmlSuite1, xmlSuite2)); tng.run(); - Assert.assertEquals(xmlSuite1.getName(), "SanityCheckSuite"); - Assert.assertEquals(xmlSuite2.getName(), "SanityCheckSuite (0)"); + assertThat(xmlSuite1.getName()).isEqualTo("SanityCheckSuite"); + assertThat(xmlSuite2.getName()).isEqualTo("SanityCheckSuite (0)"); } @Test diff --git a/testng-core/src/test/java/test/sanitycheck/CheckTestNamesTest.java b/testng-core/src/test/java/test/sanitycheck/CheckTestNamesTest.java index 3108e302a1..87082653c2 100644 --- a/testng-core/src/test/java/test/sanitycheck/CheckTestNamesTest.java +++ b/testng-core/src/test/java/test/sanitycheck/CheckTestNamesTest.java @@ -1,7 +1,8 @@ package test.sanitycheck; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -37,10 +38,10 @@ private void runSuite(String suitePath) { tng.run(); } catch (TestNGException ex) { exceptionRaised = true; - Assert.assertEquals(tla.getPassedTests().size(), 0); - Assert.assertEquals(tla.getFailedTests().size(), 0); + assertThat(tla.getPassedTests()).isEmpty(); + assertThat(tla.getFailedTests()).isEmpty(); } - Assert.assertTrue(exceptionRaised); + assertThat(exceptionRaised).isTrue(); } /** Simple suite with no two tests with same name */ @@ -52,7 +53,7 @@ public void checkNoError() { tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 2); + assertThat(tla.getPassedTests()).hasSize(2); } /** Child suites and tests within different suites have same names */ @@ -64,7 +65,7 @@ public void checkNoErrorWithChildSuites() { tng.setTestSuites(Collections.singletonList(testngXmlPath)); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 4); + assertThat(tla.getPassedTests()).hasSize(4); } /** Checks that suites created programmatically also run as expected */ diff --git a/testng-core/src/test/java/test/serviceloader/ServiceLoaderTest.java b/testng-core/src/test/java/test/serviceloader/ServiceLoaderTest.java index 34b21f9d26..4a6093c16a 100644 --- a/testng-core/src/test/java/test/serviceloader/ServiceLoaderTest.java +++ b/testng-core/src/test/java/test/serviceloader/ServiceLoaderTest.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import org.testng.Assert; import org.testng.CommandLineArgs; import org.testng.TestNG; import org.testng.annotations.Test; @@ -84,7 +83,7 @@ public void serviceLoaderShouldWorkWithConfigurationListener() { TestNG tng = create(ServiceLoaderSampleTest.class); tng.run(); - Assert.assertEquals(2, tng.getServiceLoaderListeners().size()); + assertThat(tng.getServiceLoaderListeners()).hasSize(2); ListenerAssert.assertListenerType( tng.getServiceLoaderListeners(), MyConfigurationListener.class); } diff --git a/testng-core/src/test/java/test/simple/IncludedExcludedTest.java b/testng-core/src/test/java/test/simple/IncludedExcludedTest.java index 9008876f97..7eee47f20d 100644 --- a/testng-core/src/test/java/test/simple/IncludedExcludedTest.java +++ b/testng-core/src/test/java/test/simple/IncludedExcludedTest.java @@ -1,8 +1,9 @@ package test.simple; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collection; import java.util.List; -import org.testng.Assert; import org.testng.IInvokedMethod; import org.testng.IReporter; import org.testng.ISuite; @@ -67,19 +68,19 @@ public MyReporter(String[] included, String[] excluded) { @Override public void generateReport( List xmlSuites, List suites, String outputDirectory) { - Assert.assertEquals(suites.size(), 1); + assertThat(suites).hasSize(1); ISuite suite = suites.get(0); List invoked = suite.getAllInvokedMethods(); - Assert.assertEquals(invoked.size(), m_included.length); + assertThat(invoked).hasSameSizeAs(m_included); for (String s : m_included) { - Assert.assertTrue(containsInvokedMethod(invoked, s)); + assertThat(containsInvokedMethod(invoked, s)).isTrue(); } Collection excluded = suite.getExcludedMethods(); - Assert.assertEquals(excluded.size(), m_excluded.length); + assertThat(excluded).hasSameSizeAs(m_excluded); for (String s : m_excluded) { - Assert.assertTrue(containsMethod(excluded, s)); + assertThat(containsMethod(excluded, s)).isTrue(); } } diff --git a/testng-core/src/test/java/test/skip/github1632/IssueTest.java b/testng-core/src/test/java/test/skip/github1632/IssueTest.java index 38c5c52898..d72814fb03 100644 --- a/testng-core/src/test/java/test/skip/github1632/IssueTest.java +++ b/testng-core/src/test/java/test/skip/github1632/IssueTest.java @@ -16,10 +16,10 @@ public void runTest() { SkipMonitoringListener listener = new SkipMonitoringListener(); testng.addListener(listener); testng.run(); - assertThat(listener.getStatus().get("skippingMethod")).isEqualTo(ITestResult.SKIP); - assertThat(listener.getStatus().get("passingMethod")).isEqualTo(ITestResult.SUCCESS); - assertThat(listener.getStatus().get("failingMethod")).isEqualTo(ITestResult.FAILURE); - assertThat(listener.getStatus().get("anotherFailingMethod")).isEqualTo(ITestResult.FAILURE); + assertThat(listener.getStatus()).containsEntry("skippingMethod", ITestResult.SKIP); + assertThat(listener.getStatus()).containsEntry("passingMethod", ITestResult.SUCCESS); + assertThat(listener.getStatus()).containsEntry("failingMethod", ITestResult.FAILURE); + assertThat(listener.getStatus()).containsEntry("anotherFailingMethod", ITestResult.FAILURE); } @Test diff --git a/testng-core/src/test/java/test/skip/github1632/TestClassSample.java b/testng-core/src/test/java/test/skip/github1632/TestClassSample.java index d5b521d48e..232fb7cef3 100644 --- a/testng-core/src/test/java/test/skip/github1632/TestClassSample.java +++ b/testng-core/src/test/java/test/skip/github1632/TestClassSample.java @@ -1,6 +1,7 @@ package test.skip.github1632; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.Test; public class TestClassSample { @@ -14,7 +15,7 @@ public void skippingMethod() {} @Test public void failingMethod() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test/skip/github1967/TestClassSample.java b/testng-core/src/test/java/test/skip/github1967/TestClassSample.java index 142b815921..9af54cc93d 100644 --- a/testng-core/src/test/java/test/skip/github1967/TestClassSample.java +++ b/testng-core/src/test/java/test/skip/github1967/TestClassSample.java @@ -1,6 +1,7 @@ package test.skip.github1967; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -8,16 +9,16 @@ public class TestClassSample { @Test public void test1min() { - Assert.fail(); + fail(); } @Test public void test2min() { - Assert.fail(); + fail(); } @BeforeClass public void setup() { - Assert.fail(); + fail(); } } diff --git a/testng-core/src/test/java/test/skip/issue2674/TestClassSample.java b/testng-core/src/test/java/test/skip/issue2674/TestClassSample.java index 831266ce72..32dd95c628 100644 --- a/testng-core/src/test/java/test/skip/issue2674/TestClassSample.java +++ b/testng-core/src/test/java/test/skip/issue2674/TestClassSample.java @@ -1,13 +1,14 @@ package test.skip.issue2674; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class TestClassSample { @Test void test1() { - Assert.fail(); + fail(); } @Test( diff --git a/testng-core/src/test/java/test/skipex/SkipAndExpectedTest.java b/testng-core/src/test/java/test/skipex/SkipAndExpectedTest.java index 53f6cb05f6..a3994808c3 100644 --- a/testng-core/src/test/java/test/skipex/SkipAndExpectedTest.java +++ b/testng-core/src/test/java/test/skipex/SkipAndExpectedTest.java @@ -1,6 +1,7 @@ package test.skipex; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -16,8 +17,8 @@ public void shouldSkip() { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 0); - Assert.assertEquals(tla.getSkippedTests().size(), 1); - Assert.assertEquals(tla.getFailedTests().size(), 0); + assertThat(tla.getPassedTests()).isEmpty(); + assertThat(tla.getSkippedTests()).hasSize(1); + assertThat(tla.getFailedTests()).isEmpty(); } } diff --git a/testng-core/src/test/java/test/skipex/SkippedExceptionTest.java b/testng-core/src/test/java/test/skipex/SkippedExceptionTest.java index bec8788f23..b7238d8522 100644 --- a/testng-core/src/test/java/test/skipex/SkippedExceptionTest.java +++ b/testng-core/src/test/java/test/skipex/SkippedExceptionTest.java @@ -1,7 +1,8 @@ package test.skipex; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.ITestResult; import org.testng.TestListenerAdapter; @@ -19,12 +20,12 @@ public void skippedExceptionInConfigurationMethods() { test.run(); List confSkips = listener.getConfigurationSkips(); List testSkips = listener.getSkippedTests(); - Assert.assertEquals(testSkips.size(), 1); - Assert.assertEquals(testSkips.get(0).getMethod().getMethodName(), "dummyTest"); + assertThat(testSkips).hasSize(1); + assertThat(testSkips.get(0).getMethod().getMethodName()).isEqualTo("dummyTest"); - Assert.assertEquals(confSkips.size(), 1); - Assert.assertEquals( - confSkips.get(0).getMethod().getMethodName(), "configurationLevelSkipException"); + assertThat(confSkips).hasSize(1); + assertThat(confSkips.get(0).getMethod().getMethodName()) + .isEqualTo("configurationLevelSkipException"); } @Test @@ -37,11 +38,11 @@ public void skippedExceptionInTestMethods() { List skips = listener.getSkippedTests(); List failures = listener.getFailedTests(); List passed = listener.getPassedTests(); - Assert.assertEquals(skips.size(), 1); - Assert.assertEquals(failures.size(), 1); - Assert.assertEquals(passed.size(), 1); - Assert.assertEquals(skips.get(0).getMethod().getMethodName(), "genericSkipException"); - Assert.assertEquals(failures.get(0).getMethod().getMethodName(), "timedSkipException"); - Assert.assertEquals(passed.get(0).getMethod().getMethodName(), "genericExpectedSkipException"); + assertThat(skips).hasSize(1); + assertThat(failures).hasSize(1); + assertThat(passed).hasSize(1); + assertThat(skips.get(0).getMethod().getMethodName()).isEqualTo("genericSkipException"); + assertThat(failures.get(0).getMethod().getMethodName()).isEqualTo("timedSkipException"); + assertThat(passed.get(0).getMethod().getMethodName()).isEqualTo("genericExpectedSkipException"); } } diff --git a/testng-core/src/test/java/test/superclass/BaseSampleTest3.java b/testng-core/src/test/java/test/superclass/BaseSampleTest3.java index febc1954ff..16f0b43b08 100644 --- a/testng-core/src/test/java/test/superclass/BaseSampleTest3.java +++ b/testng-core/src/test/java/test/superclass/BaseSampleTest3.java @@ -1,12 +1,12 @@ package test.superclass; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; public class BaseSampleTest3 { @Test public void base() { - assertTrue(true); + assertThat(true).isTrue(); } } diff --git a/testng-core/src/test/java/test/superclass/ChildSampleTest3.java b/testng-core/src/test/java/test/superclass/ChildSampleTest3.java index 6bfd89af05..ad62b88022 100644 --- a/testng-core/src/test/java/test/superclass/ChildSampleTest3.java +++ b/testng-core/src/test/java/test/superclass/ChildSampleTest3.java @@ -1,16 +1,17 @@ package test.superclass; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class ChildSampleTest3 extends BaseSampleTest3 { @Test public void pass() { - Assert.assertTrue(true); + assertThat(true).isTrue(); } @Test public void fail() { - Assert.assertTrue(false); + assertThat(false).isTrue(); } } diff --git a/testng-core/src/test/java/test/testnames/TestNamesTest.java b/testng-core/src/test/java/test/testnames/TestNamesTest.java index 21392b2187..a22b7ca3f4 100644 --- a/testng-core/src/test/java/test/testnames/TestNamesTest.java +++ b/testng-core/src/test/java/test/testnames/TestNamesTest.java @@ -1,7 +1,8 @@ package test.testnames; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -18,9 +19,9 @@ public void checkWithoutChildSuites() { tng.setTestSuites(Collections.singletonList(getPathToResource("testnames/upstream-suite.xml"))); tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getFailedTests().size(), 0); - Assert.assertEquals(tla.getPassedTests().size(), 1); - Assert.assertEquals( - tla.getPassedTests().get(0).getMethod().getMethodName(), "sampleOutputTest2"); + assertThat(tla.getFailedTests()).isEmpty(); + assertThat(tla.getPassedTests()).hasSize(1); + assertThat(tla.getPassedTests().get(0).getMethod().getMethodName()) + .isEqualTo("sampleOutputTest2"); } } diff --git a/testng-core/src/test/java/test/testng106/TestNG106.java b/testng-core/src/test/java/test/testng106/TestNG106.java index 5016c78151..e7b1c9c34a 100644 --- a/testng-core/src/test/java/test/testng106/TestNG106.java +++ b/testng-core/src/test/java/test/testng106/TestNG106.java @@ -1,7 +1,8 @@ package test.testng106; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; @@ -18,9 +19,8 @@ public void testFailingBeforeSuiteShouldSkipAllTests() { createXmlTest(s, "myTest-last", Test2.class.getName()); tng.setXmlSuites(List.of(s)); tng.run(); - Assert.assertEquals( - FailingSuiteFixture.s_invocations, - 0, - "@BeforeSuite has failed. All tests should be skipped."); + assertThat(FailingSuiteFixture.s_invocations) + .withFailMessage("@BeforeSuite has failed. All tests should be skipped.") + .isZero(); } } diff --git a/testng-core/src/test/java/test/testng1231/TestExecutionListenerInvocationOrder.java b/testng-core/src/test/java/test/testng1231/TestExecutionListenerInvocationOrder.java index 74e733eb6a..e66e05a803 100644 --- a/testng-core/src/test/java/test/testng1231/TestExecutionListenerInvocationOrder.java +++ b/testng-core/src/test/java/test/testng1231/TestExecutionListenerInvocationOrder.java @@ -1,7 +1,8 @@ package test.testng1231; +import static org.assertj.core.api.Assertions.assertThat; + import com.beust.jcommander.internal.Lists; -import java.util.Arrays; import java.util.LinkedList; import java.util.List; import org.testng.*; @@ -20,8 +21,7 @@ public void testListenerOrder() { TestListenerFor1231 listener = new TestListenerFor1231(); tng.addListener((ITestNGListener) listener); tng.run(); - List expected = Arrays.asList(1, 2, 3, 4, 5, 6); - Assert.assertEquals(TestListenerFor1231.order, expected); + assertThat(TestListenerFor1231.order).containsExactly(1, 2, 3, 4, 5, 6); } public static class TestListenerFor1231 diff --git a/testng-core/src/test/java/test/testng1232/TestListenerInstances.java b/testng-core/src/test/java/test/testng1232/TestListenerInstances.java index 410b860f7e..7437319409 100644 --- a/testng-core/src/test/java/test/testng1232/TestListenerInstances.java +++ b/testng-core/src/test/java/test/testng1232/TestListenerInstances.java @@ -1,6 +1,7 @@ package test.testng1232; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestNG; import org.testng.annotations.Test; @@ -39,7 +40,7 @@ private static void runTestForTestClass(Class clazz, boolean injectListenerVi tng.addListener((ITestNGListener) anotherListener); tng.run(); for (CounterTypes type : CounterTypes.values()) { - Assert.assertEquals(TestListenerFor1232.counters.get(type).intValue(), 1); + assertThat(TestListenerFor1232.counters.get(type).intValue()).isOne(); } } diff --git a/testng-core/src/test/java/test/testng1396/ParallelByInstancesInterceptorTest.java b/testng-core/src/test/java/test/testng1396/ParallelByInstancesInterceptorTest.java index 7391983f00..22ae547f6c 100644 --- a/testng-core/src/test/java/test/testng1396/ParallelByInstancesInterceptorTest.java +++ b/testng-core/src/test/java/test/testng1396/ParallelByInstancesInterceptorTest.java @@ -1,6 +1,6 @@ package test.testng1396; -import static org.testng.Assert.fail; +import static org.assertj.core.api.Assertions.fail; import java.util.Comparator; import java.util.List; diff --git a/testng-core/src/test/java/test/testng195/AfterMethodTest.java b/testng-core/src/test/java/test/testng195/AfterMethodTest.java index 9c759807ab..eda7d0737a 100644 --- a/testng-core/src/test/java/test/testng195/AfterMethodTest.java +++ b/testng-core/src/test/java/test/testng195/AfterMethodTest.java @@ -1,6 +1,7 @@ package test.testng195; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -11,6 +12,6 @@ public class AfterMethodTest extends SimpleBaseTest { public void testContextShouldBeInitialized() { TestNG tng = create(AfterMethodSampleTest.class); tng.run(); - Assert.assertTrue(AfterMethodSampleTest.m_success); + assertThat(AfterMethodSampleTest.m_success).isTrue(); } } diff --git a/testng-core/src/test/java/test/testng249/VerifyTest.java b/testng-core/src/test/java/test/testng249/VerifyTest.java index 674b1183a1..98a4c7a134 100644 --- a/testng-core/src/test/java/test/testng249/VerifyTest.java +++ b/testng-core/src/test/java/test/testng249/VerifyTest.java @@ -1,8 +1,9 @@ package test.testng249; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.Collections; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -34,6 +35,6 @@ public void verify() { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 2); + assertThat(tla.getPassedTests()).hasSize(2); } } diff --git a/testng-core/src/test/java/test/testng285/TestNG285Test.java b/testng-core/src/test/java/test/testng285/TestNG285Test.java index d8dbd216d9..8ed440201c 100644 --- a/testng-core/src/test/java/test/testng285/TestNG285Test.java +++ b/testng-core/src/test/java/test/testng285/TestNG285Test.java @@ -1,6 +1,7 @@ package test.testng285; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; import org.testng.xml.XmlSuite; import test.BaseTest; @@ -15,6 +16,6 @@ public void verifyBug() { run(); - Assert.assertEquals(BugBase.m_threadIds.size(), 1); + assertThat(BugBase.m_threadIds).hasSize(1); } } diff --git a/testng-core/src/test/java/test/testng37/NullParameterTest.java b/testng-core/src/test/java/test/testng37/NullParameterTest.java index 4908a14397..554b800c2b 100644 --- a/testng-core/src/test/java/test/testng37/NullParameterTest.java +++ b/testng-core/src/test/java/test/testng37/NullParameterTest.java @@ -1,6 +1,7 @@ package test.testng37; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -9,7 +10,7 @@ public class NullParameterTest { @Test @Parameters({"notnull", "nullvalue"}) public void nullParameter(String notNull, int mustBeNull) { - Assert.assertNotNull(notNull, "not null parameter expected"); - Assert.assertNull(mustBeNull, "null parameter expected"); + assertThat(notNull).withFailMessage("not null parameter expected").isNotNull(); + assertThat(mustBeNull).withFailMessage("null parameter expected").isNull(); } } diff --git a/testng-core/src/test/java/test/testng387/TestNG387.java b/testng-core/src/test/java/test/testng387/TestNG387.java index f6d5e3be0a..9c6b93a723 100644 --- a/testng-core/src/test/java/test/testng387/TestNG387.java +++ b/testng-core/src/test/java/test/testng387/TestNG387.java @@ -1,9 +1,12 @@ package test.testng387; -import static org.testng.Assert.assertEqualsNoOrder; +import static org.assertj.core.api.Assertions.assertThat; import java.util.List; -import org.testng.*; +import org.testng.ITestNGListener; +import org.testng.ITestNGMethod; +import org.testng.TestListenerAdapter; +import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; import test.SimpleBaseTest; @@ -22,6 +25,6 @@ public void testInvocationCounterIsCorrectForMethodWithDataProvider() { ITestNGMethod method = tla.getTestContexts().get(0).getAllTestMethods()[0]; List failed = method.getFailedInvocationNumbers(); - assertEqualsNoOrder(failed.toArray(), FailedDPTest.primes.toArray()); + assertThat(failed.toArray()).containsExactlyInAnyOrder(FailedDPTest.primes.toArray()); } } diff --git a/testng-core/src/test/java/test/testng59/Test1.java b/testng-core/src/test/java/test/testng59/Test1.java index 06f052db80..3be98478d7 100644 --- a/testng-core/src/test/java/test/testng59/Test1.java +++ b/testng-core/src/test/java/test/testng59/Test1.java @@ -1,6 +1,7 @@ package test.testng59; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -15,6 +16,8 @@ public void test1() { @AfterClass public void checkWasRun() { - Assert.assertTrue(m_run, "test1() should have been run according to testng-59.xml"); + assertThat(m_run) + .withFailMessage("test1() should have been run according to testng-59.xml") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/testng59/Test2.java b/testng-core/src/test/java/test/testng59/Test2.java index fb5e32aa5c..81e139ee95 100644 --- a/testng-core/src/test/java/test/testng59/Test2.java +++ b/testng-core/src/test/java/test/testng59/Test2.java @@ -1,6 +1,7 @@ package test.testng59; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -15,6 +16,8 @@ public void test2() { @AfterClass public void checkWasRun() { - Assert.assertTrue(m_run, "test2() should have been run according to testng-59.xml"); + assertThat(m_run) + .withFailMessage("test2() should have been run according to testng-59.xml") + .isTrue(); } } diff --git a/testng-core/src/test/java/test/testng674/BeforeClassSkipExceptionTest.java b/testng-core/src/test/java/test/testng674/BeforeClassSkipExceptionTest.java index bf02d8c00c..9160a50f28 100644 --- a/testng-core/src/test/java/test/testng674/BeforeClassSkipExceptionTest.java +++ b/testng-core/src/test/java/test/testng674/BeforeClassSkipExceptionTest.java @@ -1,6 +1,7 @@ package test.testng674; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestNG; import org.testng.annotations.Test; @@ -65,10 +66,10 @@ public void testExceptionDetailsWhenFailuresExistInSuiteConfigs() { ReportingListenerFor674 reporter = new ReportingListenerFor674(); tng.addListener((ITestNGListener) reporter); tng.run(); - Assert.assertEquals(reporter.getErrors().size(), 2); + assertThat(reporter.getErrors()).hasSize(2); for (Throwable error : reporter.getErrors()) { - Assert.assertEquals(error.getMessage(), TestClassSampleContainer.ERROR_MSG); - Assert.assertTrue(error instanceof RuntimeException); + assertThat(error.getMessage()).isEqualTo(TestClassSampleContainer.ERROR_MSG); + assertThat(error).isInstanceOf(RuntimeException.class); } } @@ -97,10 +98,10 @@ private static void createTestNGInstanceAndRun( TestNG tng = create(xmlSuite); tng.addListener((ITestNGListener) reporter); tng.run(); - Assert.assertEquals(reporter.getErrors().size(), expectedCount); + assertThat(reporter.getErrors()).hasSize(expectedCount); for (Throwable error : reporter.getErrors()) { - Assert.assertEquals(error.getMessage(), TestClassSampleContainer.ERROR_MSG); - Assert.assertTrue(error instanceof RuntimeException); + assertThat(error.getMessage()).isEqualTo(TestClassSampleContainer.ERROR_MSG); + assertThat(error).isInstanceOf(RuntimeException.class); } } } diff --git a/testng-core/src/test/java/test/thread/BaseThreadTest.java b/testng-core/src/test/java/test/thread/BaseThreadTest.java index 5947ca0aea..9349c1403d 100644 --- a/testng-core/src/test/java/test/thread/BaseThreadTest.java +++ b/testng-core/src/test/java/test/thread/BaseThreadTest.java @@ -1,9 +1,10 @@ package test.thread; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; import java.util.Map; import java.util.Set; -import org.testng.Assert; import org.testng.collections.Lists; import org.testng.collections.Maps; import org.testng.collections.Sets; @@ -78,9 +79,8 @@ protected void log(String cls, String s) { } protected void verifyThreads(int expected) { - Assert.assertEquals( - getThreadCount(), - expected, - "Ran on " + getThreadCount() + " threads instead of " + expected); + assertThat(getThreadCount()) + .withFailMessage("Ran on " + getThreadCount() + " threads instead of " + expected) + .isEqualTo(expected); } } diff --git a/testng-core/src/test/java/test/thread/DataProviderThreadPoolSizeTest.java b/testng-core/src/test/java/test/thread/DataProviderThreadPoolSizeTest.java index 05ef0423d7..745b2341b3 100644 --- a/testng-core/src/test/java/test/thread/DataProviderThreadPoolSizeTest.java +++ b/testng-core/src/test/java/test/thread/DataProviderThreadPoolSizeTest.java @@ -1,6 +1,7 @@ package test.thread; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.Test; import test.SimpleBaseTest; @@ -12,7 +13,7 @@ public void shouldUseDefaultDataProviderThreadCount() { TestNG tng = create(DataProviderThreadPoolSizeSampleTest.class); tng.setGroups("parallel"); tng.run(); - Assert.assertEquals(DataProviderThreadPoolSizeSampleTest.getThreadCount(), 10); + assertThat(DataProviderThreadPoolSizeSampleTest.getThreadCount()).isEqualTo(10); } @Test @@ -20,7 +21,7 @@ public void shouldNotUseThreadsIfNotUsingParallel() { TestNG tng = create(DataProviderThreadPoolSizeSampleTest.class); tng.setGroups("sequential"); tng.run(); - Assert.assertEquals(DataProviderThreadPoolSizeSampleTest.getThreadCount(), 1); + assertThat(DataProviderThreadPoolSizeSampleTest.getThreadCount()).isOne(); } @Test @@ -29,6 +30,6 @@ public void shouldUseSpecifiedDataProviderThreadCount() { tng.setGroups("parallel"); tng.setDataProviderThreadCount(3); tng.run(); - Assert.assertEquals(DataProviderThreadPoolSizeSampleTest.getThreadCount(), 3); + assertThat(DataProviderThreadPoolSizeSampleTest.getThreadCount()).isEqualTo(3); } } diff --git a/testng-core/src/test/java/test/thread/FactoryTest.java b/testng-core/src/test/java/test/thread/FactoryTest.java index 06aaab26ec..f42bf649f0 100644 --- a/testng-core/src/test/java/test/thread/FactoryTest.java +++ b/testng-core/src/test/java/test/thread/FactoryTest.java @@ -1,6 +1,7 @@ package test.thread; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -40,7 +41,7 @@ private void runTest(XmlSuite.ParallelMode parallelMode, int expectedThreadIdCou B.setUp(); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), 2); - Assert.assertEquals(B.m_threadIds.size(), expectedThreadIdCount); + assertThat(tla.getPassedTests()).hasSize(2); + assertThat(B.m_threadIds).hasSize(expectedThreadIdCount); } } diff --git a/testng-core/src/test/java/test/thread/MultiThreadedDependentTest.java b/testng-core/src/test/java/test/thread/MultiThreadedDependentTest.java index 361ec7fb1d..fd4c6ad8a5 100644 --- a/testng-core/src/test/java/test/thread/MultiThreadedDependentTest.java +++ b/testng-core/src/test/java/test/thread/MultiThreadedDependentTest.java @@ -1,9 +1,10 @@ package test.thread; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.List; import java.util.Map; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.collections.Lists; @@ -27,30 +28,30 @@ private void assertOrder(List methods) { Arrays.asList( "a1", "a2", "a3", "b1", "b2", "b3", "b4", "b5", "c1", "d", "x", "y", "z", "t"); int size = expectedMethods.size(); - Assert.assertEquals(methods.size(), size); + assertThat(methods).hasSize(size); for (String em : expectedMethods) { - Assert.assertTrue(methods.contains(em)); + assertThat(methods).contains(em); } Map map = Maps.newHashMap(); for (String m : methods) { map.put(m, Boolean.TRUE); if ("b1".equals(m) || "b2".equals(m) || "b3".equals(m) || "b4".equals(m) || "b5".equals(m)) { - Assert.assertTrue(map.get("a1")); - Assert.assertTrue(map.get("a2")); - Assert.assertTrue(map.get("a3")); + assertThat(map.get("a1")).isTrue(); + assertThat(map.get("a2")).isTrue(); + assertThat(map.get("a3")).isTrue(); } if ("d".equals(m)) { - Assert.assertTrue(map.get("a1")); - Assert.assertTrue(map.get("a2")); + assertThat(map.get("a1")).isTrue(); + assertThat(map.get("a2")).isTrue(); } if ("c1".equals(m)) { - Assert.assertTrue(map.get("b1")); - Assert.assertTrue(map.get("b2")); + assertThat(map.get("b1")).isTrue(); + assertThat(map.get("b2")).isTrue(); } } - Assert.assertEquals(map.size(), size); + assertThat(map).hasSize(size); for (Boolean val : map.values()) { - Assert.assertTrue(val); + assertThat(val).isTrue(); } } @@ -75,7 +76,9 @@ private void test(int threadCount) { Map map = Helper.getMap(MultiThreadedDependentSampleTest.class.getName()); try (KeyAwareAutoCloseableLock.AutoReleasable ignore = lock.lockForObject(map)) { tng.run(); - Assert.assertTrue(map.size() > 1, "Map size:" + map.size() + " expected more than 1"); + assertThat(map) + .withFailMessage("Map size:" + map.size() + " expected more than 1") + .hasSizeGreaterThan(1); assertOrder(MultiThreadedDependentSampleTest.m_methods); } } diff --git a/testng-core/src/test/java/test/thread/ParallelSuiteTest.java b/testng-core/src/test/java/test/thread/ParallelSuiteTest.java index fa62f1c341..751f3bf337 100644 --- a/testng-core/src/test/java/test/thread/ParallelSuiteTest.java +++ b/testng-core/src/test/java/test/thread/ParallelSuiteTest.java @@ -1,10 +1,12 @@ package test.thread; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -48,7 +50,7 @@ public void suitesShouldRunInParallel3() { BaseThreadTest.initThreadLog(); tng.run(); // Shouldn't not deadlock - Assert.assertEquals(BaseThreadTest.getThreadCount(), SUITE_THREAD_POOL_SIZE); + assertThat(BaseThreadTest.getThreadCount()).isEqualTo(SUITE_THREAD_POOL_SIZE); } @Test @@ -100,18 +102,19 @@ public void suitesShouldRunInOrder() { tng.run(); Map suitesMap = BaseThreadTest.getSuitesMap(); - Assert.assertEquals(BaseThreadTest.getThreadCount(), 1); - Assert.assertEquals(suitesMap.keySet().size(), 3); + assertThat(BaseThreadTest.getThreadCount()).isOne(); + assertThat(suitesMap.keySet()).hasSize(3); final String SUITE_NAME_PREFIX = "Suite Parallel "; if (suitesMap.get(SUITE_NAME_PREFIX + 1) > suitesMap.get(SUITE_NAME_PREFIX + 2)) { - Assert.fail( + fail( "Suite " + (SUITE_NAME_PREFIX + 1) + " should have run before " + (SUITE_NAME_PREFIX + 2)); } - Assert.assertTrue(suitesMap.get(SUITE_NAME_PREFIX + 2) <= suitesMap.get(SUITE_NAME_PREFIX + 0)); + assertThat(suitesMap.get(SUITE_NAME_PREFIX + 2)) + .isLessThanOrEqualTo(suitesMap.get(SUITE_NAME_PREFIX + 0)); } @Test(description = "Number of threads (1) is less than number of levels of suites (2)") @@ -180,17 +183,16 @@ private void runTest( BaseThreadTest.initThreadLog(); tng.run(); - Assert.assertEquals( - BaseThreadTest.getThreadCount(), - expectedThreadCount, - "Thread count expected:" - + expectedThreadCount - + " actual:" - + BaseThreadTest.getThreadCount()); - Assert.assertEquals( - BaseThreadTest.getSuitesMap().keySet().size(), - expectedSuiteCount, - "Suite count is incorrect"); + assertThat(BaseThreadTest.getThreadCount()) + .withFailMessage( + "Thread count expected:" + + expectedThreadCount + + " actual:" + + BaseThreadTest.getThreadCount()) + .isEqualTo(expectedThreadCount); + assertThat(BaseThreadTest.getSuitesMap().keySet()) + .withFailMessage("Suite count is incorrect") + .hasSize(expectedSuiteCount); } private static String getPathToParallelResource(String resourceName) { diff --git a/testng-core/src/test/java/test/thread/SequentialTest.java b/testng-core/src/test/java/test/thread/SequentialTest.java index ec8da9763a..a74c0b5379 100644 --- a/testng-core/src/test/java/test/thread/SequentialTest.java +++ b/testng-core/src/test/java/test/thread/SequentialTest.java @@ -1,8 +1,9 @@ package test.thread; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.HashMap; import java.util.Map; -import org.testng.Assert; import org.testng.annotations.Test; import org.testng.log4testng.Logger; import org.testng.xml.XmlSuite; @@ -73,7 +74,7 @@ private void runTest(int threadCount, String... classes) { }; for (Map m : maps) { - Assert.assertEquals(m.size(), 1); + assertThat(m).hasSize(1); } long[] ids = @@ -88,7 +89,7 @@ private void runTest(int threadCount, String... classes) { verifyMap.put(id, id); } - Assert.assertEquals(verifyMap.size(), threadCount); + assertThat(verifyMap).hasSize(threadCount); debug("COUNT:" + threadCount + " THREAD ID'S:" + ids[0] + " " + ids[1] + " " + ids[2]); } diff --git a/testng-core/src/test/java/test/thread/SingleThreadForParallelMethodsTest.java b/testng-core/src/test/java/test/thread/SingleThreadForParallelMethodsTest.java index c1b205f9fc..2d6b0dceba 100644 --- a/testng-core/src/test/java/test/thread/SingleThreadForParallelMethodsTest.java +++ b/testng-core/src/test/java/test/thread/SingleThreadForParallelMethodsTest.java @@ -1,6 +1,7 @@ package test.thread; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; import org.testng.xml.XmlSuite; import test.BaseTest; @@ -18,6 +19,6 @@ public void testPriorityDoesNotAffectSingleThreadOrder() { run(); - Assert.assertEquals(PriorityInSingleThreadTest.getThreadCount(), 1); + assertThat(PriorityInSingleThreadTest.getThreadCount()).isOne(); } } diff --git a/testng-core/src/test/java/test/thread/SuiteThreadCountTest.java b/testng-core/src/test/java/test/thread/SuiteThreadCountTest.java index 3c0f5b098d..893c5b3c6e 100644 --- a/testng-core/src/test/java/test/thread/SuiteThreadCountTest.java +++ b/testng-core/src/test/java/test/thread/SuiteThreadCountTest.java @@ -1,9 +1,10 @@ package test.thread; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.testng.internal.thread.ThreadUtil; @@ -28,6 +29,6 @@ public void test2() { @AfterClass public void checkThreading() { - Assert.assertEquals(m_threads.size(), 2, "Test should use 2 threads (suite level)"); + assertThat(m_threads).withFailMessage("Test should use 2 threads (suite level)").hasSize(2); } } diff --git a/testng-core/src/test/java/test/thread/TestThreadCountTest.java b/testng-core/src/test/java/test/thread/TestThreadCountTest.java index 478b36da5f..7c76c735ac 100644 --- a/testng-core/src/test/java/test/thread/TestThreadCountTest.java +++ b/testng-core/src/test/java/test/thread/TestThreadCountTest.java @@ -1,9 +1,10 @@ package test.thread; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; import org.testng.internal.thread.ThreadUtil; @@ -33,6 +34,6 @@ public void test3() { @AfterClass public void checkThreading() { - Assert.assertEquals(m_threads.size(), 3, "Test should use 3 threads"); + assertThat(m_threads).withFailMessage("Test should use 3 threads").hasSize(3); } } diff --git a/testng-core/src/test/java/test/thread/TrueParallelTest.java b/testng-core/src/test/java/test/thread/TrueParallelTest.java index 34ff613253..a34270dbdc 100644 --- a/testng-core/src/test/java/test/thread/TrueParallelTest.java +++ b/testng-core/src/test/java/test/thread/TrueParallelTest.java @@ -1,7 +1,8 @@ package test.thread; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.List; -import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.Test; import org.testng.xml.XmlSuite; @@ -33,7 +34,7 @@ public void shouldRunInParallel() { success = success || ii; // System.out.println(strings + " -> " + ii); } - Assert.assertTrue(success, "Couldn't find any interleaved test method run"); + assertThat(success).withFailMessage("Couldn't find any interleaved test method run").isTrue(); } private boolean isInterleaved(List strings) { diff --git a/testng-core/src/test/java/test/thread/issue2361/BaseTestClassExample.java b/testng-core/src/test/java/test/thread/issue2361/BaseTestClassExample.java index f1ce547024..b4df8fff3d 100644 --- a/testng-core/src/test/java/test/thread/issue2361/BaseTestClassExample.java +++ b/testng-core/src/test/java/test/thread/issue2361/BaseTestClassExample.java @@ -1,7 +1,7 @@ package test.thread.issue2361; import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.util.concurrent.atomic.AtomicInteger; import org.testng.annotations.Test; @@ -14,7 +14,7 @@ public class BaseTestClassExample { protected void test() { int currentTests = this.currentTests.incrementAndGet(); try { - assertEquals(currentTests, 1); + assertThat(currentTests).isOne(); MILLISECONDS.sleep(10); } catch (InterruptedException e) { throw new RuntimeException(e); diff --git a/testng-core/src/test/java/test/thread/issue2361/IssueTest.java b/testng-core/src/test/java/test/thread/issue2361/IssueTest.java index 3c25ec2fd6..b4ed18b95c 100644 --- a/testng-core/src/test/java/test/thread/issue2361/IssueTest.java +++ b/testng-core/src/test/java/test/thread/issue2361/IssueTest.java @@ -1,6 +1,7 @@ package test.thread.issue2361; -import org.assertj.core.api.Assertions; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -19,7 +20,7 @@ public void ensureClassLevelSingleThreadedNatureGetsHonoured(Class cls) { xmlTest.setParallel(ParallelMode.METHODS); TestNG testng = create(suite); testng.run(); - Assertions.assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/thread/parallelization/BaseParallelizationTest.java b/testng-core/src/test/java/test/thread/parallelization/BaseParallelizationTest.java index bb89aa905d..956f38c121 100644 --- a/testng-core/src/test/java/test/thread/parallelization/BaseParallelizationTest.java +++ b/testng-core/src/test/java/test/thread/parallelization/BaseParallelizationTest.java @@ -1,6 +1,7 @@ package test.thread.parallelization; -import static org.testng.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static test.thread.parallelization.TestNgRunStateTracker.EventInfo.CLASS_NAME; import static test.thread.parallelization.TestNgRunStateTracker.EventInfo.METHOD_NAME; import static test.thread.parallelization.TestNgRunStateTracker.EventInfo.SUITE_NAME; @@ -95,7 +96,7 @@ public static void addParams( public static void verifyEventTypeForEventsLogs( List eventLogs, TestNgRunEvent event, String failMessage) { for (EventLog eventLog : eventLogs) { - assertSame(eventLog.getEvent(), event, failMessage); + assertThat(eventLog.getEvent()).withFailMessage(failMessage).isSameAs(event); } } @@ -107,7 +108,7 @@ public static void verifyDifferentThreadIdsForEvents( List threadIds = new ArrayList<>(); for (EventLog eventLog : eventLogs) { - assertFalse(threadIds.contains(eventLog.getThreadId()), failMessage); + assertThat(threadIds).withFailMessage(failMessage).doesNotContain(eventLog.getThreadId()); threadIds.add(eventLog.getThreadId()); } } @@ -124,7 +125,7 @@ public static void verifyDifferentThreadIdsForEvents( } for (EventLog eventLog : eventLogsTwo) { - assertFalse(threadIds.contains(eventLog.getThreadId()), failMessage); + assertThat(threadIds).withFailMessage(failMessage).doesNotContain(eventLog.getThreadId()); } } @@ -137,7 +138,7 @@ public static void verifySameThreadIdForAllEvents(List eventLogs, Stri if (threadId == -1) { threadId = eventLog.getThreadId(); } else { - assertEquals(eventLog.getThreadId(), threadId, failMessage); + assertThat(eventLog.getThreadId()).withFailMessage(failMessage).isEqualTo(threadId); } } } @@ -148,7 +149,9 @@ public static void verifySameThreadIdForAllEvents(List eventLogs, Stri public static void verifyEventThreadsSpawnedAfter( Long earlierThreadId, List eventsFromLaterThread, String failMessage) { for (EventLog eventLog : eventsFromLaterThread) { - assertTrue(eventLog.getThreadId() > earlierThreadId, failMessage); + assertThat(eventLog.getThreadId()) + .withFailMessage(failMessage) + .isGreaterThan(earlierThreadId); } } @@ -228,10 +231,9 @@ public static void verifyEventsOccurBetween( EventLog laterEventLog, String failMessage) { for (EventLog eventLog : inBetweenEventLogs) { - assertTrue( - eventLog.getTimeOfEvent() >= earlierEventLog.getTimeOfEvent() - && eventLog.getTimeOfEvent() <= laterEventLog.getTimeOfEvent(), - failMessage); + assertThat(eventLog.getTimeOfEvent()) + .withFailMessage(failMessage) + .isBetween(earlierEventLog.getTimeOfEvent(), laterEventLog.getTimeOfEvent()); } } @@ -242,8 +244,9 @@ public static void verifyEventsOccurBetween( // the assertion on the timestamps fails public static void verifySequentialTimingOfEvents(List eventLogs, String failMessage) { for (int i = 0; i + 1 < eventLogs.size(); i++) { - assertTrue( - eventLogs.get(i).getTimeOfEvent() < eventLogs.get(i + 1).getTimeOfEvent(), failMessage); + assertThat(eventLogs.get(i).getTimeOfEvent()) + .withFailMessage(failMessage) + .isLessThan(eventLogs.get(i + 1).getTimeOfEvent()); } } @@ -255,11 +258,13 @@ public static void verifySequentialTimingOfEvents( if (!firstEventLogs.isEmpty() && !secondEventLogs.isEmpty()) { Pair timestampsListOne = getEarliestAndLatestTimestamps(firstEventLogs); - assertNotNull(timestampsListOne); + assertThat(timestampsListOne).isNotNull(); Pair timestampsListTwo = getEarliestAndLatestTimestamps(secondEventLogs); - assertNotNull(timestampsListTwo); + assertThat(timestampsListTwo).isNotNull(); - assertTrue(timestampsListTwo.first() > timestampsListOne.second(), failMessage); + assertThat(timestampsListTwo.first()) + .withFailMessage(failMessage) + .isGreaterThan(timestampsListOne.second()); } } @@ -307,23 +312,23 @@ public static void verifyNumberOfInstancesOfTestClassForMethod( Multimap eventLogMap = getTestMethodEventLogsForMethod(suiteName, testName, clazz.getCanonicalName(), methodName); - assertEquals( - eventLogMap.keySet().size(), - numInstances, - "There should be " - + numInstances - + " instances " - + "associated with the class " - + clazz.getCanonicalName() - + " for method " - + methodName - + " in the " - + "test " - + testName - + " in the suite " - + suiteName - + ": " - + eventLogMap); + assertThat(eventLogMap.keySet()) + .withFailMessage( + "There should be " + + numInstances + + " instances " + + "associated with the class " + + clazz.getCanonicalName() + + " for method " + + methodName + + " in the " + + "test " + + testName + + " in the suite " + + suiteName + + ": " + + eventLogMap) + .hasSize(numInstances); } // Verify that all the test methods declared in the specified list of classes have the same @@ -352,15 +357,15 @@ public static void verifySameInstancesOfTestClassAssociatedWithMethods( if (instanceKeys == null) { instanceKeys = eventLogMap.keySet(); } else { - assertTrue( - instanceKeys.containsAll(eventLogMap.keySet()) - && eventLogMap.keySet().containsAll(instanceKeys), - "The same instances of " - + clazz.getCanonicalName() - + " should be associated with its methods for the test " - + testName - + " in the suite " - + suiteName); + assertThat(eventLogMap.keySet()) + .withFailMessage( + "The same instances of " + + clazz.getCanonicalName() + + " should be associated with its methods for the test " + + testName + + " in the suite " + + suiteName) + .hasSameElementsAs(instanceKeys); } } } @@ -438,13 +443,15 @@ public static void verifySimultaneousTestMethods( ClassInstanceMethodKey classAndMethodNameAndInstanceHash = new ClassInstanceMethodKey(eventLog); - assertNull( - methodsExecuting.get(classAndMethodNameAndInstanceHash), - "There should only be one start " - + "event logged for a method in the first block of test method events"); - assertFalse( - executingMethodThreadIds.contains(eventLog.getThreadId()), - "The first block of test method " + "events should all have different thread IDs"); + assertThat(methodsExecuting.get(classAndMethodNameAndInstanceHash)) + .withFailMessage( + "There should only be one start " + + "event logged for a method in the first block of test method events") + .isNull(); + assertThat(executingMethodThreadIds) + .withFailMessage( + "The first block of test method " + "events should all have different thread IDs") + .doesNotContain(eventLog.getThreadId()); methodsExecuting.put(classAndMethodNameAndInstanceHash, eventLog); executingMethodThreadIds.add(eventLog.getThreadId()); @@ -460,55 +467,59 @@ public static void verifySimultaneousTestMethods( new ClassInstanceMethodKey(eventLog); if (eventLog.getEvent() == LISTENER_TEST_METHOD_START) { - assertTrue( - methodsExecuting.get(classAndMethodNameAndInstanceHash) == null - && methodsCompleted.get(classAndMethodNameAndInstanceHash) == null, - "There should only be one " + "execution of any given method"); - assertFalse( - executingMethodThreadIds.contains(eventLog.getThreadId()), - "Event logs for currently " - + "executing test methods should have different thread IDs"); - assertTrue( - allThreadIds.contains(eventLog.getThreadId()), - "All of the test method event logs should " - + "have the same " - + threadCount - + " thread IDs: " - + allThreadIds); - assertTrue( - methodsExecuting.size() < threadCount, - "The current event log is a test method start " - + "event. The list of currently executing methods should be less than the thread count. " - + "Thread count: " - + threadCount - + ". Currently executing methods: " - + getStringForEventLogList(methodsExecuting.values())); + assertThat( + methodsExecuting.get(classAndMethodNameAndInstanceHash) == null + && methodsCompleted.get(classAndMethodNameAndInstanceHash) == null) + .withFailMessage("There should only be one " + "execution of any given method") + .isTrue(); + assertThat(executingMethodThreadIds) + .withFailMessage( + "Event logs for currently " + + "executing test methods should have different thread IDs") + .doesNotContain(eventLog.getThreadId()); + assertThat(allThreadIds) + .withFailMessage( + "All of the test method event logs should " + + "have the same " + + threadCount + + " thread IDs: " + + allThreadIds) + .contains(eventLog.getThreadId()); + assertThat(methodsExecuting.size() < threadCount) + .withFailMessage( + "The current event log is a test method start " + + "event. The list of currently executing methods should be less than the thread count. " + + "Thread count: " + + threadCount + + ". Currently executing methods: " + + getStringForEventLogList(methodsExecuting.values())) + .isTrue(); methodsExecuting.put(classAndMethodNameAndInstanceHash, eventLog); executingMethodThreadIds.add(eventLog.getThreadId()); } if (eventLog.getEvent() == TEST_METHOD_EXECUTION) { - assertNotNull( - methodsExecuting.get(classAndMethodNameAndInstanceHash), - "Found a test method " - + "execution event log that does not have a corresponding test method start event log"); - assertEquals( - eventLog.getThreadId(), - methodsExecuting.get(classAndMethodNameAndInstanceHash).getThreadId(), - "All the event logs for a given method should have the same thread ID"); + assertThat(methodsExecuting.get(classAndMethodNameAndInstanceHash)) + .withFailMessage( + "Found a test method " + + "execution event log that does not have a corresponding test method start event log") + .isNotNull(); + assertThat(eventLog.getThreadId()) + .withFailMessage("All the event logs for a given method should have the same thread ID") + .isEqualTo(methodsExecuting.get(classAndMethodNameAndInstanceHash).getThreadId()); } if (eventLog.getEvent() == LISTENER_TEST_METHOD_PASS) { - assertNotNull( - methodsExecuting.get(classAndMethodNameAndInstanceHash), - "Found a test method " - + "pass event log that does not have a corresponding test method start event log"); - assertEquals( - eventLog.getThreadId(), - methodsExecuting.get(classAndMethodNameAndInstanceHash).getThreadId(), - "All the event logs for a given method should have the same thread ID"); + assertThat(methodsExecuting.get(classAndMethodNameAndInstanceHash)) + .withFailMessage( + "Found a test method " + + "pass event log that does not have a corresponding test method start event log") + .isNotNull(); + assertThat(eventLog.getThreadId()) + .withFailMessage("All the event logs for a given method should have the same thread ID") + .isEqualTo(methodsExecuting.get(classAndMethodNameAndInstanceHash).getThreadId()); methodsExecuting.remove(classAndMethodNameAndInstanceHash); executingMethodThreadIds.remove(eventLog.getThreadId()); methodsCompleted.put(classAndMethodNameAndInstanceHash, eventLog); @@ -603,13 +614,15 @@ public static void verifyParallelTestMethodsWithNonParallelDataProvider( String classAndMethodName = eventLog.getData(CLASS_NAME) + "." + eventLog.getData(METHOD_NAME); - assertNull( - methodsExecuting.get(classAndMethodName), - "There should only be one start event logged for a " - + "method in the first block of test method events"); - assertNull( - executingMethodThreadIds.get(classAndMethodName), - "The first block of test method events " + "should all have different thread IDs"); + assertThat(methodsExecuting.get(classAndMethodName)) + .withFailMessage( + "There should only be one start event logged for a " + + "method in the first block of test method events") + .isNull(); + assertThat(executingMethodThreadIds.get(classAndMethodName)) + .withFailMessage( + "The first block of test method events " + "should all have different thread IDs") + .isNull(); methodsExecuting.put(classAndMethodName, eventLog); executingMethodThreadIds.put(classAndMethodName, eventLog.getThreadId()); @@ -644,38 +657,42 @@ public static void verifyParallelTestMethodsWithNonParallelDataProvider( } if (eventLog.getEvent() == LISTENER_TEST_METHOD_START) { - assertTrue( - executingMethodThreadIds.get(classAndMethodName) == null - || executingMethodThreadIds.get(classAndMethodName) == eventLog.getThreadId(), - "Event logs for all invocations of a method on a give class instance should have the same " - + "thread ID "); + assertThat( + executingMethodThreadIds.get(classAndMethodName) == null + || executingMethodThreadIds.get(classAndMethodName) == eventLog.getThreadId()) + .withFailMessage( + "Event logs for all invocations of a method on a give class instance should have the same " + + "thread ID ") + .isTrue(); for (String key : executingMethodThreadIds.keySet()) { if (!key.equals(classAndMethodName)) { - assertNotEquals( - eventLog.getThreadId(), - executingMethodThreadIds.get(key), - "Events for " + "different methods should have different thread IDs"); + assertThat(eventLog.getThreadId()) + .withFailMessage( + "Events for " + "different methods should have different thread IDs") + .isNotEqualTo(executingMethodThreadIds.get(key)); } } - assertTrue( - allThreadIds.contains(eventLog.getThreadId()), - "All of the test method event logs should " - + "have the same " - + threadCount - + " thread IDs: " - + allThreadIds); + assertThat(allThreadIds) + .withFailMessage( + "All of the test method event logs should " + + "have the same " + + threadCount + + " thread IDs: " + + allThreadIds) + .contains(eventLog.getThreadId()); if (methodsExecuting.get(classAndMethodName) == null) { - assertTrue( - methodsExecuting.size() < threadCount, - "The current event log is a test method start " - + "event for a method that has not yet been invoked. The list of currently executing " - + "methods should be less than the thread count. Thread count: " - + threadCount - + ". Currently executing methods: " - + getStringForEventLogList(methodsExecuting.values())); + assertThat(methodsExecuting.size() < threadCount) + .withFailMessage( + "The current event log is a test method start " + + "event for a method that has not yet been invoked. The list of currently executing " + + "methods should be less than the thread count. Thread count: " + + threadCount + + ". Currently executing methods: " + + getStringForEventLogList(methodsExecuting.values())) + .isTrue(); methodsExecuting.put(classAndMethodName, eventLog); executingMethodThreadIds.put(classAndMethodName, eventLog.getThreadId()); @@ -683,41 +700,43 @@ public static void verifyParallelTestMethodsWithNonParallelDataProvider( } else { methodInvocationsCounts.put( classAndMethodName, methodInvocationsCounts.get(classAndMethodName) + 1); - assertTrue( - methodInvocationsCounts.get(classAndMethodName) - <= expectedInvocationCounts.get(classAndMethodName), - "Method '" - + classAndMethodName - + "' is expected to execute only " - + expectedInvocationCounts.get(classAndMethodName) - + " times, but event logs show " - + "that it was execute at least " - + methodInvocationsCounts.get(classAndMethodName) - + " times"); + assertThat( + methodInvocationsCounts.get(classAndMethodName) + <= expectedInvocationCounts.get(classAndMethodName)) + .withFailMessage( + "Method '" + + classAndMethodName + + "' is expected to execute only " + + expectedInvocationCounts.get(classAndMethodName) + + " times, but event logs show " + + "that it was execute at least " + + methodInvocationsCounts.get(classAndMethodName) + + " times") + .isTrue(); } } if (eventLog.getEvent() == TEST_METHOD_EXECUTION) { - assertNotNull( - methodsExecuting.get(classAndMethodName), - "Found a test method execution event " - + "log that does not have a corresponding test method start event log"); - assertEquals( - eventLog.getThreadId(), - methodsExecuting.get(classAndMethodName).getThreadId(), - "All the event logs for a given method should have the same thread ID"); + assertThat(methodsExecuting.get(classAndMethodName)) + .withFailMessage( + "Found a test method execution event " + + "log that does not have a corresponding test method start event log") + .isNotNull(); + assertThat(eventLog.getThreadId()) + .withFailMessage("All the event logs for a given method should have the same thread ID") + .isEqualTo(methodsExecuting.get(classAndMethodName).getThreadId()); } if (eventLog.getEvent() == LISTENER_TEST_METHOD_PASS) { - assertNotNull( - methodsExecuting.get(classAndMethodName), - "Found a test method pass event log " - + "that does not have a corresponding test method start event log"); - assertEquals( - eventLog.getThreadId(), - methodsExecuting.get(classAndMethodName).getThreadId(), - "All the event logs for a given method should have the same thread ID"); + assertThat(methodsExecuting.get(classAndMethodName)) + .withFailMessage( + "Found a test method pass event log " + + "that does not have a corresponding test method start event log") + .isNotNull(); + assertThat(eventLog.getThreadId()) + .withFailMessage("All the event logs for a given method should have the same thread ID") + .isEqualTo(methodsExecuting.get(classAndMethodName).getThreadId()); if (methodInvocationsCounts .get(classAndMethodName) @@ -797,17 +816,17 @@ public static void verifyEventsForTestMethodsRunInTheSameThread( if (threadId == -1) { threadId = eventLog.getThreadId(); } else { - assertEquals( - eventLog.getThreadId(), - threadId, - "All of the method level events for the test " - + "method " - + method.getName() - + " in the test class " - + testClass.getCanonicalName() - + " for the test " - + suiteName - + " should be run in the same thread"); + assertThat(eventLog.getThreadId()) + .withFailMessage( + "All of the method level events for the test " + + "method " + + method.getName() + + " in the test class " + + testClass.getCanonicalName() + + " for the test " + + suiteName + + " should be run in the same thread") + .isEqualTo(threadId); } } } @@ -827,13 +846,15 @@ public static void verifySequentialSuites( List suiteListenerStartEventLogs = new ArrayList<>(); for (int i = 0; i < suiteLevelEventLogs.size(); i = i + 2) { - assertTrue( - suiteLevelEventLogs.get(i).getEvent() == LISTENER_SUITE_START - && suiteLevelEventLogs.get(i + 1).getEvent() == LISTENER_SUITE_FINISH, - "Because the suites are " - + "expected to execute sequentially, the suite level event logs should consist of a series of " - + "pairs of a suite listener onStart event logger followed by a suite listener onFinish event logger: " - + suiteLevelEventLogs); + assertThat( + suiteLevelEventLogs.get(i).getEvent() == LISTENER_SUITE_START + && suiteLevelEventLogs.get(i + 1).getEvent() == LISTENER_SUITE_FINISH) + .withFailMessage( + "Because the suites are " + + "expected to execute sequentially, the suite level event logs should consist of a series of " + + "pairs of a suite listener onStart event logger followed by a suite listener onFinish event logger: " + + suiteLevelEventLogs) + .isTrue(); suiteListenerStartEventLogs.add((suiteLevelEventLogs.get(i))); } @@ -899,13 +920,15 @@ public static void verifySequentialTests( + testLevelEventLogs); for (int i = 0; i < testLevelEventLogs.size(); i = i + 2) { - assertTrue( - testLevelEventLogs.get(i).getEvent() == LISTENER_TEST_START - && testLevelEventLogs.get(i + 1).getEvent() == LISTENER_TEST_FINISH, - "Because the tests are " - + "expected to execute sequentially, the test level event logs should consist of a series of " - + "pairs of a test listener onStart event logger followed by a test listener onFinish event logger: " - + testLevelEventLogs); + assertThat( + testLevelEventLogs.get(i).getEvent() == LISTENER_TEST_START + && testLevelEventLogs.get(i + 1).getEvent() == LISTENER_TEST_FINISH) + .withFailMessage( + "Because the tests are " + + "expected to execute sequentially, the test level event logs should consist of a series of " + + "pairs of a test listener onStart event logger followed by a test listener onFinish event logger: " + + testLevelEventLogs) + .isTrue(); } } @@ -948,12 +971,14 @@ public static void verifyParallelSuitesWithUnequalExecutionTimes( + suiteLevelEventLogs); } - assertFalse( - suitesExecuting.get(suiteName) != null || suitesCompleted.get(suiteName) != null, - "There should only be one execution of any given suite"); - assertFalse( - executingSuiteThreadIds.contains(eventLog.getThreadId()), - "Event logs for currently " + "executing suites should have different thread IDs"); + assertThat( + suitesExecuting.get(suiteName) != null || suitesCompleted.get(suiteName) != null) + .withFailMessage("There should only be one execution of any given suite") + .isFalse(); + assertThat(executingSuiteThreadIds) + .withFailMessage( + "Event logs for currently " + "executing suites should have different thread IDs") + .doesNotContain(eventLog.getThreadId()); suitesExecuting.put(suiteName, eventLog); executingSuiteThreadIds.add(eventLog.getThreadId()); @@ -961,13 +986,13 @@ public static void verifyParallelSuitesWithUnequalExecutionTimes( if (!suitesCompleted.isEmpty()) { EventLog priorEventLog = suiteLevelEventLogs.get(i - 1); - assertEquals( - priorEventLog.getEvent(), - LISTENER_SUITE_FINISH, - "When suites are executing in " - + "parallel and a new suite begins execution when the active thread count was last " - + "known to be equal to the maximum thread pool size, the previously logged suite " - + "level event should be a suite listener onFinish event."); + assertThat(priorEventLog.getEvent()) + .withFailMessage( + "When suites are executing in " + + "parallel and a new suite begins execution when the active thread count was last " + + "known to be equal to the maximum thread pool size, the previously logged suite " + + "level event should be a suite listener onFinish event.") + .isEqualTo(LISTENER_SUITE_FINISH); } } @@ -985,16 +1010,17 @@ public static void verifyParallelSuitesWithUnequalExecutionTimes( if (eventLog.getEvent() == LISTENER_SUITE_FINISH) { - assertNotNull( - suitesExecuting.get(suiteName), - "Found an event logger for a suite listener " - + "onFinish event that does not have a corresponding event logger for a suite listener " - + "onStart event"); - assertEquals( - eventLog.getThreadId(), - suitesExecuting.get(suiteName).getThreadId(), - "All the " - + "suite level event logs for a given suite should have the same thread ID"); + assertThat(suitesExecuting.get(suiteName)) + .withFailMessage( + "Found an event logger for a suite listener " + + "onFinish event that does not have a corresponding event logger for a suite listener " + + "onStart event") + .isNotNull(); + assertThat(eventLog.getThreadId()) + .withFailMessage( + "All the " + + "suite level event logs for a given suite should have the same thread ID") + .isEqualTo(suitesExecuting.get(suiteName).getThreadId()); suitesExecuting.remove(suiteName); executingSuiteThreadIds.remove(eventLog.getThreadId()); diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario1.java index e350658b0f..9e2e52e775 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteAndTestLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -102,21 +102,21 @@ public void setUp() { // Verifies that the expected number of suite, test and test method level events were logged. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs); - assertEquals( - testMethodLevelEventLogs.size(), - 15, - "There should be 15 test method level event logged for " - + SUITE - + ": " - + testMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs) + .hasSize(2); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs) + .hasSize(2); + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should be 15 test method level event logged for " + + SUITE + + ": " + + testMethodLevelEventLogs) + .hasSize(15); } // Verify that the suite listener and test listener events have timestamps in the following order: diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario2.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario2.java index 9251e64e83..5571136d7f 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario2.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase1Scenario2.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllEventLogsForSuite; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; @@ -384,109 +384,109 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 6, - "There should be 6 suite level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 12, - "There should be 12 test level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 204, - "There should 204 test method level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 33, - "There should be 33 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 54, - "There should be 54 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); - - assertEquals( - suiteThreeSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_C - + ": " - + suiteThreeSuiteLevelEventLogs); - assertEquals( - suiteThreeTestLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_C - + ": " - + suiteThreeTestLevelEventLogs); - assertEquals( - suiteThreeTestMethodLevelEventLogs.size(), - 117, - "There should be 87 test method level events " - + "logged for " - + SUITE_C - + ": " - + suiteThreeTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 6 suite level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + suiteLevelEventLogs) + .hasSize(6); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 12 test level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testLevelEventLogs) + .hasSize(12); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 204 test method level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testMethodLevelEventLogs) + .hasSize(204); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 33 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(33); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 54 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(54); + + assertThat(suiteThreeSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_C + + ": " + + suiteThreeSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteThreeTestLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_C + + ": " + + suiteThreeTestLevelEventLogs) + .hasSize(6); + assertThat(suiteThreeTestMethodLevelEventLogs) + .withFailMessage( + "There should be 87 test method level events " + + "logged for " + + SUITE_C + + ": " + + suiteThreeTestMethodLevelEventLogs) + .hasSize(117); } // Verify that all the events in the second suite and third suites run have timestamps later than diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario1.java index 04c18e102f..994c407803 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -226,80 +226,80 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 4, - "There should be 4 suite level events logged for " - + SUITE_A - + ", " - + SUITE_B - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_A - + ", " - + SUITE_B - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 87, - "There should 87 test method level events logged for " - + SUITE_A - + ", " - + SUITE_B - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 33, - "There should be 33 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 54, - "There should be 54 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 4 suite level events logged for " + + SUITE_A + + ", " + + SUITE_B + + ": " + + suiteLevelEventLogs) + .hasSize(4); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_A + + ", " + + SUITE_B + + ": " + + testLevelEventLogs) + .hasSize(6); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 87 test method level events logged for " + + SUITE_A + + ", " + + SUITE_B + + ": " + + testMethodLevelEventLogs) + .hasSize(87); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 33 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(33); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 54 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(54); } // Verify that the suites run in parallel by checking that the suite and test level events for diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario2.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario2.java index 16a5850127..556f2cf780 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario2.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase2Scenario2.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -382,109 +382,109 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 6, - "There should be 6 suite level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 12, - "There should be 12 test level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 204, - "There should 204 test method level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 33, - "There should be 33 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 54, - "There should be 54 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); - - assertEquals( - suiteThreeSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_C - + ": " - + suiteThreeSuiteLevelEventLogs); - assertEquals( - suiteThreeTestLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_C - + ": " - + suiteThreeTestLevelEventLogs); - assertEquals( - suiteThreeTestMethodLevelEventLogs.size(), - 117, - "There should be 87 test method level events " - + "logged for " - + SUITE_C - + ": " - + suiteThreeTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 6 suite level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + suiteLevelEventLogs) + .hasSize(6); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 12 test level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testLevelEventLogs) + .hasSize(12); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 204 test method level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testMethodLevelEventLogs) + .hasSize(204); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 33 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(33); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 54 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(54); + + assertThat(suiteThreeSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_C + + ": " + + suiteThreeSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteThreeTestLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_C + + ": " + + suiteThreeTestLevelEventLogs) + .hasSize(6); + assertThat(suiteThreeTestMethodLevelEventLogs) + .withFailMessage( + "There should be 87 test method level events " + + "logged for " + + SUITE_C + + ": " + + suiteThreeTestMethodLevelEventLogs) + .hasSize(117); } // Verify that the suites run in parallel by checking that the suite and test level events for diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario1.java index 9bb621932f..bf5742fdb0 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteAndTestLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -139,21 +139,21 @@ public void setUp() { // Verifies that the expected number of suite, test and test method level events were logged. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs); - assertEquals( - testMethodLevelEventLogs.size(), - 45, - "There should be 45 test method level events logged for " - + SUITE - + ": " - + testMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs) + .hasSize(2); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs) + .hasSize(2); + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should be 45 test method level events logged for " + + SUITE + + ": " + + testMethodLevelEventLogs) + .hasSize(45); } // Verify that the suite listener and test listener events have timestamps in the following order: diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario2.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario2.java index 552e1432ad..98cd9ee4f0 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario2.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase3Scenario2.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllEventLogsForSuite; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; @@ -355,80 +355,80 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 4, - "There should be 4 suite level events logged for " - + SUITE_A - + ", " - + SUITE_B - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_A - + ", " - + SUITE_B - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 150, - "There should 150 test method level events logged for " - + SUITE_A - + ", " - + SUITE_B - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 69, - "There should be 69 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 81, - "There should be 54 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 4 suite level events logged for " + + SUITE_A + + ", " + + SUITE_B + + ": " + + suiteLevelEventLogs) + .hasSize(4); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_A + + ", " + + SUITE_B + + ": " + + testLevelEventLogs) + .hasSize(6); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 150 test method level events logged for " + + SUITE_A + + ", " + + SUITE_B + + ": " + + testMethodLevelEventLogs) + .hasSize(150); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 69 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(69); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 54 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(81); } // Verify that all the events in the second suite and third suites run have timestamps later than diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase4Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase4Scenario1.java index 4cd1176c61..a7c1f8d8a9 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase4Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase4Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllEventLogsForSuite; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; @@ -698,110 +698,110 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 6, - "There should be 6 suite level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 12, - "There should be 12 test level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 420, - "There should 420 test method level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 69, - "There should be 69 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 81, - "There should be 81 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); - - assertEquals( - suiteThreeSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_C - + ": " - + suiteThreeSuiteLevelEventLogs); - assertEquals( - suiteThreeTestLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_C - + ": " - + suiteThreeTestLevelEventLogs); - assertEquals( - suiteThreeTestMethodLevelEventLogs.size(), - 270, - "There should be 270 test method level events " - + "logged for " - + SUITE_C - + ": " - + suiteThreeTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 6 suite level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + suiteLevelEventLogs) + .hasSize(6); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 12 test level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testLevelEventLogs) + .hasSize(12); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 420 test method level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testMethodLevelEventLogs) + .hasSize(420); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 69 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(69); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 81 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(81); + + assertThat(suiteThreeSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_C + + ": " + + suiteThreeSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteThreeTestLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_C + + ": " + + suiteThreeTestLevelEventLogs) + .hasSize(6); + assertThat(suiteThreeTestMethodLevelEventLogs) + .withFailMessage( + "There should be 270 test method level events " + + "logged for " + + SUITE_C + + ": " + + suiteThreeTestMethodLevelEventLogs) + .hasSize(270); } // Verify that the suites run in parallel by checking that the suite and test level events for diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario1.java index 5e166f22c5..e6855c05f5 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteAndTestLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -107,21 +107,21 @@ public void setUp() { // Verifies that the expected number of suite, test and test method level events were logged. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs); - assertEquals( - testMethodLevelEventLogs.size(), - 30, - "There should be 15 test method level event logged for " - + SUITE - + ": " - + testMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs) + .hasSize(2); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs) + .hasSize(2); + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should be 15 test method level event logged for " + + SUITE + + ": " + + testMethodLevelEventLogs) + .hasSize(30); } // Verify that the suite listener and test listener events have timestamps in the following order: diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario2.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario2.java index 7bec1d2ede..1cd34b2c2d 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario2.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase5Scenario2.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllEventLogsForSuite; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; @@ -244,80 +244,80 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 4, - "There should be 4 suite level events logged for " - + SUITE_A - + " and " - + SUITE_B - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_A - + " and " - + SUITE_B - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 303, - "There should 303 test method level events logged for " - + SUITE_A - + " and " - + SUITE_B - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 84, - "There should be 84 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 219, - "There should be 219 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 4 suite level events logged for " + + SUITE_A + + " and " + + SUITE_B + + ": " + + suiteLevelEventLogs) + .hasSize(4); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_A + + " and " + + SUITE_B + + ": " + + testLevelEventLogs) + .hasSize(6); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 303 test method level events logged for " + + SUITE_A + + " and " + + SUITE_B + + ": " + + testMethodLevelEventLogs) + .hasSize(303); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 84 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(84); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 219 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(219); } // Verify that all the events in the second suite run have timestamps later than the suite diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase6Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase6Scenario1.java index c696edfe42..2b63d0d554 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase6Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase6Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -395,109 +395,109 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 6, - "There should be 6 suite level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 12, - "There should be 12 test level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 420, - "There should 420 test method level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 84, - "There should be 84 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 219, - "There should be 219 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); - - assertEquals( - suiteThreeSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_C - + ": " - + suiteThreeSuiteLevelEventLogs); - assertEquals( - suiteThreeTestLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_C - + ": " - + suiteThreeTestLevelEventLogs); - assertEquals( - suiteThreeTestMethodLevelEventLogs.size(), - 117, - "There should be 87 test method level events " - + "logged for " - + SUITE_C - + ": " - + suiteThreeTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 6 suite level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + suiteLevelEventLogs) + .hasSize(6); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 12 test level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testLevelEventLogs) + .hasSize(12); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 420 test method level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testMethodLevelEventLogs) + .hasSize(420); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 84 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(84); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 219 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(219); + + assertThat(suiteThreeSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_C + + ": " + + suiteThreeSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteThreeTestLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_C + + ": " + + suiteThreeTestLevelEventLogs) + .hasSize(6); + assertThat(suiteThreeTestMethodLevelEventLogs) + .withFailMessage( + "There should be 87 test method level events " + + "logged for " + + SUITE_C + + ": " + + suiteThreeTestMethodLevelEventLogs) + .hasSize(117); } // Verify that the suites run in parallel by checking that the suite and test level events for diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario1.java index 15d5751fbc..45bb3b3343 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteAndTestLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -112,21 +112,21 @@ public void setUp() { // Verifies that the expected number of suite, test and test method level events were logged. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs); - assertEquals( - testMethodLevelEventLogs.size(), - 45, - "There should be 45 test method level events logged for " - + SUITE - + ": " - + testMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + SUITE + ": " + suiteLevelEventLogs) + .hasSize(2); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + SUITE + ": " + testLevelEventLogs) + .hasSize(2); + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should be 45 test method level events logged for " + + SUITE + + ": " + + testMethodLevelEventLogs) + .hasSize(45); } // Verify that the suite listener and test listener events have timestamps in the following order: diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario2.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario2.java index 21935a8850..3af7a41db4 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario2.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase7Scenario2.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllEventLogsForSuite; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; @@ -265,80 +265,80 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 4, - "There should be 4 suite level events logged for " - + SUITE_A - + " and " - + SUITE_B - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_A - + " and " - + SUITE_B - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 297, - "There should 267 test method level events logged for " - + SUITE_A - + " and " - + SUITE_B - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 117, - "There should be 117 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 180, - "There should be 180 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 4 suite level events logged for " + + SUITE_A + + " and " + + SUITE_B + + ": " + + suiteLevelEventLogs) + .hasSize(4); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_A + + " and " + + SUITE_B + + ": " + + testLevelEventLogs) + .hasSize(6); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 267 test method level events logged for " + + SUITE_A + + " and " + + SUITE_B + + ": " + + testMethodLevelEventLogs) + .hasSize(297); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 117 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(117); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 180 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(180); } // Verify that all the events in the second suite run have timestamps later than the suite diff --git a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase8Scenario1.java b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase8Scenario1.java index 60dc053a90..5fe72e4a5b 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase8Scenario1.java +++ b/testng-core/src/test/java/test/thread/parallelization/ParallelByMethodsTestCase8Scenario1.java @@ -1,6 +1,6 @@ package test.thread.parallelization; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteLevelEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllSuiteListenerStartEventLogs; import static test.thread.parallelization.TestNgRunStateTracker.getAllTestLevelEventLogs; @@ -602,109 +602,109 @@ public void setUp() { // suites. @Test public void sanityCheck() { - assertEquals( - suiteLevelEventLogs.size(), - 6, - "There should be 6 suite level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + suiteLevelEventLogs); - assertEquals( - testLevelEventLogs.size(), - 12, - "There should be 12 test level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testLevelEventLogs); - - assertEquals( - testMethodLevelEventLogs.size(), - 405, - "There should 405 test method level events logged for " - + SUITE_A - + ", " - + SUITE_B - + " and " - + SUITE_C - + ": " - + testMethodLevelEventLogs); - - assertEquals( - suiteOneSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_A - + ": " - + suiteOneSuiteLevelEventLogs); - assertEquals( - suiteOneTestLevelEventLogs.size(), - 2, - "There should be 2 test level events logged for " - + SUITE_A - + ": " - + suiteOneTestLevelEventLogs); - assertEquals( - suiteOneTestMethodLevelEventLogs.size(), - 117, - "There should be 117 test method level events " - + "logged for " - + SUITE_A - + ": " - + suiteOneTestMethodLevelEventLogs); - - assertEquals( - suiteTwoSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_B - + ": " - + suiteTwoSuiteLevelEventLogs); - assertEquals( - suiteTwoTestLevelEventLogs.size(), - 4, - "There should be 4 test level events logged for " - + SUITE_B - + ": " - + suiteTwoTestLevelEventLogs); - assertEquals( - suiteTwoTestMethodLevelEventLogs.size(), - 171, - "There should be 171 test method level events " - + "logged for " - + SUITE_B - + ": " - + suiteTwoTestMethodLevelEventLogs); - - assertEquals( - suiteThreeSuiteLevelEventLogs.size(), - 2, - "There should be 2 suite level events logged for " - + SUITE_C - + ": " - + suiteThreeSuiteLevelEventLogs); - assertEquals( - suiteThreeTestLevelEventLogs.size(), - 6, - "There should be 6 test level events logged for " - + SUITE_C - + ": " - + suiteThreeTestLevelEventLogs); - assertEquals( - suiteThreeTestMethodLevelEventLogs.size(), - 117, - "There should be 117 test method level events " - + "logged for " - + SUITE_C - + ": " - + suiteThreeTestMethodLevelEventLogs); + assertThat(suiteLevelEventLogs) + .withFailMessage( + "There should be 6 suite level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + suiteLevelEventLogs) + .hasSize(6); + assertThat(testLevelEventLogs) + .withFailMessage( + "There should be 12 test level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testLevelEventLogs) + .hasSize(12); + + assertThat(testMethodLevelEventLogs) + .withFailMessage( + "There should 405 test method level events logged for " + + SUITE_A + + ", " + + SUITE_B + + " and " + + SUITE_C + + ": " + + testMethodLevelEventLogs) + .hasSize(405); + + assertThat(suiteOneSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_A + + ": " + + suiteOneSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestLevelEventLogs) + .withFailMessage( + "There should be 2 test level events logged for " + + SUITE_A + + ": " + + suiteOneTestLevelEventLogs) + .hasSize(2); + assertThat(suiteOneTestMethodLevelEventLogs) + .withFailMessage( + "There should be 117 test method level events " + + "logged for " + + SUITE_A + + ": " + + suiteOneTestMethodLevelEventLogs) + .hasSize(117); + + assertThat(suiteTwoSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_B + + ": " + + suiteTwoSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteTwoTestLevelEventLogs) + .withFailMessage( + "There should be 4 test level events logged for " + + SUITE_B + + ": " + + suiteTwoTestLevelEventLogs) + .hasSize(4); + assertThat(suiteTwoTestMethodLevelEventLogs) + .withFailMessage( + "There should be 171 test method level events " + + "logged for " + + SUITE_B + + ": " + + suiteTwoTestMethodLevelEventLogs) + .hasSize(171); + + assertThat(suiteThreeSuiteLevelEventLogs) + .withFailMessage( + "There should be 2 suite level events logged for " + + SUITE_C + + ": " + + suiteThreeSuiteLevelEventLogs) + .hasSize(2); + assertThat(suiteThreeTestLevelEventLogs) + .withFailMessage( + "There should be 6 test level events logged for " + + SUITE_C + + ": " + + suiteThreeTestLevelEventLogs) + .hasSize(6); + assertThat(suiteThreeTestMethodLevelEventLogs) + .withFailMessage( + "There should be 117 test method level events " + + "logged for " + + SUITE_C + + ": " + + suiteThreeTestMethodLevelEventLogs) + .hasSize(117); } // Verify that the suites run in parallel by checking that the suite and test level events for diff --git a/testng-core/src/test/java/test/thread/parallelization/ThreadAffinityTest.java b/testng-core/src/test/java/test/thread/parallelization/ThreadAffinityTest.java index 4be339969c..fc13507fe9 100644 --- a/testng-core/src/test/java/test/thread/parallelization/ThreadAffinityTest.java +++ b/testng-core/src/test/java/test/thread/parallelization/ThreadAffinityTest.java @@ -5,7 +5,6 @@ import java.util.Arrays; import java.util.Map; import java.util.Set; -import org.assertj.core.api.Assertions; import org.assertj.core.api.SoftAssertions; import org.testng.TestNG; import org.testng.annotations.AfterClass; @@ -105,7 +104,7 @@ public void testThreadAffinityInFactoryInstances() { createXmlTest(xmlsuite, "Test_1", TestMultipleInstance.class).setParallel(mode); TestNG testng = create(xmlsuite); testng.run(); - Assertions.assertThat(testng.getStatus()).isEqualTo(0); + assertThat(testng.getStatus()).isZero(); } @Test(description = "GITHUB-2110") diff --git a/testng-core/src/test/java/test/thread/parallelization/issue2321/TestMultipleInstance.java b/testng-core/src/test/java/test/thread/parallelization/issue2321/TestMultipleInstance.java index b0d49c6ebe..830358e6a9 100644 --- a/testng-core/src/test/java/test/thread/parallelization/issue2321/TestMultipleInstance.java +++ b/testng-core/src/test/java/test/thread/parallelization/issue2321/TestMultipleInstance.java @@ -1,6 +1,7 @@ package test.thread.parallelization.issue2321; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; @@ -20,7 +21,7 @@ public void independent() { @Test(dependsOnMethods = "independent") public void dependent() { long currentThreadId = Thread.currentThread().getId(); - Assert.assertEquals(currentThreadId, threadId, "Thread Ids didn't match"); + assertThat(currentThreadId).withFailMessage("Thread Ids didn't match").isEqualTo(threadId); } @DataProvider(name = "dp") diff --git a/testng-core/src/test/java/test/timeout/TimeOutTest.java b/testng-core/src/test/java/test/timeout/TimeOutTest.java index 76402357a8..58a5a5c245 100644 --- a/testng-core/src/test/java/test/timeout/TimeOutTest.java +++ b/testng-core/src/test/java/test/timeout/TimeOutTest.java @@ -1,10 +1,11 @@ package test.timeout; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; -import org.testng.Assert; import org.testng.ITestResult; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -73,14 +74,14 @@ public void testWithOnlyOneThread() { addClass(TestClassSample.class); run(); Collection> failed = getFailedTests().values(); - Assert.assertEquals(failed.size(), 1); + assertThat(failed).hasSize(1); ITestResult failedResult = failed.iterator().next().get(0); - Assert.assertTrue(failedResult.getThrowable() instanceof ThreadTimeoutException); - Assert.assertEquals( - failedResult.getThrowable().getMessage(), - String.format( - "Method %s.testMethod() didn't finish within the time-out 1000", - TestClassSample.class.getName())); + assertThat(failedResult.getThrowable()).isInstanceOf(ThreadTimeoutException.class); + assertThat(failedResult.getThrowable().getMessage()) + .isEqualTo( + String.format( + "Method %s.testMethod() didn't finish within the time-out 1000", + TestClassSample.class.getName())); } @Test(description = "GITHUB-2009") @@ -88,12 +89,12 @@ public void testTimeOutWhenParallelIsMethods() { addClass(TimeOutWithParallelSample.class); setParallel(ParallelMode.METHODS); run(); - Assert.assertEquals(getFailedTests().values().size(), 1); - Assert.assertEquals(getSkippedTests().values().size(), 0); - Assert.assertEquals(getPassedTests().values().size(), 0); + assertThat(getFailedTests().values()).hasSize(1); + assertThat(getSkippedTests()).isEmpty(); + assertThat(getPassedTests()).isEmpty(); ITestResult result = getFailedTests().values().iterator().next().get(0); long time = result.getEndMillis() - result.getStartMillis(); - Assert.assertTrue(time < 2000); + assertThat(time).isLessThan(2000); } @Override diff --git a/testng-core/src/test/java/test/timeout/github2440/TimeoutWithNoExecutorTest.java b/testng-core/src/test/java/test/timeout/github2440/TimeoutWithNoExecutorTest.java index 2334d7791f..3d6cece6e0 100644 --- a/testng-core/src/test/java/test/timeout/github2440/TimeoutWithNoExecutorTest.java +++ b/testng-core/src/test/java/test/timeout/github2440/TimeoutWithNoExecutorTest.java @@ -1,7 +1,8 @@ package test.timeout.github2440; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.Collections; -import org.testng.Assert; import org.testng.TestListenerAdapter; import org.testng.TestNG; import org.testng.annotations.Test; @@ -23,7 +24,7 @@ public void testTimeout() { TestListenerAdapter listener = new TestListenerAdapter(); testNG.addListener(listener); testNG.run(); - Assert.assertTrue(listener.getFailedTests().isEmpty()); - Assert.assertTrue(listener.getConfigurationFailures().isEmpty()); + assertThat(listener.getFailedTests()).isEmpty(); + assertThat(listener.getConfigurationFailures()).isEmpty(); } } diff --git a/testng-core/src/test/java/test/timeout/github2672/TimeoutStacktraceTest.java b/testng-core/src/test/java/test/timeout/github2672/TimeoutStacktraceTest.java index 54519d277d..581246fae2 100644 --- a/testng-core/src/test/java/test/timeout/github2672/TimeoutStacktraceTest.java +++ b/testng-core/src/test/java/test/timeout/github2672/TimeoutStacktraceTest.java @@ -1,6 +1,6 @@ package test.timeout.github2672; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import com.google.common.base.Throwables; import java.util.Arrays; @@ -35,10 +35,11 @@ public void verifyTimeoutStacktraceNewExecutor() { testng.run(); Throwable testError = listener.getTestError(); - assertTrue(testError instanceof ThreadTimeoutException); - assertTrue( - Arrays.stream(testError.getStackTrace()) - .anyMatch(s -> s.getMethodName().equals("testTimeoutStacktrace"))); + assertThat(testError).isInstanceOf(ThreadTimeoutException.class); + assertThat( + Arrays.stream(testError.getStackTrace()) + .anyMatch(s -> s.getMethodName().equals("testTimeoutStacktrace"))) + .isTrue(); } @Test @@ -51,10 +52,11 @@ public void verifyTimeoutStacktraceNoExecutor() { testng.run(); Throwable testError = listener.getTestError(); - assertTrue(testError instanceof ThreadTimeoutException); - assertTrue( - Throwables.getCausalChain(testError).stream() - .flatMap((Throwable throwable) -> Arrays.stream(throwable.getStackTrace())) - .anyMatch(s -> s.getMethodName().equals("testTimeoutStacktrace"))); + assertThat(testError).isInstanceOf(ThreadTimeoutException.class); + assertThat( + Throwables.getCausalChain(testError).stream() + .flatMap((Throwable throwable) -> Arrays.stream(throwable.getStackTrace())) + .anyMatch(s -> s.getMethodName().equals("testTimeoutStacktrace"))) + .isTrue(); } } diff --git a/testng-core/src/test/java/test/tmp/A.java b/testng-core/src/test/java/test/tmp/A.java index 288d7fa3a4..20133032cf 100644 --- a/testng-core/src/test/java/test/tmp/A.java +++ b/testng-core/src/test/java/test/tmp/A.java @@ -1,26 +1,26 @@ package test.tmp; +import org.assertj.core.api.SoftAssertions; import org.testng.annotations.Test; -import org.testng.asserts.SoftAssert; @Test public class A { - private final SoftAssert m_assert = new SoftAssert(); + private final SoftAssertions m_assert = new SoftAssertions(); public void test1() { - m_assert.assertTrue(true, "test1()"); + m_assert.assertThat(true).as("test1()").isTrue(); } public void test2() { - m_assert.assertTrue(true, "test2()"); + m_assert.assertThat(true).as("test2()").isTrue(); } public void multiple() { - m_assert.assertTrue(true, "Success 1"); - m_assert.assertTrue(true, "Success 2"); - m_assert.assertTrue(false, "Failure 1"); - m_assert.assertTrue(true, "Success 3"); - m_assert.assertTrue(false, "Failure 2"); + m_assert.assertThat(true).as("Success 1").isTrue(); + m_assert.assertThat(true).as("Success 2").isTrue(); + m_assert.assertThat(false).as("Failure 1").isTrue(); + m_assert.assertThat(true).as("Success 3").isTrue(); + m_assert.assertThat(false).as("Failure 2").isTrue(); m_assert.assertAll(); } } diff --git a/testng-core/src/test/java/test/tmp/DataDrivenTest.java b/testng-core/src/test/java/test/tmp/DataDrivenTest.java index 4253c7b9f7..a8ee9eb75b 100644 --- a/testng-core/src/test/java/test/tmp/DataDrivenTest.java +++ b/testng-core/src/test/java/test/tmp/DataDrivenTest.java @@ -1,12 +1,13 @@ package test.tmp; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Properties; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -31,6 +32,6 @@ public Object[][] createData() throws IOException { @Test(dataProvider = "provider") public void foo(int n) { - Assert.assertTrue(n > 0); + assertThat(n).isPositive(); } } diff --git a/testng-core/src/test/java/test/tmp/ExponentTest.java b/testng-core/src/test/java/test/tmp/ExponentTest.java index 3f91924e0d..b90c9a875e 100644 --- a/testng-core/src/test/java/test/tmp/ExponentTest.java +++ b/testng-core/src/test/java/test/tmp/ExponentTest.java @@ -1,6 +1,6 @@ package test.tmp; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; @@ -28,7 +28,7 @@ public void setUp() { @Test(dataProvider = "random") public void testExponent(double exponent, double expected) { debug("COMPARING " + myExpFunction(exponent) + " AND " + expected); - assertEquals(myExpFunction(exponent), expected); + assertThat(myExpFunction(exponent)).isEqualTo(expected); } private void debug(String s) { diff --git a/testng-core/src/test/java/test/tmp/Sub.java b/testng-core/src/test/java/test/tmp/Sub.java index 005090a7a6..cef4dc537d 100644 --- a/testng-core/src/test/java/test/tmp/Sub.java +++ b/testng-core/src/test/java/test/tmp/Sub.java @@ -1,6 +1,7 @@ package test.tmp; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.AfterClass; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; @@ -27,7 +28,7 @@ public void subTest() { @AfterSuite public void verify() { - Assert.assertTrue(m_beforeTest); - Assert.assertTrue(m_afterTest); + assertThat(m_beforeTest).isTrue(); + assertThat(m_afterTest).isTrue(); } } diff --git a/testng-core/src/test/java/test/triangle/CheckCount.java b/testng-core/src/test/java/test/triangle/CheckCount.java index d171f63041..dd02e7b07c 100644 --- a/testng-core/src/test/java/test/triangle/CheckCount.java +++ b/testng-core/src/test/java/test/triangle/CheckCount.java @@ -1,6 +1,7 @@ package test.triangle; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -14,6 +15,6 @@ public class CheckCount { public void testCheckCount(String expectedCalls) { int i = Integer.valueOf(expectedCalls); int numCalls = CountCalls.getNumCalls(); - Assert.assertEquals(numCalls, i); + assertThat(numCalls).isEqualTo(i); } } diff --git a/testng-core/src/test/java/test/triangle/Child1.java b/testng-core/src/test/java/test/triangle/Child1.java index 83caae2e43..9476b283f2 100644 --- a/testng-core/src/test/java/test/triangle/Child1.java +++ b/testng-core/src/test/java/test/triangle/Child1.java @@ -1,6 +1,6 @@ package test.triangle; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -12,11 +12,15 @@ public class Child1 extends Base { @Test public void child1() { - assertTrue(m_isInitialized, "Wasn't initialized correctly " + hashCode() + " " + getClass()); + assertThat(m_isInitialized) + .withFailMessage("Wasn't initialized correctly " + hashCode() + " " + getClass()) + .isTrue(); } @Test public void child1a() { - assertTrue(m_isInitialized, "Wasn't initialized correctly " + hashCode() + " " + getClass()); + assertThat(m_isInitialized) + .withFailMessage("Wasn't initialized correctly " + hashCode() + " " + getClass()) + .isTrue(); } } diff --git a/testng-core/src/test/java/test/triangle/Child2.java b/testng-core/src/test/java/test/triangle/Child2.java index 3a9ba9b066..55ad76f04f 100644 --- a/testng-core/src/test/java/test/triangle/Child2.java +++ b/testng-core/src/test/java/test/triangle/Child2.java @@ -1,6 +1,6 @@ package test.triangle; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import org.testng.annotations.Test; @@ -13,6 +13,6 @@ public class Child2 extends Base { @Test public void child2() { - assertTrue(m_isInitialized, "Wasn't initialized correctly"); + assertThat(m_isInitialized).withFailMessage("Wasn't initialized correctly").isTrue(); } } diff --git a/testng-core/src/test/java/test/uniquesuite/TestAfter.java b/testng-core/src/test/java/test/uniquesuite/TestAfter.java index a8565a562a..d6d04c303e 100644 --- a/testng-core/src/test/java/test/uniquesuite/TestAfter.java +++ b/testng-core/src/test/java/test/uniquesuite/TestAfter.java @@ -1,6 +1,7 @@ package test.uniquesuite; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.TestNG; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; @@ -14,7 +15,7 @@ public void testAfter() { tng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory()); tng.setTestClasses(new Class[] {TestAfter1.class, TestAfter2.class}); tng.run(); - Assert.assertEquals(BaseAfter.m_afterCount, 1); + assertThat(BaseAfter.m_afterCount).isOne(); } @AfterTest diff --git a/testng-core/src/test/java/test/uniquesuite/TestBefore1.java b/testng-core/src/test/java/test/uniquesuite/TestBefore1.java index 635531f83a..b66cf78f46 100644 --- a/testng-core/src/test/java/test/uniquesuite/TestBefore1.java +++ b/testng-core/src/test/java/test/uniquesuite/TestBefore1.java @@ -1,12 +1,13 @@ package test.uniquesuite; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class TestBefore1 extends BaseBefore { @Test public void verify() { - Assert.assertEquals(m_beforeCount, 1); + assertThat(m_beforeCount).isOne(); } } diff --git a/testng-core/src/test/java/test/uniquesuite/TestBefore2.java b/testng-core/src/test/java/test/uniquesuite/TestBefore2.java index aa3454b6d1..9b70ddcad9 100644 --- a/testng-core/src/test/java/test/uniquesuite/TestBefore2.java +++ b/testng-core/src/test/java/test/uniquesuite/TestBefore2.java @@ -1,12 +1,13 @@ package test.uniquesuite; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.annotations.Test; public class TestBefore2 extends BaseBefore { @Test public void verify() { - Assert.assertEquals(m_beforeCount, 1); + assertThat(m_beforeCount).isOne(); } } diff --git a/testng-core/src/test/java/test/verify/VerifyTest.java b/testng-core/src/test/java/test/verify/VerifyTest.java index 75323ef8c4..ce006b87f1 100644 --- a/testng-core/src/test/java/test/verify/VerifyTest.java +++ b/testng-core/src/test/java/test/verify/VerifyTest.java @@ -1,6 +1,7 @@ package test.verify; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.assertThat; + import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -15,7 +16,7 @@ private void runTest(Class cls, int expected) { tng.addListener((ITestNGListener) tla); tng.run(); - Assert.assertEquals(tla.getPassedTests().size(), expected); + assertThat(tla.getPassedTests()).hasSize(expected); } @Test @@ -33,7 +34,7 @@ public void verifyTestListener() { TestNG tng = create(Verify2SampleTest.class); VerifyTestListener.m_count = 0; tng.run(); - Assert.assertEquals(VerifyTestListener.m_count, 1); + assertThat(VerifyTestListener.m_count).isOne(); } @Test @@ -41,6 +42,6 @@ public void verifyBaseClassTestListener() { TestNG tng = create(Verify3SampleTest.class); VerifyTestListener.m_count = 0; tng.run(); - Assert.assertEquals(VerifyTestListener.m_count, 1); + assertThat(VerifyTestListener.m_count).isOne(); } } diff --git a/testng-core/src/test/java/test/xml/TestNGContentHandlerTest.java b/testng-core/src/test/java/test/xml/TestNGContentHandlerTest.java index 01d6d4882e..6ee571990e 100644 --- a/testng-core/src/test/java/test/xml/TestNGContentHandlerTest.java +++ b/testng-core/src/test/java/test/xml/TestNGContentHandlerTest.java @@ -5,7 +5,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.List; -import org.testng.Assert; import org.testng.annotations.Test; import org.testng.xml.SuiteXmlParser; import org.testng.xml.TestNGContentHandler; @@ -24,7 +23,7 @@ public void testDescriptionInclusion() throws Exception { List includes = handler.getSuite().getTests().get(0).getXmlClasses().get(0).getIncludedMethods(); String desc = includes.get(0).getDescription(); - Assert.assertEquals("simple-description", desc); + assertThat("simple-description").isEqualTo(desc); } @Test(description = "GITHUB-2501") diff --git a/testng-core/src/test/java/test/xml/XmlVerifyTest.java b/testng-core/src/test/java/test/xml/XmlVerifyTest.java index c173dc641d..9412d2e465 100644 --- a/testng-core/src/test/java/test/xml/XmlVerifyTest.java +++ b/testng-core/src/test/java/test/xml/XmlVerifyTest.java @@ -7,7 +7,6 @@ import java.util.Collections; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import org.testng.Assert; import org.testng.ITestNGListener; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -36,8 +35,7 @@ public class XmlVerifyTest extends SimpleBaseTest { public void testToXmlWithComments() { XmlSuite suite = createSuite(); String xml = suite.toXml(); - assertThat(xml).contains(COMMAND_LINE_TEST); - assertThat(xml).contains(DEFAULT_SUITE); + assertThat(xml).contains(COMMAND_LINE_TEST).contains(DEFAULT_SUITE); } @Test(description = "github-1455", dependsOnMethods = "testToXmlWithComments") @@ -45,8 +43,7 @@ public void testToXmlWithoutComments() { System.setProperty("testng.xml.weaver", "org.testng.xml.CommentDisabledXmlWeaver"); XmlSuite suite = createSuite(); String xml = suite.toXml(); - assertThat(xml).doesNotContain(COMMAND_LINE_TEST); - assertThat(xml).doesNotContain(DEFAULT_SUITE); + assertThat(xml).doesNotContain(COMMAND_LINE_TEST).doesNotContain(DEFAULT_SUITE); } @Test(description = "GITHUB-3177") @@ -60,7 +57,7 @@ public void testThreadPoolRelatedAttributesPresentInXml() throws Exception { Document document = builder.parse(new InputSource(new StringReader(xml))); document.getDocumentElement().normalize(); NodeList allSuites = document.getElementsByTagName("suite"); - assertThat(allSuites.getLength()).isEqualTo(1); + assertThat(allSuites.getLength()).isOne(); Node xmlSuite = allSuites.item(0); assertThat(xmlSuite.getNodeType()).isEqualTo(Node.ELEMENT_NODE); Element element = (Element) xmlSuite; @@ -99,7 +96,7 @@ public void handleInvalidSuites() { tng.addListener((ITestNGListener) tla); tng.run(); } catch (TestNGException ex) { - Assert.assertEquals(tla.getPassedTests().size(), 0); + assertThat(tla.getPassedTests()).isEmpty(); } } @@ -110,30 +107,30 @@ public void preserverOrderAttribute() { suite.setPreserveOrder(true); test.setPreserveOrder(false); - Assert.assertFalse(test.getPreserveOrder()); + assertThat(test.getPreserveOrder()).isFalse(); suite.setPreserveOrder(false); test.setPreserveOrder(true); - Assert.assertTrue(test.getPreserveOrder()); + assertThat(test.getPreserveOrder()).isTrue(); suite.setPreserveOrder((Boolean) null); test.setPreserveOrder(false); - Assert.assertFalse(test.getPreserveOrder()); + assertThat(test.getPreserveOrder()).isFalse(); suite.setPreserveOrder(false); test.setPreserveOrder((Boolean) null); - Assert.assertFalse(test.getPreserveOrder()); + assertThat(test.getPreserveOrder()).isFalse(); suite.setPreserveOrder((Boolean) null); test.setPreserveOrder(true); - Assert.assertTrue(test.getPreserveOrder()); + assertThat(test.getPreserveOrder()).isTrue(); suite.setPreserveOrder(true); test.setPreserveOrder((Boolean) null); - Assert.assertTrue(test.getPreserveOrder()); + assertThat(test.getPreserveOrder()).isTrue(); suite.setPreserveOrder((Boolean) null); test.setPreserveOrder((Boolean) null); - Assert.assertNull(test.getPreserveOrder()); + assertThat(test.getPreserveOrder()).isNull(); } } diff --git a/testng-core/src/test/java/test/yaml/YamlTest.java b/testng-core/src/test/java/test/yaml/YamlTest.java index e82fd9309c..783fad1ff2 100644 --- a/testng-core/src/test/java/test/yaml/YamlTest.java +++ b/testng-core/src/test/java/test/yaml/YamlTest.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.testng.internal.Yaml; @@ -50,7 +49,7 @@ public void compareFiles(String name) throws IOException { Collection s2 = new Parser(getPathToResource("yaml" + File.separator + name + ".xml")).parse(); - Assert.assertEquals(s1, s2); + assertThat(s1).isEqualTo(s2); } @Test(description = "GITHUB-1787") @@ -108,7 +107,7 @@ public void testXmlTestIndex() throws IOException { String yamlSuiteFile = "src/test/resources/yaml/testXmlTestIndex.yaml"; XmlSuite suite = yamlParser.parse(yamlSuiteFile, new FileInputStream(yamlSuiteFile), false); List tests = suite.getTests(); - assertThat(tests.size()).isEqualTo(3); + assertThat(tests).hasSize(3); for (int i = 0; i < tests.size(); i++) { assertThat(tests.get(i).getIndex()).isEqualTo(i); } diff --git a/testng-core/src/test/java/test_result/AfterListenerSample.java b/testng-core/src/test/java/test_result/AfterListenerSample.java index fbfd398363..3a6f141865 100644 --- a/testng-core/src/test/java/test_result/AfterListenerSample.java +++ b/testng-core/src/test/java/test_result/AfterListenerSample.java @@ -1,6 +1,7 @@ package test_result; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestResult; @@ -21,7 +22,7 @@ public void skippedTest() {} @Test public void succeedTest() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test_result/BeforeListenerSample.java b/testng-core/src/test/java/test_result/BeforeListenerSample.java index f7f342ac2b..79bca73afe 100644 --- a/testng-core/src/test/java/test_result/BeforeListenerSample.java +++ b/testng-core/src/test/java/test_result/BeforeListenerSample.java @@ -1,6 +1,10 @@ package test_result; -import org.testng.*; +import static org.assertj.core.api.Assertions.fail; + +import org.testng.IInvokedMethod; +import org.testng.IInvokedMethodListener; +import org.testng.ITestResult; import org.testng.annotations.Listeners; import org.testng.annotations.Test; @@ -20,7 +24,7 @@ public void skippedTest() {} @Test public void succeedTest() { - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test_result/GitHub1197Sample.java b/testng-core/src/test/java/test_result/GitHub1197Sample.java index 01234aa210..62b7cbe885 100644 --- a/testng-core/src/test/java/test_result/GitHub1197Sample.java +++ b/testng-core/src/test/java/test_result/GitHub1197Sample.java @@ -1,6 +1,7 @@ package test_result; -import org.testng.Assert; +import static org.assertj.core.api.Assertions.fail; + import org.testng.ITestResult; import org.testng.Reporter; import org.testng.annotations.Test; @@ -26,7 +27,7 @@ public void skippedTest() { @Test public void succeedTest() { Reporter.getCurrentTestResult().setStatus(ITestResult.SUCCESS); - Assert.fail(); + fail(); } @Test diff --git a/testng-core/src/test/java/test_result/TestResultTest.java b/testng-core/src/test/java/test_result/TestResultTest.java index 09db4ae408..b1ebc9c738 100644 --- a/testng-core/src/test/java/test_result/TestResultTest.java +++ b/testng-core/src/test/java/test_result/TestResultTest.java @@ -17,9 +17,9 @@ public class TestResultTest extends SimpleBaseTest { public void ensureITestResultHasValidStatusAndTimestampWhenInvokingConfigurationMethod() { TestNG testng = create(TestclassSample.class); testng.run(); - assertThat(TestclassSample.startTimestamp).isLessThanOrEqualTo(0); + assertThat(TestclassSample.startTimestamp).isNotPositive(); assertThat(TestclassSample.startStatus).isEqualTo(ITestResult.STARTED); - assertThat(TestclassSample.endTimestamp).isGreaterThan(0); + assertThat(TestclassSample.endTimestamp).isPositive(); assertThat(TestclassSample.endStatus).isEqualTo(ITestResult.SUCCESS); } diff --git a/testng-core/src/test/java/test_result/issue2535/CalculatorTestSample.java b/testng-core/src/test/java/test_result/issue2535/CalculatorTestSample.java index 6c6b8c06d0..129b9f8182 100644 --- a/testng-core/src/test/java/test_result/issue2535/CalculatorTestSample.java +++ b/testng-core/src/test/java/test_result/issue2535/CalculatorTestSample.java @@ -1,8 +1,9 @@ package test_result.issue2535; +import static org.assertj.core.api.Assertions.fail; + import java.util.HashMap; import java.util.Map; -import org.testng.Assert; import org.testng.IInvokedMethod; import org.testng.IInvokedMethodListener; import org.testng.ITestResult; @@ -20,7 +21,7 @@ public void calculatorUiTest() {} @BeforeClass public void setup() { - Assert.fail(); + fail(); } @BeforeMethod diff --git a/testng-core/src/test/kotlin/org/testng/BasicSample.kt b/testng-core/src/test/kotlin/org/testng/BasicSample.kt index 6baf1aa8f7..f3fa509a0d 100644 --- a/testng-core/src/test/kotlin/org/testng/BasicSample.kt +++ b/testng-core/src/test/kotlin/org/testng/BasicSample.kt @@ -1,12 +1,12 @@ package org.testng -import org.testng.Assert.fail +import org.assertj.core.api.Assertions.fail import org.testng.annotations.Test class BasicSample { @Test fun test() { - fail("BOUM") + fail("BOUM") } } diff --git a/testng-core/src/test/kotlin/org/testng/internal/ClassHelperTest.kt b/testng-core/src/test/kotlin/org/testng/internal/ClassHelperTest.kt index 798e53249c..9a8e92f68c 100644 --- a/testng-core/src/test/kotlin/org/testng/internal/ClassHelperTest.kt +++ b/testng-core/src/test/kotlin/org/testng/internal/ClassHelperTest.kt @@ -106,8 +106,9 @@ class ClassHelperTest { .map { it.declaringClass.name + "." + it.name } - assertThat(methods).hasSize(expectedCount) - assertThat(methods).contains(*expected) + assertThat(methods) + .hasSize(expectedCount) + .contains(*expected) } @DataProvider(name = "data") diff --git a/testng-core/testng-core-build.gradle.kts b/testng-core/testng-core-build.gradle.kts index 5637cfc3cb..c6e5f52b30 100644 --- a/testng-core/testng-core-build.gradle.kts +++ b/testng-core/testng-core-build.gradle.kts @@ -40,7 +40,6 @@ dependencies { implementation(projects.testngReflectionUtils) implementation(projects.testngRunnerApi) implementation("org.webjars:jquery:3.7.1") - testImplementation(projects.testngAsserts) // Groovy 4.x is required to support Java 21 bytecode (class file major version 65) // Groovy 3.x doesn't support reading Java 21 bytecode testImplementation("org.apache.groovy:groovy-all:4.0.29") {