2

I am testing out the following code snippet that I found here.

Eclipse Oxygen Version: Oxygen.2 Release (4.7.2) - if that matters

import org.junit.jupiter.api.Assertions;
....
@Test
void exceptionTesting() {
    Executable closureContainingCodeToTest = () -> {throw new IllegalArgumentException("a message");};
    Assertions.assertThrows(IllegalArgumentException.class, closureContainingCodeToTest, "a message");
}

However, the code doesn't compile.

I am getting the error below:

The method assertThrows(Class, Executable, String) in the type Assertions is not applicable for the arguments (Class, Executable, String) DbHandlerTest.java line 96 Java Problem

Of course my goal is not just to test the above snippet but to write a test for my code. Please help.

  • Can please expand the entire import statements block? – Sormuras Jan 30 '18 at 10:08
  • There are other tests in that class which will need the other imports ... import static org.junit.jupiter.api.Assertions.assertEquals; import java.sql.SQLException; import java.util.Properties; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Executable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; – Vishal Gokhale Jan 30 '18 at 10:43

1 Answers1

4

I figured out the problem ... Thanks somuras for the right question. Following import was wrong

import org.junit.jupiter.api.Executable;

It should have been this:

import org.junit.jupiter.api.function.Executable;
  • You're welcome. Looks like you had (or still have) multiple version of junit-jupiter-api in your classpath. – Sormuras Jan 30 '18 at 12:15