<commit_before>package com.worth.ifs.form.service;

import com.worth.ifs.BaseUnitTestMocksTest;
import com.worth.ifs.commons.error.Error;
import com.worth.ifs.commons.rest.ValidationMessages;
import com.worth.ifs.form.resource.FormInputResponseResource;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import java.util.List;
import java.util.Map;

import static com.worth.ifs.commons.error.Error.fieldError;
import static com.worth.ifs.commons.rest.RestResult.restSuccess;
import static com.worth.ifs.form.builder.FormInputResponseResourceBuilder.newFormInputResponseResource;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.springframework.http.HttpStatus.NOT_ACCEPTABLE;

/**
 * Testing FormInputResponseServiceImpl and its interactions with its mock rest service.
 */
public class FormInputResponseServiceImplTest extends BaseUnitTestMocksTest {

    @InjectMocks
    private FormInputResponseService service = new FormInputResponseServiceImpl();

    @Mock
    private FormInputResponseRestService restServiceMock;

    @Test
    public void test_getByApplication() {

        List<FormInputResponseResource> formInputResponses = newFormInputResponseResource().build(3);
        when(restServiceMock.getResponsesByApplicationId(123L)).thenReturn(restSuccess(formInputResponses));

        List<FormInputResponseResource> response = service.getByApplication(123L);
        assertEquals(formInputResponses, response);
    }

    @Test
    public void test_mapResponsesToFormInputs() {

        List<FormInputResponseResource> formInputResponses = newFormInputResponseResource().
                withFormInputs(3L, 2L, 1L).
                build(3);

        Map<Long, FormInputResponseResource> response = service.mapFormInputResponsesToFormInput(formInputResponses);
        assertEquals(formInputResponses.get(0), response.get(3L));
        assertEquals(formInputResponses.get(1), response.get(2L));
        assertEquals(formInputResponses.get(2), response.get(1L));
    }

    @Test
    public void test_save() {

        ValidationMessages validation = new ValidationMessages(fieldError("value", "an error", NOT_ACCEPTABLE), fieldError("value", "another error", NOT_ACCEPTABLE)));

        when(restServiceMock.saveQuestionResponse(123L, 456L, 789L, "A new value", false)).<commit_msg>INFUND-3403 - comp failure in test fix<commit_after>package com.worth.ifs.form.service;

import com.worth.ifs.BaseUnitTestMocksTest;
import com.worth.ifs.commons.rest.ValidationMessages;
import com.worth.ifs.form.resource.FormInputResponseResource;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import java.util.List;
import java.util.Map;

import static com.worth.ifs.commons.error.Error.fieldError;
import static com.worth.ifs.commons.rest.RestResult.restSuccess;
import static com.worth.ifs.form.builder.FormInputResponseResourceBuilder.newFormInputResponseResource;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import static org.springframework.http.HttpStatus.NOT_ACCEPTABLE;

/**
 * Testing FormInputResponseServiceImpl and its interactions with its mock rest service.
 */
public class FormInputResponseServiceImplTest extends BaseUnitTestMocksTest {

    @InjectMocks
    private FormInputResponseService service = new FormInputResponseServiceImpl();

    @Mock
    private FormInputResponseRestService restServiceMock;

    @Test
    public void test_getByApplication() {

        List<FormInputResponseResource> formInputResponses = newFormInputResponseResource().build(3);
        when(restServiceMock.getResponsesByApplicationId(123L)).thenReturn(restSuccess(formInputResponses));

        List<FormInputResponseResource> response = service.getByApplication(123L);
        assertEquals(formInputResponses, response);
    }

    @Test
    public void test_mapResponsesToFormInputs() {

        List<FormInputResponseResource> formInputResponses = newFormInputResponseResource().
                withFormInputs(3L, 2L, 1L).
                build(3);

        Map<Long, FormInputResponseResource> response = service.mapFormInputResponsesToFormInput(formInputResponses);
        assertEquals(formInputResponses.get(0), response.get(3L));
        assertEquals(formInputResponses.get(1), response.get(2L));
        assertEquals(formInputResponses.get(2), response.get(1L));
    }

    @Test
    public void test_save() {

        ValidationMessages validation = new ValidationMessages(fieldError("value", "an error", NOT_ACCEPTABLE), fieldError("value", "another error", NOT_ACCEPTABLE));

        when(restServiceMock.saveQuestionResponse(123L, 456L, 789L, "A new value", false)).
{'fraction_non_alphanumeric': 0.09395270977191882, 'fraction_numerical': 0.011717932621887424, 'mean_word_length': 4.975, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2776340', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1326, 'n_words': 243}