|
18 | 18 | package com.ao.data.dao.ini;
|
19 | 19 |
|
20 | 20 |
|
| 21 | +import static org.hamcrest.core.IsInstanceOf.instanceOf; |
21 | 22 | import static org.junit.Assert.assertEquals;
|
22 |
| -import static org.junit.Assert.assertTrue; |
| 23 | +import static org.junit.Assert.assertThat; |
23 | 24 | import static org.junit.Assert.fail;
|
| 25 | +import static org.mockito.Matchers.anyInt; |
| 26 | +import static org.mockito.Matchers.eq; |
| 27 | +import static org.mockito.Mockito.mock; |
| 28 | +import static org.mockito.Mockito.when; |
24 | 29 |
|
25 |
| -import org.easymock.classextension.EasyMock; |
26 |
| -import org.junit.After; |
27 | 30 | import org.junit.Before;
|
28 | 31 | import org.junit.Test;
|
29 | 32 |
|
@@ -60,83 +63,74 @@ public class NPCPropertiesDAOIniTest {
|
60 | 63 |
|
61 | 64 | private static final String TEST_NPCS_DAT = "src/test/resources/NPCs.dat";
|
62 | 65 |
|
63 |
| - protected NPCPropertiesDAOIni dao; |
| 66 | + private NPCPropertiesDAOIni dao; |
64 | 67 |
|
65 | 68 | @Before
|
66 | 69 | public void setUp() throws Exception {
|
67 |
| - WorldObjectProperties woProperties = EasyMock.createMock(WorldObjectProperties.class); |
68 |
| - AbstractItem item = EasyMock.createMock(AbstractItem.class); |
69 |
| - EasyMock.expect(item.getId()).andReturn(1).anyTimes(); |
70 |
| - EasyMock.expect(item.getAmount()).andReturn(1).anyTimes(); |
71 |
| - EasyMock.expect(item.addAmount(EasyMock.anyInt())).andReturn(1).anyTimes(); |
72 |
| - EasyMock.replay(woProperties, item); |
| 70 | + final WorldObjectProperties woProperties = mock(WorldObjectProperties.class); |
| 71 | + final AbstractItem item = mock(AbstractItem.class); |
73 | 72 |
|
74 |
| - WorldObjectPropertiesDAO woDao = EasyMock.createMock(WorldObjectPropertiesDAO.class); |
75 |
| - EasyMock.expect(woDao.getWorldObjectProperties(EasyMock.anyInt())).andReturn(woProperties).anyTimes(); |
| 73 | + final WorldObjectPropertiesDAO woDao = mock(WorldObjectPropertiesDAO.class); |
| 74 | + when(woDao.getWorldObjectProperties(anyInt())).thenReturn(woProperties); |
76 | 75 |
|
77 |
| - WorldObjectFactory woFactory = EasyMock.createMock(WorldObjectFactory.class); |
78 |
| - EasyMock.expect(woFactory.getWorldObject(EasyMock.eq(woProperties), EasyMock.anyInt())).andReturn(item).anyTimes(); |
79 |
| - |
80 |
| - EasyMock.replay(woDao, woFactory); |
| 76 | + final WorldObjectFactory woFactory = mock(WorldObjectFactory.class); |
| 77 | + when(woFactory.getWorldObject(eq(woProperties), anyInt())).thenReturn(item); |
81 | 78 |
|
82 | 79 | dao = new NPCPropertiesDAOIni(TEST_NPCS_DAT, woDao, woFactory);
|
83 | 80 | }
|
84 | 81 |
|
85 |
| - @After |
86 |
| - public void tearDown() throws Exception { |
87 |
| - } |
88 |
| - |
89 | 82 | @Test
|
90 | 83 | public void testRetrieveAll() {
|
91 |
| - NPCProperties[] npcProperties = null; |
| 84 | + final NPCProperties[] npcProperties; |
92 | 85 | try {
|
93 | 86 | npcProperties = dao.retrieveAll();
|
94 |
| - } catch (DAOException e) { |
| 87 | + } catch (final DAOException e) { |
95 | 88 | fail("Loading of npcs failed with message " + e.getMessage());
|
| 89 | + return; |
96 | 90 | }
|
97 | 91 |
|
98 |
| - NPCProperties snake = npcProperties[COMMON_NPC_INDEX]; |
99 |
| - assertTrue(snake instanceof CreatureNPCProperties); |
| 92 | + final NPCProperties snake = npcProperties[COMMON_NPC_INDEX]; |
| 93 | + assertThat(snake, instanceOf(CreatureNPCProperties.class)); |
100 | 94 | assertEquals(NPCType.COMMON, snake.getType());
|
101 | 95 |
|
102 |
| - NPCProperties dragon = npcProperties[DRAGON_NPC_INDEX]; |
103 |
| - assertTrue(dragon instanceof CreatureNPCProperties); |
| 96 | + final NPCProperties dragon = npcProperties[DRAGON_NPC_INDEX]; |
| 97 | + assertThat(dragon, instanceOf(CreatureNPCProperties.class)); |
104 | 98 | assertEquals(NPCType.DRAGON, dragon.getType());
|
105 | 99 |
|
106 |
| - NPCProperties trainer = npcProperties[TRAINER_NPC_INDEX]; |
107 |
| - assertTrue(trainer instanceof TrainerNPCProperties); |
| 100 | + final NPCProperties trainer = npcProperties[TRAINER_NPC_INDEX]; |
| 101 | + assertThat(trainer, instanceOf(TrainerNPCProperties.class)); |
108 | 102 | assertEquals(NPCType.TRAINER, trainer.getType());
|
109 | 103 |
|
110 |
| - NPCProperties governor = npcProperties[GOVERNOR_NPC_INDEX]; |
111 |
| - assertTrue(governor instanceof GovernorNPCProperties); |
| 104 | + final NPCProperties governor = npcProperties[GOVERNOR_NPC_INDEX]; |
| 105 | + assertThat(governor, instanceOf(GovernorNPCProperties.class)); |
112 | 106 | assertEquals(NPCType.GOVERNOR, governor.getType());
|
113 | 107 |
|
114 |
| - NPCProperties royalGuard = npcProperties[ROYAL_GUARD_NPC_INDEX]; |
115 |
| - assertTrue(royalGuard instanceof GuardNPCProperties); |
| 108 | + final NPCProperties royalGuard = npcProperties[ROYAL_GUARD_NPC_INDEX]; |
| 109 | + assertThat(royalGuard, instanceOf(GuardNPCProperties.class)); |
116 | 110 | assertEquals(NPCType.ROYAL_GUARD, royalGuard.getType());
|
117 | 111 |
|
118 |
| - NPCProperties chaosGuard = npcProperties[CHAOS_GUARD_NPC_INDEX]; |
119 |
| - assertTrue(chaosGuard instanceof GuardNPCProperties); |
| 112 | + final NPCProperties chaosGuard = npcProperties[CHAOS_GUARD_NPC_INDEX]; |
| 113 | + assertThat(chaosGuard, instanceOf(GuardNPCProperties.class)); |
120 | 114 | assertEquals(NPCType.CHAOS_GUARD, chaosGuard.getType());
|
121 | 115 |
|
122 |
| - NPCProperties newbieResucitator = npcProperties[NEWBIE_RESUCITATOR_NPC_INDEX]; |
123 |
| - assertTrue(newbieResucitator instanceof NPCProperties); |
| 116 | + final NPCProperties newbieResucitator = npcProperties[NEWBIE_RESUCITATOR_NPC_INDEX]; |
| 117 | + assertThat(newbieResucitator, instanceOf(NPCProperties.class)); |
124 | 118 | assertEquals(NPCType.NEWBIE_RESUCITATOR, newbieResucitator.getType());
|
125 | 119 |
|
126 |
| - NPCProperties resucitator = npcProperties[RESUCITATOR_NPC_INDEX]; |
127 |
| - assertTrue(resucitator instanceof NPCProperties); |
| 120 | + final NPCProperties resucitator = npcProperties[RESUCITATOR_NPC_INDEX]; |
| 121 | + assertThat(resucitator, instanceOf(NPCProperties.class)); |
128 | 122 | assertEquals(NPCType.RESUCITATOR, resucitator.getType());
|
129 | 123 |
|
130 |
| - NPCProperties gambler = npcProperties[GAMBLER_NPC_INDEX]; |
131 |
| - assertTrue(gambler instanceof NPCProperties); |
| 124 | + final NPCProperties gambler = npcProperties[GAMBLER_NPC_INDEX]; |
| 125 | + assertThat(gambler, instanceOf(NPCProperties.class)); |
132 | 126 | assertEquals(NPCType.GAMBLER, gambler.getType());
|
133 | 127 |
|
134 |
| - NPCProperties banker = npcProperties[BANKER_NPC_INDEX]; |
135 |
| - assertTrue(banker instanceof NPCProperties); |
| 128 | + final NPCProperties banker = npcProperties[BANKER_NPC_INDEX]; |
| 129 | + assertThat(banker, instanceOf(NPCProperties.class)); |
136 | 130 | assertEquals(NPCType.BANKER, banker.getType());
|
137 | 131 |
|
138 |
| - NPCProperties noble = npcProperties[NOBLE_NPC_INDEX]; |
139 |
| - assertTrue(noble instanceof NobleNPCProperties); |
| 132 | + final NPCProperties noble = npcProperties[NOBLE_NPC_INDEX]; |
| 133 | + assertThat(noble, instanceOf(NobleNPCProperties.class)); |
140 | 134 | assertEquals(NPCType.NOBLE, noble.getType());
|
141 | 135 | }
|
142 | 136 |
|
|
0 commit comments