Package test.util.proc

Source Code of test.util.proc.BroadcastPlayersProcTest$MyUI

package test.util.proc;
import net.sf.nebulacards.comm.*;
import net.sf.nebulacards.game.*;
import net.sf.nebulacards.main.*;
import net.sf.nebulacards.util.*;
import net.sf.nebulacards.util.proc.*;
import junit.framework.*;
import OneProcGame;
import Utility;

public class BroadcastPlayersProcTest
  extends TestCase
{
  OneProcGame opg;
  static final int NUMPLAYERS = 2;
  MyUI[] receivers;

  public BroadcastPlayersProcTest(String s) { super(s); }

  class MyUI extends UIAdapter
  {
    public Player[] players = null;
    public void setPlayers(Player[] p) { players = p; }
  }

  public void setUp()
  {
    opg = new OneProcGame("BroadcastPlayersProc Test", NUMPLAYERS);
    opg.setProc(new BroadcastPlayersProc(opg));
    receivers = new MyUI[NUMPLAYERS];
    for (int i = 0; i < NUMPLAYERS; i++)
    {
      ComManager.AddResult cmar = opg.add(receivers[i] = new MyUI());
      cmar.publicize();
    }
  }

  public void testRun()
      throws InterruptedException
  {
    GameProcedure gp = opg.getNextProcedure();
    // Change the player information.
    Player[] p = opg.getPlayers();
    for (int i = 0; i < NUMPLAYERS; i++)
    {
      p[i].setName("" + i);
      p[i].setScore(10 * i);
    }
    // broadcast the new information
    gp.runProcedure(Utility.getComs(opg), opg.getBroadcastCommunicator());
    // check the received information
    for (int i = 0; i < NUMPLAYERS; i++)
    {
      for (int j = 0; j < NUMPLAYERS; j++)
      {
        assertEquals(p[j].getName(), receivers[i].players[j].getName());
        assertEquals(p[j].getScore(),
                receivers[i].players[j].getScore());
        // check for shallow copies between the game and clients
        assertNotSame("Game-client shallow copy error: ",
                p[j], receivers[i].players[j]);
        if (i != j)
        {
          // check for shallow copies between clients
          assertNotSame("Client-client shallow copy error: ",
              receivers[i].players[j], receivers[j].players[j]);
        }
      }
    }
  }
}
TOP

Related Classes of test.util.proc.BroadcastPlayersProcTest$MyUI

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.