本文整理汇总了Java中org.jmock.api.Invocation类的典型用法代码示例。如果您正苦于以下问题:Java Invocation类的具体用法?Java Invocation怎么用?Java Invocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Invocation类属于org.jmock.api包,在下文中一共展示了Invocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: will
import org.jmock.api.Invocation; //导入依赖的package包/类
void will(final Closure cl) {
will(new Action() {
public void describeTo(Description description) {
description.appendText("execute closure");
}
public Object invoke(Invocation invocation) throws Throwable {
List<Object> params = Arrays.asList(invocation.getParametersAsArray());
Object result;
try {
List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
cl.getMaximumNumberOfParameters()));
result = cl.call(subParams.toArray(new Object[0]));
} catch (InvokerInvocationException e) {
throw e.getCause();
}
if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
return result;
}
return null;
}
});
}
示例2: testGetBlockAtSector2
import org.jmock.api.Invocation; //导入依赖的package包/类
public void testGetBlockAtSector2() throws RecordStoreException {
final INorFlashSectorState sector = mock(INorFlashSectorState.class);
final int offset = 10;
final MemoryHeapBlock block = new MemoryHeapBlock();
final Address address = Address.fromPrimitive(11);
final int sectorSize = 1024;
expects(new InAnyOrder() {{
one(sector).getSize();will(returnValue(sectorSize));
one(sector).getStartAddress();will(returnValue(address));
one(sector).readBytes(with(equal(offset)), with(an(byte[].class)), with(equal(0)), with(equal(NorFlashMemoryHeap.BLOCK_HEADER_SIZE)));will(new CustomAction("") {
public Object invoke(Invocation invocation) throws Throwable {
block.setBytes(new byte[] {0, 0}, 0, 1);
return null;
}
});
}});
try {
castHeap.getBlockAt(block, sector, offset);
fail();
} catch (UnexpectedException e) {
}
}
示例3: shouldGenerateContent
import org.jmock.api.Invocation; //导入依赖的package包/类
@Test(dataProvider = "cmdLinesCases")
public void shouldGenerateContent(@NotNull final RunAsParams runAsParams, @NotNull final String expectedCmdLine) {
// Given
final ResourceGenerator<RunAsParams> instance = createInstance();
myCtx.checking(new Expectations() {{
allowing(myArgumentConverter).convert(with(any(String.class)));
will(new CustomAction("convert") {
@Override
public Object invoke(final Invocation invocation) throws Throwable {
return "'" + invocation.getParameter(0) + "'";
}
});
}});
// When
final String content = instance.create(runAsParams);
// Then
then(content).isEqualTo("@ECHO OFF"
+ LINE_SEPARATOR + expectedCmdLine
+ LINE_SEPARATOR + "SET \"EXIT_CODE=%ERRORLEVEL%\""
+ LINE_SEPARATOR + "EXIT /B %EXIT_CODE%");
}
示例4: shouldGenerateContent
import org.jmock.api.Invocation; //导入依赖的package包/类
@Test(dataProvider = "cmdLinesCases")
public void shouldGenerateContent(@NotNull final RunAsParams runAsParams, @NotNull final String expectedCmdLine) {
// Given
final ResourceGenerator<RunAsParams> instance = createInstance();
myCtx.checking(new Expectations() {{
allowing(myArgumentConverter).convert(with(any(String.class)));
will(new CustomAction("convert") {
@Override
public Object invoke(final Invocation invocation) throws Throwable {
return "'" + invocation.getParameter(0) + "'";
}
});
}});
// When
final String content = instance.create(runAsParams);
// Then
then(content).isEqualTo(ShGenerator.BASH_HEADER + LINE_SEPARATOR + expectedCmdLine);
}
示例5: sendRequestWithSenderVouchesToken
import org.jmock.api.Invocation; //导入依赖的package包/类
@Test
public void sendRequestWithSenderVouchesToken() throws Exception {
ServiceClient client = this.client.getServiceClient();
client.setToken(assertion);
final StringValueHolder holder = new StringValueHolder();
context.checking(new Expectations() {{
one(soapClient).wsCall(with(equal(ADDRESS)), with(aNull(String.class)), with(aNull(String.class)), with(equal(true)), with(holder), with(equal("urn:action")));
will(new CustomAction("test") {
public Object invoke(Invocation invocation) throws Throwable {
return buildResponse(holder.getValue(), false);
}
});
}});
Assertion body = SAMLUtil.buildXMLObject(Assertion.class);
client.sendRequest(body, ADDRESS, "urn:action", null, null);
OIOSoapEnvelope env = new OIOSoapEnvelope((Envelope) SAMLUtil.unmarshallElementFromString(holder.getValue()));
assertFalse(env.isHolderOfKey());
assertTrue(env.isSigned());
Security sec = env.getHeaderElement(Security.class);
assertNotNull(sec);
assertNotNull(SAMLUtil.getFirstElement(sec, Assertion.class));
}
示例6: testJAXBRequest
import org.jmock.api.Invocation; //导入依赖的package包/类
@Test
public void testJAXBRequest() throws Exception {
final StringValueHolder holder = new StringValueHolder();
context.checking(new Expectations() {{
one(soapClient).wsCall(with(equal(ADDRESS)), with(aNull(String.class)), with(aNull(String.class)), with(equal(true)), with(holder), with(equal("urn:action")));
will(new CustomAction("test") {
public Object invoke(Invocation invocation) throws Throwable {
OIOSoapEnvelope env = new OIOSoapEnvelope((Envelope) SAMLUtil.unmarshallElementFromString(holder.getValue()));
Envelope response = SAMLUtil.buildXMLObject(Envelope.class);
response.setHeader(SAMLUtil.buildXMLObject(Header.class));
RelatesTo relatesTo = SAMLUtil.buildXMLObject(RelatesTo.class);
relatesTo.setValue(env.getMessageID());
response.getHeader().getUnknownXMLObjects().add(relatesTo);
String xml = "<test:blah xmlns:test='urn:testing'><test:more>blah</test:more></test:blah>";
response.setBody(SAMLUtil.buildXMLObject(Body.class));
response.getBody().getUnknownXMLObjects().add(new XSAnyUnmarshaller().unmarshall(SAMLUtil.loadElementFromString(xml)));
return response;
}
});
}});
client.getServiceClient().sendRequest(new TestBean(), JAXBContext.newInstance(TestBean.class), ADDRESS, "urn:action", null, null);
}
示例7: will
import org.jmock.api.Invocation; //导入依赖的package包/类
void will(final Closure cl) {
will(new Action() {
public void describeTo(Description description) {
description.appendText("execute closure");
}
public Object invoke(Invocation invocation) throws Throwable {
List<Object> params = Arrays.asList(invocation.getParametersAsArray());
Object result;
try {
List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
cl.getMaximumNumberOfParameters()));
result = cl.call(subParams.toArray(new Object[subParams.size()]));
} catch (InvokerInvocationException e) {
throw e.getCause();
}
if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
return result;
}
return null;
}
});
}
示例8: returnInstantiatedAndInitializedViewModel
import org.jmock.api.Invocation; //导入依赖的package包/类
private Action returnInstantiatedAndInitializedViewModel() {
return new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
final Class<?> cls = (Class<?>) invocation.getParameter(0);
final String memento = (String) invocation.getParameter(1);
final ViewModel viewModelInstance = (ViewModel) cls.newInstance();
viewModelInstance.viewModelInit(memento);
if(viewModelInstance instanceof UserPermissionViewModel) {
((UserPermissionViewModel) viewModelInstance).applicationPermissionRepository = mockApplicationPermissionRepository;
}
return viewModelInstance;
}
@Override
public void describeTo(Description description) {
description.appendText("return instantiated and initialized view model ");
}
};
}
示例9: setUp
import org.jmock.api.Invocation; //导入依赖的package包/类
@Before
public void setUp() {
myMockery = new JUnit4Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
myDocument = myMockery.mock(DocumentImpl.class);
myMockery.checking(new Expectations() {{
allowing(myDocument).getTextLength(); will(new CustomAction("getTextLength") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
return myArray.length();
}
});
}});
init(10);
if (myConfig != null) {
myArray.insert(myConfig.text(), 0);
myArray.setDeferredChangeMode(myConfig.deferred());
}
}
示例10: addToInMemoryDB
import org.jmock.api.Invocation; //导入依赖的package包/类
private Action addToInMemoryDB() {
return new Action() {
@Override
public Object invoke(Invocation invocation) throws Throwable {
final InMemoryDB inMemoryDB = getVar("isis", "in-memory-db", InMemoryDB.class);
final String name = (String)invocation.getParameter(0);
final SimpleObject obj = new SimpleObject();
obj.setName(name);
inMemoryDB.put(SimpleObject.class, name, obj);
return obj;
}
@Override
public void describeTo(Description description) {
description.appendText("add to database");
}
};
}
示例11: invoke
import org.jmock.api.Invocation; //导入依赖的package包/类
public Object invoke(Invocation invocation) throws Throwable {
Method method = invocation.getInvokedMethod();
if (isMethod(method, int.class, "hashCode")) {
return fakeHashCode(invocation.getInvokedObject());
}
else if (isMethod(method, String.class, "toString")) {
return fakeToString(invocation.getInvokedObject());
}
else if (isMethod(method, boolean.class, "equals", Object.class)) {
return fakeEquals(invocation.getInvokedObject(), invocation.getParameter(0));
}
else if (isMethod(method, void.class, "finalize")) {
fakeFinalize(invocation.getInvokedObject());
return null;
}
else {
return next.invoke(invocation);
}
}
示例12: invoke
import org.jmock.api.Invocation; //导入依赖的package包/类
public Object invoke(Invocation invocation) throws Throwable {
final Class<?> returnType = invocation.getInvokedMethod().getReturnType();
if (resultValuesByType.containsKey(returnType)) {
return resultValuesByType.get(returnType);
}
if (returnType.isArray()) {
return Array.newInstance(returnType.getComponentType(), 0);
}
if (isCollectionOrMap(returnType)) {
final Object instance = collectionOrMapInstanceFor(returnType);
if (instance != null) return instance;
}
if (imposteriser.canImposterise(returnType)) {
return imposteriser.imposterise(this, returnType);
}
return null;
}
示例13: describedWith
import org.jmock.api.Invocation; //导入依赖的package包/类
private Iterable<SelfDescribing> describedWith(List<Expectation> expectations, final Invocation invocation) {
final Iterator<Expectation> iterator = expectations.iterator();
return new Iterable<SelfDescribing>() {
public Iterator<SelfDescribing> iterator() {
return new Iterator<SelfDescribing>() {
public boolean hasNext() { return iterator.hasNext(); }
public SelfDescribing next() {
return new SelfDescribing() {
public void describeTo(Description description) {
iterator.next().describeMismatch(invocation, description);
}
};
}
public void remove() { iterator.remove(); }
};
}
};
}
示例14: synchroniseInvocation
import org.jmock.api.Invocation; //导入依赖的package包/类
private Object synchroniseInvocation(Invokable mockObject, Invocation invocation) throws Throwable {
synchronized (sync) {
try {
return mockObject.invoke(invocation);
}
catch (Error e) {
if (firstError == null) {
firstError = e;
}
throw e;
}
finally {
sync.notifyAll();
}
}
}
示例15: testTestsForEqualityOnTargetAndMethodSignatureAndArguments
import org.jmock.api.Invocation; //导入依赖的package包/类
public void testTestsForEqualityOnTargetAndMethodSignatureAndArguments() {
Invocation invocation1 = new Invocation(INVOKED, method, ARG_VALUES);
Invocation invocation2 = new Invocation(INVOKED, method, ARG_VALUES);
Invocation differentTarget = new Invocation("OTHER TARGET", method, ARG_VALUES);
Invocation differentMethod = new Invocation(INVOKED,
methodFactory.newMethod("OTHER_" + METHOD_NAME, ARG_TYPES, RETURN_TYPE, EXCEPTION_TYPES),
ARG_VALUES);
Invocation differentArgValues = new Invocation(INVOKED, method,
new Object[]{new Integer(1), Boolean.FALSE});
assertTrue("should be equal to itself", invocation1.equals(invocation1));
assertTrue("identical calls should be equal", invocation1.equals(invocation2));
assertFalse("should not be equal to object that is not an Invocation",
invocation1.equals(new Object()));
assertFalse("should not be equal to null",
invocation1.equals(null));
assertFalse("should not be equal if different invoked object",
invocation1.equals(differentTarget));
assertFalse("should not be equal if different method",
invocation1.equals(differentMethod));
assertFalse("should not be equal if different argumentValues",
invocation1.equals(differentArgValues));
}