@Test public void shouldRemoveMockitoInternalsFromStackTraceWhenRealMethodThrows() throws Throwable { //given FilteredCGLIBProxyRealMethod realMethod = new FilteredCGLIBProxyRealMethod(new RealMethod() { public Object invoke(Object target, Object[] arguments) throws Throwable { return new Foo().throwSomething(); }}); //when try { realMethod.invoke(null, null); fail(); //then } catch (Exception e) { assertThat(e, hasMethodInStackTraceAt(0, "throwSomething")); assertThat(e, hasMethodInStackTraceAt(1, "invoke")); assertThat(e, hasMethodInStackTraceAt(2, "shouldRemoveMockitoInternalsFromStackTraceWhenRealMethodThrows")); } }
public Invocation(Object mock, MockitoMethod mockitoMethod, Object[] args, int sequenceNumber, RealMethod realMethod) { this.method = mockitoMethod; this.mock = mock; this.realMethod = realMethod; this.arguments = expandVarArgs(mockitoMethod.isVarArgs(), args); this.rawArguments = args; this.sequenceNumber = sequenceNumber; this.location = new Location(); }
@Test public void shouldBeAbleToCallRealMethod() throws Throwable { //when Invocation invocation = invocationOf(Foo.class, "bark", new RealMethod() { public Object invoke(Object target, Object[] arguments) throws Throwable { return new Foo().bark(); }}); //then assertEquals("woof", invocation.callRealMethod()); }
public InvocationImpl(Object mock, MockitoMethod mockitoMethod, Object[] args, int sequenceNumber, RealMethod realMethod) { this.method = mockitoMethod; this.mock = mock; this.realMethod = realMethod; this.arguments = ArgumentsProcessor.expandVarArgs(mockitoMethod.isVarArgs(), args); this.rawArguments = args; this.sequenceNumber = sequenceNumber; this.location = new LocationImpl(); }
protected static Invocation invocationOf(Class<?> type, String methodName, RealMethod realMethod) throws NoSuchMethodException { return new Invocation(new Object(), new SerializableMethod(type.getMethod(methodName, new Class[0])), new Object[0], 1, realMethod); }
protected static Invocation invocationOf(Class<?> type, String methodName, RealMethod realMethod) throws NoSuchMethodException { return new InvocationImpl(new Object(), new SerializableMethod(type.getMethod(methodName, new Class[0])), new Object[0], 1, realMethod); }