package org.innovateuk.ifs.management.controller;

import org.innovateuk.ifs.BaseControllerMockMVCTest;
import org.innovateuk.ifs.competition.resource.CompetitionStatus;
import org.innovateuk.ifs.management.model.AssessmentPanelModelPopulator;
import org.innovateuk.ifs.management.viewmodel.AssessmentPanelViewModel;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.springframework.test.web.servlet.MvcResult;

import static org.innovateuk.ifs.base.amend.BaseBuilderAmendFunctions.id;
import static org.innovateuk.ifs.base.amend.BaseBuilderAmendFunctions.name;
import static org.innovateuk.ifs.competition.builder.CompetitionResourceBuilder.newCompetitionResource;
import static org.innovateuk.ifs.competition.resource.CompetitionStatus.CLOSED;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

public class CompetitionManagementAssessmentPanelControllerTest extends BaseControllerMockMVCTest<CompetitionManagementAssessmentPanelController> {

    @Spy
    @InjectMocks
    private AssessmentPanelModelPopulator assessmentPanelModelPopulator;

    @Override
    protected CompetitionManagementAssessmentPanelController supplyControllerUnderTest() {
        return new CompetitionManagementAssessmentPanelController();
    }

    @Test
    public void assessmentPanel() throws Exception {
        long competitionId = 1;
        String competitionName = "Competition x";
        CompetitionStatus competitionStatus = CLOSED;

        competitionResource = newCompetitionResource()
                .with(id(competitionId))
                .with(name(competitionName))
                .withCompetitionStatus(competitionStatus)
                .build();

        when(competitionService.getById(competitionId)).thenReturn(competitionResource);

        MvcResult result = mockMvc.perform(get("/assessment/panel/competition/{competitionId}", competitionId))
                .andExpect(status().isOk())
                .andExpect(view().name("competition/manage-assessment-panel"))
                .andReturn();

        AssessmentPanelViewModel model = (AssessmentPanelViewModel) result.getModelAndView().getModel().get("model");

        verify(competitionService, only()).getById(competitionId);

        assertEquals(competitionId, (long) model.getCompetitionId());
        assertEquals(competitionName, model.getCompetitionName());
        assertEquals(competitionStatus, model.getCompetitionStatus());
    }
}

@@ -93,24 +93,114 @@
 ockMVCTest;%0A
+import org.innovateuk.ifs.assessment.panel.resource.AssessmentPanelKeyStatisticsResource;%0A
 import org.i
@@ -327,16 +327,96 @@
 ulator;%0A
+import org.innovateuk.ifs.management.service.CompetitionAssessmentPanelService;%0A
 import o
@@ -535,16 +535,41 @@
 tMocks;%0A
+import org.mockito.Mock;%0A
 import o
@@ -1652,16 +1652,206 @@
 lator;%0A%0A
+    @Mock%0A    private CompetitionAssessmentPanelService competitionAssessmentPanelService;%0A%0A    @Mock%0A    private AssessmentPanelKeyStatisticsResource assessmentPanelKeyStatisticsResource;%0A%0A
     @Ove
@@ -2461,78 +2461,439 @@
     
-when(competitionService.getById(competitionId)).thenReturn(competition
+assessmentPanelKeyStatisticsResource.setApplicationsInPanel(1L);%0A        assessmentPanelKeyStatisticsResource.setAssessorsInvited(2L);%0A        assessmentPanelKeyStatisticsResource.setAssessorsAccepted(1L);%0A%0A%0A        when(competitionService.getById(competitionId)).thenReturn(competitionResource);%0A        when(competitionAssessmentPanelService.getAssessmentPanelKeyStatistics(competitionId)).thenReturn(assessmentPanelKeyStatistics
 Reso

Fix up existing unit test