Is there any valid variant to test controller with the predicate
in it?
@RestController
public class QueryLauncherController {
private QueryLauncherService queryLauncherService;
@Autowired
public QueryLauncherController(QueryLauncherService queryLauncherService) {
this.queryLauncherService = queryLauncherService;
}
@GetMapping("/queryLauncher/CMP")
public List<QueryLauncherDto> getLaunchersCompany(RTAdmin admin) {
return queryLauncherService.getLaunchersList(admin, QueryLauncher::getIsCompany);
}
}
I've tried to solve this issue using any(Predicate.class)
but IDE highlights it as Unchecked assignment and it looks pretty dumb.
The code I've written for the test is:
public void returnCompanyLinks_When_companyRequested() throws Exception {
when(queryLauncherService.getLaunchersList(eq(user), any(Predicate.class))).thenReturn(queryLauncherDtos);
mockMvc.perform(get(QUERY_LAUNCHER_URL + CMP).session(mockSession))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(content().json(new Gson().toJson(queryLauncherDtos)));
}
The goal is to run method only in the case when QueryLauncher::getIsInvestor
.
List<QueryLauncherDto> getLaunchersList(RTAdmin admin, Predicate<QueryLauncher> launcherType);
Are there any variants to do it?
queryLauncherService.getLaunchersList