Add a test around ChatMessageHandler, update imports

Update the previous ItemOnItemVerificationHandler test to use static
imports of PowerMockito and Assert.
This commit is contained in:
Gary Tierney
2015-09-13 01:25:00 +01:00
parent 82801df436
commit ef398dc098
2 changed files with 42 additions and 9 deletions
@@ -0,0 +1,34 @@
package org.apollo.game.message.handler;
import org.apollo.game.message.impl.ChatMessage;
import org.apollo.game.model.World;
import org.apollo.game.model.entity.Player;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Player.class})
public class ChatMessageHandlerTest {
private final World world = new World();
private final ChatMessageHandler chatMessageHandler = new ChatMessageHandler(world);
@Test
public void testTerminatedIfMuted() throws Exception {
Player player = PowerMockito.mock(Player.class);
when(player.isMuted()).thenReturn(true);
ChatMessage chatMessage = new ChatMessage("Test", "Test".getBytes(), 0, 0);
chatMessageHandler.handle(player, chatMessage);
assertTrue("ChatMessageHandler: player can send messages when muted", chatMessage.terminated());
}
}
@@ -10,12 +10,11 @@ import org.apollo.game.model.inv.Inventory;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Player.class, ItemDefinition.class})
@@ -28,17 +27,17 @@ public class ItemOnItemVerificationHandlerTest {
@BeforeClass
public static void setupTestItemDefinitions() {
PowerMockito.mockStatic(ItemDefinition.class);
Mockito.when(ItemDefinition.lookup(4151)).thenReturn(new ItemDefinition(4151));
mockStatic(ItemDefinition.class);
when(ItemDefinition.lookup(4151)).thenReturn(new ItemDefinition(4151));
}
@Test
public void testTerminateWithNoSourceItem() throws Exception {
Player player = PowerMockito.mock(Player.class);
Player player = mock(Player.class);
Inventory inventory = new Inventory(28);
inventory.set(1, new Item(4151, 1));
Mockito.when(player.getInventory()).thenReturn(inventory);
when(player.getInventory()).thenReturn(inventory);
ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.SIDEBAR_INVENTORY_ID, 500, 1,
BankConstants.SIDEBAR_INVENTORY_ID, 4151, 1);
@@ -51,11 +50,11 @@ public class ItemOnItemVerificationHandlerTest {
@Test
public void testTerminateWithNoTargetItem() throws Exception {
Player player = PowerMockito.mock(Player.class);
Player player = mock(Player.class);
Inventory inventory = new Inventory(28);
inventory.set(1, new Item(4151, 1));
Mockito.when(player.getInventory()).thenReturn(inventory);
when(player.getInventory()).thenReturn(inventory);
ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.SIDEBAR_INVENTORY_ID, 4151, 1,
BankConstants.SIDEBAR_INVENTORY_ID, 4152, 2);