Source:
public void setup() throws Exception { mockLedgerMetadataRegistry = new ConcurrentHashMap<>(); mockLedgerData = new ConcurrentHashMap<>(); mockNextLedgerId = new AtomicLong(1); fencedLedgers = new ConcurrentSkipListSet<>(); scheduler = new ScheduledThreadPoolExecutor(4); executor = OrderedSafeExecutor.newBuilder().build(); bookieWatcher = mock(BookieWatcher.class); bookieClient = mock(BookieClient.class); ledgerManager = mock(LedgerManager.class); ledgerIdGenerator = mock(LedgerIdGenerator.class); bk = mock(BookKeeper.class); Whitebox.setInternalState(bk, "bookieWatcher", bookieWatcher); Whitebox.setInternalState(bk, "disableEnsembleChangeFeature", mock(Feature.class)); NullStatsLogger nullStatsLogger = setupLoggers(); failedBookies = new ArrayList<>(); availableBookies = new HashSet<>(); when(bk.getCloseLock()).thenReturn(new ReentrantReadWriteLock()); when(bk.isClosed()).thenReturn(false); when(bk.getBookieWatcher()).thenReturn(bookieWatcher); when(bk.getExplicitLacInterval()).thenReturn(0); when(bk.getMainWorkerPool()).thenReturn(executor); when(bk.getBookieClient()).thenReturn(bookieClient); when(bk.getScheduler()).thenReturn(scheduler); when(bk.getReadSpeculativeRequestPolicy()).thenReturn(Optional.absent()); when(bk.getConf()).thenReturn(new ClientConfiguration()); when(bk.getStatsLogger()).thenReturn(nullStatsLogger); when(bk.getLedgerManager()).thenReturn(ledgerManager); when(bk.getLedgerIdGenerator()).thenReturn(ledgerIdGenerator); when(bk.getReturnRc(anyInt())).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0)); setupLedgerIdGenerator(); setupCreateLedgerMetadata(); setupReadLedgerMetadata(); setupWriteLedgerMetadata(); setupRemoveLedgerMetadata(); setupRegisterLedgerMetadataListener(); setupBookieWatcherForNewEnsemble(); setupBookieWatcherForEnsembleChange(); setupBookieClientReadEntry(); setupBookieClientAddEntry(); }

Target:
public void setup() throws Exception { mockLedgerMetadataRegistry = new ConcurrentHashMap<>(); mockLedgerData = new ConcurrentHashMap<>(); mockNextLedgerId = new AtomicLong(1); fencedLedgers = new ConcurrentSkipListSet<>(); scheduler = new ScheduledThreadPoolExecutor(4); executor = OrderedSafeExecutor.newBuilder().build(); bookieWatcher = mock(BookieWatcher.class); bookieClient = mock(BookieClient.class); ledgerManager = mock(LedgerManager.class); ledgerIdGenerator = mock(LedgerIdGenerator.class); bk = mock(BookKeeper.class); NullStatsLogger nullStatsLogger = setupLoggers(); failedBookies = new ArrayList<>(); availableBookies = new HashSet<>(); when(bk.getCloseLock()).thenReturn(new ReentrantReadWriteLock()); when(bk.isClosed()).thenReturn(false); when(bk.getBookieWatcher()).thenReturn(bookieWatcher); when(bk.getDisableEnsembleChangeFeature()).thenReturn(mock(Feature.class)); when(bk.getExplicitLacInterval()).thenReturn(0); when(bk.getMainWorkerPool()).thenReturn(executor); when(bk.getBookieClient()).thenReturn(bookieClient); when(bk.getScheduler()).thenReturn(scheduler); when(bk.getReadSpeculativeRequestPolicy()).thenReturn(Optional.absent()); when(bk.getConf()).thenReturn(new ClientConfiguration()); when(bk.getStatsLogger()).thenReturn(nullStatsLogger); when(bk.getLedgerManager()).thenReturn(ledgerManager); when(bk.getLedgerIdGenerator()).thenReturn(ledgerIdGenerator); when(bk.getReturnRc(anyInt())).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0)); setupLedgerIdGenerator(); setupCreateLedgerMetadata(); setupReadLedgerMetadata(); setupWriteLedgerMetadata(); setupRemoveLedgerMetadata(); setupRegisterLedgerMetadataListener(); setupBookieWatcherForNewEnsemble(); setupBookieWatcherForEnsembleChange(); setupBookieClientReadEntry(); setupBookieClientAddEntry(); }