How to use Capture method of org.easymock.Capture class

Best Easymock code snippet using org.easymock.Capture.Capture

Source:ConnectorsResourceTest.java Github

copy

Full Screen

...28import org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest;29import org.apache.kafka.connect.runtime.rest.entities.TaskInfo;30import org.apache.kafka.connect.util.Callback;31import org.apache.kafka.connect.util.ConnectorTaskId;32import org.easymock.Capture;33import org.easymock.EasyMock;34import org.easymock.IAnswer;35import org.junit.Before;36import org.junit.Test;37import org.junit.runner.RunWith;38import org.powermock.api.easymock.PowerMock;39import org.powermock.api.easymock.annotation.Mock;40import org.powermock.core.classloader.annotations.PowerMockIgnore;41import org.powermock.core.classloader.annotations.PrepareForTest;42import org.powermock.modules.junit4.PowerMockRunner;43import javax.ws.rs.BadRequestException;44import java.util.ArrayList;45import java.util.Arrays;46import java.util.Collection;47import java.util.Collections;48import java.util.HashMap;49import java.util.HashSet;50import java.util.List;51import java.util.Map;52import static org.junit.Assert.assertEquals;53@RunWith(PowerMockRunner.class)54@PrepareForTest(RestServer.class)55@PowerMockIgnore("javax.management.*")56@SuppressWarnings("unchecked")57public class ConnectorsResourceTest {58 // Note trailing / and that we do *not* use LEADER_URL to construct our reference values. This checks that we handle59 // URL construction properly, avoiding //, which will mess up routing in the REST server60 private static final String LEADER_URL = "http://leader:8083/";61 private static final String CONNECTOR_NAME = "test";62 private static final String CONNECTOR2_NAME = "test2";63 private static final Boolean FORWARD = true;64 private static final Map<String, String> CONNECTOR_CONFIG = new HashMap<>();65 static {66 CONNECTOR_CONFIG.put("name", CONNECTOR_NAME);67 CONNECTOR_CONFIG.put("sample_config", "test_config");68 }69 private static final List<ConnectorTaskId> CONNECTOR_TASK_NAMES = Arrays.asList(70 new ConnectorTaskId(CONNECTOR_NAME, 0),71 new ConnectorTaskId(CONNECTOR_NAME, 1)72 );73 private static final List<Map<String, String>> TASK_CONFIGS = new ArrayList<>();74 static {75 TASK_CONFIGS.add(Collections.singletonMap("config", "value"));76 TASK_CONFIGS.add(Collections.singletonMap("config", "other_value"));77 }78 private static final List<TaskInfo> TASK_INFOS = new ArrayList<>();79 static {80 TASK_INFOS.add(new TaskInfo(new ConnectorTaskId(CONNECTOR_NAME, 0), TASK_CONFIGS.get(0)));81 TASK_INFOS.add(new TaskInfo(new ConnectorTaskId(CONNECTOR_NAME, 1), TASK_CONFIGS.get(1)));82 }83 @Mock84 private Herder herder;85 private ConnectorsResource connectorsResource;86 @Before87 public void setUp() throws NoSuchMethodException {88 PowerMock.mockStatic(RestServer.class,89 RestServer.class.getMethod("httpRequest", String.class, String.class, Object.class, TypeReference.class));90 connectorsResource = new ConnectorsResource(herder);91 }92 @Test93 public void testListConnectors() throws Throwable {94 final Capture<Callback<Collection<String>>> cb = Capture.newInstance();95 herder.connectors(EasyMock.capture(cb));96 expectAndCallbackResult(cb, Arrays.asList(CONNECTOR2_NAME, CONNECTOR_NAME));97 PowerMock.replayAll();98 Collection<String> connectors = connectorsResource.listConnectors(FORWARD);99 // Ordering isn't guaranteed, compare sets100 assertEquals(new HashSet<>(Arrays.asList(CONNECTOR_NAME, CONNECTOR2_NAME)), new HashSet<>(connectors));101 PowerMock.verifyAll();102 }103 @Test104 public void testListConnectorsNotLeader() throws Throwable {105 final Capture<Callback<Collection<String>>> cb = Capture.newInstance();106 herder.connectors(EasyMock.capture(cb));107 expectAndCallbackNotLeaderException(cb);108 // Should forward request109 EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors?forward=false"), EasyMock.eq("GET"),110 EasyMock.isNull(), EasyMock.anyObject(TypeReference.class)))111 .andReturn(new RestServer.HttpResponse<>(200, new HashMap<String, List<String>>(), Arrays.asList(CONNECTOR2_NAME, CONNECTOR_NAME)));112 PowerMock.replayAll();113 Collection<String> connectors = connectorsResource.listConnectors(FORWARD);114 // Ordering isn't guaranteed, compare sets115 assertEquals(new HashSet<>(Arrays.asList(CONNECTOR_NAME, CONNECTOR2_NAME)), new HashSet<>(connectors));116 PowerMock.verifyAll();117 }118 @Test(expected = ConnectException.class)119 public void testListConnectorsNotSynced() throws Throwable {120 final Capture<Callback<Collection<String>>> cb = Capture.newInstance();121 herder.connectors(EasyMock.capture(cb));122 expectAndCallbackException(cb, new ConnectException("not synced"));123 PowerMock.replayAll();124 // throws125 connectorsResource.listConnectors(FORWARD);126 }127 @Test128 public void testCreateConnector() throws Throwable {129 CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));130 final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();131 herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));132 expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));133 PowerMock.replayAll();134 connectorsResource.createConnector(FORWARD, body);135 PowerMock.verifyAll();136 }137 @Test138 public void testCreateConnectorNotLeader() throws Throwable {139 CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));140 final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();141 herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));142 expectAndCallbackNotLeaderException(cb);143 // Should forward request144 EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors?forward=false"), EasyMock.eq("POST"), EasyMock.eq(body), EasyMock.<TypeReference>anyObject()))145 .andReturn(new RestServer.HttpResponse<>(201, new HashMap<String, List<String>>(), new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));146 PowerMock.replayAll();147 connectorsResource.createConnector(FORWARD, body);148 PowerMock.verifyAll();149 }150 @Test(expected = AlreadyExistsException.class)151 public void testCreateConnectorExists() throws Throwable {152 CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));153 final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();154 herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));155 expectAndCallbackException(cb, new AlreadyExistsException("already exists"));156 PowerMock.replayAll();157 connectorsResource.createConnector(FORWARD, body);158 PowerMock.verifyAll();159 }160 @Test161 public void testDeleteConnector() throws Throwable {162 final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();163 herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.<Map<String, String>>isNull(), EasyMock.eq(true), EasyMock.capture(cb));164 expectAndCallbackResult(cb, null);165 PowerMock.replayAll();166 connectorsResource.destroyConnector(CONNECTOR_NAME, FORWARD);167 PowerMock.verifyAll();168 }169 @Test170 public void testDeleteConnectorNotLeader() throws Throwable {171 final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();172 herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.<Map<String, String>>isNull(), EasyMock.eq(true), EasyMock.capture(cb));173 expectAndCallbackNotLeaderException(cb);174 // Should forward request175 EasyMock.expect(RestServer.httpRequest("http://leader:8083/connectors/" + CONNECTOR_NAME + "?forward=false", "DELETE", null, null))176 .andReturn(new RestServer.HttpResponse<>(204, new HashMap<String, List<String>>(), null));177 PowerMock.replayAll();178 connectorsResource.destroyConnector(CONNECTOR_NAME, FORWARD);179 PowerMock.verifyAll();180 }181 // Not found exceptions should pass through to caller so they can be processed for 404s182 @Test(expected = NotFoundException.class)183 public void testDeleteConnectorNotFound() throws Throwable {184 final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();185 herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.<Map<String, String>>isNull(), EasyMock.eq(true), EasyMock.capture(cb));186 expectAndCallbackException(cb, new NotFoundException("not found"));187 PowerMock.replayAll();188 connectorsResource.destroyConnector(CONNECTOR_NAME, FORWARD);189 PowerMock.verifyAll();190 }191 @Test192 public void testGetConnector() throws Throwable {193 final Capture<Callback<ConnectorInfo>> cb = Capture.newInstance();194 herder.connectorInfo(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));195 expectAndCallbackResult(cb, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES));196 PowerMock.replayAll();197 ConnectorInfo connInfo = connectorsResource.getConnector(CONNECTOR_NAME, FORWARD);198 assertEquals(new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES), connInfo);199 PowerMock.verifyAll();200 }201 @Test202 public void testGetConnectorConfig() throws Throwable {203 final Capture<Callback<Map<String, String>>> cb = Capture.newInstance();204 herder.connectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));205 expectAndCallbackResult(cb, CONNECTOR_CONFIG);206 PowerMock.replayAll();207 Map<String, String> connConfig = connectorsResource.getConnectorConfig(CONNECTOR_NAME, FORWARD);208 assertEquals(CONNECTOR_CONFIG, connConfig);209 PowerMock.verifyAll();210 }211 @Test(expected = NotFoundException.class)212 public void testGetConnectorConfigConnectorNotFound() throws Throwable {213 final Capture<Callback<Map<String, String>>> cb = Capture.newInstance();214 herder.connectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));215 expectAndCallbackException(cb, new NotFoundException("not found"));216 PowerMock.replayAll();217 connectorsResource.getConnectorConfig(CONNECTOR_NAME, FORWARD);218 PowerMock.verifyAll();219 }220 @Test221 public void testPutConnectorConfig() throws Throwable {222 final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();223 herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(CONNECTOR_CONFIG), EasyMock.eq(true), EasyMock.capture(cb));224 expectAndCallbackResult(cb, new Herder.Created<>(false, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));225 PowerMock.replayAll();226 connectorsResource.putConnectorConfig(CONNECTOR_NAME, FORWARD, CONNECTOR_CONFIG);227 PowerMock.verifyAll();228 }229 @Test(expected = BadRequestException.class)230 public void testPutConnectorConfigNameMismatch() throws Throwable {231 Map<String, String> connConfig = new HashMap<>(CONNECTOR_CONFIG);232 connConfig.put(ConnectorConfig.NAME_CONFIG, "mismatched-name");233 connectorsResource.putConnectorConfig(CONNECTOR_NAME, FORWARD, connConfig);234 }235 @Test236 public void testGetConnectorTaskConfigs() throws Throwable {237 final Capture<Callback<List<TaskInfo>>> cb = Capture.newInstance();238 herder.taskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));239 expectAndCallbackResult(cb, TASK_INFOS);240 PowerMock.replayAll();241 List<TaskInfo> taskInfos = connectorsResource.getTaskConfigs(CONNECTOR_NAME, FORWARD);242 assertEquals(TASK_INFOS, taskInfos);243 PowerMock.verifyAll();244 }245 @Test(expected = NotFoundException.class)246 public void testGetConnectorTaskConfigsConnectorNotFound() throws Throwable {247 final Capture<Callback<List<TaskInfo>>> cb = Capture.newInstance();248 herder.taskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));249 expectAndCallbackException(cb, new NotFoundException("connector not found"));250 PowerMock.replayAll();251 connectorsResource.getTaskConfigs(CONNECTOR_NAME, FORWARD);252 PowerMock.verifyAll();253 }254 @Test255 public void testPutConnectorTaskConfigs() throws Throwable {256 final Capture<Callback<Void>> cb = Capture.newInstance();257 herder.putTaskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(TASK_CONFIGS), EasyMock.capture(cb));258 expectAndCallbackResult(cb, null);259 PowerMock.replayAll();260 connectorsResource.putTaskConfigs(CONNECTOR_NAME, FORWARD, TASK_CONFIGS);261 PowerMock.verifyAll();262 }263 @Test(expected = NotFoundException.class)264 public void testPutConnectorTaskConfigsConnectorNotFound() throws Throwable {265 final Capture<Callback<Void>> cb = Capture.newInstance();266 herder.putTaskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(TASK_CONFIGS), EasyMock.capture(cb));267 expectAndCallbackException(cb, new NotFoundException("not found"));268 PowerMock.replayAll();269 connectorsResource.putTaskConfigs(CONNECTOR_NAME, FORWARD, TASK_CONFIGS);270 PowerMock.verifyAll();271 }272 @Test(expected = NotFoundException.class)273 public void testRestartConnectorNotFound() throws Throwable {274 final Capture<Callback<Void>> cb = Capture.newInstance();275 herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));276 expectAndCallbackException(cb, new NotFoundException("not found"));277 PowerMock.replayAll();278 connectorsResource.restartConnector(CONNECTOR_NAME, FORWARD);279 PowerMock.verifyAll();280 }281 @Test282 public void testRestartConnectorLeaderRedirect() throws Throwable {283 final Capture<Callback<Void>> cb = Capture.newInstance();284 herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));285 expectAndCallbackNotLeaderException(cb);286 EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors/" + CONNECTOR_NAME + "/restart?forward=true"),287 EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))288 .andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));289 PowerMock.replayAll();290 connectorsResource.restartConnector(CONNECTOR_NAME, null);291 PowerMock.verifyAll();292 }293 @Test294 public void testRestartConnectorOwnerRedirect() throws Throwable {295 final Capture<Callback<Void>> cb = Capture.newInstance();296 herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));297 String ownerUrl = "http://owner:8083";298 expectAndCallbackException(cb, new NotAssignedException("not owner test", ownerUrl));299 EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://owner:8083/connectors/" + CONNECTOR_NAME + "/restart?forward=false"),300 EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))301 .andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));302 PowerMock.replayAll();303 connectorsResource.restartConnector(CONNECTOR_NAME, true);304 PowerMock.verifyAll();305 }306 @Test(expected = NotFoundException.class)307 public void testRestartTaskNotFound() throws Throwable {308 ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);309 final Capture<Callback<Void>> cb = Capture.newInstance();310 herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));311 expectAndCallbackException(cb, new NotFoundException("not found"));312 PowerMock.replayAll();313 connectorsResource.restartTask(CONNECTOR_NAME, 0, FORWARD);314 PowerMock.verifyAll();315 }316 @Test317 public void testRestartTaskLeaderRedirect() throws Throwable {318 ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);319 final Capture<Callback<Void>> cb = Capture.newInstance();320 herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));321 expectAndCallbackNotLeaderException(cb);322 EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=true"),323 EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))324 .andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));325 PowerMock.replayAll();326 connectorsResource.restartTask(CONNECTOR_NAME, 0, null);327 PowerMock.verifyAll();328 }329 @Test330 public void testRestartTaskOwnerRedirect() throws Throwable {331 ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);332 final Capture<Callback<Void>> cb = Capture.newInstance();333 herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));334 String ownerUrl = "http://owner:8083";335 expectAndCallbackException(cb, new NotAssignedException("not owner test", ownerUrl));336 EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://owner:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=false"),337 EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))338 .andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));339 PowerMock.replayAll();340 connectorsResource.restartTask(CONNECTOR_NAME, 0, true);341 PowerMock.verifyAll();342 }343 private <T> void expectAndCallbackResult(final Capture<Callback<T>> cb, final T value) {344 PowerMock.expectLastCall().andAnswer(new IAnswer<Void>() {345 @Override346 public Void answer() throws Throwable {347 cb.getValue().onCompletion(null, value);348 return null;349 }350 });351 }352 private <T> void expectAndCallbackException(final Capture<Callback<T>> cb, final Throwable t) {353 PowerMock.expectLastCall().andAnswer(new IAnswer<Void>() {354 @Override355 public Void answer() throws Throwable {356 cb.getValue().onCompletion(t, null);357 return null;358 }359 });360 }361 private <T> void expectAndCallbackNotLeaderException(final Capture<Callback<T>> cb) {362 expectAndCallbackException(cb, new NotLeaderException("not leader test", LEADER_URL));363 }364}...

Full Screen

Full Screen

Source:WorkerImplTest.java Github

copy

Full Screen

...4import io.reactivex.rxjava3.disposables.Disposable;5import java.util.List;6import java.util.concurrent.Executor;7import java.util.concurrent.TimeUnit;8import org.easymock.Capture;9import org.easymock.CaptureType;10import org.easymock.EasyMock;11import static org.junit.Assert.assertEquals;12import static org.junit.Assert.assertSame;13import org.junit.Before;14import org.junit.Test;15import org.krybrig.exclutor.ExclusiveRunnable;1617/**18 *19 * @author kassle20 */21public class WorkerImplTest {22 private String scope = "worker.scope";23 private boolean exclusive = false;24 private Scheduler.Worker delayWorker;25 private Executor executor;26 27 private WorkerImpl worker;28 29 @Before30 public void setUp() {31 delayWorker = EasyMock.createMock(Scheduler.Worker.class);32 executor = EasyMock.createMock(Executor.class);33 34 worker = new WorkerImpl(delayWorker, executor, exclusive, scope);35 }36 37 @Test38 public void scheduleDriectShouldDelegateToDelayWorkerWithZeroDelay() {39 Runnable run = EasyMock.createMock(Runnable.class);40 Disposable disposable = EasyMock.createMock(Disposable.class);41 42 EasyMock.expect(delayWorker.schedule(43 EasyMock.anyObject(Runnable.class),44 EasyMock.eq(0L), EasyMock.same(TimeUnit.MILLISECONDS)))45 .andReturn(disposable);46 EasyMock.replay(delayWorker);47 48 Disposable result = worker.schedule(run);49 50 assertSame(disposable, result);51 EasyMock.verify(delayWorker);52 }53 54 @Test55 public void scheduleShouldDelegateToDelayWorker() {56 long delay = 5L;57 TimeUnit unit = TimeUnit.DAYS;58 Runnable run = EasyMock.createMock(Runnable.class);59 Disposable disposable = EasyMock.createMock(Disposable.class);60 61 EasyMock.expect(delayWorker.schedule(62 EasyMock.anyObject(Runnable.class),63 EasyMock.eq(delay), EasyMock.same(unit)))64 .andReturn(disposable);65 EasyMock.replay(delayWorker);66 67 Disposable result = worker.schedule(run, delay, unit);68 69 assertSame(disposable, result);70 EasyMock.verify(delayWorker);71 }72 73 @Test74 public void schedulePeriodicallyShouldDelegateToDelayWorker() {75 long delay = 5L;76 long period = 1L;77 TimeUnit unit = TimeUnit.DAYS;78 Runnable run = EasyMock.createMock(Runnable.class);79 Disposable disposable = EasyMock.createMock(Disposable.class);80 81 EasyMock.expect(delayWorker.schedulePeriodically(82 EasyMock.anyObject(Runnable.class),83 EasyMock.eq(delay), EasyMock.eq(period), EasyMock.same(unit)))84 .andReturn(disposable);85 EasyMock.replay(delayWorker);86 87 Disposable result = worker.schedulePeriodically(run, delay, period, unit);88 89 assertSame(disposable, result);90 EasyMock.verify(delayWorker);91 }9293 @Test94 public void onTaskExecuteViaScheduleShouldExecuteUsingExecutor() {95 long delay = 5L;96 TimeUnit unit = TimeUnit.DAYS;97 Runnable run = EasyMock.createMock(Runnable.class);98 Disposable disposable = EasyMock.createMock(Disposable.class);99 Capture<Runnable> subRunCapture = EasyMock.newCapture(CaptureType.ALL);100 101 EasyMock.expect(delayWorker.schedule(EasyMock.capture(subRunCapture),102 EasyMock.eq(delay), EasyMock.same(unit)))103 .andReturn(disposable);104 EasyMock.replay(delayWorker);105 106 worker.schedule(run, delay, unit);107 List<Runnable> subRunList = subRunCapture.getValues();108 109 assertEquals(1, subRunList.size());110 Runnable subRun = subRunList.get(0);111 112 Capture<ExclusiveRunnable> exRunCapture = EasyMock.newCapture(CaptureType.ALL);113 executor.execute(EasyMock.capture(exRunCapture));114 EasyMock.replay(executor);115 116 subRun.run();117118 List<ExclusiveRunnable> exRunList = exRunCapture.getValues();119 assertEquals(1, exRunList.size());120 121 ExclusiveRunnable exRun = exRunList.get(0);122 assertEquals(scope, exRun.getScope());123 assertEquals(exclusive, exRun.isExclusive());124 125 run.run();126 EasyMock.replay(run);127 128 exRun.run();129 130 EasyMock.verify(run);131 }132 133 @Test134 public void onTaskExecuteViaSchedulePeriodicallyShouldExecuteUsingExecutor() {135 long delay = 5L;136 TimeUnit unit = TimeUnit.DAYS;137 Runnable run = EasyMock.createMock(Runnable.class);138 Disposable disposable = EasyMock.createMock(Disposable.class);139 Capture<Runnable> subRunCapture = EasyMock.newCapture(CaptureType.ALL);140 141 EasyMock.expect(delayWorker.schedulePeriodically(EasyMock.capture(subRunCapture),142 EasyMock.eq(delay), EasyMock.eq(delay), EasyMock.same(unit)))143 .andReturn(disposable);144 EasyMock.replay(delayWorker);145 146 worker.schedulePeriodically(run, delay, delay, unit);147 List<Runnable> subRunList = subRunCapture.getValues();148 149 assertEquals(1, subRunList.size());150 Runnable subRun = subRunList.get(0);151 152 Capture<ExclusiveRunnable> exRunCapture = EasyMock.newCapture(CaptureType.ALL);153 executor.execute(EasyMock.capture(exRunCapture));154 EasyMock.replay(executor);155 156 subRun.run();157158 List<ExclusiveRunnable> exRunList = exRunCapture.getValues();159 assertEquals(1, exRunList.size());160 161 ExclusiveRunnable exRun = exRunList.get(0);162 assertEquals(scope, exRun.getScope());163 assertEquals(exclusive, exRun.isExclusive());164 165 run.run();166 EasyMock.replay(run);167 168 exRun.run();169 170 EasyMock.verify(run);171 }172 ...

Full Screen

Full Screen

Capture

Using AI Code Generation

copy

Full Screen

1import org.easymock.Capture;2import org.easymock.EasyMock;3import org.easymock.IMocksControl;4import org.junit.After;5import org.junit.Before;6import org.junit.Test;7import org.junit.runner.RunWith;8import org.junit.runners.JUnit4;9import static org.junit.Assert.*;10import static org.easymock.EasyMock.*;11@RunWith(JUnit4.class)12public class TestCapture {13 IMocksControl control;14 ICalculator cal;15 public void setUp() {16 control = createControl();17 cal = control.createMock(ICalculator.class);18 }19 public void tearDown() {20 control.verify();21 }22 public void testCapture() {23 Capture<Integer> capture = new Capture<Integer>();24 cal.add(capture(capture), capture(capture));25 control.replay();26 cal.add(2, 3);27 assertEquals(5, capture.getValue().intValue());28 }29}30import org.easymock.Capture;31import org.easymock.EasyMock;32import org.easymock.IMocksControl;33import org.junit.After;34import org.junit.Before;35import org.junit.Test;36import org.junit.runner.RunWith;37import org.junit.runners.JUnit4;38import static org.junit.Assert.*;39import static org.easymock.EasyMock.*;40@RunWith(JUnit4.class)41public class TestCapture {42 IMocksControl control;43 ICalculator cal;44 public void setUp() {45 control = createControl();46 cal = control.createMock(ICalculator.class);47 }48 public void tearDown() {49 control.verify();50 }51 public void testCapture() {52 Capture<Integer> capture = new Capture<Integer>();53 cal.add(capture(capture), capture(capture));54 control.replay();55 cal.add(2, 3);56 assertEquals(5, capture.getValue().intValue());57 }58}59import org.easymock.Capture;60import org.easymock.EasyMock;61import org.easymock.IMocksControl;62import org.junit.After;63import org.junit.Before;64import org.junit.Test;65import org.junit.runner

Full Screen

Full Screen

Capture

Using AI Code Generation

copy

Full Screen

1import org.easymock.Capture;2import org.easymock.EasyMock;3import org.easymock.IMocksControl;4import org.junit.Test;5public class CaptureTest {6 public void test() {7 IMocksControl control = EasyMock.createControl();8 IMethods mock = control.createMock(IMethods.class);9 Capture<String> capture = new Capture<String>();10 mock.oneArg(EasyMock.capture(capture));11 control.replay();12 mock.oneArg("foo");13 control.verify();14 System.out.println(capture.getValue());15 }16}17interface IMethods {18 void oneArg(String arg);19}

Full Screen

Full Screen

Capture

Using AI Code Generation

copy

Full Screen

1import org.easymock.Capture;2import org.easymock.EasyMock;3import org.junit.Test;4public class CaptureDemo {5 public void testCapture() {6 Capture<String> capture = new Capture<String>();7 ICalculator calculator = EasyMock.createMock(ICalculator.class);8 EasyMock.expect(calculator.add(EasyMock.capture(capture))).andReturn(5);9 EasyMock.replay(calculator);10 calculator.add(2);11 EasyMock.verify(calculator);12 String capturedValue = capture.getValue();13 System.out.println(capturedValue);14 }15}16public interface ICalculator {17 public int add(int a);18}

Full Screen

Full Screen

Capture

Using AI Code Generation

copy

Full Screen

1import org.easymock.Capture;2import org.easymock.EasyMock;3import org.easymock.IMocksControl;4import org.junit.Test;5public class CaptureTest {6 public void testCapture() {7 IMocksControl control = EasyMock.createControl();8 IMyInterface myInterface = control.createMock(IMyInterface.class);9 Capture<String> capture = new Capture<String>();10 myInterface.myMethod(EasyMock.capture(capture));11 control.replay();12 myInterface.myMethod("Hello");13 System.out.println(capture.getValue());14 }15}16interface IMyInterface {17 public void myMethod(String str);18}19Capture is used to capture the arguments of the method. The captureValue() method

Full Screen

Full Screen

Capture

Using AI Code Generation

copy

Full Screen

1package org.easymock;2import org.easymock.Capture;3public class CaptureExample {4 public static void main(String[] args) {5 Capture<String> capture = new Capture<String>();6 Capture<Throwable> captureThrowable = new Capture<Throwable>();7 Capture<Object> captureObject = new Capture<Object>();8 }9}10Capture.capture() is used to capture the argument passed to a method11Capture.captureThrowable() is used to capture the throwable passed to a method12Capture.captureObject() is used to capture the object passed to a method

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.

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful