How to use Capture class of org.easymock package

Best Easymock code snippet using org.easymock.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:Mocks.java Github

copy

Full Screen

...23import static org.easymock.EasyMock.isA;24import static org.easymock.EasyMock.replay;25import com.android.io.IAbstractFolder;26import com.android.io.IAbstractResource;27import org.easymock.Capture;28import org.easymock.EasyMock;29import org.easymock.IAnswer;30import org.eclipse.core.resources.IFile;31import org.eclipse.core.resources.IFolder;32import org.eclipse.core.resources.IProject;33import org.eclipse.core.resources.IResource;34import org.eclipse.core.runtime.IPath;35import org.eclipse.core.runtime.IProgressMonitor;36import org.eclipse.core.runtime.Path;37import org.eclipse.jdt.core.IClasspathEntry;38import org.eclipse.jdt.core.IJavaProject;39import org.eclipse.jdt.core.JavaCore;40import java.util.Map;41public class Mocks {42 public static IJavaProject createProject(IClasspathEntry[] entries, IPath outputLocation)43 throws Exception {44 IJavaProject javaProject = createMock(IJavaProject.class);45 final Capture<IClasspathEntry[]> capturedEntries = new Capture<IClasspathEntry[]>();46 Capture<IPath> capturedOutput = new Capture<IPath>();47 capturedEntries.setValue(entries);48 capturedOutput.setValue(outputLocation);49 IProject project = createProject();50 expect(javaProject.getProject()).andReturn(project).anyTimes();51 expect(javaProject.getOutputLocation()).andReturn(capturedOutput.getValue()).anyTimes();52 expect(javaProject.getRawClasspath()).andAnswer(new IAnswer<IClasspathEntry[]>() {53 @Override54 public IClasspathEntry[] answer() throws Throwable {55 return capturedEntries.getValue();56 }57 }).anyTimes();58 javaProject.setRawClasspath(capture(capturedEntries), isA(IProgressMonitor.class));59 expectLastCall().anyTimes();60 javaProject.setRawClasspath(capture(capturedEntries), capture(capturedOutput),61 isA(IProgressMonitor.class));62 expectLastCall().anyTimes();63 final Capture<String> capturedCompliance = new Capture<String>();64 capturedCompliance.setValue("1.4");65 final Capture<String> capturedSource = new Capture<String>();66 capturedSource.setValue("1.4");67 final Capture<String> capturedTarget = new Capture<String>();68 capturedTarget.setValue("1.4");69 expect(javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true)).andAnswer(70 new IAnswer<String>() {71 @Override72 public String answer() throws Throwable {73 return capturedCompliance.getValue();74 }75 });76 expect(javaProject.getOption(JavaCore.COMPILER_SOURCE, true)).andAnswer(77 new IAnswer<String>() {78 @Override79 public String answer() throws Throwable {80 return capturedSource.getValue();81 }...

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.junit.Before;4import org.junit.Test;5import static org.easymock.EasyMock.*;6import static org.junit.Assert.*;7public class TestEasyMock {8 private static final String NAME = "test";9 private static final String NEW_NAME = "new test";10 private static final int ID = 1;11 private static final int NEW_ID = 2;12 private Capture<Person> capture;13 private PersonDao personDao;14 private Person person;15 private PersonService personService;16 public void setUp() {17 capture = new Capture<Person>();18 personDao = createMock(PersonDao.class);19 person = createMock(Person.class);20 personService = new PersonServiceImpl(personDao);21 }22 public void testUpdatePerson() {23 expect(personDao.getPerson(ID)).andReturn(person);24 expect(person.getName()).andReturn(NAME);25 expect(person.getId()).andReturn(ID);26 person.setName(NEW_NAME);27 expectLastCall();28 personDao.updatePerson(capture(person));29 expectLastCall();30 replay(personDao, person);31 personService.updatePerson(ID, NEW_NAME);32 assertEquals(capture.getValue().getName(), NEW_NAME);33 assertEquals(capture.getValue().getId(), ID);34 verify(personDao, person);35 }36}37OK (1 test)

Full Screen

Full Screen

Capture

Using AI Code Generation

copy

Full Screen

1package org.easymock;2import org.easymock.Capture;3import org.easymock.CaptureType;4import org.easymock.EasyMock;5import org.easymock.IMocksControl;6import org.easymock.internal.MocksControl;7import org.easymock.internal.matchers.CaptureMatcher;8import org.junit.Test;9import static org.easymock.EasyMock.*;10import static org.junit.Assert.*;11public class CaptureTest {12 public void testCapture(){13 IMocksControl control = createControl();14 Capture<String> capture = new Capture<String>();15 CaptureMatcher<String> captureMatcher = new CaptureMatcher<String>(capture);16 CaptureType captureType = new CaptureType(captureMatcher);17 CaptureType[] captureTypeArray = new CaptureType[]{captureType};18 TestInterface mock = control.createMock(TestInterface.class);19 mock.testMethod(captureTypeArray);20 control.replay();21 mock.testMethod("test");22 String result = capture.getValue();23 assertEquals("test", result);24 }25}26package org.easymock;27public interface TestInterface {28 public void testMethod(String... args);29}30 at org.junit.Assert.fail(Assert.java:88)31 at org.junit.Assert.failNotEquals(Assert.java:743)32 at org.junit.Assert.assertEquals(Assert.java:118)33 at org.junit.Assert.assertEquals(Assert.java:555)34 at org.junit.Assert.assertEquals(Assert.java:542)35 at org.easymock.CaptureTest.testCapture(CaptureTest.java:31)36public void testCapture() {37 IMocksControl control = createControl();38 Capture<String> capture = new Capture<String>();39 TestInterface mock = control.createMock(TestInterface.class);40 mock.testMethod(capture("test"));41 control.replay();42 mock.testMethod("test");43 String result = capture.getValue();

Full Screen

Full Screen

Capture

Using AI Code Generation

copy

Full Screen

1import org.easymock.*;2import org.easymock.internal.*;3import org.easymock.internal.matchers.*;4import org.easymock.internal.matchers.Equals;5import org.easymock.internal.matchers.InstanceOf;6import org.easymock.internal.matchers.LessThan;7import org.easymock.internal.matchers.LessThanOrEqual;8import org.easymock.internal.matchers.NotNull;9import org.easymock.internal.matchers.Null;10import org.easymock.internal.matchers.Or;11import org.easymock.internal.matchers.Regex;12import org.easymock.internal.matchers.Same;13import org.easymock.internal.matchers.StartsWith;14import org.easymock.internal.matchers.StringContains;15import org.easymock.internal.matchers.ArrayEquals;16import org.easymock.internal.matchers.ArrayEqualsWithDelta;17import org.easymock.internal.matchers.ArrayEqualsWithTolerance;18import org.eas

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 1 {6 public void test() {7 IMocksControl control = EasyMock.createControl();8 MyInterface mock = control.createMock(MyInterface.class);9 Capture<String> capture = new Capture<String>();10 mock.doSomething(EasyMock.capture(capture));11 control.replay();12 mock.doSomething("Hello");13 String capturedValue = capture.getValue();14 System.out.println(capturedValue);15 }16}

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful