Package games.stendhal.server.actions.query

Source Code of games.stendhal.server.actions.query.WhoActionTest

/* $Id: WhoActionTest.java,v 1.1 2010/12/04 20:28:33 nhnb Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2010 - Stendhal                    *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.server.actions.query;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
import games.stendhal.common.constants.Actions;
import games.stendhal.server.actions.admin.AdministrationAction;
import games.stendhal.server.actions.query.WhoAction;
import games.stendhal.server.entity.player.Player;
import games.stendhal.server.maps.MockStendhalRPRuleProcessor;
import games.stendhal.server.maps.MockStendlRPWorld;
import marauroa.common.game.RPAction;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;

import utilities.PlayerTestHelper;

public class WhoActionTest {

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    MockStendlRPWorld.get();
  }

  @After
  public void tearDown() throws Exception {
    MockStendhalRPRuleProcessor.get().clearPlayers();
  }

  /**
   * Tests for onAction.
   */
  @Test
  public void testOnAction() {
    final WhoAction pq = new WhoAction();
    final RPAction action = new RPAction();
    action.put(Actions.TYPE, "who");
    final Player player = PlayerTestHelper.createPlayer("player");
    pq.onAction(player, action);
    assertThat(player.events().get(0).get("text"), equalTo("0 Players online: "));
    player.clearEvents();
    MockStendhalRPRuleProcessor.get().addPlayer(player);
    pq.onAction(player, action);
    assertThat(player.events().get(0).get("text"), equalTo("1 Players online: player(0) "));
    player.clearEvents();

    player.setAdminLevel(AdministrationAction.getLevelForCommand("ghostmode") - 1);
    player.setGhost(true);
    pq.onAction(player, action);
    assertThat(player.events().get(0).get("text"), equalTo("0 Players online: "));
    player.clearEvents();

    player.setAdminLevel(AdministrationAction.getLevelForCommand("ghostmode"));
    player.setGhost(true);
    pq.onAction(player, action);
    assertThat(player.events().get(0).get("text"), equalTo("1 Players online: player(!0) "));
    player.clearEvents();
   
    player.setAdminLevel(AdministrationAction.getLevelForCommand("ghostmode") + 1);
    player.setGhost(true);
    pq.onAction(player, action);
    assertThat(player.events().get(0).get("text"), equalTo("1 Players online: player(!0) "));
  }

}
TOP

Related Classes of games.stendhal.server.actions.query.WhoActionTest

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.