TracingFormServiceImpl implements TracingFormService { public boolean isReady() { return tracingFormDao.getTracingForm(PrimeroAppConfiguration.getApiBaseUrl()) != null && tracingFormDao .getTracingForm(PrimeroAppConfiguration.getApiBaseUrl()).getForm () != null; } TracingFormServiceImpl(TracingFormDao tracingFormDao); boolean isReady(); TracingTemplateForm getCPTemplate(); void saveOrUpdate(TracingForm tracingForm); static final String TAG; }
@Test public void should_be_true_when_form_is_ready() { TracingForm tracingForm = new TracingForm(); tracingForm.setForm(new Blob()); when(tracingFormDao.getTracingForm(PrimeroAppConfiguration.getApiBaseUrl())).thenReturn(tracingForm); boolean result = tracingFormService.isReady(); assertThat(result, is(true)); verify(tracingFormDao, times(2)).getTracingForm(PrimeroAppConfiguration.getApiBaseUrl()); }
@Test public void should_be_false_when_form_is_not_exist_in_db() { when(tracingFormDao.getTracingForm(PrimeroAppConfiguration.getApiBaseUrl())).thenReturn(null); assertThat(tracingFormService.isReady(), is(false)); verify(tracingFormDao, times(1)).getTracingForm(PrimeroAppConfiguration.getApiBaseUrl()); }
@Test public void should_be_false_when_tracing_form_can_not_get_form() { TracingForm tracingForm = new TracingForm(); when(tracingFormDao.getTracingForm(PrimeroAppConfiguration.getApiBaseUrl())).thenReturn(tracingForm); assertThat(tracingFormService.isReady(), is(false)); verify(tracingFormDao, times(2)).getTracingForm(PrimeroAppConfiguration.getApiBaseUrl()); }