CaseFormServiceImpl implements CaseFormService { public boolean isReady() { User.Role roleType = PrimeroAppConfiguration.getCurrentUser().getRoleType(); if (roleType == User.Role.CP) { return caseFormDao.getCaseForm(PrimeroAppConfiguration.MODULE_ID_CP, PrimeroAppConfiguration .getApiBaseUrl()) != null && caseFormDao .getCaseForm(PrimeroAppConfiguration.MODULE_ID_CP, PrimeroAppConfiguration.getApiBaseUrl()) .getForm() != null; } if (roleType == User.Role.GBV) { return caseFormDao.getCaseForm(PrimeroAppConfiguration.MODULE_ID_GBV, PrimeroAppConfiguration .getApiBaseUrl()) != null && caseFormDao.getCaseForm(PrimeroAppConfiguration.MODULE_ID_GBV, PrimeroAppConfiguration .getApiBaseUrl()).getForm() != null; } return caseFormDao.getCaseForm(PrimeroAppConfiguration.MODULE_ID_CP, PrimeroAppConfiguration.getApiBaseUrl()) != null && caseFormDao .getCaseForm(PrimeroAppConfiguration.MODULE_ID_CP, PrimeroAppConfiguration.getApiBaseUrl()).getForm() != null; } CaseFormServiceImpl(CaseFormDao caseFormDao); boolean isReady(); CaseTemplateForm getCPTemplate(); @Override CaseTemplateForm getGBVTemplate(); void saveOrUpdate(CaseForm caseForm); static final String TAG; }
@Test public void should_return_true_if_form_is_ready() throws Exception { User user = new User(); user.setRole(User.Role.CP.getValue()); Mockito.when(PrimeroAppConfiguration.getCurrentUser()).thenReturn(user); CaseForm cpCaseForm = createCPCaseForm(); when(caseFormDao.getCaseForm(PrimeroAppConfiguration.MODULE_ID_CP, PrimeroAppConfiguration.getApiBaseUrl())) .thenReturn(cpCaseForm); assertTrue(caseFormService.isReady()); }
@Test public void should_return_false_if_form_is_not_ready() throws Exception { User user = new User(); user.setRole(User.Role.CP.getValue()); Mockito.when(PrimeroAppConfiguration.getCurrentUser()).thenReturn(user); when(caseFormDao.getCaseForm(PrimeroAppConfiguration.MODULE_ID_CP, PrimeroAppConfiguration.getApiBaseUrl())) .thenReturn(null); assertFalse(caseFormService.isReady()); }