MyFileUploader(FileSystem submitFs, Configuration conf) throws IOException { super(submitFs, false); // Initialize the real client, but don't start it. We don't need or want // to create an actual proxy because we only use this for mocking out the // getFileChecksum method. scClient.init(conf); when(mockscClient.getFileChecksum(any(Path.class))).thenAnswer( new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { Path file = (Path) invocation.getArguments()[0]; // Use the real scClient to generate the checksum. We use an // answer/mock combination to avoid having to spy on a real // SharedCacheClient object. return scClient.getFileChecksum(file); } }); }