@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@PreAuthorize("@messageSecurityService.isAuthorized(#userAuthentication)")
public
Have you stub the return of the @MockBean e.g
@MockBean(name = "messageSecurityService")
public MessageSecurityService messageSecurityService;
@Test
public void testing(){
when(messageSecurityService.isAuthorized(anyString())).thenReturn("somethingHere");
//rest of your assertions
}
also have you added the following in your test class:
@BeforeEach
public void init() {
MockitoAnnotations.initMocks(this);
}