Package ch.fusun.baron.player.test

Source Code of ch.fusun.baron.player.test.PlayerServiceTest

package ch.fusun.baron.player.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;

import ch.fusun.baron.core.rmi.User;
import ch.fusun.baron.player.Dynasty;
import ch.fusun.baron.player.Gender;
import ch.fusun.baron.player.Player;
import ch.fusun.baron.player.PlayerServiceImpl;
import ch.fusun.baron.player.api.PlayerService;

/**
* Tests the player service
*/
public class PlayerServiceTest {

  /**
   * Tests all accessors
   */
  @Test
  public void testGettersAndSetters() {
    Dynasty dynasty = new Dynasty("TestDynasty", null); //$NON-NLS-1$
    Dynasty dynasty2 = new Dynasty("TestDynasty2", null); //$NON-NLS-1$
    User user = new User("username", "password"); //$NON-NLS-1$ //$NON-NLS-2$
    User user2 = new User("username2", "password2"); //$NON-NLS-1$ //$NON-NLS-2$
    Player player1 = new Player(0, "player1", Gender.MALE); //$NON-NLS-1$
    dynasty.addPlayer(player1);
    Player player2 = new Player(1, "player2", Gender.FEMALE); //$NON-NLS-1$
    dynasty.addPlayer(player2);

    PlayerService service = new PlayerServiceImpl();
    assertNotNull(service.getAllPlayers());

    assertEquals(service.getDynasty(user), null);
    service.setDynastyForUser(dynasty, user);
    assertTrue(service.getDynasty(user) == dynasty);

    List<Player> players = service.getPlayers(user);
    assertNotNull(players);
    assertEquals(2, players.size());
    assertTrue(players.contains(player1));
    assertTrue(players.contains(player2));

    service.setDynastyForUser(dynasty2, user2);
    List<Dynasty> allDynasties = service.getAllDynasties();
    assertEquals(2, allDynasties.size());
    assertTrue(allDynasties.contains(dynasty));
    assertTrue(allDynasties.contains(dynasty2));
  }
}
TOP

Related Classes of ch.fusun.baron.player.test.PlayerServiceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.