public Object answer(InvocationOnMock invocation) throws Throwable { return invocation.callRealMethod(); } }
@Override public T answer(InvocationOnMock invocationOnMock) throws Throwable { result = (T) invocationOnMock.callRealMethod(); return result; }
public Object answer(InvocationOnMock invocation) throws Throwable { if (Modifier.isAbstract(invocation.getMethod().getModifiers())) { return RETURNS_DEFAULTS.answer(invocation); } return invocation.callRealMethod(); }
@Override public Object answer(InvocationOnMock invocation) throws Throwable { r.writestate.writesEnabled = false; return invocation.callRealMethod(); } }).when(spyR).doRegionCompactionPrep();
@Override public Object answer(InvocationOnMock invocation) throws Throwable { if (invocations++ < 10) { return offHeapChainMap; } else { return invocation.callRealMethod(); } } });
@Override public Object answer(InvocationOnMock invocation) throws Throwable { if (invocations++ < 10) { return offHeapChainMap; } else { return invocation.callRealMethod(); } } });
@Override public Object answer(InvocationOnMock invocation) throws Throwable { if (invocations++ < 10) { return offHeapChainMap; } else { return invocation.callRealMethod(); } } });
@Override public Void answer(InvocationOnMock invocation) throws Throwable { // pass on the error to the master invocation.callRealMethod(); // then count down the got error latch coordinatorReceivedErrorLatch.countDown(); return null; } }).when(coordinatorTask).receive(Mockito.any());
@Override public FSDataInputStream answer(InvocationOnMock invocation) throws Throwable { Thread.sleep(1500); // Sleep a while and wait report status invoked return (FSDataInputStream)invocation.callRealMethod(); } }).when(spiedFs).open(Mockito.<Path>any(), Mockito.anyInt());
@Override public FSDataInputStream answer(InvocationOnMock invocation) throws Throwable { if (count < 3) { throw new IOException(errors[count++]); } return (FSDataInputStream)invocation.callRealMethod(); } }).when(spiedFs).open(Mockito.<Path>any(), Mockito.anyInt());
@Override public Object answer(InvocationOnMock invocation) throws Throwable { try { return invocation.callRealMethod(); } catch (ReplicationException e) { LOG.debug("caught " + e); getListOfReplicatorsFailed.set(true); throw e; } } }).when(queueStorage).getAllWALs();
protected Object passThrough(InvocationOnMock invocation) throws Throwable { try { Object ret = invocation.callRealMethod(); returnValue = ret; return ret; } catch (Throwable t) { thrown = t; throw t; } finally { resultCounter.incrementAndGet(); resultLatch.countDown(); } }
@Override public Iterable<FileStatus> answer(InvocationOnMock invocation) throws Throwable { counter[0]++; LOG.debug(counter[0] + "/ " + expected + ") Wrapping call to getDeletableFiles for files: " + invocation.getArgument(0)); @SuppressWarnings("unchecked") Iterable<FileStatus> ret = (Iterable<FileStatus>) invocation.callRealMethod(); if (counter[0] >= expected) finished.countDown(); return ret; } }).when(delegateSpy).getDeletableFiles(Mockito.anyListOf(FileStatus.class));
@Override public Object answer( InvocationOnMock invocation ) throws Throwable { if ( !(reference instanceof RecordReference.SkippingReference<?>) ) { log.log( reporter, invocation ); } return invocation.callRealMethod(); } }
@Override public Boolean answer(InvocationOnMock invocation) throws Throwable { fs.create(racyFile).close(); FSUtils.logFileSystemState(fs, testDir, LOG); return (Boolean) invocation.callRealMethod(); } }).when(spy).isFileDeletable(Mockito.any());
@Override public Boolean answer(InvocationOnMock invocation) throws Throwable { fs.create(addedFile).close(); FSUtils.logFileSystemState(fs, testDir, LOG); return (Boolean) invocation.callRealMethod(); } }).when(spy).isFileDeletable(Mockito.any());
@Override public ResultScanner answer(InvocationOnMock invocation) throws Throwable { // first invocation return the busted mock scanner if (cnt++ < failCnt) { // create mock ResultScanner that always fails. Scan scan = mock(Scan.class); doReturn("bogus".getBytes()).when(scan).getStartRow(); // avoid npe ResultScanner scanner = mock(ResultScanner.class); // simulate TimeoutException / IOException doThrow(new IOException("Injected exception")).when(scanner).next(); return scanner; } // otherwise return the real scanner. return (ResultScanner) invocation.callRealMethod(); } };
private Object invokeWithError(InvocationOnMock invocation, boolean errorBeforeUpdate) throws Throwable { if (errorBeforeUpdate) { throw new ReplicationException("mock error before update"); } invocation.callRealMethod(); throw new ReplicationException("mock error after update"); }
@Override public Void answer(InvocationOnMock invocationOnMock) throws Throwable { invocationOnMock.callRealMethod(); Object[] args = invocationOnMock.getArguments(); project = (Project) args[0]; project.setProperty("group1:artifact1:jar", "path1"); project.setProperty("group2:artifact2:jar", "path2"); project.setProperty("group3:artifact3:jar:classifier3", "path3"); return null; } }).when(dependenciesTask).setProject(any(Project.class));
@Override public void configure(Map props) { super.configure( props ); DataSource ds = unwrap( DataSource.class ); DataSource dataSource = spy( ds ); try { Mockito.doAnswer( invocation -> { Connection connection = (Connection) invocation.callRealMethod(); Connection connectionSpy = spy( connection ); connectionSpyMap.put( connectionSpy, connection ); return connectionSpy; } ).when( dataSource ).getConnection(); } catch (SQLException e) { throw new IllegalStateException( e ); } ReflectionUtil.setField( C3P0ConnectionProvider.class.cast( this ), "ds", dataSource ); }