LeagueService testing standings.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.gempukku.lotro.league;
|
||||
|
||||
import com.gempukku.lotro.PlayerStanding;
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.db.LeagueDAO;
|
||||
import com.gempukku.lotro.db.LeagueMatchDAO;
|
||||
@@ -15,8 +16,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class LeagueServiceTest {
|
||||
@Test
|
||||
@@ -123,4 +123,70 @@ public class LeagueServiceTest {
|
||||
assertFalse(leagueService.canPlayRankedGameAgainst(league, leagueSerie, "player1", "player2"));
|
||||
assertFalse(leagueService.canPlayRankedGameAgainst(league, leagueSerie, "player1", "player3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandings() throws Exception {
|
||||
LeagueDAO leagueDao = Mockito.mock(LeagueDAO.class);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("20120502" + "," + "default" + "," + "1" + "," + "1");
|
||||
for (int i = 0; i < 1; i++)
|
||||
sb.append("," + "lotr_block" + "," + "7" + "," + "2");
|
||||
|
||||
|
||||
List<League> leagues = new ArrayList<League>();
|
||||
League league = new League(5000, "League name", "leagueType", NewConstructedLeagueData.class.getName(), sb.toString(), 0);
|
||||
leagues.add(league);
|
||||
|
||||
LeagueSerieData leagueSerie = league.getLeagueData().getSeries().get(0);
|
||||
|
||||
Mockito.when(leagueDao.loadActiveLeagues(Mockito.anyInt())).thenReturn(leagues);
|
||||
|
||||
LeaguePointsDAO leaguePointsDAO = Mockito.mock(LeaguePointsDAO.class);
|
||||
LeagueMatchDAO leagueMatchDAO = Mockito.mock(LeagueMatchDAO.class);
|
||||
|
||||
Set<LeagueMatch> matches = new HashSet<LeagueMatch>();
|
||||
|
||||
Mockito.when(leagueMatchDAO.getLeagueMatches(league)).thenReturn(new HashSet<LeagueMatch>(matches));
|
||||
Mockito.when(leagueMatchDAO.getLeagueSerieMatches(league, leagueSerie)).thenReturn(new HashSet<LeagueMatch>(matches));
|
||||
|
||||
LeagueParticipationDAO leagueParticipationDAO = Mockito.mock(LeagueParticipationDAO.class);
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
|
||||
LeagueService leagueService = new LeagueService(leagueDao, leaguePointsDAO, leagueMatchDAO, leagueParticipationDAO, collectionsManager);
|
||||
|
||||
leagueService.reportLeagueGameResult(league, leagueSerie, "player1", "player2");
|
||||
leagueService.reportLeagueGameResult(league, leagueSerie, "player1", "player3");
|
||||
leagueService.reportLeagueGameResult(league, leagueSerie, "player2", "player3");
|
||||
|
||||
final List<PlayerStanding> leagueSerieStandings = leagueService.getLeagueSerieStandings(league, leagueSerie);
|
||||
assertEquals(3, leagueSerieStandings.size());
|
||||
assertEquals("player1", leagueSerieStandings.get(0).getPlayerName());
|
||||
assertEquals(4, leagueSerieStandings.get(0).getPoints());
|
||||
assertEquals(2, leagueSerieStandings.get(0).getGamesPlayed());
|
||||
assertEquals(1, leagueSerieStandings.get(0).getStanding());
|
||||
assertEquals("player2", leagueSerieStandings.get(1).getPlayerName());
|
||||
assertEquals(3, leagueSerieStandings.get(1).getPoints());
|
||||
assertEquals(2, leagueSerieStandings.get(1).getGamesPlayed());
|
||||
assertEquals(2, leagueSerieStandings.get(1).getStanding());
|
||||
assertEquals("player3", leagueSerieStandings.get(2).getPlayerName());
|
||||
assertEquals(2, leagueSerieStandings.get(2).getPoints());
|
||||
assertEquals(2, leagueSerieStandings.get(2).getGamesPlayed());
|
||||
assertEquals(3, leagueSerieStandings.get(2).getStanding());
|
||||
|
||||
final List<PlayerStanding> leagueStandings = leagueService.getLeagueStandings(league);
|
||||
assertEquals(3, leagueStandings.size());
|
||||
assertEquals("player1", leagueStandings.get(0).getPlayerName());
|
||||
assertEquals(4, leagueStandings.get(0).getPoints());
|
||||
assertEquals(2, leagueStandings.get(0).getGamesPlayed());
|
||||
assertEquals(1, leagueStandings.get(0).getStanding());
|
||||
assertEquals("player2", leagueStandings.get(1).getPlayerName());
|
||||
assertEquals(3, leagueStandings.get(1).getPoints());
|
||||
assertEquals(2, leagueStandings.get(1).getGamesPlayed());
|
||||
assertEquals(2, leagueStandings.get(1).getStanding());
|
||||
assertEquals("player3", leagueStandings.get(2).getPlayerName());
|
||||
assertEquals(2, leagueStandings.get(2).getPoints());
|
||||
assertEquals(2, leagueStandings.get(2).getGamesPlayed());
|
||||
assertEquals(3, leagueStandings.get(2).getStanding());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user