Package org.mockito.exceptions.base

Examples of org.mockito.exceptions.base.MockitoException


            return declaringClass.getDeclaredMethod(methodName, parameterTypes);
        } catch (SecurityException e) {
            String message = String.format(
                    "The method %1$s.%2$s is probably private or protected and cannot be mocked.\n" +
                            "Please report this as a defect with an example of how to reproduce it.", declaringClass, methodName);
            throw new MockitoException(message, e);
        } catch (NoSuchMethodException e) {
            String message = String.format(
                    "The method %1$s.%2$s does not exists and you should not get to this point.\n" +
                            "Please report this as a defect with an example of how to reproduce it.", declaringClass, methodName);
            throw new MockitoException(message, e);
        }
    }   
View Full Code Here


                                .spiedInstance(instance)
                                .defaultAnswer(Mockito.CALLS_REAL_METHODS)
                                .name(field.getName())));
                    }
                } catch (IllegalAccessException e) {
                    throw new MockitoException("Problems initiating spied field " + field.getName(), e);
                }
            }
        }
    }
View Full Code Here

    public Object read() {
        try {
            return field.get(target);
        } catch (Exception e) {
            throw new MockitoException("Cannot read state from field: " + field + ", on instance: " + target);
        }
    }
View Full Code Here

    final LinkedList elements;

    public ReturnsElementsOf(Collection elements) {
        if (elements == null) {
            throw new MockitoException("ReturnsElementsOf does not accept null as constructor argument.\n" +
                "Please pass a collection instance");
        }
        this.elements = new LinkedList(elements);
    }
View Full Code Here

        changer.enableAccess(field);

        try {
            return acquireFieldInstance();
        } catch(IllegalAccessException e) {
            throw new MockitoException("Problems initializing field '" + field.getName() + "' of type '" + field.getType().getSimpleName() + "'", e);
        } finally {
            changer.safelyDisableAccess(field);
        }
    }
View Full Code Here

        }
    }

    private void checkNotLocal(Field field) {
        if(field.getType().isLocalClass()) {
            throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is a local class.");
        }
    }
View Full Code Here

        }
    }

    private void checkNotInner(Field field) {
        if(field.getType().isMemberClass() && !Modifier.isStatic(field.getType().getModifiers())) {
            throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is an inner class.");
        }
    }
View Full Code Here

        }
    }

    private void checkNotInterface(Field field) {
        if(field.getType().isInterface()) {
            throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is an interface.");
        }
    }
View Full Code Here

        }
    }

    private void checkNotAbstract(Field field) {
        if(Modifier.isAbstract(field.getType().getModifiers())) {
            throw new MockitoException("the type '" + field.getType().getSimpleName() + " is an abstract class.");
        }
    }
View Full Code Here

                Object newFieldInstance = constructor.newInstance(noArg);
                new FieldSetter(testClass, field).set(newFieldInstance);

                return field.get(testClass);
            } catch (NoSuchMethodException e) {
                throw new MockitoException("the type '" + field.getType().getSimpleName() + "' has no default constructor", e);
            } catch (InvocationTargetException e) {
                throw new MockitoException("the default constructor of type '" + field.getType().getSimpleName() + "' has raised an exception (see the stack trace for cause): " + e.getTargetException().toString(), e);
            } catch (InstantiationException e) {
                throw new MockitoException("InstantiationException (see the stack trace for cause): " + e.toString(), e);
            } catch (IllegalAccessException e) {
                throw new MockitoException("IllegalAccessException (see the stack trace for cause): " + e.toString(), e);
            } finally {
                if(constructor != null) {
                    changer.safelyDisableAccess(constructor);
                }
            }
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.