

package cz.muni.fi.pa165.soccermanager.mapper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import cz.muni.fi.pa165.soccermanager.dto.ChampionshipDto;
import cz.muni.fi.pa165.soccermanager.dto.request.CreateChampionshipRequest;
import cz.muni.fi.pa165.soccermanager.entity.Championship;
import cz.muni.fi.pa165.soccermanager.enums.Nation;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;

/**
 * @author Stanislav Koshchienko (uco: 506549)
 */
@ExtendWith(MockitoExtension.class)
public class ChampionshipMapperTest {

    @InjectMocks
    private ChampionshipMapperImpl championshipMapper;

    @ParameterizedTest
    @NullSource
    public void mapNullTest(Championship championship) {
        assertNull(championshipMapper.map(championship));
    }

    @ParameterizedTest
    @NullSource
    public void mapNullTest(CreateChampionshipRequest request) {
        assertNull(championshipMapper.map(request));
    }

    @Test
    public void createTest() {
        final var request = new CreateChampionshipRequest();
        request.setCountry(Nation.CZECH_REPUBLIC);
        request.setName("Moon Championship");

        final var res = championshipMapper.map(request);
        assertEquals(res.getName(), "Moon Championship");
        assertEquals(res.getCountry(), Nation.CZECH_REPUBLIC);
    }

    @Test
    public void mapSourceHappy() {
        final var championship = new Championship();
        championship.setName("Moon Championship");
        championship.setCountry(Nation.CZECH_REPUBLIC);

        final var res = championshipMapper.map(championship);

        assertEquals(res.getName(), "Moon Championship");
        assertEquals(res.getCountry(), Nation.CZECH_REPUBLIC);
    }

    @Test
    public void updateMapTest() {
        final var championship = new Championship();
        championship.setName("Moon Championship");
        championship.setCountry(Nation.CZECH_REPUBLIC);

        final var dto = new ChampionshipDto();
        dto.setName("Earth Championship");
        dto.setCountry(Nation.RUSSIAN_FEDERATION);

        championshipMapper.mapOnUpdate(championship, dto);
        assertEquals(championship.getName(), "Earth Championship");
        assertEquals(championship.getCountry(), Nation.RUSSIAN_FEDERATION);
    }
}
