private Method methodMatching(Invocation invocation) throws NoSuchMethodException { Method invokedMethod = invocation.getInvokedMethod(); return object.getClass().getDeclaredMethod(invokedMethod.getName(), invokedMethod.getParameterTypes()); } }
public Object invoke(Invocation invocation) throws Throwable { if (isThrowingCheckedException()) { checkTypeCompatiblity(invocation.getInvokedMethod().getExceptionTypes()); } throwable.fillInStackTrace(); throw throwable; }
private Object resultFor(Invocation invocation) { Method invokedMethod = invocation.getInvokedMethod(); Type returnType = invokedMethod.getGenericReturnType(); if (returnType == String.class) return FieldAccess.fieldNameForAccessor(invokedMethod); if (returnType == Void.TYPE) return null; return factory.createA(returnType); } }
@Override public Object invoke(Invocation invocation) throws Throwable { Method invokedMethod = invocation.getInvokedMethod(); if (METHOD_OBJECT_FINALIZE.equals(invokedMethod)) { return mockObject.invoke(invocation); } return invokable.invoke(invocation); } };
public Object invoke(Invocation invocation) throws Throwable { if (invocation.getInvokedMethod().getDeclaringClass() == declaringType) { return invocation.applyTo(target); } else { return next.invoke(invocation); } } }
@Override public Object invoke(Invocation invocation) throws Throwable { return handler.invoke(null, invocation.getInvokedMethod(), invocation.getParametersAsArray()); } };
@Override public Object invoke(Invocation invocation) throws Throwable { Method method = invocation.getInvokedMethod(); try { if (method.getParameterTypes().length == 0) { Field field = object.getClass().getDeclaredField(fieldNameForAccessor(method)); field.setAccessible(true); return returnValueFor(field.get(object), method.getGenericReturnType(), method.getName()); } else { Field field = object.getClass().getDeclaredField(fieldNameForMutator(method)); field.setAccessible(true); field.set(object, invocation.getParametersAsArray()[0]); return null; } } catch (NoSuchFieldException e) { return next.invoke(invocation); } }
public Object invoke(Invocation invocation) throws Throwable { final Class<?> returnType = invocation.getInvokedMethod().getReturnType(); if(Object.class.equals(returnType) && invocation.isBuildingExpectation()) { return null; } 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) && !invocation.isBuildingExpectation()) { return imposteriser.imposterise(this, returnType); } return null; }
public boolean matches(Invocation invocation) { return allowsMoreInvocations() && objectMatcher.matches(invocation.getInvokedObject()) && methodMatcher.matches(invocation.getInvokedMethod()) && parametersMatcher.matches(invocation.getParametersAsArray()) && isInCorrectOrder(); }
public void describeMismatch(Invocation invocation, Description description) { describeExpectation(description); final Object[] parameters = invocation.getParametersAsArray(); if (methodMatcher.matches(invocation.getInvokedMethod()) && parametersMatcher.isCompatibleWith(parameters)) { parametersMatcher.describeMismatch(parameters, description); } }
public void testCanBeConstructedFromAMethodObject() throws Exception { Invocation invocation = new Invocation(INVOKED, method, ARG_VALUES); assertSame("invoked object", INVOKED, invocation.getInvokedObject()); assertEquals("invoked method", method, invocation.getInvokedMethod()); assertEquals("name", method.getName(), invocation.getInvokedMethod().getName()); assertEquals("parameter types", Arrays.asList(method.getParameterTypes()), Arrays.asList(invocation.getInvokedMethod().getParameterTypes())); assertEquals("return type", method.getReturnType(), invocation.getInvokedMethod().getReturnType()); assertEquals("parameter count", ARG_VALUES.length, invocation.getParameterCount()); assertEquals("parameter values", Arrays.asList(ARG_VALUES), Arrays.asList(invocation.getParametersAsArray())); }
public void createExpectationFrom(Invocation invocation) { expectation.setMethod(invocation.getInvokedMethod()); if (capturedParameterMatchers.isEmpty()) { expectation.setParametersMatcher(new AllParametersMatcher(invocation.getParametersAsArray())); } else { checkParameterMatcherCount(invocation); expectation.setParametersMatcher(new AllParametersMatcher(capturedParameterMatchers)); } }
public void testMockeryReportsFirstFailedObject() { try { maskedExpectationFailure(mock, otherMock); fail("should have thrown ExpectationError"); } catch (ExpectationError e) { assertSame("invoked object", mock, e.invocation.getInvokedObject()); assertEquals("invoked method", "realExpectationFailure", e.invocation.getInvokedMethod().getName() ); } }
public void testMockeryReportsFirstFailedMethod() { try { maskedExpectationFailure(mock, mock); fail("should have thrown ExpectationError"); } catch (ExpectationError e) { assertSame("invoked object", mock, e.invocation.getInvokedObject()); assertEquals("invoked method", "realExpectationFailure", e.invocation.getInvokedMethod().getName() ); } }
public void testVerifyReportsFirstFailure() { try { mock.realExpectationFailure(2); } catch (ExpectationError e) { /* swallowed */ } try { context.assertIsSatisfied(); fail("should have thrown ExpectationError"); } catch (ExpectationError e) { assertSame("invoked object", mock, e.invocation.getInvokedObject()); assertEquals("invoked method", "realExpectationFailure", e.invocation.getInvokedMethod().getName() ); } } }
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); } }