I am not getting how to write assertDoesNotThrow() using AssertJ library How to write assertDoesNotThrow() exception using AssertJ library? This is my question and anyone pls help me out in solving this .
CodePudding user response:
assertDoesNotThrow
is not an AssertJ assertion but it belongs to JUnit's org.junit.jupiter.api.Assertions.
AssertJ provides other options, like:
More examples in the docs.
CodePudding user response:
JUnit's Assertions.assertDoesNotThrow
expects an instance of the Executable
interface.
Before Java 8, which introduced lambdas, this would be:
Assertions.assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
// your code here which must not throw an exception
}
});
Java 8 introduced lambdas which allow to make this code much more concise:
Assertions.assertDoesNotThrow(() -> {
// your code here which must not throw an exception
});