package org.junit.jupiter.api;
import static org.junit.jupiter.api.AssertionUtils.buildPrefix;
import static org.junit.jupiter.api.AssertionUtils.nullSafeGet;
import java.util.function.Supplier;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.function.ThrowingSupplier;
import org.junit.platform.commons.util.BlacklistedExceptions;
import org.junit.platform.commons.util.StringUtils;
import org.opentest4j.AssertionFailedError;
class AssertDoesNotThrow {
private AssertDoesNotThrow() {
}
static void assertDoesNotThrow(Executable executable) {
assertDoesNotThrow(executable, (Object) null);
}
static void assertDoesNotThrow(Executable executable, String message) {
assertDoesNotThrow(executable, (Object) message);
}
static void assertDoesNotThrow(Executable executable, Supplier<String> messageSupplier) {
assertDoesNotThrow(executable, (Object) messageSupplier);
}
private static void assertDoesNotThrow(Executable executable, Object messageOrSupplier) {
try {
executable.execute();
}
catch (Throwable t) {
BlacklistedExceptions.rethrowIfBlacklisted(t);
throw createAssertionFailedError(messageOrSupplier, t);
}
}
static <T> T assertDoesNotThrow(ThrowingSupplier<T> supplier) {
return assertDoesNotThrow(supplier, (Object) null);
}
static <T> T assertDoesNotThrow(ThrowingSupplier<T> supplier, String message) {
return assertDoesNotThrow(supplier, (Object) message);
}
static <T> T assertDoesNotThrow(ThrowingSupplier<T> supplier, Supplier<String> messageSupplier) {
return assertDoesNotThrow(supplier, (Object) messageSupplier);
}
private static <T> T assertDoesNotThrow(ThrowingSupplier<T> supplier, Object messageOrSupplier) {
try {
return supplier.get();
}
catch (Throwable t) {
BlacklistedExceptions.rethrowIfBlacklisted(t);
throw createAssertionFailedError(messageOrSupplier, t);
}
}
private static AssertionFailedError createAssertionFailedError(Object messageOrSupplier, Throwable t) {
String message = buildPrefix(nullSafeGet(messageOrSupplier)) + "Unexpected exception thrown: "
+ t.getClass().getName() + buildSuffix(t.getMessage());
return new AssertionFailedError(message, t);
}
private static String buildSuffix(String message) {
return StringUtils.isNotBlank(message) ? ": " + message : "";
}
}