TracingFormServiceImpl implements TracingFormService { public void saveOrUpdate(TracingForm tracingForm) { TracingForm existingTracingForm = tracingFormDao.getTracingForm(PrimeroAppConfiguration.getApiBaseUrl()); if (existingTracingForm == null) { Log.d(TAG, "save new tracing form"); tracingForm.setServerUrl(PrimeroAppConfiguration.getApiBaseUrl()); tracingForm.save(); } else { Log.d(TAG, "update existing tracing form"); existingTracingForm.setForm(tracingForm.getForm()); existingTracingForm.update(); } } TracingFormServiceImpl(TracingFormDao tracingFormDao); boolean isReady(); TracingTemplateForm getCPTemplate(); void saveOrUpdate(TracingForm tracingForm); static final String TAG; }
@Test public void should_save_when_existing_tracing_form_is_null() { when(tracingFormDao.getTracingForm(anyString())).thenReturn(null); TracingForm tracingForm = mock(TracingForm.class); tracingFormService.saveOrUpdate(tracingForm); verify(tracingForm, times(1)).save(); }
@Test public void should_update_when_existing_tracing_form_is_not_null() { TracingForm existingTracingForm = mock(TracingForm.class); when(tracingFormDao.getTracingForm(PrimeroAppConfiguration.getApiBaseUrl())).thenReturn(existingTracingForm); TracingForm tracingForm = mock(TracingForm.class); tracingFormService.saveOrUpdate(tracingForm); verify(existingTracingForm, times(1)).setForm(tracingForm.getForm()); verify(existingTracingForm, times(1)).update(); }