本文整理了Java中org.easymock.EasyMock.and()
方法的一些代码示例,展示了EasyMock.and()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.and()
方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:and
[英]Expects a byte that matches both given expectations.
[中]需要一个与给定期望值都匹配的字节。
代码示例来源:origin: apache/shiro
@Test
public void testPropertySetting() throws Exception {
IMocksControl control = createControl();
TypeEncounter<SomeInjectableBean> encounter = control.createMock(TypeEncounter.class);
Provider<Injector> injectorProvider = control.createMock(Provider.class);
Injector injector = control.createMock(Injector.class);
expect(encounter.getProvider(Injector.class)).andReturn(injectorProvider);
expect(injectorProvider.get()).andReturn(injector).anyTimes();
Capture<MembersInjector<SomeInjectableBean>> capture = new Capture<MembersInjector<SomeInjectableBean>>();
encounter.register(and(anyObject(MembersInjector.class), capture(capture)));
SecurityManager securityManager = control.createMock(SecurityManager.class);
String property = "myPropertyValue";
expect(injector.getInstance(Key.get(SecurityManager.class))).andReturn(securityManager);
expect(injector.getInstance(Key.get(String.class, Names.named("shiro.myProperty")))).andReturn(property);
expect(injector.getInstance(Key.get(String.class, Names.named("shiro.unavailableProperty"))))
.andThrow(new ConfigurationException(Collections.singleton(new Message("Not Available!"))));
expect((Map)injector.getInstance(BeanTypeListener.MAP_KEY)).andReturn(Collections.EMPTY_MAP).anyTimes();
control.replay();
BeanTypeListener underTest = new BeanTypeListener();
underTest.hear(TypeLiteral.get(SomeInjectableBean.class), encounter);
SomeInjectableBean bean = new SomeInjectableBean();
capture.getValue().injectMembers(bean);
assertSame(securityManager, bean.securityManager);
assertSame(property, bean.myProperty);
assertNull(bean.unavailableProperty);
control.verify();
}
代码示例来源:origin: apache/shiro
@Test
public void testConstructor() {
WebSecurityManager securityManager = createMock(WebSecurityManager.class);
FilterChainResolver filterChainResolver = createMock(FilterChainResolver.class);
ServletContext servletContext = createMock(ServletContext.class);
Capture<WebGuiceEnvironment> capture = new Capture<WebGuiceEnvironment>();
servletContext.setAttribute(eq(EnvironmentLoaderListener.ENVIRONMENT_ATTRIBUTE_KEY), and(anyObject(WebGuiceEnvironment.class), capture(capture)));
replay(servletContext, securityManager, filterChainResolver);
WebGuiceEnvironment underTest = new WebGuiceEnvironment(filterChainResolver, servletContext, securityManager);
assertSame(securityManager, underTest.getSecurityManager());
assertSame(filterChainResolver, underTest.getFilterChainResolver());
assertSame(securityManager, underTest.getWebSecurityManager());
assertSame(servletContext, underTest.getServletContext());
assertSame(underTest, capture.getValue());
verify(servletContext);
}
}
代码示例来源:origin: apache/shiro
@Test
public void testDoFilter() throws Exception {
IMocksControl ctrl = createStrictControl();
FilterChain originalChain = ctrl.createMock(FilterChain.class);
Filter filter1 = ctrl.createMock("filter1", Filter.class);
Filter filter2 = ctrl.createMock("filter2", Filter.class);
ServletRequest request = ctrl.createMock(ServletRequest.class);
ServletResponse response = ctrl.createMock(ServletResponse.class);
Capture<FilterChain> fc1 = new Capture<FilterChain>();
Capture<FilterChain> fc2 = new Capture<FilterChain>();
filter1.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc1)));
filter2.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc2)));
originalChain.doFilter(request, response);
ctrl.replay();
SimpleFilterChain underTest = new SimpleFilterChain(originalChain, Arrays.asList(filter1, filter2).iterator());
// all we actually care about is that, if we keep calling the filter chain, everything is called in the right
// order - we don't care what fc actually contains
underTest.doFilter(request, response);
fc1.getValue().doFilter(request, response);
fc2.getValue().doFilter(request, response);
ctrl.verify();
}
}
代码示例来源:origin: apache/incubator-druid
watcher.registerQuery(
EasyMock.anyObject(),
EasyMock.and(EasyMock.anyObject(), EasyMock.capture(capturedFuture))
);
EasyMock.expectLastCall()
代码示例来源:origin: apache/incubator-druid
watcher.registerQuery(
EasyMock.anyObject(),
EasyMock.and(EasyMock.anyObject(), EasyMock.capture(capturedFuture))
);
EasyMock.expectLastCall()
代码示例来源:origin: apache/httpcomponents-client
EasyMock.expect(
mockExecChain.proceed(
EasyMock.and(eqRequest(conditionalValidationRequest), EasyMock.capture(cap1)),
EasyMock.isA(ExecChain.Scope.class))).andReturn(conditionalResponse).times(0, 1);
EasyMock.expect(
mockExecChain.proceed(
EasyMock.and(eqRequest(unconditionalValidationRequest), EasyMock.capture(cap2)),
EasyMock.isA(ExecChain.Scope.class))).andReturn(unconditionalResponse).times(0, 1);
代码示例来源:origin: apache/httpcomponents-client
EasyMock.and(eqRequest(conditional), EasyMock.capture(condCap)),
EasyMock.isA(ExecChain.Scope.class))).andReturn(resp304).times(0,1);
EasyMock.expect(
mockExecChain.proceed(
EasyMock.and(eqRequest(req2), EasyMock.capture(uncondCap)),
EasyMock.isA(ExecChain.Scope.class))).andReturn(resp200).times(0,1);
代码示例来源:origin: bedatadriven/activityinfo
private void captureDispatch(Capture<CreateEntity> cmd) {
dispatcher.execute(and(isA(CreateEntity.class), capture(cmd)),
optionalMonitor(), isA(AsyncCallback.class));
}
代码示例来源:origin: com.lmco.shindig/shindig-gadgets
@Test
public void execute() throws Exception {
PipelinedData pipeline = getPipelinedData(CONTENT);
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
JSONObject expectedData = new JSONObject("{result: {foo: 'bar'}}");
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask("key", expectedData.toString());
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(context),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
PipelineExecutor.Results results = executor.execute(context,
ImmutableList.of(pipeline));
// Verify the data set is injected, and the os-data was deleted
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
JsonAssert.assertJsonEquals("[{id: 'key', result: {foo: 'bar'}}]",
JsonSerializer.serialize(results.results));
JsonAssert.assertJsonEquals("{foo: 'bar'}",
JsonSerializer.serialize(results.keyedResults.get("key")));
assertTrue(results.remainingPipelines.isEmpty());
control.verify();
}
代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets
@Test
public void execute() throws Exception {
PipelinedData pipeline = getPipelinedData(CONTENT);
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
JSONObject expectedData = new JSONObject("{result: {foo: 'bar'}}");
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask("key", expectedData.toString());
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(context),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
PipelineExecutor.Results results = executor.execute(context,
ImmutableList.of(pipeline));
// Verify the data set is injected, and the os-data was deleted
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
JsonAssert.assertJsonEquals("[{id: 'key', result: {foo: 'bar'}}]",
JsonSerializer.serialize(results.results));
JsonAssert.assertJsonEquals("{foo: 'bar'}",
JsonSerializer.serialize(results.keyedResults.get("key")));
assertTrue(results.remainingPipelines.isEmpty());
control.verify();
}
代码示例来源:origin: org.apache.shindig/shindig-gadgets
@Test
public void executeError() throws Exception {
PipelinedData pipeline = getPipelinedData(CONTENT);
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
JSONObject expectedData = new JSONObject("{error: {message: 'NO!', code: 500}}");
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask("key", expectedData.toString());
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(context),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
PipelineExecutor.Results results = executor.execute(context,
ImmutableList.of(pipeline));
// Verify the data set is injected, and the os-data was deleted
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
JsonAssert.assertJsonEquals("[{id: 'key', error: {message: 'NO!', code: 500}}]",
JsonSerializer.serialize(results.results));
JsonAssert.assertJsonEquals("{message: 'NO!', code: 500}",
JsonSerializer.serialize(results.keyedResults.get("key")));
assertTrue(results.remainingPipelines.isEmpty());
control.verify();
}
代码示例来源:origin: org.apache.shindig/shindig-gadgets
@Test
public void execute() throws Exception {
PipelinedData pipeline = getPipelinedData(CONTENT);
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
JSONObject expectedData = new JSONObject("{result: {foo: 'bar'}}");
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask("key", expectedData.toString());
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(context),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
PipelineExecutor.Results results = executor.execute(context,
ImmutableList.of(pipeline));
// Verify the data set is injected, and the os-data was deleted
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
JsonAssert.assertJsonEquals("[{id: 'key', result: {foo: 'bar'}}]",
JsonSerializer.serialize(results.results));
JsonAssert.assertJsonEquals("{foo: 'bar'}",
JsonSerializer.serialize(results.keyedResults.get("key")));
assertTrue(results.remainingPipelines.isEmpty());
control.verify();
}
代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets
@Test
public void executeError() throws Exception {
PipelinedData pipeline = getPipelinedData(CONTENT);
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
JSONObject expectedData = new JSONObject("{error: {message: 'NO!', code: 500}}");
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask("key", expectedData.toString());
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(context),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
PipelineExecutor.Results results = executor.execute(context,
ImmutableList.of(pipeline));
// Verify the data set is injected, and the os-data was deleted
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
JsonAssert.assertJsonEquals("[{id: 'key', error: {message: 'NO!', code: 500}}]",
JsonSerializer.serialize(results.results));
JsonAssert.assertJsonEquals("{message: 'NO!', code: 500}",
JsonSerializer.serialize(results.keyedResults.get("key")));
assertTrue(results.remainingPipelines.isEmpty());
control.verify();
}
代码示例来源:origin: com.lmco.shindig/shindig-gadgets
@Test
public void executeError() throws Exception {
PipelinedData pipeline = getPipelinedData(CONTENT);
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
JSONObject expectedData = new JSONObject("{error: {message: 'NO!', code: 500}}");
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask("key", expectedData.toString());
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(context),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
PipelineExecutor.Results results = executor.execute(context,
ImmutableList.of(pipeline));
// Verify the data set is injected, and the os-data was deleted
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
JsonAssert.assertJsonEquals("[{id: 'key', error: {message: 'NO!', code: 500}}]",
JsonSerializer.serialize(results.results));
JsonAssert.assertJsonEquals("{message: 'NO!', code: 500}",
JsonSerializer.serialize(results.keyedResults.get("key")));
assertTrue(results.remainingPipelines.isEmpty());
control.verify();
}
代码示例来源:origin: com.lmco.shindig/shindig-gadgets
and(eqBatch(0, 1), capture(firstBatch))))
.andReturn(ImmutableList.of(firstTask));
and(eqBatch(1, 0), capture(secondBatch))))
.andReturn(ImmutableList.of(secondTask));
代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets
and(eqBatch(0, 1), capture(firstBatch))))
.andReturn(ImmutableList.of(firstTask));
and(eqBatch(1, 0), capture(secondBatch))))
.andReturn(ImmutableList.of(secondTask));
代码示例来源:origin: org.apache.shindig/shindig-gadgets
and(eqBatch(0, 1), capture(firstBatch))))
.andReturn(ImmutableList.of(firstTask));
and(eqBatch(1, 0), capture(secondBatch))))
.andReturn(ImmutableList.of(secondTask));
代码示例来源:origin: com.lmco.shindig/shindig-gadgets
@Test
public void rewrite() throws Exception {
setupGadget(getGadgetXml(CONTENT));
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask(
"key", "{result: {foo: 'bar'}}");
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(gadget.getContext()),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
rewriter.rewrite(gadget, content);
// Verify the data set is injected, and the os-data was deleted
assertTrue("Script not inserted", content.getContent().contains("DataContext.putDataSet(\"key\",{\"foo\":\"bar\"})"));
assertFalse("os-data wasn't deleted",
content.getContent().contains("type=\"text/os-data\""));
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
assertFalse(gadget.getDirectFeatureDeps().contains("opensocial-data"));
assertTrue(gadget.getDirectFeatureDeps().contains("opensocial-data-context"));
control.verify();
}
@Test
代码示例来源:origin: org.apache.shindig/shindig-gadgets
@Test
public void rewrite() throws Exception {
setupGadget(getGadgetXml(CONTENT));
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask(
"key", "{result: {foo: 'bar'}}");
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(gadget.getContext()),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
rewriter.rewrite(gadget, content);
// Verify the data set is injected, and the os-data was deleted
assertTrue("Script not inserted", content.getContent().contains("DataContext.putDataSet(\"key\",{\"foo\":\"bar\"})"));
assertFalse("os-data wasn't deleted",
content.getContent().contains("type=\"text/os-data\""));
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
assertFalse(gadget.getDirectFeatureDeps().contains("opensocial-data"));
assertTrue(gadget.getDirectFeatureDeps().contains("opensocial-data-context"));
control.verify();
}
@Test
代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets
@Test
public void rewrite() throws Exception {
setupGadget(getGadgetXml(CONTENT));
Capture<PipelinedData.Batch> batchCapture =
new Capture<PipelinedData.Batch>();
// Dummy return results (the "real" return would have two values)
Callable<PreloadedData> callable = createPreloadTask(
"key", "{result: {foo: 'bar'}}");
// One batch with 1 each HTTP and Social preload
expect(preloader.createPreloadTasks(same(gadget.getContext()),
and(eqBatch(1, 1), capture(batchCapture))))
.andReturn(ImmutableList.of(callable));
control.replay();
rewriter.rewrite(gadget, content);
// Verify the data set is injected, and the os-data was deleted
assertTrue("Script not inserted", content.getContent().contains("DataContext.putDataSet(\"key\",{\"foo\":\"bar\"})"));
assertFalse("os-data wasn't deleted",
content.getContent().contains("type=\"text/os-data\""));
assertTrue(batchCapture.getValue().getPreloads().containsKey("me"));
assertTrue(batchCapture.getValue().getPreloads().containsKey("json"));
assertFalse(gadget.getDirectFeatureDeps().contains("opensocial-data"));
assertTrue(gadget.getDirectFeatureDeps().contains("opensocial-data-context"));
control.verify();
}
@Test
内容来源于网络,如有侵权,请联系作者删除!