Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate default error message #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apiguardian.api.API;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.function.ThrowingSupplier;
import org.junit.platform.commons.util.StringUtils;
import org.opentest4j.MultipleFailuresError;

/**
Expand Down Expand Up @@ -135,6 +136,9 @@ public static <V> V fail() {
* }</pre>
*/
public static <V> V fail(String message) {
if (StringUtils.isBlank(message)) {
AssertionUtils.fail("Assertion.fail() called");
}
AssertionUtils.fail(message);
return null; // appeasing the compiler: this line will never be executed.
}
Expand All @@ -147,6 +151,9 @@ public static <V> V fail(String message) {
* generic return type {@code V}.
*/
public static <V> V fail(String message, Throwable cause) {
if (StringUtils.isBlank(message)) {
AssertionUtils.fail("Assertion.fail() called", cause);
}
AssertionUtils.fail(message, cause);
return null; // appeasing the compiler: this line will never be executed.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package org.junit.jupiter.api;

import static org.junit.jupiter.api.AssertionTestUtils.assertEmptyMessage;
import static org.junit.jupiter.api.AssertionTestUtils.assertMessageContains;
import static org.junit.jupiter.api.AssertionTestUtils.assertMessageEquals;
import static org.junit.jupiter.api.AssertionTestUtils.expectAssertionFailedError;
Expand All @@ -36,7 +35,7 @@ void failWithoutArgument() {
expectAssertionFailedError();
}
catch (AssertionFailedError ex) {
assertEmptyMessage(ex);
assertMessageEquals(ex, "Assertion.fail() called");
}
}

Expand Down Expand Up @@ -69,7 +68,7 @@ void failWithNullString() {
expectAssertionFailedError();
}
catch (AssertionFailedError ex) {
assertEmptyMessage(ex);
assertMessageEquals(ex, "Assertion.fail() called");
}
}

Expand All @@ -80,7 +79,7 @@ void failWithNullMessageSupplier() {
expectAssertionFailedError();
}
catch (AssertionFailedError ex) {
assertEmptyMessage(ex);
assertMessageEquals(ex, "Assertion.fail() called");
}
}

Expand All @@ -104,7 +103,7 @@ void failWithThrowable() {
expectAssertionFailedError();
}
catch (AssertionFailedError ex) {
assertEmptyMessage(ex);
assertMessageEquals(ex, "Assertion.fail() called");
Throwable cause = ex.getCause();
assertMessageContains(cause, "cause");
}
Expand All @@ -131,7 +130,7 @@ void failWithNullStringAndThrowable() {
expectAssertionFailedError();
}
catch (AssertionFailedError ex) {
assertEmptyMessage(ex);
assertMessageEquals(ex, "Assertion.fail() called");
Throwable cause = ex.getCause();
assertMessageContains(cause, "cause");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.junit.jupiter.api

import org.junit.jupiter.api.AssertEquals.assertEquals
import org.junit.jupiter.api.AssertionTestUtils.assertEmptyMessage
import org.junit.jupiter.api.AssertionTestUtils.assertMessageContains
import org.junit.jupiter.api.AssertionTestUtils.assertMessageEquals
import org.opentest4j.AssertionFailedError
Expand Down Expand Up @@ -43,7 +42,7 @@ class KotlinFailAssertionsTests {
assertThrows<AssertionFailedError> {
fail(null as String?)
}
assertEmptyMessage(ex)
assertMessageEquals(ex, "Assertion.fail() called")
}

@Test
Expand All @@ -52,7 +51,7 @@ class KotlinFailAssertionsTests {
assertThrows<AssertionFailedError> {
fail(null as (() -> String)?)
}
assertEmptyMessage(ex)
assertMessageEquals(ex, "Assertion.fail() called")
}

@Test
Expand All @@ -75,7 +74,7 @@ class KotlinFailAssertionsTests {
assertThrows<AssertionFailedError> {
fail(Throwable(throwableCause))
}
assertEmptyMessage(ex)
assertMessageEquals(ex, "Assertion.fail() called")
val cause = ex.cause
assertMessageContains(cause, throwableCause)
}
Expand All @@ -100,7 +99,7 @@ class KotlinFailAssertionsTests {
assertThrows<AssertionFailedError> {
fail(null, Throwable(throwableCause))
}
assertEmptyMessage(ex)
assertMessageEquals(ex, "Assertion.fail() called")
val cause = ex.cause
assertMessageContains(cause, throwableCause)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static ReportEntry from(Map<String, String> keyValuePairs) {
/**
* Factory for creating a new {@code ReportEntry} from a key-value pair.
*
* @param key the key under which the value should published; never
* @param key the key under which the value should be published; never
* {@code null} or blank
* @param value the value to publish; never {@code null} or blank
*/
Expand Down