Examples of MockUtil


Examples of org.mockito.internal.util.MockUtil

                "threw an exception : " + listenerThrowable.getClass().getName() + listenerThrowable.getMessage()), listenerThrowable);
    }

    public void cannotInjectDependency(Field field, Object matchingMock, Exception details) {
        throw new MockitoException(join(
                "Mockito couldn't inject mock dependency '" + new MockUtil().getMockName(matchingMock) + "' on field ",
                "'" + field + "'",
                "whose type '" + field.getDeclaringClass().getCanonicalName() + "' was annotated by @InjectMocks in your test.",
                "Also I failed because: " + details.getCause().getMessage(),
                ""
        ), details);
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

    }

    public int invalidArgumentPositionRangeAtInvocationTime(InvocationOnMock invocation, boolean willReturnLastParameter, int argumentIndex) {
        throw new MockitoException(
                join("Invalid argument index for the current invocation of method : ",
                        " -> " + new MockUtil().getMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()",
                        "",
                        (willReturnLastParameter ?
                                "Last parameter wanted" :
                                "Wanted parameter at position " + argumentIndex) + " but " + possibleArgumentTypesOf(invocation),
                        "The index need to be a positive number that indicates a valid position of the argument in the invocation.",
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

    public void wrongTypeOfArgumentToReturn(InvocationOnMock invocation, String expectedType, Class actualType, int argumentIndex) {
        throw new WrongTypeOfReturnValue(join(
                "The argument of type '" + actualType.getSimpleName() + "' cannot be returned because the following ",
                "method should return the type '" + expectedType + "'",
                " -> " + new MockUtil().getMockName(invocation.getMock()) + "." + invocation.getMethod().getName() + "()",
                "",
                "The reason for this error can be :",
                "1. The wanted argument position is incorrect.",
                "2. The answer is used on the wrong interaction.",
                "",
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

    }
   
    public void delegatedMethodHasWrongReturnType(Method mockMethod, Method delegateMethod, Object mock, Object delegate) {
      throw new MockitoException(join(
              "Methods called on delegated instance must have compatible return types with the mock.",
              "When calling: " + mockMethod + " on mock: " + new MockUtil().getMockName(mock),
              "return type should be: " + mockMethod.getReturnType().getSimpleName() + ", but was: " + delegateMethod.getReturnType().getSimpleName(),
              "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods",
              "(delegate instance had type: " + delegate.getClass().getSimpleName() + ")"
      ));
    }
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

    }

  public void delegatedMethodDoesNotExistOnDelegate(Method mockMethod, Object mock, Object delegate) {
    throw new MockitoException(join(
              "Methods called on mock must exist in delegated instance.",
              "When calling: " + mockMethod + " on mock: " + new MockUtil().getMockName(mock),
              "no such method was found.",
              "Check that the instance passed to delegatesTo() is of the correct type or contains compatible methods",
              "(delegate instance had type: " + delegate.getClass().getSimpleName() + ")"
      ));
  }
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

                "threw an exception : " + listenerThrowable.getClass().getName() + listenerThrowable.getMessage()), listenerThrowable);
    }

    public void cannotInjectDependency(Field field, Object matchingMock, Exception details) {
        throw new MockitoException(join(
                "Mockito couldn't inject mock dependency '" + new MockUtil().getMockName(matchingMock) + "' on field ",
                "'" + field + "'",
                "whose type '" + field.getDeclaringClass().getCanonicalName() + "' was annotated by @InjectMocks in your test.",
                "Also I failed because: " + details.getCause().getMessage(),
                ""
        ), details);
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

     * @see org.mockito.stubbing.Answer#answer(org.mockito.invocation.InvocationOnMock)
     */
    public Object answer(InvocationOnMock invocation) {
        if (methodsGuru.isToString(invocation.getMethod())) {
            Object mock = invocation.getMock();
            MockName name = new MockUtil().getMockName(mock);
            if (name.isSurrogate()) {
                return "Mock for " + ClassNameFinder.classNameForMock(mock) + ", hashCode: " + mock.hashCode();
            } else {
                return name.toString();
            }
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

                    instance = report.fieldInstance();
                } catch (MockitoException e) {
                    new Reporter().cannotInitializeForSpyAnnotation(field.getName(), e);
                }
                try {
                    if (new MockUtil().isMock(instance)) {
                        // instance has been spied earlier
                        // for example happens when MockitoAnnotations.initMocks is called two times.
                        Mockito.reset(instance);
                    } else {
                        field.setAccessible(true);
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

    final List<Answer> answers = new LinkedList<Answer>();
    private final Reporter reporter = new Reporter();

    public <T> T when(T mock) {
        MockUtil mockUtil = new MockUtil();
       
        if (mock == null) {
            reporter.nullPassedToWhenMethod();
        } else {
            if (!mockUtil.isMock(mock)) {
                reporter.notAMockPassedToWhenMethod();
            }
        }
       
        mockUtil.getMockHandler(mock).setAnswersForStubbing(answers);
        return mock;
    }
View Full Code Here

Examples of org.mockito.internal.util.MockUtil

        // TODO refoctor : code duplicated in SpyAnnotationEngine
        if(!fieldReader.isNull() && field.isAnnotationPresent(Spy.class)) {
            try {
                Object instance = fieldReader.read();
                if (new MockUtil().isMock(instance)) {
                    // A. instance has been spied earlier
                    // B. protect against multiple use of MockitoAnnotations.initMocks()
                    Mockito.reset(instance);
                } else {
                    new FieldSetter(fieldOwner, field).set(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.