Skip to content

Commit ff9f94b

Browse files
author
Lloyd Watkin
committed
Drop HelperMock
1 parent 815482f commit ff9f94b

1 file changed

Lines changed: 24 additions & 29 deletions

File tree

  • src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set

src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreateTest.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.buddycloud.channelserver.channel.ChannelManager;
1212
import org.buddycloud.channelserver.channel.node.configuration.Helper;
13-
import org.buddycloud.channelserver.channel.node.configuration.HelperMock;
1413
import org.buddycloud.channelserver.channel.node.configuration.NodeConfigurationException;
1514
import org.buddycloud.channelserver.channel.node.configuration.field.ChannelTitle;
1615
import org.buddycloud.channelserver.db.exception.NodeStoreException;
@@ -34,25 +33,21 @@ public class NodeCreateTest extends IQTestHandler {
3433
private BlockingQueue<Packet> queue = new LinkedBlockingQueue<Packet>();
3534
private String node = "/user/capulet@shakespeare.lit/posts";
3635

37-
private ChannelManager channelManagerMock;
38-
3936
@Before
4037
public void setUp() throws Exception {
41-
channelManagerMock = Mockito.mock(ChannelManager.class);
42-
Mockito.when(channelManagerMock.isLocalNode(Mockito.anyString()))
38+
channelManager = Mockito.mock(ChannelManager.class);
39+
Mockito.when(channelManager.isLocalNode(Mockito.anyString()))
4340
.thenReturn(true);
4441

4542
queue = new LinkedBlockingQueue<Packet>();
46-
nodeCreate = new NodeCreate(queue, channelManagerMock);
43+
nodeCreate = new NodeCreate(queue, channelManager);
4744
jid = new JID("juliet@shakespeare.lit");
4845
request = readStanzaAsIq("/iq/pubsub/channel/create/request.stanza");
4946

5047
nodeCreate.setServerDomain("shakespeare.lit");
5148

5249
element = new BaseElement("create");
5350
element.addAttribute("node", node);
54-
55-
5651
}
5752

5853
@Test
@@ -85,10 +80,10 @@ public void testRequestingAlreadyExistingNodeReturnsErrorStanza()
8580
throws Exception {
8681

8782
Mockito.when(
88-
channelManagerMock
83+
channelManager
8984
.nodeExists("/user/capulet@shakespeare.lit/posts"))
9085
.thenReturn(true);
91-
nodeCreate.setChannelManager(channelManagerMock);
86+
nodeCreate.setChannelManager(channelManager);
9287

9388
nodeCreate.process(element, jid, request, null);
9489

@@ -166,13 +161,13 @@ public void testNewNodeMustBeOnADomainSupportedByCurrentServer()
166161
public void testchannelManagerFailureReturnsInternalServerErrorResponse()
167162
throws Exception {
168163
Mockito.doThrow(new NodeStoreException())
169-
.when(channelManagerMock)
164+
.when(channelManager)
170165
.createNode(Mockito.any(JID.class), Mockito.anyString(),
171166
Mockito.anyMapOf(String.class, String.class));
172-
nodeCreate.setChannelManager(channelManagerMock);
173-
Helper helperMock = Mockito.mock(Helper.class);
174-
Mockito.doReturn(true).when(helperMock).isValid();
175-
nodeCreate.setConfigurationHelper(helperMock);
167+
nodeCreate.setChannelManager(channelManager);
168+
Helper helper = Mockito.mock(Helper.class);
169+
Mockito.doReturn(true).when(helper).isValid();
170+
nodeCreate.setConfigurationHelper(helper);
176171

177172
nodeCreate.process(element, jid, request, null);
178173
Packet response = queue.poll(100, TimeUnit.MILLISECONDS);
@@ -192,9 +187,9 @@ public void testchannelManagerFailureReturnsInternalServerErrorResponse()
192187
@Test
193188
public void testValidCreateNodeRequestReturnsConfirmationStanza()
194189
throws Exception {
195-
HelperMock helperMock = Mockito.mock(HelperMock.class);
196-
Mockito.doReturn(true).when(helperMock).isValid();
197-
nodeCreate.setConfigurationHelper(helperMock);
190+
Helper helper = Mockito.mock(Helper.class);
191+
Mockito.doReturn(true).when(helper).isValid();
192+
nodeCreate.setConfigurationHelper(helper);
198193

199194
nodeCreate.process(element, jid, request, null);
200195
Packet response = queue.poll(100, TimeUnit.MILLISECONDS);
@@ -217,19 +212,19 @@ public void testCreateNodeWithConfigurationResultsInExpectedConfig()
217212
HashMap<String, String> configurationProperties = new HashMap<String, String>();
218213
configurationProperties.put(ChannelTitle.FIELD_NAME, channelTitle);
219214

220-
HelperMock helperMock = Mockito.mock(HelperMock.class);
221-
Mockito.when(helperMock.getValues())
215+
Helper helper = Mockito.mock(Helper.class);
216+
Mockito.when(helper.getValues())
222217
.thenReturn(configurationProperties);
223-
Mockito.doReturn(true).when(helperMock).isValid();
218+
Mockito.doReturn(true).when(helper).isValid();
224219

225-
ChannelManager channelManagerMock = Mockito.mock(ChannelManager.class);
220+
ChannelManager channelManager = Mockito.mock(ChannelManager.class);
226221

227222
HashMap<String, String> conf = new HashMap<String, String>();
228223
conf.put(ChannelTitle.FIELD_NAME, channelTitle);
229224

230-
Mockito.when(channelManagerMock.getNodeConf(Mockito.anyString())).thenReturn(conf);
231-
nodeCreate.setChannelManager(channelManagerMock);
232-
nodeCreate.setConfigurationHelper(helperMock);
225+
Mockito.when(channelManager.getNodeConf(Mockito.anyString())).thenReturn(conf);
226+
nodeCreate.setChannelManager(channelManager);
227+
nodeCreate.setConfigurationHelper(helper);
233228

234229
nodeCreate.process(element, jid, request, null);
235230

@@ -241,7 +236,7 @@ public void testCreateNodeWithConfigurationResultsInExpectedConfig()
241236
} catch (NullPointerException e) {
242237
Assert.assertNull(error);
243238
}
244-
Map<String, String> nodeConfiguration = channelManagerMock
239+
Map<String, String> nodeConfiguration = channelManager
245240
.getNodeConf(node);
246241
Assert.assertEquals(channelTitle,
247242
nodeConfiguration.get(ChannelTitle.FIELD_NAME));
@@ -255,10 +250,10 @@ public void testFailingNodeConfigurationReturnsErrorStanza()
255250
HashMap<String, String> configurationProperties = new HashMap<String, String>();
256251
configurationProperties.put(ChannelTitle.FIELD_NAME, channelTitle);
257252

258-
HelperMock helperMock = Mockito.mock(HelperMock.class);
259-
Mockito.doThrow(new NodeConfigurationException()).when(helperMock)
253+
Helper helper = Mockito.mock(Helper.class);
254+
Mockito.doThrow(new NodeConfigurationException()).when(helper)
260255
.parse(request);
261-
nodeCreate.setConfigurationHelper(helperMock);
256+
nodeCreate.setConfigurationHelper(helper);
262257

263258
nodeCreate.process(element, jid, request, null);
264259

0 commit comments

Comments
 (0)