@WebMvcTest(DashboardController.class)
class DashboardControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private DashboardService dashboardService;
@Test
public void shouldReturnViewWithPrefilledData() throws Exception {
when(dashboardService.getAnalyticsGraphData()).thenReturn(new Integer[]{13, 42});
this.mockMvc
.perform(get("/dashboard"))
.andExpect(status().isOk())
.andExpect(view().name("dashboard"))
.andExpect(model().attribute("user", "Duke"))
.andExpect(model().attribute("analyticsGraph", Matchers.arrayContaining(13, 42)))
.andExpect(model().attributeExists("quickNote"));
}
}