### Question:
CitationManager implements ICitationManager { @Override public void updateCitation(IUser user, String groupId, ICitation citation) throws ZoteroConnectionException, CitationIsOutdatedException, ZoteroHttpStatusException { long citationVersion = zoteroManager.getGroupItemVersion(user, groupId, citation.getKey()); Optional<ICitation> storedCitationOptional = citationRepository.findByKey(citation.getKey()); if (storedCitationOptional.isPresent()) { ICitation storedCitation = storedCitationOptional.get(); if (storedCitation.getVersion() != citationVersion) { throw new CitationIsOutdatedException(); } citationRepository.delete((Citation) storedCitationOptional.get()); } ICitation updatedCitation = zoteroManager.updateCitation(user, groupId, citation); citationRepository.save((Citation) updatedCitation); }  @PostConstruct void init(); @Override ICitation getCitation(IUser user, String groupId, String key); @Override ICitation getCitationFromZotero(IUser user, String groupId, String key); @Override void updateCitation(IUser user, String groupId, ICitation citation); @Override ICitation createCitation(IUser user, String groupId, List<String> collectionIds, ICitation citation); @Override ICitation updateCitationFromZotero(IUser user, String groupId, String itemKey); @Override List<ICitationGroup> getGroups(IUser user); @Override @SuppressWarnings("unchecked") CloseableIterator<ICitation> getAllGroupItems(IUser user, String groupId, String collectionId); @Override CitationResults getGroupItems(IUser user, String groupId, String collectionId, int page, String sortBy); @Override void forceGroupItemsRefresh(IUser user, String groupId, String collectionId, int page, String sortBy); @Override List<BibField> getItemTypeFields(IUser user, ItemType itemType); @Override List<String> getValidCreatorTypes(IUser user, ItemType itemType); @Override CitationPage getPrevAndNextCitation(IUser user, String groupId, String collectionId, int page, String sortBy,
            int index);  }### Answer:
@Test public void test_updateCitation_success() throws ZoteroConnectionException, CitationIsOutdatedException, ZoteroHttpStatusException { Mockito.when(zoteroManager.getGroupItemVersion(user, GROUP_ID, EXISTING_ID)).thenReturn(currentVersion); ICitation updatedCitation = new Citation(); updatedCitation.setKey(EXISTING_ID); updatedCitation.setVersion(new Long(2)); Mockito.when(zoteroManager.updateCitation(user, GROUP_ID, existingCitation)).thenReturn(updatedCitation); managerToTest.updateCitation(user, GROUP_ID, existingCitation); Mockito.verify(citationRepository).save((Citation)updatedCitation); }
@Test(expected=CitationIsOutdatedException.class) public void test_updateCitation_conflict() throws ZoteroConnectionException, CitationIsOutdatedException, ZoteroHttpStatusException { Mockito.when(zoteroManager.getGroupItemVersion(user, GROUP_ID, EXISTING_ID)).thenReturn(new Long(2)); managerToTest.updateCitation(user, GROUP_ID, existingCitation); }