@Test public void testSaveDraftNew() { final String intygId = "intygId"; final String questionId = "questionId"; final String text = "text"; final String amne = "amne"; when(repo.findByIntygIdAndQuestionId(intygId, questionId)).thenReturn(null); boolean res = arendeDraftService.saveDraft(intygId, questionId, text, amne); assertTrue(res); verify(repo).findByIntygIdAndQuestionId(intygId, questionId); ArgumentCaptor<ArendeDraft> captor = ArgumentCaptor.forClass(ArendeDraft.class); verify(repo).save(captor.capture()); assertEquals(intygId, captor.getValue().getIntygId()); assertEquals(questionId, captor.getValue().getQuestionId()); assertEquals(text, captor.getValue().getText()); assertEquals(amne, captor.getValue().getAmne()); verifyNoMoreInteractions(repo); }
@Override public boolean saveDraft(String intygId, String questionId, String text, String amne) { ArendeDraft draft = arendeDraftRepository.findByIntygIdAndQuestionId(intygId, questionId); if (draft != null) { draft.setText(text); draft.setAmne(amne); } else { draft = createDraft(intygId, questionId, text, amne); } arendeDraftRepository.save(draft); return true; }
ArendeDraftServiceImpl implements ArendeDraftService { @Override public boolean saveDraft(String intygId, String questionId, String text, String amne) { ArendeDraft draft = arendeDraftRepository.findByIntygIdAndQuestionId(intygId, questionId); if (draft != null) { draft.setText(text); draft.setAmne(amne); } else { draft = createDraft(intygId, questionId, text, amne); } arendeDraftRepository.save(draft); return true; } }
ArendeDraftServiceImpl implements ArendeDraftService { @Override public boolean saveDraft(String intygId, String questionId, String text, String amne) { ArendeDraft draft = arendeDraftRepository.findByIntygIdAndQuestionId(intygId, questionId); if (draft != null) { draft.setText(text); draft.setAmne(amne); } else { draft = createDraft(intygId, questionId, text, amne); } arendeDraftRepository.save(draft); return true; }  }
ArendeDraftServiceImpl implements ArendeDraftService { @Override public boolean saveDraft(String intygId, String questionId, String text, String amne) { ArendeDraft draft = arendeDraftRepository.findByIntygIdAndQuestionId(intygId, questionId); if (draft != null) { draft.setText(text); draft.setAmne(amne); } else { draft = createDraft(intygId, questionId, text, amne); } arendeDraftRepository.save(draft); return true; }  @Override boolean saveDraft(String intygId, String questionId, String text, String amne); @Override boolean delete(String intygId, String questionId); @Override List<ArendeDraft> listAnswerDrafts(String intygId); @Override ArendeDraft getQuestionDraft(String intygId); }
ArendeDraftServiceImpl implements ArendeDraftService { @Override public boolean saveDraft(String intygId, String questionId, String text, String amne) { ArendeDraft draft = arendeDraftRepository.findByIntygIdAndQuestionId(intygId, questionId); if (draft != null) { draft.setText(text); draft.setAmne(amne); } else { draft = createDraft(intygId, questionId, text, amne); } arendeDraftRepository.save(draft); return true; }  @Override boolean saveDraft(String intygId, String questionId, String text, String amne); @Override boolean delete(String intygId, String questionId); @Override List<ArendeDraft> listAnswerDrafts(String intygId); @Override ArendeDraft getQuestionDraft(String intygId);  }