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

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

Source:DistributedHerderTest.java Github

copy

Full Screen

...163 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);164 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);165 worker.startTask(EasyMock.eq(TASK1), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));166 PowerMock.expectLastCall();167 member.poll(EasyMock.anyInt());168 PowerMock.expectLastCall();169 PowerMock.replayAll();170 herder.tick();171 PowerMock.verifyAll();172 }173 @Test174 public void testRebalance() throws Exception {175 // Join group and get assignment176 EasyMock.expect(member.memberId()).andStubReturn("member");177 expectRebalance(1, Arrays.asList(CONN1), Arrays.asList(TASK1));178 expectPostRebalanceCatchup(SNAPSHOT);179 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),180 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));181 PowerMock.expectLastCall();182 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);183 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);184 worker.startTask(EasyMock.eq(TASK1), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));185 PowerMock.expectLastCall();186 member.poll(EasyMock.anyInt());187 PowerMock.expectLastCall();188 expectRebalance(Arrays.asList(CONN1), Arrays.asList(TASK1), ConnectProtocol.Assignment.NO_ERROR,189 1, Arrays.asList(CONN1), Arrays.<ConnectorTaskId>asList());190 // and the new assignment started191 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),192 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));193 PowerMock.expectLastCall();194 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);195 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);196 member.poll(EasyMock.anyInt());197 PowerMock.expectLastCall();198 PowerMock.replayAll();199 herder.tick();200 herder.tick();201 PowerMock.verifyAll();202 }203 @Test204 public void testRebalanceFailedConnector() throws Exception {205 // Join group and get assignment206 EasyMock.expect(member.memberId()).andStubReturn("member");207 expectRebalance(1, Arrays.asList(CONN1), Arrays.asList(TASK1));208 expectPostRebalanceCatchup(SNAPSHOT);209 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),210 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));211 PowerMock.expectLastCall();212 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);213 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);214 worker.startTask(EasyMock.eq(TASK1), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));215 PowerMock.expectLastCall();216 member.poll(EasyMock.anyInt());217 PowerMock.expectLastCall();218 expectRebalance(Arrays.asList(CONN1), Arrays.asList(TASK1), ConnectProtocol.Assignment.NO_ERROR,219 1, Arrays.asList(CONN1), Arrays.<ConnectorTaskId>asList());220 // and the new assignment started221 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),222 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));223 PowerMock.expectLastCall();224 EasyMock.expect(worker.isRunning(CONN1)).andReturn(false);225 // worker is not running, so we should see no call to connectorTaskConfigs()226 member.poll(EasyMock.anyInt());227 PowerMock.expectLastCall();228 PowerMock.replayAll();229 herder.tick();230 herder.tick();231 PowerMock.verifyAll();232 }233 @Test234 public void testHaltCleansUpWorker() {235 EasyMock.expect(worker.connectorNames()).andReturn(Collections.singleton(CONN1));236 worker.stopConnector(CONN1);237 PowerMock.expectLastCall();238 EasyMock.expect(worker.taskIds()).andReturn(Collections.singleton(TASK1));239 worker.stopTasks(Collections.singleton(TASK1));240 PowerMock.expectLastCall();241 worker.awaitStopTasks(Collections.singleton(TASK1));242 PowerMock.expectLastCall();243 member.stop();244 PowerMock.expectLastCall();245 configStorage.stop();246 PowerMock.expectLastCall();247 statusBackingStore.stop();248 PowerMock.expectLastCall();249 worker.stop();250 PowerMock.expectLastCall();251 PowerMock.replayAll();252 herder.halt();253 PowerMock.verifyAll();254 }255 @Test256 public void testCreateConnector() throws Exception {257 EasyMock.expect(member.memberId()).andStubReturn("leader");258 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());259 expectPostRebalanceCatchup(SNAPSHOT);260 member.wakeup();261 PowerMock.expectLastCall();262 // CONN2 is new, should succeed263 configStorage.putConnectorConfig(CONN2, CONN2_CONFIG);264 PowerMock.expectLastCall();265 ConnectorInfo info = new ConnectorInfo(CONN2, CONN2_CONFIG, Collections.<ConnectorTaskId>emptyList());266 putConnectorCallback.onCompletion(null, new Herder.Created<>(true, info));267 PowerMock.expectLastCall();268 member.poll(EasyMock.anyInt());269 PowerMock.expectLastCall();270 // No immediate action besides this -- change will be picked up via the config log271 PowerMock.replayAll();272 herder.putConnectorConfig(CONN2, CONN2_CONFIG, false, putConnectorCallback);273 herder.tick();274 PowerMock.verifyAll();275 }276 @Test277 public void testCreateConnectorAlreadyExists() throws Exception {278 EasyMock.expect(member.memberId()).andStubReturn("leader");279 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());280 expectPostRebalanceCatchup(SNAPSHOT);281 member.wakeup();282 PowerMock.expectLastCall();283 // CONN1 already exists284 putConnectorCallback.onCompletion(EasyMock.<AlreadyExistsException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());285 PowerMock.expectLastCall();286 member.poll(EasyMock.anyInt());287 PowerMock.expectLastCall();288 // No immediate action besides this -- change will be picked up via the config log289 PowerMock.replayAll();290 herder.putConnectorConfig(CONN1, CONN1_CONFIG, false, putConnectorCallback);291 herder.tick();292 PowerMock.verifyAll();293 }294 @Test295 public void testDestroyConnector() throws Exception {296 EasyMock.expect(member.memberId()).andStubReturn("leader");297 // Start with one connector298 expectRebalance(1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());299 expectPostRebalanceCatchup(SNAPSHOT);300 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),301 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));302 PowerMock.expectLastCall();303 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);304 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);305 // And delete the connector306 member.wakeup();307 PowerMock.expectLastCall();308 configStorage.removeConnectorConfig(CONN1);309 PowerMock.expectLastCall();310 putConnectorCallback.onCompletion(null, new Herder.Created<ConnectorInfo>(false, null));311 PowerMock.expectLastCall();312 member.poll(EasyMock.anyInt());313 PowerMock.expectLastCall();314 // No immediate action besides this -- change will be picked up via the config log315 PowerMock.replayAll();316 herder.putConnectorConfig(CONN1, null, true, putConnectorCallback);317 herder.tick();318 PowerMock.verifyAll();319 }320 @Test321 public void testRestartConnector() throws Exception {322 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andStubReturn(TASK_CONFIGS);323 // get the initial assignment324 EasyMock.expect(member.memberId()).andStubReturn("leader");325 expectRebalance(1, Collections.singletonList(CONN1), Collections.<ConnectorTaskId>emptyList());326 expectPostRebalanceCatchup(SNAPSHOT);327 member.poll(EasyMock.anyInt());328 PowerMock.expectLastCall();329 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),330 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));331 PowerMock.expectLastCall();332 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);333 // now handle the connector restart334 member.wakeup();335 PowerMock.expectLastCall();336 member.ensureActive();337 PowerMock.expectLastCall();338 member.poll(EasyMock.anyInt());339 PowerMock.expectLastCall();340 EasyMock.expect(worker.ownsConnector(CONN1)).andReturn(true);341 worker.stopConnector(CONN1);342 PowerMock.expectLastCall();343 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),344 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));345 PowerMock.expectLastCall();346 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);347 PowerMock.replayAll();348 herder.tick();349 FutureCallback<Void> callback = new FutureCallback<>();350 herder.restartConnector(CONN1, callback);351 herder.tick();352 callback.get(1000L, TimeUnit.MILLISECONDS);353 PowerMock.verifyAll();354 }355 @Test356 public void testRestartUnknownConnector() throws Exception {357 // get the initial assignment358 EasyMock.expect(member.memberId()).andStubReturn("leader");359 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());360 expectPostRebalanceCatchup(SNAPSHOT);361 member.poll(EasyMock.anyInt());362 PowerMock.expectLastCall();363 // now handle the connector restart364 member.wakeup();365 PowerMock.expectLastCall();366 member.ensureActive();367 PowerMock.expectLastCall();368 member.poll(EasyMock.anyInt());369 PowerMock.expectLastCall();370 PowerMock.replayAll();371 herder.tick();372 FutureCallback<Void> callback = new FutureCallback<>();373 herder.restartConnector(CONN2, callback);374 herder.tick();375 try {376 callback.get(1000L, TimeUnit.MILLISECONDS);377 fail("Expected NotLeaderException to be raised");378 } catch (ExecutionException e) {379 assertTrue(e.getCause() instanceof NotFoundException);380 }381 PowerMock.verifyAll();382 }383 @Test384 public void testRestartConnectorRedirectToLeader() throws Exception {385 // get the initial assignment386 EasyMock.expect(member.memberId()).andStubReturn("member");387 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());388 expectPostRebalanceCatchup(SNAPSHOT);389 member.poll(EasyMock.anyInt());390 PowerMock.expectLastCall();391 // now handle the connector restart392 member.wakeup();393 PowerMock.expectLastCall();394 member.ensureActive();395 PowerMock.expectLastCall();396 member.poll(EasyMock.anyInt());397 PowerMock.expectLastCall();398 EasyMock.expect(worker.ownsConnector(CONN1)).andReturn(false);399 PowerMock.replayAll();400 herder.tick();401 FutureCallback<Void> callback = new FutureCallback<>();402 herder.restartConnector(CONN1, callback);403 herder.tick();404 try {405 callback.get(1000L, TimeUnit.MILLISECONDS);406 fail("Expected NotLeaderException to be raised");407 } catch (ExecutionException e) {408 assertTrue(e.getCause() instanceof NotLeaderException);409 }410 PowerMock.verifyAll();411 }412 @Test413 public void testRestartConnectorRedirectToOwner() throws Exception {414 // get the initial assignment415 EasyMock.expect(member.memberId()).andStubReturn("leader");416 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());417 expectPostRebalanceCatchup(SNAPSHOT);418 member.poll(EasyMock.anyInt());419 PowerMock.expectLastCall();420 // now handle the connector restart421 member.wakeup();422 PowerMock.expectLastCall();423 member.ensureActive();424 PowerMock.expectLastCall();425 member.poll(EasyMock.anyInt());426 PowerMock.expectLastCall();427 String ownerUrl = "ownerUrl";428 EasyMock.expect(worker.ownsConnector(CONN1)).andReturn(false);429 EasyMock.expect(member.ownerUrl(CONN1)).andReturn(ownerUrl);430 PowerMock.replayAll();431 herder.tick();432 FutureCallback<Void> callback = new FutureCallback<>();433 herder.restartConnector(CONN1, callback);434 herder.tick();435 try {436 callback.get(1000L, TimeUnit.MILLISECONDS);437 fail("Expected NotLeaderException to be raised");438 } catch (ExecutionException e) {439 assertTrue(e.getCause() instanceof NotAssignedException);440 NotAssignedException notAssignedException = (NotAssignedException) e.getCause();441 assertEquals(ownerUrl, notAssignedException.forwardUrl());442 }443 PowerMock.verifyAll();444 }445 @Test446 public void testRestartTask() throws Exception {447 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andStubReturn(TASK_CONFIGS);448 // get the initial assignment449 EasyMock.expect(member.memberId()).andStubReturn("leader");450 expectRebalance(1, Collections.<String>emptyList(), Collections.singletonList(TASK0));451 expectPostRebalanceCatchup(SNAPSHOT);452 member.poll(EasyMock.anyInt());453 PowerMock.expectLastCall();454 worker.startTask(EasyMock.eq(TASK0), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));455 PowerMock.expectLastCall();456 // now handle the task restart457 member.wakeup();458 PowerMock.expectLastCall();459 member.ensureActive();460 PowerMock.expectLastCall();461 member.poll(EasyMock.anyInt());462 PowerMock.expectLastCall();463 EasyMock.expect(worker.ownsTask(TASK0)).andReturn(true);464 worker.stopAndAwaitTask(TASK0);465 PowerMock.expectLastCall();466 worker.startTask(EasyMock.eq(TASK0), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));467 PowerMock.expectLastCall();468 PowerMock.replayAll();469 herder.tick();470 FutureCallback<Void> callback = new FutureCallback<>();471 herder.restartTask(TASK0, callback);472 herder.tick();473 callback.get(1000L, TimeUnit.MILLISECONDS);474 PowerMock.verifyAll();475 }476 @Test477 public void testRestartUnknownTask() throws Exception {478 // get the initial assignment479 EasyMock.expect(member.memberId()).andStubReturn("member");480 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());481 expectPostRebalanceCatchup(SNAPSHOT);482 member.poll(EasyMock.anyInt());483 PowerMock.expectLastCall();484 member.wakeup();485 PowerMock.expectLastCall();486 member.ensureActive();487 PowerMock.expectLastCall();488 member.poll(EasyMock.anyInt());489 PowerMock.expectLastCall();490 PowerMock.replayAll();491 FutureCallback<Void> callback = new FutureCallback<>();492 herder.tick();493 herder.restartTask(new ConnectorTaskId("blah", 0), callback);494 herder.tick();495 try {496 callback.get(1000L, TimeUnit.MILLISECONDS);497 fail("Expected NotLeaderException to be raised");498 } catch (ExecutionException e) {499 assertTrue(e.getCause() instanceof NotFoundException);500 }501 PowerMock.verifyAll();502 }503 @Test504 public void testRestartTaskRedirectToLeader() throws Exception {505 // get the initial assignment506 EasyMock.expect(member.memberId()).andStubReturn("member");507 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());508 expectPostRebalanceCatchup(SNAPSHOT);509 member.poll(EasyMock.anyInt());510 PowerMock.expectLastCall();511 // now handle the task restart512 EasyMock.expect(worker.ownsTask(TASK0)).andReturn(false);513 member.wakeup();514 PowerMock.expectLastCall();515 member.ensureActive();516 PowerMock.expectLastCall();517 member.poll(EasyMock.anyInt());518 PowerMock.expectLastCall();519 PowerMock.replayAll();520 herder.tick();521 FutureCallback<Void> callback = new FutureCallback<>();522 herder.restartTask(TASK0, callback);523 herder.tick();524 try {525 callback.get(1000L, TimeUnit.MILLISECONDS);526 fail("Expected NotLeaderException to be raised");527 } catch (ExecutionException e) {528 assertTrue(e.getCause() instanceof NotLeaderException);529 }530 PowerMock.verifyAll();531 }532 @Test533 public void testRestartTaskRedirectToOwner() throws Exception {534 // get the initial assignment535 EasyMock.expect(member.memberId()).andStubReturn("leader");536 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());537 expectPostRebalanceCatchup(SNAPSHOT);538 member.poll(EasyMock.anyInt());539 PowerMock.expectLastCall();540 // now handle the task restart541 String ownerUrl = "ownerUrl";542 EasyMock.expect(worker.ownsTask(TASK0)).andReturn(false);543 EasyMock.expect(member.ownerUrl(TASK0)).andReturn(ownerUrl);544 member.wakeup();545 PowerMock.expectLastCall();546 member.ensureActive();547 PowerMock.expectLastCall();548 member.poll(EasyMock.anyInt());549 PowerMock.expectLastCall();550 PowerMock.replayAll();551 herder.tick();552 FutureCallback<Void> callback = new FutureCallback<>();553 herder.restartTask(TASK0, callback);554 herder.tick();555 try {556 callback.get(1000L, TimeUnit.MILLISECONDS);557 fail("Expected NotLeaderException to be raised");558 } catch (ExecutionException e) {559 assertTrue(e.getCause() instanceof NotAssignedException);560 NotAssignedException notAssignedException = (NotAssignedException) e.getCause();561 assertEquals(ownerUrl, notAssignedException.forwardUrl());562 }563 PowerMock.verifyAll();564 }565 @Test566 public void testConnectorConfigAdded() {567 // If a connector was added, we need to rebalance568 EasyMock.expect(member.memberId()).andStubReturn("member");569 // join, no configs so no need to catch up on config topic570 expectRebalance(-1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());571 member.poll(EasyMock.anyInt());572 PowerMock.expectLastCall();573 // apply config574 member.wakeup();575 member.ensureActive();576 PowerMock.expectLastCall();577 // Checks for config updates and starts rebalance578 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT);579 member.requestRejoin();580 PowerMock.expectLastCall();581 // Performs rebalance and gets new assignment582 expectRebalance(Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList(),583 ConnectProtocol.Assignment.NO_ERROR, 1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());584 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),585 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));586 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);587 PowerMock.expectLastCall();588 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);589 member.poll(EasyMock.anyInt());590 PowerMock.expectLastCall();591 PowerMock.replayAll();592 herder.tick(); // join593 configUpdateListener.onConnectorConfigUpdate(CONN1); // read updated config594 herder.tick(); // apply config595 herder.tick(); // do rebalance596 PowerMock.verifyAll();597 }598 @Test599 public void testConnectorConfigUpdate() throws Exception {600 // Connector config can be applied without any rebalance601 EasyMock.expect(member.memberId()).andStubReturn("member");602 EasyMock.expect(worker.connectorNames()).andStubReturn(Collections.singleton(CONN1));603 // join604 expectRebalance(1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());605 expectPostRebalanceCatchup(SNAPSHOT);606 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),607 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));608 PowerMock.expectLastCall();609 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);610 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);611 member.poll(EasyMock.anyInt());612 PowerMock.expectLastCall();613 // apply config614 member.wakeup();615 member.ensureActive();616 PowerMock.expectLastCall();617 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT); // for this test, it doesn't matter if we use the same config snapshot618 worker.stopConnector(CONN1);619 PowerMock.expectLastCall();620 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),621 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));622 PowerMock.expectLastCall();623 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);624 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);625 member.poll(EasyMock.anyInt());626 PowerMock.expectLastCall();627 PowerMock.replayAll();628 herder.tick(); // join629 configUpdateListener.onConnectorConfigUpdate(CONN1); // read updated config630 herder.tick(); // apply config631 PowerMock.verifyAll();632 }633 @Test634 public void testConnectorPaused() throws Exception {635 // ensure that target state changes are propagated to the worker636 EasyMock.expect(member.memberId()).andStubReturn("member");637 EasyMock.expect(worker.connectorNames()).andStubReturn(Collections.singleton(CONN1));638 // join639 expectRebalance(1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());640 expectPostRebalanceCatchup(SNAPSHOT);641 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),642 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));643 PowerMock.expectLastCall();644 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);645 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);646 member.poll(EasyMock.anyInt());647 PowerMock.expectLastCall();648 // handle the state change649 member.wakeup();650 member.ensureActive();651 PowerMock.expectLastCall();652 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT_PAUSED_CONN1);653 PowerMock.expectLastCall();654 EasyMock.expect(worker.ownsConnector(CONN1)).andReturn(true);655 worker.setTargetState(CONN1, TargetState.PAUSED);656 PowerMock.expectLastCall();657 member.poll(EasyMock.anyInt());658 PowerMock.expectLastCall();659 PowerMock.replayAll();660 herder.tick(); // join661 configUpdateListener.onConnectorTargetStateChange(CONN1); // state changes to paused662 herder.tick(); // worker should apply the state change663 PowerMock.verifyAll();664 }665 @Test666 public void testConnectorResumed() throws Exception {667 EasyMock.expect(member.memberId()).andStubReturn("member");668 EasyMock.expect(worker.connectorNames()).andStubReturn(Collections.singleton(CONN1));669 // start with the connector paused670 expectRebalance(1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());671 expectPostRebalanceCatchup(SNAPSHOT_PAUSED_CONN1);672 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),673 EasyMock.eq(herder), EasyMock.eq(TargetState.PAUSED));674 PowerMock.expectLastCall();675 member.poll(EasyMock.anyInt());676 PowerMock.expectLastCall();677 // handle the state change678 member.wakeup();679 member.ensureActive();680 PowerMock.expectLastCall();681 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT);682 PowerMock.expectLastCall();683 // we expect reconfiguration after resuming684 EasyMock.expect(worker.ownsConnector(CONN1)).andReturn(true);685 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);686 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);687 worker.setTargetState(CONN1, TargetState.STARTED);688 PowerMock.expectLastCall();689 member.poll(EasyMock.anyInt());690 PowerMock.expectLastCall();691 PowerMock.replayAll();692 herder.tick(); // join693 configUpdateListener.onConnectorTargetStateChange(CONN1); // state changes to started694 herder.tick(); // apply state change695 PowerMock.verifyAll();696 }697 @Test698 public void testUnknownConnectorPaused() throws Exception {699 EasyMock.expect(member.memberId()).andStubReturn("member");700 EasyMock.expect(worker.connectorNames()).andStubReturn(Collections.singleton(CONN1));701 // join702 expectRebalance(1, Collections.<String>emptyList(), Collections.singletonList(TASK0));703 expectPostRebalanceCatchup(SNAPSHOT);704 worker.startTask(EasyMock.eq(TASK0), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));705 PowerMock.expectLastCall();706 member.poll(EasyMock.anyInt());707 PowerMock.expectLastCall();708 // state change is ignored since we have no target state709 member.wakeup();710 member.ensureActive();711 PowerMock.expectLastCall();712 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT);713 PowerMock.expectLastCall();714 member.poll(EasyMock.anyInt());715 PowerMock.expectLastCall();716 PowerMock.replayAll();717 herder.tick(); // join718 configUpdateListener.onConnectorTargetStateChange("unknown-connector");719 herder.tick(); // continue720 PowerMock.verifyAll();721 }722 @Test723 public void testConnectorPausedRunningTaskOnly() throws Exception {724 // even if we don't own the connector, we should still propagate target state725 // changes to the worker so that tasks will transition correctly726 EasyMock.expect(member.memberId()).andStubReturn("member");727 EasyMock.expect(worker.connectorNames()).andStubReturn(Collections.<String>emptySet());728 // join729 expectRebalance(1, Collections.<String>emptyList(), Collections.singletonList(TASK0));730 expectPostRebalanceCatchup(SNAPSHOT);731 worker.startTask(EasyMock.eq(TASK0), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));732 PowerMock.expectLastCall();733 member.poll(EasyMock.anyInt());734 PowerMock.expectLastCall();735 // handle the state change736 member.wakeup();737 member.ensureActive();738 PowerMock.expectLastCall();739 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT_PAUSED_CONN1);740 PowerMock.expectLastCall();741 EasyMock.expect(worker.ownsConnector(CONN1)).andReturn(false);742 worker.setTargetState(CONN1, TargetState.PAUSED);743 PowerMock.expectLastCall();744 member.poll(EasyMock.anyInt());745 PowerMock.expectLastCall();746 PowerMock.replayAll();747 herder.tick(); // join748 configUpdateListener.onConnectorTargetStateChange(CONN1); // state changes to paused749 herder.tick(); // apply state change750 PowerMock.verifyAll();751 }752 @Test753 public void testConnectorResumedRunningTaskOnly() throws Exception {754 // even if we don't own the connector, we should still propagate target state755 // changes to the worker so that tasks will transition correctly756 EasyMock.expect(member.memberId()).andStubReturn("member");757 EasyMock.expect(worker.connectorNames()).andStubReturn(Collections.<String>emptySet());758 // join759 expectRebalance(1, Collections.<String>emptyList(), Collections.singletonList(TASK0));760 expectPostRebalanceCatchup(SNAPSHOT_PAUSED_CONN1);761 worker.startTask(EasyMock.eq(TASK0), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.PAUSED));762 PowerMock.expectLastCall();763 member.poll(EasyMock.anyInt());764 PowerMock.expectLastCall();765 // handle the state change766 member.wakeup();767 member.ensureActive();768 PowerMock.expectLastCall();769 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT);770 PowerMock.expectLastCall();771 EasyMock.expect(worker.ownsConnector(CONN1)).andReturn(false);772 worker.setTargetState(CONN1, TargetState.STARTED);773 PowerMock.expectLastCall();774 member.poll(EasyMock.anyInt());775 PowerMock.expectLastCall();776 PowerMock.replayAll();777 herder.tick(); // join778 configUpdateListener.onConnectorTargetStateChange(CONN1); // state changes to paused779 herder.tick(); // apply state change780 PowerMock.verifyAll();781 }782 @Test783 public void testTaskConfigAdded() {784 // Task config always requires rebalance785 EasyMock.expect(member.memberId()).andStubReturn("member");786 // join787 expectRebalance(-1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());788 member.poll(EasyMock.anyInt());789 PowerMock.expectLastCall();790 // apply config791 member.wakeup();792 member.ensureActive();793 PowerMock.expectLastCall();794 // Checks for config updates and starts rebalance795 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT);796 member.requestRejoin();797 PowerMock.expectLastCall();798 // Performs rebalance and gets new assignment799 expectRebalance(Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList(),800 ConnectProtocol.Assignment.NO_ERROR, 1, Collections.<String>emptyList(),801 Arrays.asList(TASK0));802 worker.startTask(EasyMock.eq(TASK0), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));803 PowerMock.expectLastCall();804 member.poll(EasyMock.anyInt());805 PowerMock.expectLastCall();806 PowerMock.replayAll();807 herder.tick(); // join808 configUpdateListener.onTaskConfigUpdate(Arrays.asList(TASK0, TASK1, TASK2)); // read updated config809 herder.tick(); // apply config810 herder.tick(); // do rebalance811 PowerMock.verifyAll();812 }813 @Test814 public void testJoinLeaderCatchUpFails() throws Exception {815 // Join group and as leader fail to do assignment816 EasyMock.expect(member.memberId()).andStubReturn("leader");817 expectRebalance(Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList(),818 ConnectProtocol.Assignment.CONFIG_MISMATCH, 1, Collections.<String>emptyList(),819 Collections.<ConnectorTaskId>emptyList());820 // Reading to end of log times out821 configStorage.refresh(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));822 EasyMock.expectLastCall().andThrow(new TimeoutException());823 member.maybeLeaveGroup();824 EasyMock.expectLastCall();825 PowerMock.expectPrivate(herder, "backoff", DistributedConfig.WORKER_UNSYNC_BACKOFF_MS_DEFAULT);826 member.requestRejoin();827 // After backoff, restart the process and this time succeed828 expectRebalance(1, Arrays.asList(CONN1), Arrays.asList(TASK1));829 expectPostRebalanceCatchup(SNAPSHOT);830 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),831 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));832 PowerMock.expectLastCall();833 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);834 worker.startTask(EasyMock.eq(TASK1), EasyMock.<TaskConfig>anyObject(), EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));835 PowerMock.expectLastCall();836 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);837 member.poll(EasyMock.anyInt());838 PowerMock.expectLastCall();839 PowerMock.replayAll();840 herder.tick();841 herder.tick();842 PowerMock.verifyAll();843 }844 @Test845 public void testAccessors() throws Exception {846 EasyMock.expect(member.memberId()).andStubReturn("leader");847 expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());848 expectPostRebalanceCatchup(SNAPSHOT);849 member.wakeup();850 PowerMock.expectLastCall().anyTimes();851 // list connectors, get connector info, get connector config, get task configs852 member.poll(EasyMock.anyInt());853 PowerMock.expectLastCall();854 PowerMock.replayAll();855 FutureCallback<Collection<String>> listConnectorsCb = new FutureCallback<>();856 herder.connectors(listConnectorsCb);857 FutureCallback<ConnectorInfo> connectorInfoCb = new FutureCallback<>();858 herder.connectorInfo(CONN1, connectorInfoCb);859 FutureCallback<Map<String, String>> connectorConfigCb = new FutureCallback<>();860 herder.connectorConfig(CONN1, connectorConfigCb);861 FutureCallback<List<TaskInfo>> taskConfigsCb = new FutureCallback<>();862 herder.taskConfigs(CONN1, taskConfigsCb);863 herder.tick();864 assertTrue(listConnectorsCb.isDone());865 assertEquals(Collections.singleton(CONN1), listConnectorsCb.get());866 assertTrue(connectorInfoCb.isDone());867 ConnectorInfo info = new ConnectorInfo(CONN1, CONN1_CONFIG, Arrays.asList(TASK0, TASK1, TASK2));868 assertEquals(info, connectorInfoCb.get());869 assertTrue(connectorConfigCb.isDone());870 assertEquals(CONN1_CONFIG, connectorConfigCb.get());871 assertTrue(taskConfigsCb.isDone());872 assertEquals(Arrays.asList(873 new TaskInfo(TASK0, TASK_CONFIG),874 new TaskInfo(TASK1, TASK_CONFIG),875 new TaskInfo(TASK2, TASK_CONFIG)),876 taskConfigsCb.get());877 PowerMock.verifyAll();878 }879 @Test880 public void testPutConnectorConfig() throws Exception {881 EasyMock.expect(member.memberId()).andStubReturn("leader");882 expectRebalance(1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());883 expectPostRebalanceCatchup(SNAPSHOT);884 worker.startConnector(EasyMock.<ConnectorConfig>anyObject(), EasyMock.<ConnectorContext>anyObject(),885 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));886 PowerMock.expectLastCall();887 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);888 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);889 // list connectors, get connector info, get connector config, get task configs890 member.wakeup();891 PowerMock.expectLastCall().anyTimes();892 member.poll(EasyMock.anyInt());893 PowerMock.expectLastCall();894 // Poll loop for second round of calls895 member.ensureActive();896 PowerMock.expectLastCall();897 configStorage.putConnectorConfig(CONN1, CONN1_CONFIG_UPDATED);898 PowerMock.expectLastCall().andAnswer(new IAnswer<Object>() {899 @Override900 public Object answer() throws Throwable {901 // Simulate response to writing config + waiting until end of log to be read902 configUpdateListener.onConnectorConfigUpdate(CONN1);903 return null;904 }905 });906 // As a result of reconfig, should need to update snapshot. With only connector updates, we'll just restart907 // connector without rebalance908 EasyMock.expect(configStorage.snapshot()).andReturn(SNAPSHOT_UPDATED_CONN1_CONFIG);909 worker.stopConnector(CONN1);910 PowerMock.expectLastCall();911 Capture<ConnectorConfig> capturedUpdatedConfig = EasyMock.newCapture();912 worker.startConnector(EasyMock.capture(capturedUpdatedConfig), EasyMock.<ConnectorContext>anyObject(),913 EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));914 PowerMock.expectLastCall();915 EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);916 EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);917 member.poll(EasyMock.anyInt());918 PowerMock.expectLastCall();919 // Third tick just to read the config920 member.ensureActive();921 PowerMock.expectLastCall();922 member.poll(EasyMock.anyInt());923 PowerMock.expectLastCall();924 PowerMock.replayAll();925 // Should pick up original config926 FutureCallback<Map<String, String>> connectorConfigCb = new FutureCallback<>();927 herder.connectorConfig(CONN1, connectorConfigCb);928 herder.tick();929 assertTrue(connectorConfigCb.isDone());930 assertEquals(CONN1_CONFIG, connectorConfigCb.get());931 // Apply new config.932 FutureCallback<Herder.Created<ConnectorInfo>> putConfigCb = new FutureCallback<>();933 herder.putConnectorConfig(CONN1, CONN1_CONFIG_UPDATED, true, putConfigCb);934 herder.tick();935 assertTrue(putConfigCb.isDone());936 ConnectorInfo updatedInfo = new ConnectorInfo(CONN1, CONN1_CONFIG_UPDATED, Arrays.asList(TASK0, TASK1, TASK2));...

Full Screen

Full Screen

Source:SearchTaskTests.java Github

copy

Full Screen

...40 public void testDocumentFitsInViewport() {41 SearchTask task = new SearchTask(document, createMockViewport(document, 12), scheduler);42 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);43 expect(44 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))45 .andReturn(true).times(12);46 replay(executor);47 task.searchDocument(executor, null);48 verify(executor);49 }50 public void testSchedulerRunsThroughDocument() {51 SearchTask task = new SearchTask(document, createMockViewport(document, 5), scheduler);52 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);53 expect(54 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))55 .andReturn(true).times(5);56 expect(executor.onSearchLine(57 EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(false)))58 .andReturn(true).times(7);59 replay(executor);60 task.searchDocument(executor, null);61 verify(executor);62 }63 public void testDirectionDownWorks() {64 ViewportModel viewport = createMockViewport(document, 5);65 SearchTask task = new SearchTask(document, viewport, scheduler);66 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);67 expect(executor.onSearchLine(viewport.getTopLine(), 0, true)).andReturn(true);68 expect(69 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))70 .andReturn(true).times(3);71 expect(executor.onSearchLine(viewport.getBottomLine(), 4, true)).andReturn(true);72 expect(executor.onSearchLine(73 EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(false)))74 .andReturn(true).times(7);75 replay(executor);76 task.searchDocument(executor, null, SearchDirection.DOWN);77 verify(executor);78 }79 public void testDirectionUpWorks() {80 ViewportModel viewport = createMockViewport(document, 5);81 SearchTask task = new SearchTask(document, viewport, scheduler);82 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);83 expect(executor.onSearchLine(viewport.getBottomLine(), 4, true)).andReturn(true);84 expect(85 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))86 .andReturn(true).times(3);87 expect(executor.onSearchLine(viewport.getTopLine(), 0, true)).andReturn(true);88 expect(executor.onSearchLine(document.getLastLine(), 11, false)).andReturn(true);89 expect(executor.onSearchLine(90 EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(false)))91 .andReturn(true).times(6);92 replay(executor);93 task.searchDocument(executor, null, SearchDirection.UP);94 verify(executor);95 }96 public void testStartingAtLineWorks() {97 ViewportModel viewport = createMockViewport(document, 5);98 SearchTask task = new SearchTask(document, viewport, scheduler);99 LineInfo lineInfo = viewport.getTopLineInfo();100 lineInfo.moveToNext();101 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);102 expect(executor.onSearchLine(lineInfo.line(), 1, true)).andReturn(true);103 expect(104 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))105 .andReturn(true).times(2);106 expect(executor.onSearchLine(viewport.getBottomLine(), 4, true)).andReturn(true);107 expect(executor.onSearchLine(108 EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(false)))109 .andReturn(true).times(7);110 expect(executor.onSearchLine(viewport.getTopLine(), 0, false)).andReturn(true);111 replay(executor);112 task.searchDocumentStartingAtLine(executor, null, SearchDirection.DOWN, lineInfo);113 verify(executor);114 }115 public void testNoWrapWorks() {116 ViewportModel viewport = createMockViewport(document, 5);117 SearchTask task = new SearchTask(document, viewport, scheduler);118 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);119 expect(executor.onSearchLine(viewport.getBottomLine(), 4, true)).andReturn(true);120 expect(121 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))122 .andReturn(true).times(3);123 expect(executor.onSearchLine(viewport.getTopLine(), 0, true)).andReturn(true);124 replay(executor);125 task.setShouldWrapDocument(false);126 task.searchDocument(executor, null, SearchDirection.UP);127 verify(executor);128 }129 public void testHaltViewportSearch() {130 ViewportModel viewport = createMockViewport(document, 5);131 SearchTask task = new SearchTask(document, viewport, scheduler);132 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);133 expect(executor.onSearchLine(viewport.getTopLine(), 0, true)).andReturn(true);134 expect(135 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))136 .andReturn(true).times(3);137 expect(executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.eq(4), EasyMock.eq(true)))138 .andReturn(false);139 replay(executor);140 task.searchDocument(executor, null);141 verify(executor);142 }143 public void testHaltSchedulerSearch() {144 ViewportModel viewport = createMockViewport(document, 5);145 SearchTask task = new SearchTask(document, viewport, scheduler);146 SearchTaskExecutor executor = EasyMock.createMock(SearchTaskExecutor.class);147 expect(148 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.anyInt(), EasyMock.eq(true)))149 .andReturn(true).times(5);150 expect(151 executor.onSearchLine(EasyMock.anyObject(Line.class), EasyMock.eq(5), EasyMock.eq(false)))152 .andReturn(false);153 replay(executor);154 task.searchDocument(executor, null);155 verify(executor);156 }157}...

Full Screen

Full Screen

anyInt

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.EasyMockSupport;3public class 1 extends EasyMockSupport {4 public static void main(String[] args) {5 1 test = new 1();6 test.testAnyInt();7 }8 public void testAnyInt() {9 List mock = createMock(List.class);10 mock.add(anyInt());11 expectLastCall().times(2);12 replayAll();13 mock.add(1);14 mock.add(2);15 verifyAll();16 }17}18org.easymock.AssertionError: Expected 2, actual 0: Unexpected method call List.add(1):19 List.add(1);20 at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:53)21 at com.sun.proxy.$Proxy0.add(Unknown Source)22 at 1.testAnyInt(1.java:25)23 at 1.main(1.java:12)

Full Screen

Full Screen

anyInt

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.IArgumentMatcher;3import org.junit.Test;4import static org.easymock.EasyMock.*;5import static org.junit.Assert.*;6public class AnyIntTest {7public void testAnyInt() {8List mock = createMock(List.class);9expect(mock.get(anyInt())).andReturn("Hello");10replay(mock);11assertEquals("Hello", mock.get(1));12assertEquals("Hello", mock.get(2));13assertEquals("Hello", mock.get(3));14verify(mock);15}16}

Full Screen

Full Screen

anyInt

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.EasyMockSupport;3import org.junit.Test;4public class anyIntTest extends EasyMockSupport {5 public void test() {6 TestClass testClass = createMock(TestClass.class);7 expect(testClass.testMethod(anyInt())).andReturn(1);8 replayAll();9 testClass.testMethod(10);10 verifyAll();11 }12}13public class TestClass {14 public int testMethod(int i) {15 return 0;16 }17}18Related posts: EasyMock – anyLong() method EasyMock – anyObject() method EasyMock – anyString() method EasyMock – anyBoolean() method EasyMock – anyObject(Class) method EasyMock – anyDouble() method EasyMock – anyFloat() method EasyMock – anyByte() method EasyMock – anyShort() method EasyMock – anyChar() method EasyMock – anyObject(Class[]) metho

Full Screen

Full Screen

anyInt

Using AI Code Generation

copy

Full Screen

1package org.easymock;2import java.util.List;3import org.junit.Test;4import static org.easymock.EasyMock.*;5public class EasyMockTest {6 public void test() {7 List mockedList = createMock(List.class);8 mockedList.add(anyInt());9 replay(mockedList);10 mockedList.add(1);11 verify(mockedList);12 }13}14org.easymock.EasyMockTest > test() PASSED

Full Screen

Full Screen

anyInt

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.IAnswer;3import org.junit.Test;4public class TestAnyIntMethod {5public void testAnyIntMethod() {6Calculator calc = EasyMock.createMock(Calculator.class);7EasyMock.expect(calc.add(EasyMock.anyInt(), EasyMock.anyInt())).andAnswer(new IAnswer<Integer>() {8public Integer answer() throws Throwable {9Integer firstArg = (Integer) EasyMock.getCurrentArguments()[0];10Integer secondArg = (Integer) EasyMock.getCurrentArguments()[1];11return firstArg + secondArg;12}13});14EasyMock.replay(calc);15System.out.println(calc.add(1, 2));16System.out.println(calc.add(3, 4));17EasyMock.verify(calc);18}19}

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