Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/main/java/org/testng/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ protected Assert() {
* @param message the assertion error message
*/
public static void assertTrue(boolean condition, String message) {
if (!condition) {
failNotEquals(condition, Boolean.TRUE, message);
}
// Delegated to AssertJ (behaviour-identical, only the failure message differs).
assertThat(condition).as(message).isTrue();
}

/**
Expand All @@ -81,9 +80,8 @@ public static void assertTrue(boolean condition) {
* @param message the assertion error message
*/
public static void assertFalse(boolean condition, String message) {
if (condition) {
failNotEquals(condition, Boolean.FALSE, message); // TESTNG-81
}
// Delegated to AssertJ (behaviour-identical, only the failure message differs).
assertThat(condition).as(message).isFalse();
}

/**
Expand All @@ -102,10 +100,9 @@ public static void assertFalse(boolean condition) {
* @param realCause the original exception
*/
public static void fail(String message, Throwable realCause) {
AssertionError ae = new AssertionError(message);
ae.initCause(realCause);

throw ae;
// Delegated to AssertJ (behaviour-identical: throws an AssertionError with the given message
// and cause).
org.assertj.core.api.Assertions.fail(message, realCause);
}

/**
Expand All @@ -114,7 +111,8 @@ public static void fail(String message, Throwable realCause) {
* @param message the assertion error message
*/
public static void fail(String message) {
throw new AssertionError(message);
// Delegated to AssertJ (behaviour-identical: throws an AssertionError with the given message).
org.assertj.core.api.Assertions.fail(message);
}

/** Fails a test with no message. */
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/testng/AssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,15 @@ public void testAssertEqualsNoOrderNotDeep() {
@Test(
description = "GITHUB-2080",
expectedExceptions = AssertionError.class,
expectedExceptionsMessageRegExp = "test expected \\[true\\] but found \\[false\\]")
expectedExceptionsMessageRegExp = "(?s)\\[test\\] .*Expecting value to be true but was false")
public void testAssertTrueMessage() {
Assert.assertTrue(false, "test");
}

@Test(
description = "GITHUB-2080",
expectedExceptions = AssertionError.class,
expectedExceptionsMessageRegExp = "test expected \\[false\\] but found \\[true\\]")
expectedExceptionsMessageRegExp = "(?s)\\[test\\] .*Expecting value to be false but was true")
public void testAssertFalseMessage() {
Assert.assertFalse(true, "test");
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/test/assertion/AssertionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public void test2() {
"onAfterAssert");
}

@Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = "Raw test .*")
@Test(
expectedExceptions = AssertionError.class,
expectedExceptionsMessageRegExp = "(?s)\\[Raw test\\] .*")
public void test2_fails() {
try {
rawAssertion.assertTrue(true);
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/test/assertion/SoftAssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public void testAssertAllCount() {
sa.assertAll();
Assert.fail("Exception expected");
} catch (AssertionError e) {
String[] lines = e.getMessage().split("\r?\n");
Assert.assertEquals(lines.length, 2);
lines[1] = lines[1].replaceFirst(message, "");
Assert.assertFalse(lines[1].contains(message));
// Exactly one assertion failed, so the user message is reported exactly once. (Line counting
// is avoided here because the delegated AssertJ failure messages span multiple lines.)
String report = e.getMessage();
Assert.assertTrue(report.contains(message), report);
Assert.assertEquals(report.indexOf(message), report.lastIndexOf(message), report);
}
}

Expand Down