<commit_before>package uk.ac.ox.zoo.seeg.abraid.mp.publicsite.web.admin;

import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import uk.ac.ox.zoo.seeg.abraid.mp.common.domain.Expert;
import uk.ac.ox.zoo.seeg.abraid.mp.common.dto.json.geojson.GeoJsonObjectMapper;
import uk.ac.ox.zoo.seeg.abraid.mp.common.service.core.ExpertService;
import uk.ac.ox.zoo.seeg.abraid.mp.publicsite.domain.JsonExpertFull;
import uk.ac.ox.zoo.seeg.abraid.mp.publicsite.validator.ValidationException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

/**
 * Tests for AdminExpertsController.
 * Copyright (c) 2014 University of Oxford
 */
public class AdminExpertsControllerTest {
    @Test
    public void showPageReturnsCorrectTemplate() throws Exception {
        // Arrange
        ExpertService expertService = mock(ExpertService.class);
        when(expertService.getAllExperts()).thenReturn(new ArrayList<Expert>());
        GeoJsonObjectMapper objectMapper = new GeoJsonObjectMapper();

        AdminExpertsController target = new AdminExpertsController(expertService, objectMapper, null);

        // Act
        String result = target.showPage(mock(Model.class));

        // Assert
        assertThat(result).isEqualTo("admin/experts");
    }

    @Test
    public void showPageAddsAllExpertsToTheFreemarkerModelAsJson() throws Exception {
        // Arrange
        ExpertService expertService = mock(ExpertService.class);
        List<Expert> experts = Arrays.asList(mock(Expert.class), mock(Expert.class));
        when(expertService.getAllExperts()).thenReturn(experts);
        GeoJsonObjectMapper objectMapper = new GeoJsonObjectMapper();

        AdminExpertsController target = new AdminExpertsController(expertService, objectMapper, null);
        Model model = mock(Model.class);

        // Act
        String result = target.showPage(model);

        // Assert
        ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
        verify(model, times(1)).addAttribute(eq("experts"), captor.capture());
        String json = captor.getValue();

        assertThat(json).startsWith("[{");
        assertThat(json).endsWith("}]");
        String[] objects = json.split("\\},\\{");

        assertThat(objects).hasSize(2);
        <commit_msg>Whitespace fix<commit_after>package uk.ac.ox.zoo.seeg.abraid.mp.publicsite.web.admin;

import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import uk.ac.ox.zoo.seeg.abraid.mp.common.domain.Expert;
import uk.ac.ox.zoo.seeg.abraid.mp.common.dto.json.geojson.GeoJsonObjectMapper;
import uk.ac.ox.zoo.seeg.abraid.mp.common.service.core.ExpertService;
import uk.ac.ox.zoo.seeg.abraid.mp.publicsite.domain.JsonExpertFull;
import uk.ac.ox.zoo.seeg.abraid.mp.publicsite.validator.ValidationException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

/**
 * Tests for AdminExpertsController.
 * Copyright (c) 2014 University of Oxford
 */
public class AdminExpertsControllerTest {
    @Test
    public void showPageReturnsCorrectTemplate() throws Exception {
        // Arrange
        ExpertService expertService = mock(ExpertService.class);
        when(expertService.getAllExperts()).thenReturn(new ArrayList<Expert>());
        GeoJsonObjectMapper objectMapper = new GeoJsonObjectMapper();

        AdminExpertsController target = new AdminExpertsController(expertService, objectMapper, null);

        // Act
        String result = target.showPage(mock(Model.class));

        // Assert
        assertThat(result).isEqualTo("admin/experts");
    }

    @Test
    public void showPageAddsAllExpertsToTheFreemarkerModelAsJson() throws Exception {
        // Arrange
        ExpertService expertService = mock(ExpertService.class);
        List<Expert> experts = Arrays.asList(mock(Expert.class), mock(Expert.class));
        when(expertService.getAllExperts()).thenReturn(experts);
        GeoJsonObjectMapper objectMapper = new GeoJsonObjectMapper();

        AdminExpertsController target = new AdminExpertsController(expertService, objectMapper, null);
        Model model = mock(Model.class);

        // Act
        String result = target.showPage(model);

        // Assert
        ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
        verify(model, times(1)).addAttribute(eq("experts"), captor.capture());
        String json = captor.getValue();

        assertThat(json).startsWith("[{");
        assertThat(json).endsWith("}]");
        String[] objects = json.split("\\},\\{");

        assertThat(objects).hasSize(2);

{'fraction_non_alphanumeric': 0.11961440094432421, 'fraction_numerical': 0.0023608105449537675, 'mean_word_length': 3.8052930056710776, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3026486', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1496, 'n_words': 249}