<commit_before>package com.worth.ifs.management.controller;

import com.worth.ifs.BaseControllerMockMVCTest;
import com.worth.ifs.competition.resource.CompetitionResource;
import com.worth.ifs.management.model.CompetitionClosedModelPopulator;
import com.worth.ifs.management.model.CompetitionInAssessmentModelPopulator;
import com.worth.ifs.management.viewmodel.CompetitionClosedViewModel;
import com.worth.ifs.management.viewmodel.CompetitionInAssessmentViewModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MvcResult;

import static com.worth.ifs.competition.builder.CompetitionResourceBuilder.newCompetitionResource;
import static com.worth.ifs.competition.resource.CompetitionStatus.CLOSED;
import static com.worth.ifs.competition.resource.CompetitionStatus.IN_ASSESSMENT;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(MockitoJUnitRunner.class)
@TestPropertySource(locations = "classpath:application.properties")
public class CompetitionManagementCompetitionControllerTest extends BaseControllerMockMVCTest<CompetitionManagementCompetitionController> {

    @Spy
    @InjectMocks
    private CompetitionInAssessmentModelPopulator competitionInAssessmentModelPopulator;

    @Spy
    @InjectMocks
    private CompetitionClosedModelPopulator competitionClosedModelPopulator;

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

    @Test
    public void competition_inAssessment() throws Exception {
        CompetitionResource competition = newCompetitionResource()
                .withCompetitionStatus(IN_ASSESSMENT)
                .withName("Technology inspired")
                .build();

        when(competitionService.getById(competition.getId())).thenReturn(competition);

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

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

        assertEquals(competition.getId(), model.getCompetitionId());
        assertEquals("Technology inspired", model.getCompetitionName());

        verify(competitionService, only()).getById(competition.getId());
    }

    @Test
    public void competition_closed() throws Exception {
        CompetitionResource competition = newCompetitionResource()
                .withCompetitionStatus(CLOSED)
                .withName("Photonics for health")
                .build();

        when(competitionService.getById(competition.getId())).thenReturn(competition);

        MvcResult result = mockMvc.perform(get("/competition/{competitionId}", competition.getId()))
                .andExpect(status().isOk())
                .andExpect(model().attributeExists("model"))
                .andExpect(view().name("competition/competition-closed"))
                .andReturn();

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

        assertEquals(competition.getId(), model.getCompetitionId());
        assertEquals("Photonics for health", model.getCompetitionName());

        verify(competitionService, only()).getById(competition.getId());
    }

    @Test
    public void closeAssessment() throws Exception {
        Long competitionId = 1L;
        mockMvc.perform(post("/competition/{competitionId}/close-assessment", competitionId))
                .andExpect(status().is3xxRedirection())
                .andExpect(redirectedUrl("/dashboard/live"));
        verify(competitionService, only()).closeAssessment(competitionId);
    }
}<commit_msg>INFUND-6604 Fixing failing test caused by INFUND-6459.<commit_after>package com.worth.ifs.management.controller;

import com.worth.ifs.BaseControllerMockMVCTest;
import com.worth.ifs.competition.resource.CompetitionResource;
import com.worth.ifs.management.model.CompetitionClosedModelPopulator;
import com.worth.ifs.management.model.CompetitionInAssessmentModelPopulator;
import com.worth.ifs.management.viewmodel.CompetitionClosedViewModel;
import com.worth.ifs.management.viewmodel.CompetitionInAssessmentViewModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.MvcResult;

import static com.worth.ifs.competition.builder.CompetitionResourceBuilder.newCompetitionResource;
import static com.worth.ifs.competition.resource.CompetitionStatus.CLOSED;
import static com.worth.ifs.competition.resource.CompetitionStatus.IN_ASSESSMENT;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@RunWith(MockitoJUnitRunner.class)
@TestPropertySource(locations = "classpath:application.properties")
public class CompetitionManagementCompetitionControllerTest extends BaseControllerMockMVCTest<CompetitionManagementCompetitionController> {

    @Spy
    @InjectMocks
    private CompetitionInAssessmentModelPopulator competitionInAssessmentModelPopulator;

    @Spy
    @InjectMocks
    private CompetitionClosedModelPopulator competitionClosedModelPopulator;

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

    @Test
    public void competition_inAssessment() throws Exception {
        CompetitionResource competition = newCompetitionResource()
                .withCompetitionStatus(IN_ASSESSMENT)
                .withName("Technology inspired")
                .build();

        when(competitionService.getById(competition.getId())).thenReturn(competition);

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

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

        assertEquals(competition.getId(), model.getCompetitionId());
        assertEquals("Technology inspired", model.getCompetitionName());

        verify(competitionService, only()).getById(competition.getId());
    }

    @Test
    public void competition_closed() throws Exception {
        CompetitionResource competition = newCompetitionResource()
                .withCompetitionStatus(CLOSED)
                .withName("Photonics for health")
                .build();

        when(competitionService.getById(competition.getId())).thenReturn(competition);

        MvcResult result = mockMvc.perform(get("/competition/{competitionId}", competition.getId()))
                .andExpect(status().isOk())
                .andExpect(model().attributeExists("model"))
                .andExpect(view().name("competition/competition-closed"))
                .andReturn();

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

        assertEquals(competition.getId(), model.getCompetitionId());
        assertEquals("Photonics for health", model.getCompetitionName());

        verify(competitionService, only()).getById(competition.getId());
    }

    @Test
    public void closeAssessment() throws Exception {
        Long competitionId = 1L;
        mockMvc.perform(post("/competition/{competitionId}/close-assessment", competitionId))
                .andExpect(status().is3xxRedirection())
                .andExpect(redirectedUrl("/dashboard"));
        verify(competitionService, only()).closeAssessment(competitionId);
    }
}
{'fraction_non_alphanumeric': 0.10403972015346423, 'fraction_numerical': 0.0013540961408259986, 'mean_word_length': 4.285032796660704, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5942320', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2230, 'n_words': 326}