Package org.mockito.exceptions.base

Examples of org.mockito.exceptions.base.MockitoException


                boolean wasAccessible = f.isAccessible();
                f.setAccessible(true);
                try {
                    f.set(testClass, Mockito.mock(f.getType(), f.getName()));
                } catch (IllegalAccessException e) {
                    throw new MockitoException("Problems initiating mocks annotated with @Mock", e);
                } finally {
                    f.setAccessible(wasAccessible);
                }
            }
        }
View Full Code Here


    }

    private Object processAnnotationOn(Captor annotation, Field field) {
        Class<?> type = field.getType();
        if (!ArgumentCaptor.class.isAssignableFrom(type)) {
            throw new MockitoException("@Captor field must be of the type ArgumentCaptor.\n" + "Field: '"
                    + field.getName() + "' has wrong type\n"
                    + "For info how to use @Captor annotations see examples in javadoc for MockitoAnnotations class.");
        }
        Class cls = new GenericMaster().getGenericType(field);
        return ArgumentCaptor.forClass(cls);
View Full Code Here

    private String pluralize(int number) {
        return number == 1 ? "1 time" : number + " times";
    }

    public void checkedExceptionInvalid(Throwable t) {
        throw new MockitoException(join(
                "Checked exception is invalid for this method!",
                "Invalid: " + t
                ));
    }
View Full Code Here

                "Invalid: " + t
                ));
    }

    public void cannotStubWithNullThrowable() {
        throw new MockitoException(join(
                "Cannot stub with null throwable!"
                ));

    }
View Full Code Here

                "Also, if you use @Mock annotation don't miss initMocks()"
        ));
    }
   
    public void mocksHaveToBePassedToVerifyNoMoreInteractions() {
        throw new MockitoException(join(
                "Method requires argument(s)!",
                "Pass mocks that should be verified, e.g:",
                "    verifyNoMoreInteractions(mockOne, mockTwo);",
                "    verifyZeroInteractions(mockOne, mockTwo);"
                ));
View Full Code Here

                "    InOrder inOrder = inOrder(mockOne, mockTwo);"
                ));
    }
   
    public void mocksHaveToBePassedWhenCreatingInOrder() {
        throw new MockitoException(join(
                "Method requires argument(s)!",
                "Pass mocks that require verification in order.",
                "For example:",
                "    InOrder inOrder = inOrder(mockOne, mockTwo);"
                ));
View Full Code Here

                "    InOrder inOrder = inOrder(mockOne, mockTwo);"
                ));
    }
   
    public void inOrderRequiresFamiliarMock() {
        throw new MockitoException(join(
                "InOrder can only verify mocks that were passed in during creation of InOrder.",
                "For example:",
                "    InOrder inOrder = inOrder(mockOne);",
                "    inOrder.verify(mockOne).doStuff();"
                ));
View Full Code Here

        cause.setStackTrace(actualInvocationStackTrace.getStackTrace());
        throw new NoInteractionsWanted(join("No interactions wanted"), cause);
    }
   
    public void cannotMockFinalClass(Class<?> clazz) {
        throw new MockitoException(join(
                "Mockito cannot mock final classes like: ",
                clazz.toString()
        ));
    }
View Full Code Here

                clazz.toString()
        ));
    }

    public void cannotStubVoidMethodWithAReturnValue() {
        throw new MockitoException(join(
                "Cannot stub a void method with a return value!",
                "Voids are usually stubbed with Throwables:",
                "    doThrow(exception).when(mock).someVoidMethod();"
             ));
    }
View Full Code Here

                "    doThrow(exception).when(mock).someVoidMethod();"
             ));
    }

    public void onlyVoidMethodsCanBeSetToDoNothing() {
        throw new MockitoException(join(
                "Only void methods can doNothing()!",
                "Example of correct use of doNothing():",
                "    doNothing().",
                "    doThrow(new RuntimeException())",
                "    .when(mock).someVoidMethod();",
View Full Code Here

TOP

Related Classes of org.mockito.exceptions.base.MockitoException

Copyright © 2018 www.massapicom. 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.