Source:
public void testReplicationDocWithEmptyId() throws Exception { CouchDB mockRemoteDb = mock(CouchDB.class); when(mockRemoteDb.changes(null, null, 1000)).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { JSONHelper jsonHelper = new JSONHelper(); FileReader fr = new FileReader(TestUtils.loadFixture ("fixture/testReplicationDocWithEmptyId_changes.json")); return jsonHelper.fromJson(fr, ChangesResult.class); } }); when(mockRemoteDb.exists()).thenReturn(true); when(mockRemoteDb.bulkGetRevisions((List<BulkGetRequest>)anyObject(), eq(false))).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { List<BulkGetRequest> requests = ((List<BulkGetRequest>)invocation.getArguments()[0]); System.out.println(requests.get(0).id); if (requests.get(0).id.equals("")) { return loadOpenRevsResponseFromFixture("fixture/testReplicationDocWithEmptyId_open_revs_1.json"); } else if (requests.get(0).id.equals("4d3b3f01362649d79b31d9092799a7e0")) { return loadOpenRevsResponseFromFixture("fixture/testReplicationDocWithEmptyId_open_revs_2.json"); } System.out.println("This shouldn't happen"); return null; } }); StrategyListener mockListener = mock(StrategyListener.class); final BasicPullStrategy pullStrategy = new BasicPullStrategy(createPullReplication()); pullStrategy.sourceDb = mockRemoteDb; pullStrategy.getEventBus().register(mockListener); pullStrategy.run(); Assert.assertEquals(this.datastore.getDocumentCount(), 1); verify(mockListener).complete(any(ReplicationStrategyCompleted.class)); verify(mockListener,never()).error(any(ReplicationStrategyErrored.class)); }

Target:
public void testReplicationDocWithEmptyId() throws Exception { CouchDB mockRemoteDb = mock(CouchDB.class); when(mockRemoteDb.changes(null, null, 1000)).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { JSONHelper jsonHelper = new JSONHelper(); FileReader fr = new FileReader(TestUtils.loadFixture ("fixture/testReplicationDocWithEmptyId_changes.json")); return jsonHelper.fromJson(fr, ChangesResult.class); } }); when(mockRemoteDb.exists()).thenReturn(true); Collection<String> revs = new ArrayList<String>(); revs.add("1-bd42b942b8b672f0289cf3cd1f67044c"); when(mockRemoteDb.getRevisions("", revs, new HashSet<String>(), false)).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return loadOpenRevsResponseFromFixture("testReplicationDocWithEmptyId_open_revs_1" + ".json"); } }); revs = new ArrayList<String>(); revs.add("1-13d33701a0954729ad029adf8fdc5a04"); when(mockRemoteDb.getRevisions("4d3b3f01362649d79b31d9092799a7e0", revs, new ArrayList <String>(), false)).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return loadOpenRevsResponseFromFixture ("fixture/testReplicationDocWithEmptyId_open_revs_2.json"); } }); StrategyListener mockListener = mock(StrategyListener.class); final BasicPullStrategy pullStrategy = new BasicPullStrategy(createPullReplication()); pullStrategy.sourceDb = mockRemoteDb; pullStrategy.getEventBus().register(mockListener); pullStrategy.run(); Assert.assertEquals(this.datastore.getDocumentCount(), 1); verify(mockListener).complete(any(ReplicationStrategyCompleted.class)); verify(mockListener,never()).error(any(ReplicationStrategyErrored.class)); }