I have this controller :
``
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.constraints.NotNull;
@Validated
@RestController
public class ControllerFoo {
public String getFoo(@NotNull String foo) {
System.out.println(foo);
return foo;
}
}
``
I want to test @NotNull, see my test :
`@ExtendWith(MockitoExtension.class)
class TestControllerFooTests {
@Test
void testControllerFooKONotNull() {
ControllerFoo controllerFoo = new ControllerFoo();
assertThrows(Exception.class, () -> controllerFoo.getFoo(null));
}
}`
Actually my test is KO because controllerFoo.getFoo(null), do not throw anything.
What should I do ?
Thanks in advance
I want to test my parameter to be not null. It doesn’t work and I need to understand why
New contributor
Clement Boissiere is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.