BAEL-5210 JUnit fail assertions use cases (#11314)
Co-authored-by: Andres Luzuriaga <aluzuriaga@proofpoint.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user