I am using JUnit 5
library and I try to use assertThrows and get the exception thrown in order to get the message of the exception. I have such piece of code:
import org.junit.jupiter.api.Assertions;
//import org.junit.Assert;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
public class Tests {
private static void execute() throws Exception {
ArrayList<String> filter = ListString.filter(new ArrayList<String>(Arrays.asList("1", "2", "3")), "4");
}
@Test
public void listStringTest() {
// This part doesn't work
Throwable throwable = Assertions.assertThrows(Exception.class, Tests::execute);
assertEquals("Exception texnt", throwable.getMessage());
}
}
I get the following message:
But the documentation says that assert throws returns T extends Throwable
, not void
:
Where did I make a mistake?