Skip to content
Snippets Groups Projects
Commit e1cdc1e5 authored by Ján Dovjak's avatar Ján Dovjak
Browse files

test: getPlayers

parent 033d804e
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.icehockeymanager.services;
import cz.muni.fi.pa165.icehockeymanager.config.ApplicationConfig;
import cz.muni.fi.pa165.icehockeymanager.dao.PlayerDao;
import cz.muni.fi.pa165.icehockeymanager.dto.PlayerDTO;
import cz.muni.fi.pa165.icehockeymanager.model.Player;
import cz.muni.fi.pa165.icehockeymanager.model.Team;
import org.junit.jupiter.api.Test;
......@@ -11,6 +12,8 @@ import org.mockito.Mock;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -51,6 +54,26 @@ class PlayerServiceImplTest {
verify(playerDao).create(player);
}
@Test
public void getFreePlayersEmpty() {
when(playerDao.getAllFreePlayers()).thenReturn(new ArrayList<>());
assertThat(playerService.getFreePlayers()).isEmpty();
verify(playerDao).getAllFreePlayers();
}
@Test
public void getFreePlayersNonEmpty() {
var players = Arrays.asList(
buildPlayerMock(1L, "Zdeno Chara"),
buildPlayerMock(2L, "David Pastrnak")
);
when(playerDao.getAllFreePlayers()).thenReturn(players);
assertThat(playerService.getFreePlayers()).hasSameElementsAs(players);
verify(playerDao).getAllFreePlayers();
}
public Team buildTeamMock(Long id, String name) {
var team = mock(Team.class);
when(team.getId()).thenReturn(id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment