BAEL-5210 JUnit fail assertions use cases (#11314)

Co-authored-by: Andres Luzuriaga <aluzuriaga@proofpoint.com>
This commit is contained in:
andresluzu
2021-10-11 19:00:54 -05:00
committed by GitHub
parent 3cee038dfe
commit 8dce57b64f
2 changed files with 122 additions and 0 deletions
@@ -0,0 +1,50 @@
package com.baeldung;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.function.Supplier;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.fail;
public class FailAssertionUnitTest {
@Test
void failThrowable() {
try {
safeMethod();
// more testing code
} catch (Exception e) {
fail(e);
}
}
@Test
void failMessageThrowable() {
try {
safeMethod();
// more testing code
} catch (Exception e) {
fail("Unexpected exception was thrown", e);
}
}
@Test
@Disabled
void failMessageSupplier() {
Supplier<String> timedMessage = () -> DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now());
fail(timedMessage);
}
@Test
void genericType() {
Stream.of().map(entry -> fail("should not be called"));
}
private void safeMethod() {
return;
}
}