How to use anyString method of org.easymock.EasyMock class

Best Easymock code snippet using org.easymock.EasyMock.anyString

Source:QueueServiceEasyMockTest.java Github

copy

Full Screen

...72 73 @Test74 public void sendMessageToWithValidArgumentsShouldReturnATrueResponse() throws Exception {75 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);76 connectionMock.setClientID(EasyMock.anyString());77 EasyMock.expectLastCall();78 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);79 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);80 EasyMock.expect(sessionMock.createProducer(queueDestinationMock)).andReturn(messageProducerMock);81 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock); 82 messageProducerMock.send(textMessageMock);83 EasyMock.expectLastCall(); 84 sessionMock.close();85 EasyMock.expectLastCall();86 connectionMock.close();87 EasyMock.expectLastCall();88 89 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);90 91 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");92 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);93 assertThat(result, notNullValue());94 assertThat(result, equalTo(true));95 }96 97 @Test98 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenConnectionCloseThrowsAnException() throws Exception {99 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);100 connectionMock.setClientID(EasyMock.anyString());101 EasyMock.expectLastCall();102 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);103 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);104 EasyMock.expect(sessionMock.createProducer(queueDestinationMock)).andReturn(messageProducerMock);105 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);106 messageProducerMock.send(textMessageMock);107 EasyMock.expectLastCall(); 108 sessionMock.close();109 EasyMock.expectLastCall();110 connectionMock.close();111 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));;112 113 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);114 115 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");116 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);117 assertThat(result, notNullValue());118 assertThat(result, equalTo(true));119 }120 @Test121 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSessionCloseThrowsAnException() throws Exception {122 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);123 connectionMock.setClientID(EasyMock.anyString());124 EasyMock.expectLastCall();125 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);126 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);127 EasyMock.expect(sessionMock.createProducer(queueDestinationMock)).andReturn(messageProducerMock);128 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);129 messageProducerMock.send(textMessageMock);130 EasyMock.expectLastCall(); 131 sessionMock.close();132 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));133 connectionMock.close();134 EasyMock.expectLastCall();135 136 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);137 138 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");139 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);140 assertThat(result, notNullValue());141 assertThat(result, equalTo(true));142 }143 @Test144 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSessionAndConnectionCloseThrowsAnException() throws Exception {145 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);146 connectionMock.setClientID(EasyMock.anyString());147 EasyMock.expectLastCall();148 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);149 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);150 EasyMock.expect(sessionMock.createProducer(queueDestinationMock)).andReturn(messageProducerMock);151 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);152 messageProducerMock.send(textMessageMock);153 EasyMock.expectLastCall(); 154 sessionMock.close();155 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));;156 connectionMock.close();157 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));158 159 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);160 161 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");162 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);163 assertThat(result, notNullValue());164 assertThat(result, equalTo(true));165 }166 167 @Test168 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSendMessageThrowsAnException() throws Exception {169 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);170 connectionMock.setClientID(EasyMock.anyString());171 EasyMock.expectLastCall();172 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);173 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);174 EasyMock.expect(sessionMock.createProducer(queueDestinationMock)).andReturn(messageProducerMock);175 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);176 messageProducerMock.send(textMessageMock);177 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception")); 178 sessionMock.close();179 EasyMock.expectLastCall();180 connectionMock.close();181 EasyMock.expectLastCall();182 183 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);184 185 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");186 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock, textMessageMock);187 assertThat(result, notNullValue());188 assertThat(result, equalTo(false));189 }190 @Test191 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateTextMessageThrowsAnException() throws Exception {192 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);193 connectionMock.setClientID(EasyMock.anyString());194 EasyMock.expectLastCall();195 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);196 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);197 EasyMock.expect(sessionMock.createProducer(queueDestinationMock)).andReturn(messageProducerMock);198 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andThrow(new JMSException("Some JMS Exception")); 199 sessionMock.close();200 EasyMock.expectLastCall();201 connectionMock.close();202 EasyMock.expectLastCall();203 204 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock);205 206 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");207 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageProducerMock);208 assertThat(result, notNullValue());209 assertThat(result, equalTo(false));210 }211 @Test212 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateProducerThrowsAnException() throws Exception {213 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);214 connectionMock.setClientID(EasyMock.anyString());215 EasyMock.expectLastCall();216 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);217 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);218 EasyMock.expect(sessionMock.createProducer(queueDestinationMock)).andThrow(new JMSException("Some JMS Exception")); 219 sessionMock.close();220 EasyMock.expectLastCall();221 connectionMock.close();222 EasyMock.expectLastCall();223 224 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock);225 226 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");227 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock);228 assertThat(result, notNullValue());229 assertThat(result, equalTo(false));230 }231 @Test232 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateQueueThrowsAnException() throws Exception {233 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);234 connectionMock.setClientID(EasyMock.anyString());235 EasyMock.expectLastCall();236 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);237 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andThrow(new JMSException("Some JMS Exception")); 238 sessionMock.close();239 EasyMock.expectLastCall();240 connectionMock.close();241 EasyMock.expectLastCall();242 243 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);244 245 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");246 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock);247 assertThat(result, notNullValue());248 assertThat(result, equalTo(false));249 }250 @Test251 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateSessionThrowsAnException() throws Exception {252 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);253 connectionMock.setClientID(EasyMock.anyString());254 EasyMock.expectLastCall();255 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andThrow(new JMSException("Some JMS Exception")); 256 sessionMock.close();257 EasyMock.expectLastCall();258 connectionMock.close();259 EasyMock.expectLastCall();260 261 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);262 263 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");264 EasyMock.verify(connectionFactoryMock, connectionMock);265 assertThat(result, notNullValue());266 assertThat(result, equalTo(false));267 }268 @Test269 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSetClientIDThrowsAnException() throws Exception {270 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);271 connectionMock.setClientID(EasyMock.anyString());272 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));273 sessionMock.close();274 EasyMock.expectLastCall();275 connectionMock.close();276 EasyMock.expectLastCall();277 278 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);279 280 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");281 EasyMock.verify(connectionFactoryMock, connectionMock);282 assertThat(result, notNullValue());283 assertThat(result, equalTo(false));284 }285 @Test286 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateConnectionThrowsAnException() throws Exception {287 EasyMock.expect(connectionFactoryMock.createConnection()).andThrow(new JMSException("Some JMS Exception"));288 sessionMock.close();289 EasyMock.expectLastCall();290 connectionMock.close();291 EasyMock.expectLastCall();292 293 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);294 295 boolean result = queueService.sendMessageTo("QUEUE_001", "someMessage");296 EasyMock.verify(connectionFactoryMock);297 assertThat(result, notNullValue());298 assertThat(result, equalTo(false));299 }300 @Test301 public void browserMessagesFromWithValidArgumentsShouldReturnAMapOfMessages() throws Exception {302 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);303 connectionMock.setClientID(EasyMock.anyString());304 EasyMock.expectLastCall();305 connectionMock.start();306 EasyMock.expectLastCall();307 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);308 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);309 EasyMock.expect(sessionMock.createBrowser(queueDestinationMock)).andReturn(queueBrowserMock);310 EasyMock.expect(queueBrowserMock.getEnumeration()).andReturn(queueMessages.elements());311 sessionMock.close();312 EasyMock.expectLastCall();313 connectionMock.close();314 EasyMock.expectLastCall();315 316 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);317 318 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");319 320 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);321 322 assertThat(result, notNullValue());323 assertThat(result.size(), equalTo(expectedMessages.size()));324 assertThat(result.get("1"), equalTo(expectedMessages.get("1")));325 assertThat(result.get("2"), equalTo(expectedMessages.get("2")));326 assertThat(result.get("3"), equalTo(expectedMessages.get("3")));327 }328 @Test329 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenConsumeZeoMessages() throws Exception {330 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);331 connectionMock.setClientID(EasyMock.anyString());332 EasyMock.expectLastCall();333 connectionMock.start();334 EasyMock.expectLastCall();335 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);336 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);337 EasyMock.expect(sessionMock.createBrowser(queueDestinationMock)).andReturn(queueBrowserMock);338 EasyMock.expect(queueBrowserMock.getEnumeration()).andReturn(Collections.emptyEnumeration());339 sessionMock.close();340 EasyMock.expectLastCall();341 connectionMock.close();342 EasyMock.expectLastCall();343 344 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);345 346 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");347 348 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);349 350 assertThat(result, notNullValue());351 assertThat(result.size(), equalTo(0));352 }353 @Test354 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenNotFoundMessages() throws Exception {355 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);356 connectionMock.setClientID(EasyMock.anyString());357 EasyMock.expectLastCall();358 connectionMock.start();359 EasyMock.expectLastCall();360 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);361 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);362 EasyMock.expect(sessionMock.createBrowser(queueDestinationMock)).andReturn(queueBrowserMock);363 EasyMock.expect(queueBrowserMock.getEnumeration()).andReturn(null);364 sessionMock.close();365 EasyMock.expectLastCall();366 connectionMock.close();367 EasyMock.expectLastCall();368 369 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);370 371 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");372 373 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);374 375 assertThat(result, notNullValue());376 assertThat(result.size(), equalTo(0));377 }378 @Test379 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenSessionCloseThrowsAnException() throws Exception {380 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);381 connectionMock.setClientID(EasyMock.anyString());382 EasyMock.expectLastCall();383 connectionMock.start();384 EasyMock.expectLastCall();385 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);386 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);387 EasyMock.expect(sessionMock.createBrowser(queueDestinationMock)).andReturn(queueBrowserMock);388 EasyMock.expect(queueBrowserMock.getEnumeration()).andReturn(Collections.emptyEnumeration());389 sessionMock.close();390 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));391 connectionMock.close();392 EasyMock.expectLastCall();393 394 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);395 396 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");397 398 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);399 400 assertThat(result, notNullValue());401 assertThat(result.size(), equalTo(0));402 }403 @Test404 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenConnectionCloseThrowsAnException() throws Exception {405 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);406 connectionMock.setClientID(EasyMock.anyString());407 EasyMock.expectLastCall();408 connectionMock.start();409 EasyMock.expectLastCall();410 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);411 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);412 EasyMock.expect(sessionMock.createBrowser(queueDestinationMock)).andReturn(queueBrowserMock);413 EasyMock.expect(queueBrowserMock.getEnumeration()).andReturn(Collections.emptyEnumeration());414 sessionMock.close();415 EasyMock.expectLastCall();416 connectionMock.close();417 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));418 419 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);420 421 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");422 423 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);424 425 assertThat(result, notNullValue());426 assertThat(result.size(), equalTo(0));427 }428 @Test429 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenGetEnumeratoinThrowsAnException() throws Exception {430 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);431 connectionMock.setClientID(EasyMock.anyString());432 EasyMock.expectLastCall();433 connectionMock.start();434 EasyMock.expectLastCall();435 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);436 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);437 EasyMock.expect(sessionMock.createBrowser(queueDestinationMock)).andReturn(queueBrowserMock);438 EasyMock.expect(queueBrowserMock.getEnumeration()).andThrow(new JMSException("Some JMS Exception"));439 sessionMock.close();440 EasyMock.expectLastCall();441 connectionMock.close();442 EasyMock.expectLastCall();443 444 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);445 446 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");447 448 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, queueBrowserMock);449 450 assertThat(result, notNullValue());451 assertThat(result.size(), equalTo(0));452 }453 @Test454 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenCreateBrowserThrowsAnException() throws Exception {455 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);456 connectionMock.setClientID(EasyMock.anyString());457 EasyMock.expectLastCall();458 connectionMock.start();459 EasyMock.expectLastCall();460 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);461 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);462 EasyMock.expect(sessionMock.createBrowser(queueDestinationMock)).andThrow(new JMSException("Some JMS Exception"));463 sessionMock.close();464 EasyMock.expectLastCall();465 connectionMock.close();466 EasyMock.expectLastCall();467 468 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock);469 470 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");471 472 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock);473 474 assertThat(result, notNullValue());475 assertThat(result.size(), equalTo(0));476 }477 @Test478 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenCreateQueueThrowsAnException() throws Exception {479 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);480 connectionMock.setClientID(EasyMock.anyString());481 EasyMock.expectLastCall();482 connectionMock.start();483 EasyMock.expectLastCall();484 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);485 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andThrow(new JMSException("Some JMS Exception"));486 sessionMock.close();487 EasyMock.expectLastCall();488 connectionMock.close();489 EasyMock.expectLastCall();490 491 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);492 493 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");494 495 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock);496 497 assertThat(result, notNullValue());498 assertThat(result.size(), equalTo(0));499 }500 @Test501 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenCreateSessionThrowsAnException() throws Exception {502 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);503 connectionMock.setClientID(EasyMock.anyString());504 EasyMock.expectLastCall();505 connectionMock.start();506 EasyMock.expectLastCall();507 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andThrow(new JMSException("Some JMS Exception"));508 sessionMock.close();509 EasyMock.expectLastCall();510 connectionMock.close();511 EasyMock.expectLastCall();512 513 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);514 515 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");516 517 EasyMock.verify(connectionFactoryMock, connectionMock);518 519 assertThat(result, notNullValue());520 assertThat(result.size(), equalTo(0));521 }522 @Test523 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenSetClientIdThrowsAnException() throws Exception {524 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);525 connectionMock.setClientID(EasyMock.anyString());526 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));527 sessionMock.close();528 EasyMock.expectLastCall();529 connectionMock.close();530 EasyMock.expectLastCall();531 532 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);533 534 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");535 536 EasyMock.verify(connectionFactoryMock, connectionMock);537 538 assertThat(result, notNullValue());539 assertThat(result.size(), equalTo(0));540 }541 @Test542 public void browserMessagesFromWithValidArgumentsShouldReturnAnEmptyMapOfMessagesWhenCreateConnectionThrowsAnException() throws Exception {543 EasyMock.expect(connectionFactoryMock.createConnection()).andThrow(new JMSException("Some JMS Exception"));544 sessionMock.close();545 EasyMock.expectLastCall();546 connectionMock.close();547 EasyMock.expectLastCall();548 549 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock);550 551 Map<String,String> result = queueService.browseMessagesFrom("QUEUE_001");552 553 EasyMock.verify(connectionFactoryMock);554 555 assertThat(result, notNullValue());556 assertThat(result.size(), equalTo(0));557 }558 @Test559 public void removeMessagesFromWithValidArgumentsShouldReturnATrueResponse() throws Exception {560 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);561 connectionMock.setClientID(EasyMock.anyString());562 EasyMock.expectLastCall();563 connectionMock.start();564 EasyMock.expectLastCall();565 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);566 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);567 EasyMock.expect(sessionMock.createConsumer(queueDestinationMock)).andReturn(messageConsumerMock);568 EasyMock.expect(messageConsumerMock.receive(EasyMock.anyLong())).andReturn(queueMessages.get(0)).andReturn(null);569 messageConsumerMock.close();570 EasyMock.expectLastCall();571 sessionMock.close();572 EasyMock.expectLastCall();573 connectionMock.close();574 EasyMock.expectLastCall();575 576 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);577 578 boolean result = queueService.removeMessagesFrom("QUEUE_001");579 580 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);581 582 assertThat(result, notNullValue());583 assertThat(result, equalTo(true));584 }585 @Test586 public void removeMessagesFromWithValidArgumentsShouldReturnATrueResponseWhenNotReceiveMessages() throws Exception {587 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);588 connectionMock.setClientID(EasyMock.anyString());589 EasyMock.expectLastCall();590 connectionMock.start();591 EasyMock.expectLastCall();592 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);593 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);594 EasyMock.expect(sessionMock.createConsumer(queueDestinationMock)).andReturn(messageConsumerMock);595 EasyMock.expect(messageConsumerMock.receive(EasyMock.anyLong())).andReturn(null);596 messageConsumerMock.close();597 EasyMock.expectLastCall();598 sessionMock.close();599 EasyMock.expectLastCall();600 connectionMock.close();601 EasyMock.expectLastCall();602 603 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);604 605 boolean result = queueService.removeMessagesFrom("QUEUE_001");606 607 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);608 609 assertThat(result, notNullValue());610 assertThat(result, equalTo(true));611 }612 @Test613 public void removeMessagesFromWithValidArgumentsShouldReturnATrueResponseWhenMessageConsumerCloseThrowsAnException() throws Exception {614 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);615 connectionMock.setClientID(EasyMock.anyString());616 EasyMock.expectLastCall();617 connectionMock.start();618 EasyMock.expectLastCall();619 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);620 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);621 EasyMock.expect(sessionMock.createConsumer(queueDestinationMock)).andReturn(messageConsumerMock);622 EasyMock.expect(messageConsumerMock.receive(EasyMock.anyLong())).andReturn(null);623 messageConsumerMock.close();624 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));625 sessionMock.close();626 EasyMock.expectLastCall();627 connectionMock.close();628 EasyMock.expectLastCall();629 630 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);631 632 boolean result = queueService.removeMessagesFrom("QUEUE_001");633 634 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);635 636 assertThat(result, notNullValue());637 assertThat(result, equalTo(true));638 }639 @Test640 public void removeMessagesFromWithValidArgumentsShouldReturnATrueResponseWhenSessionCloseThrowsAnException() throws Exception {641 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);642 connectionMock.setClientID(EasyMock.anyString());643 EasyMock.expectLastCall();644 connectionMock.start();645 EasyMock.expectLastCall();646 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);647 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);648 EasyMock.expect(sessionMock.createConsumer(queueDestinationMock)).andReturn(messageConsumerMock);649 EasyMock.expect(messageConsumerMock.receive(EasyMock.anyLong())).andReturn(null);650 messageConsumerMock.close();651 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));652 sessionMock.close();653 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));654 connectionMock.close();655 EasyMock.expectLastCall();656 657 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);658 659 boolean result = queueService.removeMessagesFrom("QUEUE_001");660 661 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);662 663 assertThat(result, notNullValue());664 assertThat(result, equalTo(true));665 }666 @Test667 public void removeMessagesFromWithValidArgumentsShouldReturnATrueResponseWhenConnectionCloseThrowsAnException() throws Exception {668 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);669 connectionMock.setClientID(EasyMock.anyString());670 EasyMock.expectLastCall();671 connectionMock.start();672 EasyMock.expectLastCall();673 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);674 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);675 EasyMock.expect(sessionMock.createConsumer(queueDestinationMock)).andReturn(messageConsumerMock);676 EasyMock.expect(messageConsumerMock.receive(EasyMock.anyLong())).andReturn(null);677 messageConsumerMock.close();678 EasyMock.expectLastCall();679 sessionMock.close();680 EasyMock.expectLastCall();681 connectionMock.close();682 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));683 684 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);685 686 boolean result = queueService.removeMessagesFrom("QUEUE_001");687 688 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);689 690 assertThat(result, notNullValue());691 assertThat(result, equalTo(true));692 }693 @Test694 public void removeMessagesFromWithValidArgumentsShouldReturnAFalseResponseWhenReceiveThrowsAnException() throws Exception {695 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);696 connectionMock.setClientID(EasyMock.anyString());697 EasyMock.expectLastCall();698 connectionMock.start();699 EasyMock.expectLastCall();700 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);701 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);702 EasyMock.expect(sessionMock.createConsumer(queueDestinationMock)).andReturn(messageConsumerMock);703 EasyMock.expect(messageConsumerMock.receive(EasyMock.anyLong())).andThrow(new JMSException("Some JMS Exception"));704 messageConsumerMock.close();705 EasyMock.expectLastCall();706 sessionMock.close();707 EasyMock.expectLastCall();708 connectionMock.close();709 EasyMock.expectLastCall();710 711 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);712 713 boolean result = queueService.removeMessagesFrom("QUEUE_001");714 715 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);716 717 assertThat(result, notNullValue());718 assertThat(result, equalTo(false));719 }720 @Test721 public void removeMessagesFromWithValidArgumentsShouldReturnAFalseResponseWhenCreateConsumerThrowsAnException() throws Exception {722 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);723 connectionMock.setClientID(EasyMock.anyString());724 EasyMock.expectLastCall();725 connectionMock.start();726 EasyMock.expectLastCall();727 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);728 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andReturn(queueDestinationMock);729 EasyMock.expect(sessionMock.createConsumer(queueDestinationMock)).andThrow(new JMSException("Some JMS Exception"));730 messageConsumerMock.close();731 EasyMock.expectLastCall();732 sessionMock.close();733 EasyMock.expectLastCall();734 connectionMock.close();735 EasyMock.expectLastCall();736 737 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock, messageConsumerMock);738 739 boolean result = queueService.removeMessagesFrom("QUEUE_001");740 741 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock, queueDestinationMock);742 743 assertThat(result, notNullValue());744 assertThat(result, equalTo(false));745 }746 @Test747 public void removeMessagesFromWithValidArgumentsShouldReturnAFalseResponseWhenCreateQueueThrowsAnException() throws Exception {748 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);749 connectionMock.setClientID(EasyMock.anyString());750 EasyMock.expectLastCall();751 connectionMock.start();752 EasyMock.expectLastCall();753 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);754 EasyMock.expect(sessionMock.createQueue(EasyMock.anyString())).andThrow(new JMSException("Some JMS Exception"));755 messageConsumerMock.close();756 EasyMock.expectLastCall();757 sessionMock.close();758 EasyMock.expectLastCall();759 connectionMock.close();760 EasyMock.expectLastCall();761 762 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, messageConsumerMock);763 764 boolean result = queueService.removeMessagesFrom("QUEUE_001");765 766 EasyMock.verify(connectionFactoryMock, connectionMock, sessionMock);767 768 assertThat(result, notNullValue());769 assertThat(result, equalTo(false));770 }771 @Test772 public void removeMessagesFromWithValidArgumentsShouldReturnAFalseResponseWhenCreateSessionThrowsAnException() throws Exception {773 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);774 connectionMock.setClientID(EasyMock.anyString());775 EasyMock.expectLastCall();776 connectionMock.start();777 EasyMock.expectLastCall();778 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andThrow(new JMSException("Some JMS Exception"));779 messageConsumerMock.close();780 EasyMock.expectLastCall();781 sessionMock.close();782 EasyMock.expectLastCall();783 connectionMock.close();784 EasyMock.expectLastCall();785 786 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, messageConsumerMock);787 788 boolean result = queueService.removeMessagesFrom("QUEUE_001");789 790 EasyMock.verify(connectionFactoryMock, connectionMock);791 792 assertThat(result, notNullValue());793 assertThat(result, equalTo(false));794 }795 @Test796 public void removeMessagesFromWithValidArgumentsShouldReturnAFalseResponseWhenSetClientIDThrowsAnException() throws Exception {797 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);798 connectionMock.setClientID(EasyMock.anyString());799 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));800 messageConsumerMock.close();801 EasyMock.expectLastCall();802 sessionMock.close();803 EasyMock.expectLastCall();804 connectionMock.close();805 EasyMock.expectLastCall();806 807 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, messageConsumerMock);808 809 boolean result = queueService.removeMessagesFrom("QUEUE_001");810 811 EasyMock.verify(connectionFactoryMock, connectionMock);812 ...

Full Screen

Full Screen

Source:TopicServiceEasyMockTest.java Github

copy

Full Screen

...74 }75 @Test76 public void sendMessageToWithValidArgumentsShouldReturnATrueResponse() throws Exception {77 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);78 connectionMock.setClientID(EasyMock.anyString());79 EasyMock.expectLastCall();80 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);81 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andReturn(topicDestinationMock);82 EasyMock.expect(sessionMock.createProducer(topicDestinationMock)).andReturn(messageProducerMock);83 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);84 messageProducerMock.send(textMessageMock);85 EasyMock.expectLastCall();86 sessionMock.close();87 EasyMock.expectLastCall();88 connectionMock.close();89 EasyMock.expectLastCall();90 91 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);92 93 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");94 95 assertThat(result, notNullValue());96 assertThat(result, equalTo(true));97 }98 @Test99 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenConnectionCloseThrowsAnException() throws Exception {100 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);101 connectionMock.setClientID(EasyMock.anyString());102 EasyMock.expectLastCall();103 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);104 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andReturn(topicDestinationMock);105 EasyMock.expect(sessionMock.createProducer(topicDestinationMock)).andReturn(messageProducerMock);106 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);107 messageProducerMock.send(textMessageMock);108 EasyMock.expectLastCall();109 sessionMock.close();110 EasyMock.expectLastCall();111 connectionMock.close();112 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));113 114 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);115 116 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");117 118 assertThat(result, notNullValue());119 assertThat(result, equalTo(true));120 }121 @Test122 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSessionCloseThrowsAnException() throws Exception {123 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);124 connectionMock.setClientID(EasyMock.anyString());125 EasyMock.expectLastCall();126 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);127 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andReturn(topicDestinationMock);128 EasyMock.expect(sessionMock.createProducer(topicDestinationMock)).andReturn(messageProducerMock);129 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);130 messageProducerMock.send(textMessageMock);131 EasyMock.expectLastCall();132 sessionMock.close();133 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));134 connectionMock.close();135 EasyMock.expectLastCall();136 137 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);138 139 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");140 141 assertThat(result, notNullValue());142 assertThat(result, equalTo(true));143 }144 @Test145 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSessionAndConnectionCloseThrowsAnException() throws Exception {146 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);147 connectionMock.setClientID(EasyMock.anyString());148 EasyMock.expectLastCall();149 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);150 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andReturn(topicDestinationMock);151 EasyMock.expect(sessionMock.createProducer(topicDestinationMock)).andReturn(messageProducerMock);152 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);153 messageProducerMock.send(textMessageMock);154 EasyMock.expectLastCall();155 sessionMock.close();156 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));157 connectionMock.close();158 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));159 160 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);161 162 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");163 164 assertThat(result, notNullValue());165 assertThat(result, equalTo(true));166 }167 @Test168 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSendMessageThrowsAnException() throws Exception {169 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);170 connectionMock.setClientID(EasyMock.anyString());171 EasyMock.expectLastCall();172 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);173 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andReturn(topicDestinationMock);174 EasyMock.expect(sessionMock.createProducer(topicDestinationMock)).andReturn(messageProducerMock);175 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andReturn(textMessageMock);176 messageProducerMock.send(textMessageMock);177 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));178 sessionMock.close();179 EasyMock.expectLastCall();180 connectionMock.close();181 EasyMock.expectLastCall();182 183 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);184 185 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");186 187 assertThat(result, notNullValue());188 assertThat(result, equalTo(false));189 }190 @Test191 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateTextMessageThrowsAnException() throws Exception {192 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);193 connectionMock.setClientID(EasyMock.anyString());194 EasyMock.expectLastCall();195 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);196 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andReturn(topicDestinationMock);197 EasyMock.expect(sessionMock.createProducer(topicDestinationMock)).andReturn(messageProducerMock);198 EasyMock.expect(sessionMock.createTextMessage(EasyMock.anyString())).andThrow(new JMSException("Some JMS Exception"));199 sessionMock.close();200 EasyMock.expectLastCall();201 connectionMock.close();202 EasyMock.expectLastCall();203 204 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);205 206 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");207 208 assertThat(result, notNullValue());209 assertThat(result, equalTo(false));210 }211 @Test212 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateProducerThrowsAnException() throws Exception {213 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);214 connectionMock.setClientID(EasyMock.anyString());215 EasyMock.expectLastCall();216 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);217 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andReturn(topicDestinationMock);218 EasyMock.expect(sessionMock.createProducer(topicDestinationMock)).andThrow(new JMSException("Some JMS Exception"));219 sessionMock.close();220 EasyMock.expectLastCall();221 connectionMock.close();222 EasyMock.expectLastCall();223 224 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);225 226 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");227 228 assertThat(result, notNullValue());229 assertThat(result, equalTo(false));230 }231 @Test232 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateTopicThrowsAnException() throws Exception {233 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);234 connectionMock.setClientID(EasyMock.anyString());235 EasyMock.expectLastCall();236 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andReturn(sessionMock);237 EasyMock.expect(sessionMock.createTopic(EasyMock.anyString())).andThrow(new JMSException("Some JMS Exception"));238 sessionMock.close();239 EasyMock.expectLastCall();240 connectionMock.close();241 EasyMock.expectLastCall();242 243 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);244 245 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");246 247 assertThat(result, notNullValue());248 assertThat(result, equalTo(false));249 }250 @Test251 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenCreateSessionThrowsAnException() throws Exception {252 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);253 connectionMock.setClientID(EasyMock.anyString());254 EasyMock.expectLastCall();255 EasyMock.expect(connectionMock.createSession(EasyMock.anyBoolean(), EasyMock.anyInt())).andThrow(new JMSException("Some JMS Exception"));256 sessionMock.close();257 EasyMock.expectLastCall();258 connectionMock.close();259 EasyMock.expectLastCall();260 261 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);262 263 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");264 265 assertThat(result, notNullValue());266 assertThat(result, equalTo(false));267 }268 @Test269 public void sendMessageToWithValidArgumentsShouldReturnATrueResponseWhenSetClientIDThrowsAnException() throws Exception {270 EasyMock.expect(connectionFactoryMock.createConnection()).andReturn(connectionMock);271 connectionMock.setClientID(EasyMock.anyString());272 EasyMock.expectLastCall().andThrow(new JMSException("Some JMS Exception"));273 sessionMock.close();274 EasyMock.expectLastCall();275 connectionMock.close();276 EasyMock.expectLastCall();277 278 EasyMock.replay(connectionFactoryMock, connectionMock, sessionMock, topicDestinationMock, messageProducerMock, textMessageMock);279 280 boolean result = topicService.sendMessageTo("TOPIC_001", "someMessage");281 282 assertThat(result, notNullValue());283 assertThat(result, equalTo(false));284 }285 @Test...

Full Screen

Full Screen

Source:DefaultArchetypeGenerationConfigurator2Test.java Github

copy

Full Screen

...112 request.setArchetypeGroupId( "archetypeGroupId" );113 request.setArchetypeArtifactId( "archetypeArtifactId" );114 request.setArchetypeVersion( "archetypeVersion" );115 Properties properties = new Properties();116 EasyMock.expect( queryer.getPropertyValue( EasyMock.eq("groupName"), EasyMock.anyString(),117 EasyMock.<Pattern> isNull() ) ).andReturn( "myGroupName" );118 EasyMock.expect( queryer.getPropertyValue( EasyMock.eq("serviceName"), EasyMock.anyString(),119 EasyMock.<Pattern> isNull() ) ).andReturn( "myServiceName" );120 EasyMock.expect( queryer.getPropertyValue( EasyMock.anyString(), EasyMock.anyString(),121 EasyMock.<Pattern> anyObject())).andAnswer( new IAnswer<String>() {122 @Override123 public String answer() throws Throwable {124 return (String) EasyMock.getCurrentArguments()[1];125 }}126 ).anyTimes();127 EasyMock.expect( queryer.confirmConfiguration( EasyMock.<ArchetypeConfiguration> anyObject() ) )128 .andReturn( Boolean.TRUE );129 EasyMock.replay( queryer );130 configurator.configureArchetype( request, Boolean.TRUE, properties );131 assertEquals( "com.example.myGroupName", request.getGroupId() );132 assertEquals( "myServiceName", request.getArtifactId() );133 assertEquals( "1.0-SNAPSHOT", request.getVersion() );134 assertEquals( "com.example.myGroupName", request.getPackage() );135 }136 public void testArchetype406ComplexCustomPropertyValue() throws Exception137 {138 RequiredProperty custom = new RequiredProperty();139 custom.setKey( "serviceUpper" );140 custom.setDefaultValue( "${serviceName.toUpperCase()}" );141 descriptor.addRequiredProperty( custom );142 ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();143 request.setArchetypeGroupId( "archetypeGroupId" );144 request.setArchetypeArtifactId( "archetypeArtifactId" );145 request.setArchetypeVersion( "archetypeVersion" );146 Properties properties = new Properties();147 EasyMock.expect( queryer.getPropertyValue( EasyMock.eq("groupName"), EasyMock.anyString(),148 EasyMock.<Pattern> isNull() ) ).andReturn( "myGroupName" );149 EasyMock.expect( queryer.getPropertyValue( EasyMock.eq("serviceName"), EasyMock.anyString(),150 EasyMock.<Pattern> isNull() ) ).andReturn( "myServiceName" );151 EasyMock.expect( queryer.getPropertyValue( EasyMock.anyString(), EasyMock.anyString(),152 EasyMock.<Pattern> anyObject())).andAnswer( new IAnswer<String>() {153 @Override154 public String answer() throws Throwable {155 return (String) EasyMock.getCurrentArguments()[1];156 }}157 ).anyTimes();158 EasyMock.expect( queryer.confirmConfiguration( EasyMock.<ArchetypeConfiguration> anyObject() ) )159 .andReturn( Boolean.TRUE );160 EasyMock.replay( queryer );161 configurator.configureArchetype( request, Boolean.TRUE, properties );162 assertEquals( "MYSERVICENAME", request.getProperties().get( "serviceUpper" ) );163 }164 public void testArchetype618() throws Exception165 {166 RequiredProperty custom = getRequiredProperty( "serviceName" );167 custom.setKey( "camelArtifact" );168 custom.setDefaultValue( "${artifactId.class.forName('org.codehaus.plexus.util.StringUtils').capitaliseAllWords($artifactId.replaceAll('[^A-Za-z_\\$0-9]', ' ').replaceFirst('^(\\d)', '_$1').replaceAll('\\d', '$0 ').replaceAll('[A-Z](?=[^A-Z])', ' $0').toLowerCase()).replaceAll('\\s', '')}" );169 descriptor.addRequiredProperty( custom );170 getRequiredProperty( "artifactId" ).setDefaultValue( null );171 ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();172 request.setArchetypeGroupId( "archetypeGroupId" );173 request.setArchetypeArtifactId( "archetypeArtifactId" );174 request.setArchetypeVersion( "archetypeVersion" );175 Properties properties = new Properties();176 EasyMock.expect( queryer.getPropertyValue( EasyMock.eq("groupName"), EasyMock.anyString(),177 EasyMock.<Pattern> isNull() ) ).andReturn( "myGroupName" );178 EasyMock.expect( queryer.getPropertyValue( EasyMock.eq("artifactId"), EasyMock.anyString(),179 EasyMock.<Pattern> isNull() ) ).andReturn( "my-service-name" );180 EasyMock.expect( queryer.getPropertyValue( EasyMock.anyString(), EasyMock.anyString(),181 EasyMock.<Pattern> anyObject())).andAnswer( new IAnswer<String>() {182 @Override183 public String answer() throws Throwable {184 return (String) EasyMock.getCurrentArguments()[1];185 }}186 ).anyTimes();187 EasyMock.expect( queryer.confirmConfiguration( EasyMock.<ArchetypeConfiguration> anyObject() ) )188 .andReturn( Boolean.TRUE );189 EasyMock.replay( queryer );190 configurator.configureArchetype( request, Boolean.TRUE, properties );191 assertEquals( "MyServiceName", request.getProperties().get( "camelArtifact" ) );192 }193 private RequiredProperty getRequiredProperty( String propertyName )194 {...

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.IArgumentMatcher;3public class anyString implements IArgumentMatcher {4 public void appendTo(StringBuffer buffer) {5 buffer.append("anyString()");6 }7 public boolean matches(Object argument) {8 if (argument instanceof String) {9 return true;10 }11 return false;12 }13 public static String anyString() {14 EasyMock.reportMatcher(new anyString());15 return null;16 }17}18import static org.easymock.EasyMock.*;19import org.junit.Test;20import static org.junit.Assert.*;21public class TestClass {22 public void test() {23 ClassToBeMocked mock = createMock(ClassToBeMocked.class);24 expect(mock.method(anyString(), anyString())).andReturn(1);25 replay(mock);26 assertEquals(1, mock.method("a", "b"));27 verify(mock);28 }29}30public class ClassToBeMocked {31 public int method(String a, String b) {32 return 1;33 }34}35BUILD SUCCESSFUL (total time: 1 second)

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1import static org.easymock.EasyMock.*;2import org.easymock.IAnswer;3import org.junit.Test;4import org.junit.runner.RunWith;5import org.powermock.api.easymock.annotation.Mock;6import org.powermock.core.classloader.annotations.PrepareForTest;7import org.powermock.modules.junit4.PowerMockRunner;8import static org.powermock.api.easymock.PowerMock.*;9import static org.junit.Assert.*;10import static org.powermock.api.easymock.PowerMock.*;11@RunWith(PowerMockRunner.class)12@PrepareForTest({1.class})13public class 1Test {14 private 1 mock1;15 public void test1() throws Exception {16 expectNew(1.class).andReturn(mock1);17 expect(mock1.add(anyString())).andAnswer(new IAnswer<Object>() {18 public Object answer() throws Throwable {19 String arg = (String) getCurrentArguments()[0];20 return arg;21 }22 });23 replayAll();24 1 obj = new 1();25 String result = obj.add("hello");26 assertEquals("hello", result);27 verifyAll();28 }29}30import org.easymock.EasyMock;31public class 1 {32 public String add(String str) {33 return str;34 }35}36import org.easymock.EasyMock;37import org.junit.Test;38import static org.junit.Assert.*;39public class 1Test {40 public void test1() {41 1 obj = EasyMock.createMock(1.class);42 EasyMock.expect(obj.add(EasyMock.anyString())).andReturn("hello");43 EasyMock.replay(obj);44 String result = obj.add("hello");45 assertEquals("hello", result);46 EasyMock.verify(obj);47 }48}49public class 1 {50 public String add(String str) {51 return str;52 }53}54import org.easymock.EasyMock;55import org.junit.Test;56import static org

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.EasyMockSupport;3import org.junit.Test;4import static org.easymock.EasyMock.*;5import static org.junit.Assert.*;6public class Test1 extends EasyMockSupport {7public void test1() {8List mockList = EasyMock.createMock(List.class);9mockList.add(anyString());10replay(mockList);11mockList.add("abc");12verify(mockList);13}14}15org.easymock.MockControl$UnexpectedInvocationError: Unexpected method call List.add("abc"):16List.add("abc");17at org.easymock.MockControl$InvocationMatcher.checkCall(MockControl.java:295)18at org.easymock.MockControl$InvocationMatcher.matches(MockControl.java:250)19at org.easymock.MockControl$InvocationMatcher.matches(MockControl.java:1)20at org.easymock.MockControl$1.matches(MockControl.java:117)21at org.easymock.MockControl$1.matches(MockControl.java:1)

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1package com.ack.j2se.mocking.easymock;2import junit.framework.TestCase;3import org.easymock.EasyMock;4public class AnyStringMethodTest extends TestCase {5 public void testAnyStringMethod() {6 MockInterface mock = EasyMock.createMock( MockInterface.class );7 mock.doSomething( EasyMock.anyString() );8 EasyMock.replay( mock );9 mock.doSomething( "Hello World" );10 EasyMock.verify( mock );11 }12}13package com.ack.j2se.mocking.easymock;14public interface MockInterface {15 public void doSomething(String s);16}

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.junit.Test;3import static org.easymock.EasyMock.*;4import static org.junit.Assert.*;5public class TestAnyString {6public void testAnyString() {7MockInterface mockObj = EasyMock.createMock(MockInterface.class);8expect(mockObj.method(anyString())).andReturn("result");9replay(mockObj);10assertEquals("result", mockObj.method("test"));11verify(mockObj);12}13}14import org.easymock.classextension.EasyMock;15import org.junit.Test;16import static org.easymock.classextension.EasyMock.*;17import static org.junit.Assert.*;18public class TestAnyString {19public void testAnyString() {20MockInterface mockObj = EasyMock.createMock(MockInterface.class);21expect(mockObj.method(anyString())).andReturn("result");22replay(mockObj);23assertEquals("result", mockObj.method("test"));24verify(mockObj);25}26}27import org.easymock.classextension.EasyMock;28import org.junit.Test;29import static org.easymock.classextension.EasyMock.*;30import static org.junit.Assert.*;31public class TestAnyString {32public void testAnyString() {33MockInterface mockObj = EasyMock.createMock(MockInterface.class);34expect(mockObj.method(anyString())).andReturn("result");35replay(mockObj);36assertEquals("result", mockObj.method("test"));37verify(mockObj);38}39}40import org.easymock.classextension.EasyMock;41import org.junit.Test;42import static org.easymock.classextension.Easy

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import junit.framework.TestCase;3public class TestEasyMock extends TestCase {4 public void testAnyString() {5 String s = EasyMock.anyString();6 EasyMock.replay(s);7 assertEquals(true, s.equals("Hello"));8 assertEquals(true, s.equals("World"));9 assertEquals(true, s.equals("Welcome"));10 assertEquals(true, s.equals("to"));11 assertEquals(true, s.equals("EasyMock"));12 EasyMock.verify(s);13 }14}15java -cp easymock-3.0.jar;cglib-2.2.jar;objenesis-1.0.jar;hamcrest-core-1.1.jar;. TestEasyMock16OK (1 test)17Output of the above code is shown in the above screenshot. In the above code we have used anyString() method of EasyMock cl

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1package com.mycompany.app;2import static org.easymock.EasyMock.*;3import org.easymock.IArgumentMatcher;4import org.junit.Test;5import static org.junit.Assert.*;6public class Test1 {7 public void test1() {8 String expected = "Hello World!";9 String actual = "Hello World!";10 assertEquals(expected, actual);11 }12 public void test2() {13 String expected = "Hello World!";14 String actual = "Hello World!";15 assertEquals(expected, actual);16 }17}18package com.mycompany.app;19import static org.easymock.EasyMock.*;20import org.easymock.IArgumentMatcher;21import org.junit.Test;22import static org.junit.Assert.*;23public class Test2 {24 public void test1() {25 String expected = "Hello World!";26 String actual = "Hello World!";27 assertEquals(expected, actual);28 }29 public void test2() {30 String expected = "Hello World!";31 String actual = "Hello World!";32 assertEquals(expected, actual);33 }34}35package com.mycompany.app;36import static org.easymock.EasyMock.*;37import org.easymock.IArgumentMatcher;38import org.junit.Test;39import static org.junit.Assert.*;40public class Test3 {41 public void test1() {42 String expected = "Hello World!";43 String actual = "Hello World!";44 assertEquals(expected, actual);45 }46 public void test2() {47 String expected = "Hello World!";48 String actual = "Hello World!";49 assertEquals(expected, actual);50 }51}52package com.mycompany.app;53import static org.easymock.EasyMock.*;54import org.easymock.IArgumentMatcher;55import org.junit.Test;56import static org.junit.Assert.*;57public class Test4 {58 public void test1() {59 String expected = "Hello World!";60 String actual = "Hello World!";61 assertEquals(expected, actual);62 }

Full Screen

Full Screen

anyString

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.IAnswer;3import java.io.IOException;4public class Test {5 public static void main(String[] args) {6 IStudent mock = EasyMock.createMock(IStudent.class);7 EasyMock.expect(mock.getName()).andReturn("John");8 EasyMock.expect(mock.getAge()).andReturn(20);9 EasyMock.expect(mock.getAge()).andReturn(20);10 EasyMock.replay(mock);11 System.out.println(mock.getName());12 System.out.println(mock.getAge());13 System.out.println(mock.getAge());14 }15}16import org.easymock.EasyMock;17import org.easymock.IAnswer;18import java.io.IOException;19public class Test {20 public static void main(String[] args) {21 IStudent mock = EasyMock.createMock(IStudent.class);22 EasyMock.expect(mock.getName()).andReturn("John");23 EasyMock.expect(mock.getAge()).andReturn(20);24 EasyMock.expect(mock.getAge()).andReturn(20);25 EasyMock.replay(mock);26 System.out.println(mock.getName());27 System.out.println(mock.getAge());28 System.out.println(mock.getAge());29 }30}31import org.easymock.EasyMock;32import org.easymock.IAnswer;33import java.io.IOException;34public class Test {35 public static void main(String[] args) {36 IStudent mock = EasyMock.createMock(IStudent.class);37 EasyMock.expect(mock.getName()).andReturn("John");38 EasyMock.expect(mock.getAge()).andReturn(20);39 EasyMock.expect(mock.getAge()).andReturn(20);40 EasyMock.replay(mock);41 System.out.println(mock.getName());42 System.out.println(mock.getAge());43 System.out.println(mock.getAge());44 }45}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful