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


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import cz.muni.fi.pa165.soccermanager.dto.request.CreateUserRequest;
import cz.muni.fi.pa165.soccermanager.factory.UserFactory;
import cz.muni.fi.pa165.soccermanager.entity.User;
import java.util.List;
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.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class UserMapperTest {

    @Mock
    private UserFactory userFactory;

    @InjectMocks
    private UserMapperImpl userMapper;

    @ParameterizedTest
    @NullSource
    public void mapNullTest(User user) {
        assertNull(userMapper.map(user));
    }

    @ParameterizedTest
    @NullSource
    public void mapNullTest(List<User> users) {
        assertNull(userMapper.map(users));
    }

    @ParameterizedTest
    @NullSource
    public void mapNullTest(CreateUserRequest request) {
        assertNull(userMapper.map(request));
    }

    @Test
    public void mapDTOHappy() {
        final var request = new CreateUserRequest();
        request.setNickName("nick");
        request.setPassword("qwerty");

        when(userFactory.prepare(any(CreateUserRequest.class))).thenReturn(new User());

        final var res = userMapper.map(request);

        assertEquals(res.getNickName(), "nick");
    }


}
