method2testcases
stringlengths
118
3.08k
### Question: SettingsRepository extends DrishtiRepository { public static void onUpgrade(SQLiteDatabase database) { database.execSQL(ADD_SETTINGS_VERSION); database.execSQL(ADD_SETTINGS_TYPE); database.execSQL(ADD_SETTINGS_SYNC_STATUS); } static void onUpgrade(SQLiteDatabase database); void updateSetting(String key, String value); void updateSetting(Setting setting); void updateBLOB(String key, byte[] value); String querySetting(String key, String defaultValue); byte[] queryBLOB(String key); Setting querySetting(String key); List<Setting> querySettingsByType(String type); List<Setting> queryUnsyncedSettings(); int queryUnsyncedSettingsCount(); static final String SETTINGS_TABLE_NAME; static final String SETTINGS_KEY_COLUMN; static final String SETTINGS_VALUE_COLUMN; static final String SETTINGS_VERSION_COLUMN; static final String SETTINGS_TYPE_COLUMN; static final String SETTINGS_SYNC_STATUS_COLUMN; static final String SETTINGS_SQL; static final String ADD_SETTINGS_VERSION; static final String ADD_SETTINGS_TYPE; static final String ADD_SETTINGS_SYNC_STATUS; }### Answer: @Test public void testOnUpgradeExecutesCorrectSQLStatement() { settingsRepository.onUpgrade(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(3)).execSQL(anyString()); }
### Question: SettingsRepository extends DrishtiRepository { public byte[] queryBLOB(String key) { byte[] value = null; Cursor cursor = null; try { SQLiteDatabase database = masterRepository.getReadableDatabase(); cursor = database.query(SETTINGS_TABLE_NAME, new String[]{SETTINGS_VALUE_COLUMN}, SETTINGS_KEY_COLUMN + " = ?", new String[]{key}, null, null, null, "1"); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { value = cursor.getBlob(0); } } catch (Exception e) { Timber.e(e); } finally { if (cursor != null) { cursor.close(); } } return value; } static void onUpgrade(SQLiteDatabase database); void updateSetting(String key, String value); void updateSetting(Setting setting); void updateBLOB(String key, byte[] value); String querySetting(String key, String defaultValue); byte[] queryBLOB(String key); Setting querySetting(String key); List<Setting> querySettingsByType(String type); List<Setting> queryUnsyncedSettings(); int queryUnsyncedSettingsCount(); static final String SETTINGS_TABLE_NAME; static final String SETTINGS_KEY_COLUMN; static final String SETTINGS_VALUE_COLUMN; static final String SETTINGS_VERSION_COLUMN; static final String SETTINGS_TYPE_COLUMN; static final String SETTINGS_SYNC_STATUS_COLUMN; static final String SETTINGS_SQL; static final String ADD_SETTINGS_VERSION; static final String ADD_SETTINGS_TYPE; static final String ADD_SETTINGS_SYNC_STATUS; }### Answer: @Test public void assertqueryBlob() { Mockito.when(sqLiteDatabase.query(anyString(), any(String[].class), anyString(), any(String[].class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class), anyString())).thenReturn(getCursor()); Assert.assertEquals(settingsRepository.queryBLOB(""), null); }
### Question: SettingsRepository extends DrishtiRepository { public void updateSetting(String key, String value) { ContentValues values = new ContentValues(); values.put(SETTINGS_KEY_COLUMN, key); values.put(SETTINGS_VALUE_COLUMN, value); replace(values); } static void onUpgrade(SQLiteDatabase database); void updateSetting(String key, String value); void updateSetting(Setting setting); void updateBLOB(String key, byte[] value); String querySetting(String key, String defaultValue); byte[] queryBLOB(String key); Setting querySetting(String key); List<Setting> querySettingsByType(String type); List<Setting> queryUnsyncedSettings(); int queryUnsyncedSettingsCount(); static final String SETTINGS_TABLE_NAME; static final String SETTINGS_KEY_COLUMN; static final String SETTINGS_VALUE_COLUMN; static final String SETTINGS_VERSION_COLUMN; static final String SETTINGS_TYPE_COLUMN; static final String SETTINGS_SYNC_STATUS_COLUMN; static final String SETTINGS_SQL; static final String ADD_SETTINGS_VERSION; static final String ADD_SETTINGS_TYPE; static final String ADD_SETTINGS_SYNC_STATUS; }### Answer: @Test public void testUpdateSetting() { Setting s = new Setting(); s.setKey("test"); s.setValue("testValue"); s.setVersion("test"); s.setType("test"); s.setSyncStatus("test"); ArgumentCaptor<ContentValues> contentValuesArgumentCaptor = ArgumentCaptor.forClass(ContentValues.class); Mockito.doReturn(1L).when(sqLiteDatabase).replace(Mockito.eq(SETTINGS_TABLE_NAME), Mockito.nullable(String.class), contentValuesArgumentCaptor.capture()); settingsRepository.updateSetting(s); Mockito.verify(sqLiteDatabase, Mockito.times(1)).replace(anyString(), Mockito.isNull(String.class), any(ContentValues.class)); Assert.assertEquals(contentValuesArgumentCaptor.getValue().get(SETTINGS_KEY_COLUMN), "test"); }
### Question: SettingsRepository extends DrishtiRepository { protected Setting queryCore(Cursor cursor) { Setting value = new Setting(); value.setKey(cursor.getString(cursor.getColumnIndex(SETTINGS_KEY_COLUMN))); value.setValue(cursor.getString(cursor.getColumnIndex(SETTINGS_VALUE_COLUMN))); value.setType(cursor.getString(cursor.getColumnIndex(SETTINGS_TYPE_COLUMN))); value.setVersion(cursor.getString(cursor.getColumnIndex(SETTINGS_VERSION_COLUMN))); value.setSyncStatus(cursor.getString(cursor.getColumnIndex(SETTINGS_SYNC_STATUS_COLUMN))); return value; } static void onUpgrade(SQLiteDatabase database); void updateSetting(String key, String value); void updateSetting(Setting setting); void updateBLOB(String key, byte[] value); String querySetting(String key, String defaultValue); byte[] queryBLOB(String key); Setting querySetting(String key); List<Setting> querySettingsByType(String type); List<Setting> queryUnsyncedSettings(); int queryUnsyncedSettingsCount(); static final String SETTINGS_TABLE_NAME; static final String SETTINGS_KEY_COLUMN; static final String SETTINGS_VALUE_COLUMN; static final String SETTINGS_VERSION_COLUMN; static final String SETTINGS_TYPE_COLUMN; static final String SETTINGS_SYNC_STATUS_COLUMN; static final String SETTINGS_SQL; static final String ADD_SETTINGS_VERSION; static final String ADD_SETTINGS_TYPE; static final String ADD_SETTINGS_SYNC_STATUS; }### Answer: @Test public void testQueryCore() { MatrixCursor cursor = getMatrixCursor(); cursor.moveToFirst(); Setting s = settingsRepository.queryCore(cursor); Assert.assertEquals(s.getKey(), "testKey"); }
### Question: ChildRepository extends DrishtiRepository { @Override protected void onCreate(SQLiteDatabase database) { database.execSQL(CHILD_SQL); } void add(Child child); void update(Child child); List<Child> all(); Child find(String caseId); List<Child> findChildrenByCaseIds(String... caseIds); void updateDetails(String caseId, Map<String, String> details); List<Child> findByMotherCaseId(String caseId); long count(); void close(String caseId); List<Child> allChildrenWithMotherAndEC(); void updatePhotoPath(String caseId, String imagePath); List<Child> findAllChildrenByECId(String ecId); void delete(String childId); static final String CHILD_TABLE_NAME; static final String PHOTO_PATH_COLUMN; static final String NOT_CLOSED; static final String[] CHILD_TABLE_COLUMNS; }### Answer: @Test public void assertOnCreateCallDatabaseExecSql() { childRepository.onCreate(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(1)).execSQL(Mockito.anyString()); }
### Question: ChildRepository extends DrishtiRepository { public void add(Child child) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.insert(CHILD_TABLE_NAME, null, createValuesFor(child)); } void add(Child child); void update(Child child); List<Child> all(); Child find(String caseId); List<Child> findChildrenByCaseIds(String... caseIds); void updateDetails(String caseId, Map<String, String> details); List<Child> findByMotherCaseId(String caseId); long count(); void close(String caseId); List<Child> allChildrenWithMotherAndEC(); void updatePhotoPath(String caseId, String imagePath); List<Child> findAllChildrenByECId(String ecId); void delete(String childId); static final String CHILD_TABLE_NAME; static final String PHOTO_PATH_COLUMN; static final String NOT_CLOSED; static final String[] CHILD_TABLE_COLUMNS; }### Answer: @Test public void assertAddChildCallsDatabaseSqlInsert() { childRepository.updateMasterRepository(repository); Mockito.when(repository.getWritableDatabase()).thenReturn(sqLiteDatabase); childRepository.add(getMockChild()); Mockito.verify(sqLiteDatabase, Mockito.times(1)).insert(Mockito.anyString(), Mockito.isNull(String.class), Mockito.any(ContentValues.class)); }
### Question: ChildRepository extends DrishtiRepository { public void update(Child child) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.update(CHILD_TABLE_NAME, createValuesFor(child), ID_COLUMN + " = ?", new String[]{child.caseId()}); } void add(Child child); void update(Child child); List<Child> all(); Child find(String caseId); List<Child> findChildrenByCaseIds(String... caseIds); void updateDetails(String caseId, Map<String, String> details); List<Child> findByMotherCaseId(String caseId); long count(); void close(String caseId); List<Child> allChildrenWithMotherAndEC(); void updatePhotoPath(String caseId, String imagePath); List<Child> findAllChildrenByECId(String ecId); void delete(String childId); static final String CHILD_TABLE_NAME; static final String PHOTO_PATH_COLUMN; static final String NOT_CLOSED; static final String[] CHILD_TABLE_COLUMNS; }### Answer: @Test public void assertUpdateChildCallsDatabaseSqlUpdate() { childRepository.updateMasterRepository(repository); Mockito.when(repository.getWritableDatabase()).thenReturn(sqLiteDatabase); childRepository.update(getMockChild()); Mockito.verify(sqLiteDatabase, Mockito.times(1)).update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: ChildRepository extends DrishtiRepository { public List<Child> all() { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database .query(CHILD_TABLE_NAME, CHILD_TABLE_COLUMNS, IS_CLOSED_COLUMN + " = ?", new String[]{NOT_CLOSED}, null, null, null, null); return readAll(cursor); } void add(Child child); void update(Child child); List<Child> all(); Child find(String caseId); List<Child> findChildrenByCaseIds(String... caseIds); void updateDetails(String caseId, Map<String, String> details); List<Child> findByMotherCaseId(String caseId); long count(); void close(String caseId); List<Child> allChildrenWithMotherAndEC(); void updatePhotoPath(String caseId, String imagePath); List<Child> findAllChildrenByECId(String ecId); void delete(String childId); static final String CHILD_TABLE_NAME; static final String PHOTO_PATH_COLUMN; static final String NOT_CLOSED; static final String[] CHILD_TABLE_COLUMNS; }### Answer: @Test public void assertAllChildReturnsListOfChilds() { childRepository.updateMasterRepository(repository); Mockito.when(repository.getReadableDatabase()).thenReturn(sqLiteDatabase); Mockito.when(sqLiteDatabase.query(Mockito.anyString(), Mockito.any(String[].class), Mockito.anyString(), Mockito.any(String[].class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class))).thenReturn(getChildCursor()); Assert.assertNotNull(childRepository.all()); Mockito.verify(sqLiteDatabase, Mockito.times(1)).query(Mockito.anyString(), Mockito.any(String[].class), Mockito.anyString(), Mockito.any(String[].class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class)); }
### Question: ChildRepository extends DrishtiRepository { public List<Child> findChildrenByCaseIds(String... caseIds) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.rawQuery( String.format("SELECT * FROM %s WHERE %s IN (%s)", CHILD_TABLE_NAME, ID_COLUMN, insertPlaceholdersForInClause(caseIds.length)), caseIds); return readAll(cursor); } void add(Child child); void update(Child child); List<Child> all(); Child find(String caseId); List<Child> findChildrenByCaseIds(String... caseIds); void updateDetails(String caseId, Map<String, String> details); List<Child> findByMotherCaseId(String caseId); long count(); void close(String caseId); List<Child> allChildrenWithMotherAndEC(); void updatePhotoPath(String caseId, String imagePath); List<Child> findAllChildrenByECId(String ecId); void delete(String childId); static final String CHILD_TABLE_NAME; static final String PHOTO_PATH_COLUMN; static final String NOT_CLOSED; static final String[] CHILD_TABLE_COLUMNS; }### Answer: @Test public void assertFindChildSReturnsListOfChilds() { childRepository.updateMasterRepository(repository); Mockito.when(repository.getReadableDatabase()).thenReturn(sqLiteDatabase); Mockito.when(sqLiteDatabase.rawQuery(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(getChildCursor()); Assert.assertNotNull(childRepository.findChildrenByCaseIds("0")); Mockito.verify(sqLiteDatabase, Mockito.times(1)).rawQuery(Mockito.anyString(), Mockito.any(String[].class)); }
### Question: ChildRepository extends DrishtiRepository { public void delete(String childId) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.delete(CHILD_TABLE_NAME, ID_COLUMN + "= ?", new String[]{childId}); } void add(Child child); void update(Child child); List<Child> all(); Child find(String caseId); List<Child> findChildrenByCaseIds(String... caseIds); void updateDetails(String caseId, Map<String, String> details); List<Child> findByMotherCaseId(String caseId); long count(); void close(String caseId); List<Child> allChildrenWithMotherAndEC(); void updatePhotoPath(String caseId, String imagePath); List<Child> findAllChildrenByECId(String ecId); void delete(String childId); static final String CHILD_TABLE_NAME; static final String PHOTO_PATH_COLUMN; static final String NOT_CLOSED; static final String[] CHILD_TABLE_COLUMNS; }### Answer: @Test public void assertDeleteCallsDatabaseDelete() { childRepository.updateMasterRepository(repository); Mockito.when(repository.getReadableDatabase()).thenReturn(sqLiteDatabase); Mockito.when(repository.getWritableDatabase()).thenReturn(sqLiteDatabase); Mockito.when(sqLiteDatabase.delete(Mockito.anyString(), Mockito.anyString(), Mockito.any(String[].class))).thenReturn(1); childRepository.delete(""); Mockito.verify(sqLiteDatabase, Mockito.times(1)).delete(Mockito.anyString(), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: ClientDaoImpl extends EventClientRepository implements ClientDao { @Override public List<Patient> findClientById(String id) { Client client = fetchClientByBaseEntityId(id); return Collections.singletonList(ClientConverter.convertClientToPatientResource(client)); } @Override List<Patient> findClientById(String id); @Override List<Patient> findFamilyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyByResidence(String structureId); @Override List<Patient> findFamilyMemberyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyMemberByResidence(String structureId); @Override List<Patient> findClientByRelationship(String relationship, String id); }### Answer: @Test public void testFindClientById() throws Exception { String query = "SELECT json FROM client WHERE baseEntityId = ? "; String[] params = new String[]{"41587456-b7c8-4c4e-b433-23a786f742fc"}; when(sqLiteDatabase.rawQuery(anyString(), any())).thenReturn(getCursor(1)); List<Patient> patients = clientDao.findClientById(params[0]); verify(sqLiteDatabase).rawQuery(query, params); assertEquals(1, patients.size()); Patient patient = patients.iterator().next(); assertNotNull(patient); assertEquals("03b1321a-d1fb-4fd0-b1cd-a3f3509fc6a6", patient.getId()); }
### Question: ClientDaoImpl extends EventClientRepository implements ClientDao { @Override public List<Patient> findFamilyByJurisdiction(String jurisdiction) { return fetchClients(String.format("select %s from %s where %s =? and %s =?", client_column.json, clientTable.name(), client_column.locationId, client_column.clientType), new String[]{jurisdiction, AllConstants.FAMILY}) .stream() .map(ClientConverter::convertClientToPatientResource) .collect(Collectors.toList()); } @Override List<Patient> findClientById(String id); @Override List<Patient> findFamilyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyByResidence(String structureId); @Override List<Patient> findFamilyMemberyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyMemberByResidence(String structureId); @Override List<Patient> findClientByRelationship(String relationship, String id); }### Answer: @Test public void testFindFamilyByJurisdiction() throws Exception { String query = "select json from client where locationId =? and clientType =?"; String[] params = new String[]{"41587456-b7c8-4c4e-b433-23a786f742fc", "Family"}; when(sqLiteDatabase.rawQuery(anyString(), any())).thenReturn(getCursor()); List<Patient> patients = clientDao.findFamilyByJurisdiction(params[0]); verify(sqLiteDatabase).rawQuery(query, params); assertEquals(16, patients.size()); Patient patient = patients.iterator().next(); assertNotNull(patient); assertEquals("03b1321a-d1fb-4fd0-b1cd-a3f3509fc6a6", patient.getId()); }
### Question: ClientDaoImpl extends EventClientRepository implements ClientDao { @Override public List<Patient> findFamilyByResidence(String structureId) { return fetchClients(String.format("select %s from %s where %s =? and %s =?", client_column.json, clientTable.name(), client_column.residence, client_column.clientType), new String[]{structureId, AllConstants.FAMILY}) .stream() .map(ClientConverter::convertClientToPatientResource) .collect(Collectors.toList()); } @Override List<Patient> findClientById(String id); @Override List<Patient> findFamilyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyByResidence(String structureId); @Override List<Patient> findFamilyMemberyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyMemberByResidence(String structureId); @Override List<Patient> findClientByRelationship(String relationship, String id); }### Answer: @Test public void testFindFamilyByResidence() throws Exception { String query = "select json from client where residence =? and clientType =?"; String[] params = new String[]{"41587456-b7c8-4c4e-b433-23a786f742fc", "Family"}; when(sqLiteDatabase.rawQuery(anyString(), any())).thenReturn(getCursor()); List<Patient> patients = clientDao.findFamilyByResidence(params[0]); verify(sqLiteDatabase).rawQuery(query, params); assertEquals(16, patients.size()); Patient patient = patients.iterator().next(); assertNotNull(patient); assertEquals("03b1321a-d1fb-4fd0-b1cd-a3f3509fc6a6", patient.getId()); }
### Question: ClientDaoImpl extends EventClientRepository implements ClientDao { @Override public List<Patient> findFamilyMemberyByJurisdiction(String jurisdiction) { return fetchClients(String.format("select %s from %s where %s =? and (%s is null or %s !=? )", client_column.json, clientTable.name(), client_column.locationId, client_column.clientType, client_column.clientType), new String[]{jurisdiction, AllConstants.FAMILY}) .stream() .map(ClientConverter::convertClientToPatientResource) .collect(Collectors.toList()); } @Override List<Patient> findClientById(String id); @Override List<Patient> findFamilyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyByResidence(String structureId); @Override List<Patient> findFamilyMemberyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyMemberByResidence(String structureId); @Override List<Patient> findClientByRelationship(String relationship, String id); }### Answer: @Test public void testFindFamilyMemberByJurisdiction() throws Exception { String query = "select json from client where locationId =? and (clientType is null or clientType !=? )"; String[] params = new String[]{"41587456-b7c8-4c4e-b433-23a786f742fc", "Family"}; when(sqLiteDatabase.rawQuery(anyString(), any())).thenReturn(getCursor(10)); List<Patient> patients = clientDao.findFamilyMemberyByJurisdiction(params[0]); verify(sqLiteDatabase).rawQuery(query, params); assertEquals(10, patients.size()); Patient patient = patients.iterator().next(); assertNotNull(patient); assertEquals("03b1321a-d1fb-4fd0-b1cd-a3f3509fc6a6", patient.getId()); }
### Question: ClientDaoImpl extends EventClientRepository implements ClientDao { @Override public List<Patient> findFamilyMemberByResidence(String structureId) { return fetchClients(String.format("select %s from %s where %s =? and (%s is null or %s !=? )", client_column.json, clientTable.name(), client_column.residence, client_column.clientType, client_column.clientType), new String[]{structureId, AllConstants.FAMILY}) .stream() .map(ClientConverter::convertClientToPatientResource) .collect(Collectors.toList()); } @Override List<Patient> findClientById(String id); @Override List<Patient> findFamilyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyByResidence(String structureId); @Override List<Patient> findFamilyMemberyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyMemberByResidence(String structureId); @Override List<Patient> findClientByRelationship(String relationship, String id); }### Answer: @Test public void testFindFamilyMemberByResidence() throws Exception { String query = "select json from client where residence =? and (clientType is null or clientType !=? )"; String[] params = new String[]{"41587456-b7c8-4c4e-b433-23a786f742fc", "Family"}; when(sqLiteDatabase.rawQuery(anyString(), any())).thenReturn(getCursor(2)); List<Patient> patients = clientDao.findFamilyMemberByResidence(params[0]); verify(sqLiteDatabase).rawQuery(query, params); assertEquals(2, patients.size()); Patient patient = patients.iterator().next(); assertNotNull(patient); assertEquals("03b1321a-d1fb-4fd0-b1cd-a3f3509fc6a6", patient.getId()); }
### Question: ClientDaoImpl extends EventClientRepository implements ClientDao { @Override public List<Patient> findClientByRelationship(String relationship, String id) { return CoreLibrary.getInstance().context().getClientRelationshipRepository().findClientByRelationship(relationship, id) .stream() .map(ClientConverter::convertClientToPatientResource) .collect(Collectors.toList()); } @Override List<Patient> findClientById(String id); @Override List<Patient> findFamilyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyByResidence(String structureId); @Override List<Patient> findFamilyMemberyByJurisdiction(String jurisdiction); @Override List<Patient> findFamilyMemberByResidence(String structureId); @Override List<Patient> findClientByRelationship(String relationship, String id); }### Answer: @Test public void testFindClientByRelationship() throws Exception { String query = "SELECT json FROM client_relationship JOIN client ON base_entity_id=baseEntityId WHERE relationship=? AND relational_id =?"; String[] params = new String[]{"41587456-b7c8-4c4e-b433-23a786f742fc", "Family"}; when(sqLiteDatabase.rawQuery(anyString(), any())).thenReturn(getCursor(2)); List<Patient> patients = clientDao.findClientByRelationship(params[0], params[1]); verify(sqLiteDatabase).rawQuery(query, params); assertEquals(2, patients.size()); Patient patient = patients.iterator().next(); assertNotNull(patient); assertEquals("03b1321a-d1fb-4fd0-b1cd-a3f3509fc6a6", patient.getId()); }
### Question: EventDaoImpl extends EventClientRepository implements EventDao { @Override public List<QuestionnaireResponse> findEventsByEntityIdAndPlan(String resourceId, String planIdentifier) { return fetchEvents(String.format("select %s from %s where %s =? and (%s is null or %s =? )", event_column.json, eventTable.name(), event_column.baseEntityId, event_column.planId, event_column.planId), new String[]{resourceId, planIdentifier}) .stream() .map(this::convert) .collect(Collectors.toList()); } @Override List<QuestionnaireResponse> findEventsByEntityIdAndPlan(String resourceId, String planIdentifier); }### Answer: @Test public void testFindEventsByEntityIdAndPlan() throws Exception { String query = "select json from event where baseEntityId =? and (planId is null or planId =? )"; String[] params = new String[]{"location.properties.uid:41587456-b7c8-4c4e-b433-23a786f742fc", "IRS_2018_S1"}; when(sqLiteDatabase.rawQuery(query, params)).thenReturn(EventClientRepositoryTest.getEventCursor()); List<QuestionnaireResponse> questionnaireResponses = eventDao.findEventsByEntityIdAndPlan("location.properties.uid:41587456-b7c8-4c4e-b433-23a786f742fc", "IRS_2018_S1"); verify(sqLiteDatabase).rawQuery(query, params); assertEquals(20, questionnaireResponses.size()); QuestionnaireResponse questionnaireResponse = questionnaireResponses.iterator().next(); assertEquals("Household_Registration", questionnaireResponse.getQuestionnaire().getValue()); assertEquals("2184aaaa-d1cf-4099-945a-c66bd8a93e1e", questionnaireResponse.getId()); assertEquals(11, questionnaireResponse.getItem().size()); }
### Question: FormDataRepository extends DrishtiRepository { @JavascriptInterface public String queryUniqueResult(String sql, String[] selectionArgs) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.rawQuery(sql, selectionArgs); cursor.moveToFirst(); Map<String, String> result = readARow(cursor); cursor.close(); return new Gson().toJson(result); } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertqueryUniqueResult() { assertNotNull(formDataRepository.queryUniqueResult("sql",new String[0])); }
### Question: FormDataRepository extends DrishtiRepository { @JavascriptInterface public String queryList(String sql, String[] selectionArgs) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.rawQuery(sql, selectionArgs); List<Map<String, String>> results = new ArrayList<Map<String, String>>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { results.add(readARow(cursor)); cursor.moveToNext(); } cursor.close(); return new Gson().toJson(results); } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertqueryList() { assertNotNull(formDataRepository.queryList("sql",new String[0])); } @Test public void assertqueryListWithdetails() { Mockito.when(sqLiteDatabase.rawQuery(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(getCursor2()); assertNotNull(formDataRepository.queryList("sql", new String[0])); }
### Question: FormDataRepository extends DrishtiRepository { public FormSubmission fetchFromSubmission(String instanceId) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_SUBMISSION_TABLE_NAME, FORM_SUBMISSION_TABLE_COLUMNS, INSTANCE_ID_COLUMN + " = ?", new String[]{instanceId}, null, null, null); return readFormSubmission(cursor).get(0); } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertfetchFromSubmission() { assertNotNull(formDataRepository.fetchFromSubmission("")); }
### Question: FormDataRepository extends DrishtiRepository { public List<FormSubmission> getPendingFormSubmissions() { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_SUBMISSION_TABLE_NAME, FORM_SUBMISSION_TABLE_COLUMNS, SYNC_STATUS_COLUMN + " = ?", new String[]{PENDING.value()}, null, null, null); return readFormSubmission(cursor); } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertgetPendingFormSubmissions() { assertNotNull(formDataRepository.getPendingFormSubmissions()); }
### Question: FormDataRepository extends DrishtiRepository { public boolean submissionExists(String instanceId) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_SUBMISSION_TABLE_NAME, new String[]{INSTANCE_ID_COLUMN}, INSTANCE_ID_COLUMN + " = ?", new String[]{instanceId}, null, null, null); boolean isThere = cursor.moveToFirst(); cursor.close(); return isThere; } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertsubmissionExists() { assertEquals(formDataRepository.submissionExists("1"), true); }
### Question: FormDataRepository extends DrishtiRepository { @JavascriptInterface public String saveEntity(String entityType, String fields) { SQLiteDatabase database = masterRepository.getWritableDatabase(); Map<String, String> updatedFieldsMap = new Gson() .fromJson(fields, new TypeToken<Map<String, String>>() { }.getType()); String entityId = updatedFieldsMap.get(ENTITY_ID_FIELD_NAME); Map<String, String> entityMap = loadEntityMap(entityType, database, entityId); ContentValues contentValues = getContentValues(updatedFieldsMap, entityType, entityMap); database.replace(entityType, null, contentValues); return entityId; } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertsaveEntity() { assertEquals(formDataRepository.saveEntity(EligibleCoupleRepository.EC_TABLE_NAME, "{\"id\":\"1\"}"), "1"); }
### Question: FormDataRepository extends DrishtiRepository { public Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs) { Map<String, String> map = new HashMap<String, String>(); Cursor cursor = null; try { SQLiteDatabase database = masterRepository.getReadableDatabase(); cursor = database.rawQuery(sql, selectionArgs); map = sqliteRowToMap(cursor); } catch (Exception e) { Timber.e(e); } finally { if (cursor != null) { cursor.close(); } } return map; } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertgetMapFromSQLQuery() { assertNotNull(formDataRepository.getMapFromSQLQuery("",null)); }
### Question: FormDataRepository extends DrishtiRepository { public void updateServerVersion(String instanceId, String serverVersion) { SQLiteDatabase database = masterRepository.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(SERVER_VERSION_COLUMN, serverVersion); database.update(FORM_SUBMISSION_TABLE_NAME, values, INSTANCE_ID_COLUMN + " = ?", new String[]{instanceId}); } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertupdateServerVersion() { formDataRepository.updateServerVersion("", ""); Mockito.verify(sqLiteDatabase, Mockito.times(1)).update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: FormDataRepository extends DrishtiRepository { @Override protected void onCreate(SQLiteDatabase database) { database.execSQL(FORM_SUBMISSION_SQL); } FormDataRepository(); void addTableColumnMap(String key, String[] val); @JavascriptInterface String queryUniqueResult(String sql, String[] selectionArgs); @JavascriptInterface String queryList(String sql, String[] selectionArgs); @JavascriptInterface String saveFormSubmission(String paramsJSON, String data, String formDataDefinitionVersion); @JavascriptInterface void saveFormSubmission(FormSubmission formSubmission); FormSubmission fetchFromSubmission(String instanceId); List<FormSubmission> getPendingFormSubmissions(); long getPendingFormSubmissionsCount(); void markFormSubmissionsAsSynced(List<FormSubmission> formSubmissions); void updateServerVersion(String instanceId, String serverVersion); boolean submissionExists(String instanceId); @JavascriptInterface String saveEntity(String entityType, String fields); @JavascriptInterface String generateIdFor(String entityType); Map<String, String> getMapFromSQLQuery(String sql, String[] selectionArgs); Map<String, String> sqliteRowToMap(Cursor cursor); static final String INSTANCE_ID_COLUMN; static final String ENTITY_ID_COLUMN; static final String ID_COLUMN; static final String[] FORM_SUBMISSION_TABLE_COLUMNS; }### Answer: @Test public void assertOnCreateCallsDatabaseExec() { formDataRepository.onCreate(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(1)).execSQL(Mockito.anyString()); }
### Question: P2PReceiverTransferDao extends BaseP2PTransferDao implements ReceiverTransferDao { @Override public TreeSet<DataType> getDataTypes() { return (TreeSet<DataType>) dataTypes.clone(); } @Override TreeSet<DataType> getDataTypes(); @VisibleForTesting P2PClassifier<JSONObject> getP2PClassifier(); @Override long receiveJson(@NonNull DataType dataType, @NonNull JSONArray jsonArray); @Override long receiveMultimedia(@NonNull DataType dataType, @NonNull File file, @Nullable HashMap<String, Object> multimediaDetails, long fileRecordId); }### Answer: @Test public void getDataTypesShouldReturnAClonedMatchOfDataTypes() { TreeSet<DataType> dataTypes = p2PReceiverTransferDao.getDataTypes(); Assert.assertTrue(p2PReceiverTransferDao.dataTypes != dataTypes); Assert.assertEquals(p2PReceiverTransferDao.dataTypes.size(), dataTypes.size()); Assert.assertEquals(p2PReceiverTransferDao.dataTypes.first(), dataTypes.first()); Assert.assertEquals(p2PReceiverTransferDao.dataTypes.last(), dataTypes.last()); }
### Question: P2PReceiverTransferDao extends BaseP2PTransferDao implements ReceiverTransferDao { @VisibleForTesting public P2PClassifier<JSONObject> getP2PClassifier() { return DrishtiApplication.getInstance().getP2PClassifier(); } @Override TreeSet<DataType> getDataTypes(); @VisibleForTesting P2PClassifier<JSONObject> getP2PClassifier(); @Override long receiveJson(@NonNull DataType dataType, @NonNull JSONArray jsonArray); @Override long receiveMultimedia(@NonNull DataType dataType, @NonNull File file, @Nullable HashMap<String, Object> multimediaDetails, long fileRecordId); }### Answer: @Test public void getP2PClassifier() { Assert.assertEquals(DrishtiApplication.getInstance().getP2PClassifier(), p2PReceiverTransferDao.getP2PClassifier()); }
### Question: AllEligibleCouples { public void close(String entityId) { alertRepository.deleteAllAlertsForEntity(entityId); timelineEventRepository.deleteAllTimelineEventsForEntity(entityId); eligibleCoupleRepository.close(entityId); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void shouldCloseEC() throws Exception { allEligibleCouples.close("entity id 1"); Mockito.verify(alertRepository).deleteAllAlertsForEntity("entity id 1"); Mockito.verify(eligibleCoupleRepository).close("entity id 1"); Mockito.verify(timelineEventRepository).deleteAllTimelineEventsForEntity("entity id 1"); }
### Question: AllEligibleCouples { public EligibleCouple findByCaseID(String caseId) { return eligibleCoupleRepository.findByCaseID(caseId); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void assertFindByCaseID() { Mockito.when(eligibleCoupleRepository.findByCaseID(Mockito.anyString())).thenReturn(Mockito.mock(EligibleCouple.class)); Assert.assertNotNull(allEligibleCouples.findByCaseID("")); }
### Question: AllEligibleCouples { public List<EligibleCouple> findByCaseIDs(List<String> caseIds) { return eligibleCoupleRepository.findByCaseIDs(caseIds.toArray(new String[caseIds.size()])); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void assertFindByCaseIDs() { Mockito.when(eligibleCoupleRepository.findByCaseIDs(Mockito.anyString())).thenReturn(Mockito.mock(ArrayList.class)); Assert.assertNotNull(allEligibleCouples.findByCaseIDs(new ArrayList<String>())); }
### Question: AllEligibleCouples { public void updatePhotoPath(String caseId, String imagePath) { eligibleCoupleRepository.updatePhotoPath(caseId, imagePath); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void assertUpdatePhotoPathCallsRepositoryUpdate() { Mockito.doNothing().when(eligibleCoupleRepository).updatePhotoPath(Mockito.anyString(), Mockito.anyString()); allEligibleCouples.updatePhotoPath("", ""); Mockito.verify(eligibleCoupleRepository, Mockito.times(1)).updatePhotoPath(Mockito.anyString(), Mockito.anyString()); }
### Question: AllEligibleCouples { public void mergeDetails(String entityId, Map<String, String> details) { eligibleCoupleRepository.mergeDetails(entityId, details); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void assertMergeDetailsCallsRepositoryUpdate() { Mockito.doNothing().when(eligibleCoupleRepository).mergeDetails(Mockito.anyString(), Mockito.any(Map.class)); allEligibleCouples.mergeDetails("", new HashMap<String, String>()); Mockito.verify(eligibleCoupleRepository, Mockito.times(1)).mergeDetails(Mockito.anyString(), Mockito.any(Map.class)); }
### Question: AllEligibleCouples { public long count() { return eligibleCoupleRepository.count(); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void assertCountreturnsLong() { Mockito.when(eligibleCoupleRepository.count()).thenReturn(0l); Assert.assertEquals(allEligibleCouples.count(), 0l); }
### Question: AllEligibleCouples { public long fpCount() { return eligibleCoupleRepository.fpCount(); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void assertFPCountreturnsLong() { Mockito.when(eligibleCoupleRepository.fpCount()).thenReturn(0l); Assert.assertEquals(allEligibleCouples.fpCount(), 0l); }
### Question: AllEligibleCouples { public List<String> villages() { return eligibleCoupleRepository.villages(); } AllEligibleCouples(EligibleCoupleRepository eligibleCoupleRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); List<EligibleCouple> all(); EligibleCouple findByCaseID(String caseId); long count(); long fpCount(); List<String> villages(); List<EligibleCouple> findByCaseIDs(List<String> caseIds); void updatePhotoPath(String caseId, String imagePath); void close(String entityId); void mergeDetails(String entityId, Map<String, String> details); }### Answer: @Test public void assertVillagesReturnsList() { Mockito.when(eligibleCoupleRepository.villages()).thenReturn(new ArrayList<String>()); Assert.assertNotNull(allEligibleCouples.villages()); }
### Question: MotherRepository extends DrishtiRepository { @Override protected void onCreate(SQLiteDatabase database) { database.execSQL(MOTHER_SQL); database.execSQL(MOTHER_TYPE_INDEX_SQL); database.execSQL(MOTHER_REFERENCE_DATE_INDEX_SQL); } void add(Mother mother); void switchToPNC(String caseId); List<Mother> allANCs(); Mother findById(String entityId); List<Mother> allPNCs(); long ancCount(); long pncCount(); Mother findOpenCaseByCaseID(String caseId); List<Mother> findAllCasesForEC(String ecCaseId); List<Mother> findByCaseIds(String... caseIds); List<Pair<Mother, EligibleCouple>> allMothersOfATypeWithEC(String type); void closeAllCasesForEC(String ecCaseId); void close(String caseId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void update(Mother mother); static final String MOTHER_TABLE_NAME; static final String ID_COLUMN; static final String EC_CASEID_COLUMN; static final String THAYI_CARD_NUMBER_COLUMN; static final String REF_DATE_COLUMN; static final String DETAILS_COLUMN; static final String TYPE_ANC; static final String TYPE_PNC; static final String[] MOTHER_TABLE_COLUMNS; }### Answer: @Test public void assertOnCreateCallDatabaseExecSql() { motherRepository.onCreate(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(3)).execSQL(Mockito.anyString()); }
### Question: MotherRepository extends DrishtiRepository { public void add(Mother mother) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.insert(MOTHER_TABLE_NAME, null, createValuesFor(mother, TYPE_ANC)); } void add(Mother mother); void switchToPNC(String caseId); List<Mother> allANCs(); Mother findById(String entityId); List<Mother> allPNCs(); long ancCount(); long pncCount(); Mother findOpenCaseByCaseID(String caseId); List<Mother> findAllCasesForEC(String ecCaseId); List<Mother> findByCaseIds(String... caseIds); List<Pair<Mother, EligibleCouple>> allMothersOfATypeWithEC(String type); void closeAllCasesForEC(String ecCaseId); void close(String caseId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void update(Mother mother); static final String MOTHER_TABLE_NAME; static final String ID_COLUMN; static final String EC_CASEID_COLUMN; static final String THAYI_CARD_NUMBER_COLUMN; static final String REF_DATE_COLUMN; static final String DETAILS_COLUMN; static final String TYPE_ANC; static final String TYPE_PNC; static final String[] MOTHER_TABLE_COLUMNS; }### Answer: @Test public void assertAddMotherCallsDatabaseSqlInsert() { motherRepository.updateMasterRepository(repository); Mockito.when(repository.getWritableDatabase()).thenReturn(sqLiteDatabase); motherRepository.add(getMockMother()); Mockito.verify(sqLiteDatabase, Mockito.times(1)).insert(Mockito.anyString(), Mockito.isNull(String.class), Mockito.any(ContentValues.class)); }
### Question: MotherRepository extends DrishtiRepository { public void update(Mother mother) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.update(MOTHER_TABLE_NAME, createValuesFor(mother, TYPE_ANC), ID_COLUMN + " = ?", new String[]{mother.caseId()}); } void add(Mother mother); void switchToPNC(String caseId); List<Mother> allANCs(); Mother findById(String entityId); List<Mother> allPNCs(); long ancCount(); long pncCount(); Mother findOpenCaseByCaseID(String caseId); List<Mother> findAllCasesForEC(String ecCaseId); List<Mother> findByCaseIds(String... caseIds); List<Pair<Mother, EligibleCouple>> allMothersOfATypeWithEC(String type); void closeAllCasesForEC(String ecCaseId); void close(String caseId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void update(Mother mother); static final String MOTHER_TABLE_NAME; static final String ID_COLUMN; static final String EC_CASEID_COLUMN; static final String THAYI_CARD_NUMBER_COLUMN; static final String REF_DATE_COLUMN; static final String DETAILS_COLUMN; static final String TYPE_ANC; static final String TYPE_PNC; static final String[] MOTHER_TABLE_COLUMNS; }### Answer: @Test public void assertUpdateMotherCallsDatabaseUpdate() { motherRepository.updateMasterRepository(repository); Mockito.when(repository.getWritableDatabase()).thenReturn(sqLiteDatabase); Mockito.when(sqLiteDatabase.update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class))).thenReturn(1); motherRepository.update(getMockMother()); Mockito.verify(sqLiteDatabase, Mockito.times(1)).update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: MotherRepository extends DrishtiRepository { public void closeAllCasesForEC(String ecCaseId) { List<Mother> mothers = findAllCasesForEC(ecCaseId); for (Mother mother : mothers) { close(mother.caseId()); } } void add(Mother mother); void switchToPNC(String caseId); List<Mother> allANCs(); Mother findById(String entityId); List<Mother> allPNCs(); long ancCount(); long pncCount(); Mother findOpenCaseByCaseID(String caseId); List<Mother> findAllCasesForEC(String ecCaseId); List<Mother> findByCaseIds(String... caseIds); List<Pair<Mother, EligibleCouple>> allMothersOfATypeWithEC(String type); void closeAllCasesForEC(String ecCaseId); void close(String caseId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void update(Mother mother); static final String MOTHER_TABLE_NAME; static final String ID_COLUMN; static final String EC_CASEID_COLUMN; static final String THAYI_CARD_NUMBER_COLUMN; static final String REF_DATE_COLUMN; static final String DETAILS_COLUMN; static final String TYPE_ANC; static final String TYPE_PNC; static final String[] MOTHER_TABLE_COLUMNS; }### Answer: @Test public void assertCloseAllCasesForECCallsDatabaseUpdate() { motherRepository.updateMasterRepository(repository); Mockito.when(repository.getReadableDatabase()).thenReturn(sqLiteDatabase); Mockito.when(repository.getWritableDatabase()).thenReturn(sqLiteDatabase); Mockito.when(sqLiteDatabase.query(Mockito.anyString(), Mockito.any(String[].class), Mockito.anyString(), Mockito.any(String[].class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class))).thenReturn(getMotherCursor()); motherRepository.closeAllCasesForEC("0"); }
### Question: LocationRepository extends BaseRepository { public List<Location> getAllLocations() { Cursor cursor = null; List<Location> locations = new ArrayList<>(); try { cursor = getReadableDatabase().rawQuery("SELECT * FROM " + getLocationTableName(), null); while (cursor.moveToNext()) { locations.add(readCursor(cursor)); } cursor.close(); } catch (Exception e) { Timber.e(e); } finally { if (cursor != null) cursor.close(); } return locations; } static void createTable(SQLiteDatabase database); void addOrUpdate(Location location); void deleteLocations(@NonNull Set<String> locationIdentifiers); List<Location> getAllLocations(); List<String> getAllLocationIds(); Location getLocationById(String id); Location getLocationById(String id, String tableName); Location getLocationByUUId(String uuid); List<Location> getLocationsByParentId(String parentId); List<Location> getLocationsByParentId(String parentId, String tableName); Location getLocationByName(String name); List<Location> getLocationsByIds(List<String> ids); List<Location> getLocationsByIds(List<String> ids, Boolean inclusive); List<Location> getAllUnsynchedLocation(); void markLocationsAsSynced(String locationId); List<Location> getLocationsByTagName(String tagName); }### Answer: @Test public void tesGetAllLocations() { when(sqLiteDatabase.rawQuery("SELECT * FROM location", null)).thenReturn(getCursor()); List<Location> allLocations = locationRepository.getAllLocations(); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals("SELECT * FROM location", stringArgumentCaptor.getValue()); assertEquals(1, allLocations.size()); Location location = allLocations.get(0); assertEquals(locationJson, stripTimezone(gson.toJson(location))); }
### Question: LocationRepository extends BaseRepository { public List<Location> getLocationsByParentId(String parentId) { return getLocationsByParentId(parentId, getLocationTableName()); } static void createTable(SQLiteDatabase database); void addOrUpdate(Location location); void deleteLocations(@NonNull Set<String> locationIdentifiers); List<Location> getAllLocations(); List<String> getAllLocationIds(); Location getLocationById(String id); Location getLocationById(String id, String tableName); Location getLocationByUUId(String uuid); List<Location> getLocationsByParentId(String parentId); List<Location> getLocationsByParentId(String parentId, String tableName); Location getLocationByName(String name); List<Location> getLocationsByIds(List<String> ids); List<Location> getLocationsByIds(List<String> ids, Boolean inclusive); List<Location> getAllUnsynchedLocation(); void markLocationsAsSynced(String locationId); List<Location> getLocationsByTagName(String tagName); }### Answer: @Test public void tesGetLocationsByParentId() { when(sqLiteDatabase.rawQuery("SELECT * FROM location WHERE parent_id =?", new String[]{"21"})).thenReturn(getCursor()); List<Location> allLocations = locationRepository.getLocationsByParentId("21"); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals("SELECT * FROM location WHERE parent_id =?", stringArgumentCaptor.getValue()); assertEquals(1, argsCaptor.getValue().length); assertEquals("21", argsCaptor.getValue()[0]); assertEquals(1, allLocations.size()); Location location = allLocations.get(0); assertEquals(locationJson, stripTimezone(gson.toJson(location))); }
### Question: LocationRepository extends BaseRepository { public Location getLocationById(String id) { return getLocationById(id, getLocationTableName()); } static void createTable(SQLiteDatabase database); void addOrUpdate(Location location); void deleteLocations(@NonNull Set<String> locationIdentifiers); List<Location> getAllLocations(); List<String> getAllLocationIds(); Location getLocationById(String id); Location getLocationById(String id, String tableName); Location getLocationByUUId(String uuid); List<Location> getLocationsByParentId(String parentId); List<Location> getLocationsByParentId(String parentId, String tableName); Location getLocationByName(String name); List<Location> getLocationsByIds(List<String> ids); List<Location> getLocationsByIds(List<String> ids, Boolean inclusive); List<Location> getAllUnsynchedLocation(); void markLocationsAsSynced(String locationId); List<Location> getLocationsByTagName(String tagName); }### Answer: @Test public void tesGetLocationById() { when(sqLiteDatabase.rawQuery("SELECT * FROM location WHERE _id =?", new String[]{"3734"})).thenReturn(getCursor()); Location location = locationRepository.getLocationById("3734"); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals("SELECT * FROM location WHERE _id =?", stringArgumentCaptor.getValue()); assertEquals(1, argsCaptor.getValue().length); assertEquals("3734", argsCaptor.getValue()[0]); assertEquals(locationJson, stripTimezone(gson.toJson(location))); }
### Question: LocationRepository extends BaseRepository { public Location getLocationByName(String name) { Cursor cursor = null; try { cursor = getReadableDatabase().rawQuery("SELECT * FROM " + getLocationTableName() + " WHERE " + NAME + " =?", new String[]{name}); if (cursor.moveToFirst()) { return readCursor(cursor); } cursor.close(); } catch (Exception e) { Timber.e(e); } finally { if (cursor != null) cursor.close(); } return null; } static void createTable(SQLiteDatabase database); void addOrUpdate(Location location); void deleteLocations(@NonNull Set<String> locationIdentifiers); List<Location> getAllLocations(); List<String> getAllLocationIds(); Location getLocationById(String id); Location getLocationById(String id, String tableName); Location getLocationByUUId(String uuid); List<Location> getLocationsByParentId(String parentId); List<Location> getLocationsByParentId(String parentId, String tableName); Location getLocationByName(String name); List<Location> getLocationsByIds(List<String> ids); List<Location> getLocationsByIds(List<String> ids, Boolean inclusive); List<Location> getAllUnsynchedLocation(); void markLocationsAsSynced(String locationId); List<Location> getLocationsByTagName(String tagName); }### Answer: @Test public void tesGetLocationByName() { when(sqLiteDatabase.rawQuery("SELECT * FROM location WHERE name =?", new String[]{"01_5"})).thenReturn(getCursor()); Location location = locationRepository.getLocationByName("01_5"); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals("SELECT * FROM location WHERE name =?", stringArgumentCaptor.getValue()); assertEquals(1, argsCaptor.getValue().length); assertEquals("01_5", argsCaptor.getValue()[0]); assertEquals(locationJson, stripTimezone(gson.toJson(location))); }
### Question: LocationRepository extends BaseRepository { public List<Location> getLocationsByTagName(String tagName) { LocationTagRepository locationTagRepository = new LocationTagRepository(); List<LocationTag> locationTags = locationTagRepository.getLocationTagsByTagName(tagName); List<String> locationIds = locationTags.stream() .map(LocationTag::getLocationId) .collect(Collectors.toList()); return getLocationsByIds(locationIds); } static void createTable(SQLiteDatabase database); void addOrUpdate(Location location); void deleteLocations(@NonNull Set<String> locationIdentifiers); List<Location> getAllLocations(); List<String> getAllLocationIds(); Location getLocationById(String id); Location getLocationById(String id, String tableName); Location getLocationByUUId(String uuid); List<Location> getLocationsByParentId(String parentId); List<Location> getLocationsByParentId(String parentId, String tableName); Location getLocationByName(String name); List<Location> getLocationsByIds(List<String> ids); List<Location> getLocationsByIds(List<String> ids, Boolean inclusive); List<Location> getAllUnsynchedLocation(); void markLocationsAsSynced(String locationId); List<Location> getLocationsByTagName(String tagName); }### Answer: @Test public void testGetLocationsByTagName() { when(sqLiteDatabase.rawQuery("SELECT * FROM location_tag WHERE name =?", new String[]{"Facility"})).thenReturn(getLocationTagsCursor()); when(sqLiteDatabase.rawQuery("SELECT * FROM location WHERE _id IN (?)", new String[]{"1"})).thenReturn(getCursor()); List<Location> tags = locationRepository.getLocationsByTagName("Facility"); assertNotNull(tags); assertEquals(1, tags.size()); }
### Question: ManifestRepository extends BaseRepository { public List<Manifest> getAllManifests() { List<Manifest> manifests = new ArrayList<>(); try (Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + getManifestTableName() + " ORDER BY " + CREATED_AT + " DESC ", null)) { while (cursor.moveToNext()) { manifests.add(readCursor(cursor)); } } catch (Exception e) { Timber.e(e); } return manifests; } static void createTable(SQLiteDatabase database); static void addVersionColumn(@NonNull SQLiteDatabase database); static boolean isVersionColumnExist(@NonNull SQLiteDatabase database); void addOrUpdate(Manifest manifest); List<Manifest> getAllManifests(); List<Manifest> getManifestByAppVersion(String appVersion); Manifest getActiveManifest(); void delete(String manifestId); }### Answer: @Test public void testGetAllManifests() { when(sqLiteDatabase.rawQuery("SELECT * FROM " + MANIFEST_TABLE + " ORDER BY " + CREATED_AT + " DESC ", null)).thenReturn(getCursor()); List<Manifest> manifests = manifestRepository.getAllManifests(); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals("SELECT * FROM manifest ORDER BY created_at DESC ", stringArgumentCaptor.getValue()); assertEquals(1, manifests.size()); Manifest manifest = manifests.get(0); assertEquals("1", manifest.getId()); }
### Question: ManifestRepository extends BaseRepository { public List<Manifest> getManifestByAppVersion(String appVersion) { List<Manifest> manifests = new ArrayList<>(); try (Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + getManifestTableName() + " WHERE " + APP_VERSION + " =?", new String[]{appVersion})) { while (cursor.moveToNext()) { manifests.add(readCursor(cursor)); } } catch (Exception e) { Timber.e(e); } return manifests; } static void createTable(SQLiteDatabase database); static void addVersionColumn(@NonNull SQLiteDatabase database); static boolean isVersionColumnExist(@NonNull SQLiteDatabase database); void addOrUpdate(Manifest manifest); List<Manifest> getAllManifests(); List<Manifest> getManifestByAppVersion(String appVersion); Manifest getActiveManifest(); void delete(String manifestId); }### Answer: @Test public void testGetManifestByAppVersion() { String appVersion = "1.1.0"; when(sqLiteDatabase.rawQuery("SELECT * FROM " + MANIFEST_TABLE + " WHERE " + APP_VERSION + " =?", new String[]{appVersion})).thenReturn(getCursor()); List<Manifest> manifests = manifestRepository.getManifestByAppVersion(appVersion); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals("SELECT * FROM " + MANIFEST_TABLE + " WHERE " + APP_VERSION + " =?", stringArgumentCaptor.getValue()); assertEquals(1, argsCaptor.getValue().length); assertEquals(appVersion, argsCaptor.getValue()[0]); Manifest manifest = manifests.get(0); assertEquals("1", manifest.getId()); }
### Question: ManifestRepository extends BaseRepository { public Manifest getActiveManifest() { try (Cursor cursor = getReadableDatabase().rawQuery("SELECT * FROM " + getManifestTableName() + " WHERE " + ACTIVE + " =?", new String[]{"1"})) { if (cursor.moveToFirst()) { return readCursor(cursor); } } catch (Exception e) { Timber.e(e); } return null; } static void createTable(SQLiteDatabase database); static void addVersionColumn(@NonNull SQLiteDatabase database); static boolean isVersionColumnExist(@NonNull SQLiteDatabase database); void addOrUpdate(Manifest manifest); List<Manifest> getAllManifests(); List<Manifest> getManifestByAppVersion(String appVersion); Manifest getActiveManifest(); void delete(String manifestId); }### Answer: @Test public void testGetActiveManifest() { when(sqLiteDatabase.rawQuery("SELECT * FROM " + MANIFEST_TABLE + " WHERE " + ACTIVE + " =?", new String[]{"1"})).thenReturn(getCursor()); Manifest manifest = manifestRepository.getActiveManifest(); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals("SELECT * FROM " + MANIFEST_TABLE + " WHERE " + ACTIVE + " =?", stringArgumentCaptor.getValue()); assertEquals(1, argsCaptor.getValue().length); assertEquals("1", argsCaptor.getValue()[0]); assertEquals(true, manifest.isActive()); }
### Question: Hia2ReportRepository extends BaseRepository { public List<JSONObject> getUnSyncedReports(int limit) { List<JSONObject> reports = new ArrayList<JSONObject>(); String query = "select " + report_column.json + "," + report_column.syncStatus + " from " + Table.hia2_report.name() + " where " + report_column.syncStatus + " = ? and length(" + report_column.json + ")>2 order by " + report_column.updatedAt + " asc limit " + limit; Cursor cursor = null; try { cursor = getWritableDatabase().rawQuery(query, new String[]{BaseRepository.TYPE_Unsynced}); while (cursor.moveToNext()) { String jsonEventStr = (cursor.getString(0)); if (StringUtils.isBlank(jsonEventStr) || "{}".equals(jsonEventStr)) { continue; } jsonEventStr = jsonEventStr.replaceAll("'", ""); JSONObject jsonObectEvent = new JSONObject(jsonEventStr); reports.add(jsonObectEvent); } } catch (Exception e) { Timber.e(e.getMessage()); } finally { if (cursor != null) { cursor.close(); } } return reports; } List<JSONObject> getUnSyncedReports(int limit); List<String> getUnValidatedReportFormSubmissionIds(int limit); void addReport(JSONObject jsonObject); void markReportAsSynced(String formSubmissionId); void markReportValidationStatus(String formSubmissionId, boolean valid); void markReportsAsSynced(List<JSONObject> syncedReports); Boolean checkIfExistsByFormSubmissionId(Table table, String formSubmissionId); }### Answer: @Test public void assertGetUnSyncedReportsReturnsList() { when(sqliteDatabase.rawQuery(anyString(), any(String[].class))).thenReturn(getCursorSyncStatus()); assertNotNull(hia2ReportRepository.getUnSyncedReports(1)); }
### Question: Hia2ReportRepository extends BaseRepository { public List<String> getUnValidatedReportFormSubmissionIds(int limit) { List<String> ids = new ArrayList<String>(); final String validateFilter = " where " + report_column.syncStatus + " = ? " + " AND ( " + report_column.validationStatus + " is NULL or " + report_column.validationStatus + " != ? ) "; String query = "select " + report_column.formSubmissionId + " from " + Table.hia2_report.name() + validateFilter + ORDER_BY + report_column.updatedAt + " asc limit " + limit; Cursor cursor = null; try { cursor = getWritableDatabase().rawQuery(query, new String[]{BaseRepository.TYPE_Synced, BaseRepository.TYPE_Valid}); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { String id = cursor.getString(0); ids.add(id); cursor.moveToNext(); } } } catch (Exception e) { Timber.e(e); } finally { if (cursor != null) { cursor.close(); } } return ids; } List<JSONObject> getUnSyncedReports(int limit); List<String> getUnValidatedReportFormSubmissionIds(int limit); void addReport(JSONObject jsonObject); void markReportAsSynced(String formSubmissionId); void markReportValidationStatus(String formSubmissionId, boolean valid); void markReportsAsSynced(List<JSONObject> syncedReports); Boolean checkIfExistsByFormSubmissionId(Table table, String formSubmissionId); }### Answer: @Test public void assertGetUnValidatedReportFormSubmissionIdsReturnsList() { when(sqliteDatabase.rawQuery(anyString(), any(String[].class))).thenReturn(getCursorSyncStatus()); assertNotNull(hia2ReportRepository.getUnValidatedReportFormSubmissionIds(1)); }
### Question: Hia2ReportRepository extends BaseRepository { public void markReportsAsSynced(List<JSONObject> syncedReports) { try { if (syncedReports != null && !syncedReports.isEmpty()) { for (JSONObject report : syncedReports) { String formSubmissionId = report.getString(report_column.formSubmissionId .name()); markReportAsSynced(formSubmissionId); } } } catch (Exception e) { Timber.e(e); } } List<JSONObject> getUnSyncedReports(int limit); List<String> getUnValidatedReportFormSubmissionIds(int limit); void addReport(JSONObject jsonObject); void markReportAsSynced(String formSubmissionId); void markReportValidationStatus(String formSubmissionId, boolean valid); void markReportsAsSynced(List<JSONObject> syncedReports); Boolean checkIfExistsByFormSubmissionId(Table table, String formSubmissionId); }### Answer: @Test public void assertmarkReportsAsSyncedCallsDatabaseUpdate() throws Exception { String jsonReport = "{\"reportType\":\"reportType\", \"formSubmissionId\":\"formSubmissionId\"}"; List<JSONObject> reports = new ArrayList<>(); reports.add(new JSONObject(jsonReport)); hia2ReportRepository.markReportsAsSynced(reports); verify(sqliteDatabase, Mockito.times(1)).update(anyString(), any(ContentValues.class), anyString(), any(String[].class)); }
### Question: DetailsRepository extends DrishtiRepository { @Override protected void onCreate(SQLiteDatabase database) { database.execSQL(SQL); } void add(String baseEntityId, String key, String value, Long timestamp); Map<String, String> getAllDetailsForClient(String baseEntityId); Map<String, String> updateDetails(CommonPersonObjectClient commonPersonObjectClient); Map<String, String> updateDetails(CommonPersonObject commonPersonObject); boolean deleteDetails(String baseEntityId); }### Answer: @Test public void assertOnCreateCallsDatabaseExec() { detailsRepository.onCreate(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(1)).execSQL(Mockito.anyString()); }
### Question: DetailsRepository extends DrishtiRepository { public Map<String, String> getAllDetailsForClient(String baseEntityId) { Cursor cursor = null; Map<String, String> clientDetails = new HashMap<String, String>(); try { SQLiteDatabase db = masterRepository.getReadableDatabase(); String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + BASE_ENTITY_ID_COLUMN + " =?"; cursor = db.rawQuery(query, new String[]{baseEntityId}); if (cursor != null && cursor.moveToFirst()) { do { String key = cursor.getString(cursor.getColumnIndex(KEY_COLUMN)); String value = cursor.getString(cursor.getColumnIndex(VALUE_COLUMN)); clientDetails.put(key, value); } while (cursor.moveToNext()); } return clientDetails; } catch (Exception e) { Timber.e(e); } finally { if (cursor != null) { cursor.close(); } } return clientDetails; } void add(String baseEntityId, String key, String value, Long timestamp); Map<String, String> getAllDetailsForClient(String baseEntityId); Map<String, String> updateDetails(CommonPersonObjectClient commonPersonObjectClient); Map<String, String> updateDetails(CommonPersonObject commonPersonObject); boolean deleteDetails(String baseEntityId); }### Answer: @Test public void assertgetAllDetailsForClient() { Map<String, String> detail = detailsRepository.getAllDetailsForClient("1"); Assert.assertNotNull(detail); Assert.assertEquals(detail.get("key"), "value"); }
### Question: DetailsRepository extends DrishtiRepository { public Map<String, String> updateDetails(CommonPersonObjectClient commonPersonObjectClient) { Map<String, String> details = getAllDetailsForClient(commonPersonObjectClient.entityId()); details.putAll(commonPersonObjectClient.getColumnmaps()); if (commonPersonObjectClient.getDetails() != null) { commonPersonObjectClient.getDetails().putAll(details); } else { commonPersonObjectClient.setDetails(details); } return details; } void add(String baseEntityId, String key, String value, Long timestamp); Map<String, String> getAllDetailsForClient(String baseEntityId); Map<String, String> updateDetails(CommonPersonObjectClient commonPersonObjectClient); Map<String, String> updateDetails(CommonPersonObject commonPersonObject); boolean deleteDetails(String baseEntityId); }### Answer: @Test public void assertupdateDetails() { Assert.assertNotNull(detailsRepository.updateDetails(Mockito.mock(CommonPersonObject.class))); } @Test public void assertupdateDetails2() { Assert.assertNotNull(detailsRepository.updateDetails(Mockito.mock(CommonPersonObjectClient.class))); }
### Question: DetailsRepository extends DrishtiRepository { public boolean deleteDetails(String baseEntityId) { try { SQLiteDatabase db = masterRepository.getWritableDatabase(); int afftectedRows = db .delete(TABLE_NAME, BASE_ENTITY_ID_COLUMN + " = ?", new String[]{baseEntityId}); if (afftectedRows > 0) { return true; } } catch (Exception e) { Timber.e(e); } return false; } void add(String baseEntityId, String key, String value, Long timestamp); Map<String, String> getAllDetailsForClient(String baseEntityId); Map<String, String> updateDetails(CommonPersonObjectClient commonPersonObjectClient); Map<String, String> updateDetails(CommonPersonObject commonPersonObject); boolean deleteDetails(String baseEntityId); }### Answer: @Test public void assertdeleteDetails() { Assert.assertEquals(detailsRepository.deleteDetails("1"), false); Mockito.when(sqLiteDatabase.delete(Mockito.anyString(), Mockito.anyString(), Mockito.any(String[].class))).thenReturn(1); Assert.assertEquals(detailsRepository.deleteDetails("1"), true); }
### Question: AllBeneficiaries { public Mother findMotherWithOpenStatus(String caseId) { return motherRepository.findOpenCaseByCaseID(caseId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindMotherWithOpenStatus() { Mockito.when(motherRepository.findOpenCaseByCaseID(Mockito.anyString())).thenReturn(Mockito.mock(Mother.class)); Assert.assertNotNull(allBeneficiaries.findMotherWithOpenStatus("")); }
### Question: AllBeneficiaries { public Mother findMother(String caseId) { List<Mother> mothers = motherRepository.findByCaseIds(caseId); if (mothers.isEmpty()) { return null; } return mothers.get(0); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindMotherReturnsMother() { Mockito.when(motherRepository.findByCaseIds(Mockito.anyString())).thenReturn(new ArrayList<Mother>()); Assert.assertNull(allBeneficiaries.findMother("")); List<Mother> list = new ArrayList<Mother>(); list.add(Mockito.mock(Mother.class)); Mockito.when(motherRepository.findByCaseIds(Mockito.anyString())).thenReturn(list); Assert.assertNotNull(allBeneficiaries.findMother("")); }
### Question: AllBeneficiaries { public List<Child> findAllChildrenByCaseIDs(List<String> caseIds) { return childRepository.findChildrenByCaseIds(caseIds.toArray(new String[caseIds.size()])); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindAllChildrenByCaseIDs() { Mockito.when(childRepository.findChildrenByCaseIds(Mockito.any(String[].class))).thenReturn(Mockito.mock(List.class)); Assert.assertNotNull(allBeneficiaries.findAllChildrenByCaseIDs(new ArrayList<String>())); }
### Question: AllBeneficiaries { public List<Child> allChildrenWithMotherAndEC() { return childRepository.allChildrenWithMotherAndEC(); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertAllChildrenWithMotherAndEC() { Mockito.when(childRepository.allChildrenWithMotherAndEC()).thenReturn(Mockito.mock(List.class)); Assert.assertNotNull(allBeneficiaries.allChildrenWithMotherAndEC()); }
### Question: AllBeneficiaries { public List<Child> findAllChildrenByECId(String ecId) { return childRepository.findAllChildrenByECId(ecId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindAllChildrenByECId() { Mockito.when(childRepository.findAllChildrenByECId(Mockito.anyString())).thenReturn(Mockito.mock(List.class)); Assert.assertNotNull(allBeneficiaries.findAllChildrenByECId("")); }
### Question: AllBeneficiaries { public Mother findMotherWithOpenStatusByECId(String ecId) { return motherRepository.findMotherWithOpenStatusByECId(ecId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindMotherWithOpenStatusByECId() { Mockito.when(motherRepository.findMotherWithOpenStatusByECId(Mockito.anyString())).thenReturn(Mockito.mock(Mother.class)); Assert.assertNotNull(allBeneficiaries.findMotherWithOpenStatusByECId("")); }
### Question: AllBeneficiaries { public boolean isPregnant(String ecId) { return motherRepository.isPregnant(ecId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertIsPregnant() { Mockito.when(motherRepository.isPregnant(Mockito.anyString())).thenReturn(false); Assert.assertEquals(allBeneficiaries.isPregnant(""), false); }
### Question: AllBeneficiaries { public void switchMotherToPNC(String entityId) { motherRepository.switchToPNC(entityId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertSwitchMotherToPNC() { Mockito.doNothing().when(motherRepository).switchToPNC(Mockito.anyString()); allBeneficiaries.switchMotherToPNC(""); Mockito.verify(motherRepository, Mockito.times(1)).switchToPNC(Mockito.anyString()); }
### Question: AllBeneficiaries { public List<Mother> findAllMothersByCaseIDs(List<String> caseIds) { return motherRepository.findByCaseIds(caseIds.toArray(new String[caseIds.size()])); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindAllMothersByCaseIDs() { Mockito.when(motherRepository.findByCaseIds(Mockito.any(String[].class))).thenReturn(Mockito.mock(List.class)); Assert.assertNotNull(allBeneficiaries.findAllMothersByCaseIDs(new ArrayList<String>())); }
### Question: AllBeneficiaries { public List<Child> findAllChildrenByMotherId(String entityId) { return childRepository.findByMotherCaseId(entityId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindAllChildrenByMotherId() { Mockito.when(childRepository.findByMotherCaseId(Mockito.anyString())).thenReturn(Mockito.mock(List.class)); Assert.assertNotNull(allBeneficiaries.findAllChildrenByMotherId("")); }
### Question: AllBeneficiaries { public Child findChild(String caseId) { return childRepository.find(caseId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertFindChild() { Mockito.when(childRepository.find(Mockito.anyString())).thenReturn(Mockito.mock(Child.class)); Assert.assertNotNull(allBeneficiaries.findChild("")); }
### Question: AllBeneficiaries { public long ancCount() { return motherRepository.ancCount(); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertANCcountReturnsLong() { Mockito.when(motherRepository.ancCount()).thenReturn(0l); Assert.assertEquals(allBeneficiaries.ancCount(), 0l); }
### Question: AllBeneficiaries { public long pncCount() { return motherRepository.pncCount(); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertPNCcountReturnsLong() { Mockito.when(motherRepository.pncCount()).thenReturn(0l); Assert.assertEquals(allBeneficiaries.pncCount(), 0l); }
### Question: AllBeneficiaries { public long childCount() { return childRepository.count(); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertChildcountReturnsLong() { Mockito.when(childRepository.count()).thenReturn(0l); Assert.assertEquals(allBeneficiaries.childCount(), 0l); }
### Question: AllBeneficiaries { public List<Pair<Mother, EligibleCouple>> allANCsWithEC() { return motherRepository.allMothersOfATypeWithEC(TYPE_ANC); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertAllANCsWithECReturnsList() { Mockito.when(motherRepository.allMothersOfATypeWithEC(Mockito.anyString())).thenReturn(Mockito.mock(List.class)); Assert.assertNotNull(allBeneficiaries.allANCsWithEC()); }
### Question: AllBeneficiaries { public List<Pair<Mother, EligibleCouple>> allPNCsWithEC() { return motherRepository.allMothersOfATypeWithEC(TYPE_PNC); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void assertAllPNCsWithECReturnsList() { Mockito.when(motherRepository.allMothersOfATypeWithEC(Mockito.anyString())).thenReturn(Mockito.mock(List.class)); Assert.assertNotNull(allBeneficiaries.allPNCsWithEC()); }
### Question: AllBeneficiaries { public void closeMother(String entityId) { alertRepository.deleteAllAlertsForEntity(entityId); timelineEventRepository.deleteAllTimelineEventsForEntity(entityId); motherRepository.close(entityId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void shouldDeleteTimelineEventsAndAlertsWhileClosingMother() throws Exception { allBeneficiaries.closeMother("entity id 1"); Mockito.verify(alertRepository).deleteAllAlertsForEntity("entity id 1"); Mockito.verify(timelineEventRepository).deleteAllTimelineEventsForEntity("entity id 1"); }
### Question: AllBeneficiaries { public void closeChild(String entityId) { alertRepository.deleteAllAlertsForEntity(entityId); timelineEventRepository.deleteAllTimelineEventsForEntity(entityId); childRepository.close(entityId); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void shouldDeleteTimelineEventsAndAlertsWhenAChildIsClosed() throws Exception { Mockito.when(childRepository.find("child id 1")) .thenReturn(new Child("child id 1", "mother id 1", "male", new HashMap<String, String>())); allBeneficiaries.closeChild("child id 1"); Mockito.verify(alertRepository).deleteAllAlertsForEntity("child id 1"); Mockito.verify(timelineEventRepository).deleteAllTimelineEventsForEntity("child id 1"); Mockito.verify(childRepository).close("child id 1"); }
### Question: AllBeneficiaries { public void updateChild(Child child) { childRepository.update(child); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void shouldDelegateToChildRepositoryWhenUpdateChildIsCalled() throws Exception { allBeneficiaries.updateChild(child); Mockito.verify(childRepository).update(child); }
### Question: AllBeneficiaries { public void updateMother(Mother mother) { motherRepository.update(mother); } AllBeneficiaries(MotherRepository motherRepository, ChildRepository childRepository, AlertRepository alertRepository, TimelineEventRepository timelineEventRepository); Mother findMotherWithOpenStatus(String caseId); Mother findMother(String caseId); Child findChild(String caseId); long ancCount(); long pncCount(); long childCount(); List<Pair<Mother, EligibleCouple>> allANCsWithEC(); List<Pair<Mother, EligibleCouple>> allPNCsWithEC(); Mother findMotherByECCaseId(String ecCaseId); List<Child> findAllChildrenByMotherId(String entityId); List<Child> findAllChildrenByCaseIDs(List<String> caseIds); List<Mother> findAllMothersByCaseIDs(List<String> caseIds); void switchMotherToPNC(String entityId); void closeMother(String entityId); void closeChild(String entityId); void closeAllMothersForEC(String ecId); List<Child> allChildrenWithMotherAndEC(); List<Child> findAllChildrenByECId(String ecId); Mother findMotherWithOpenStatusByECId(String ecId); boolean isPregnant(String ecId); void updateChild(Child child); void updateMother(Mother mother); }### Answer: @Test public void shouldDelegateToMotherRepositoryWhenUpdateMotherIsCalled() throws Exception { allBeneficiaries.updateMother(mother); Mockito.verify(motherRepository).update(mother); }
### Question: StructureRepository extends LocationRepository { public boolean batchInsertStructures(JSONArray array) { if (array == null || array.length() == 0) { return false; } try { getWritableDatabase().beginTransaction(); for (int i = 0; i < array.length(); i++) { JSONObject jsonObject = array.getJSONObject(i); Location structure = LocationServiceHelper.locationGson.fromJson(jsonObject.toString(), Location.class); addOrUpdate(structure); } getWritableDatabase().setTransactionSuccessful(); getWritableDatabase().endTransaction(); return true; } catch (Exception e) { Timber.e(e, "EXCEPTION %s", e.toString()); getWritableDatabase().endTransaction(); return false; } } static void createTable(SQLiteDatabase database); @Override void deleteLocations(@NonNull Set<String> locationIdentifiers); @Override List<Location> getAllLocations(); List<Location> getAllUnsynchedCreatedStructures(); void markStructuresAsSynced(String structureId); void addOrUpdate(Location location); void setHelper(MappingHelper helper); boolean batchInsertStructures(JSONArray array); @Nullable JsonData getStructures(long lastRowId, int limit, String parentLocationId); int getUnsyncedStructuresCount(); static String STRUCTURE_TABLE; }### Answer: @Test public void testBatchInsertStructures() throws Exception { Location expectedStructure = gson.fromJson(locationJson, Location.class); JSONArray structureArray = new JSONArray().put(new JSONObject(locationJson)); structureRepository = spy(structureRepository); boolean inserted = structureRepository.batchInsertStructures(structureArray); assertTrue(inserted); verify(sqLiteDatabase).beginTransaction(); verify(sqLiteDatabase).setTransactionSuccessful(); verify(sqLiteDatabase).endTransaction(); verify(structureRepository).addOrUpdate(structureArgumentCapture.capture()); assertEquals(expectedStructure.getId(), structureArgumentCapture.getValue().getId()); assertEquals(expectedStructure.getType(), structureArgumentCapture.getValue().getType()); }
### Question: StructureRepository extends LocationRepository { public List<Location> getAllUnsynchedCreatedStructures() { Cursor cursor = null; List<Location> structures = new ArrayList<>(); try { cursor = getReadableDatabase().rawQuery(String.format("SELECT * FROM %s WHERE %s =?", STRUCTURE_TABLE, SYNC_STATUS), new String[]{BaseRepository.TYPE_Created}); while (cursor.moveToNext()) { structures.add(readCursor(cursor)); } cursor.close(); } catch (Exception e) { Timber.e(e, "EXCEPTION %s", e.toString()); } finally { if (cursor != null) cursor.close(); } return structures; } static void createTable(SQLiteDatabase database); @Override void deleteLocations(@NonNull Set<String> locationIdentifiers); @Override List<Location> getAllLocations(); List<Location> getAllUnsynchedCreatedStructures(); void markStructuresAsSynced(String structureId); void addOrUpdate(Location location); void setHelper(MappingHelper helper); boolean batchInsertStructures(JSONArray array); @Nullable JsonData getStructures(long lastRowId, int limit, String parentLocationId); int getUnsyncedStructuresCount(); static String STRUCTURE_TABLE; }### Answer: @Test public void testGetAllUnsynchedCreatedStructures() { String sql = "SELECT * FROM structure WHERE sync_status =?"; when(sqLiteDatabase.rawQuery(anyString(), any())).thenReturn(getCursor()); List<Location> actualStructures = structureRepository.getAllUnsynchedCreatedStructures(); verify(sqLiteDatabase).rawQuery(stringArgumentCaptor.capture(), argsCaptor.capture()); assertEquals(sql, stringArgumentCaptor.getValue()); assertEquals(BaseRepository.TYPE_Created, argsCaptor.getValue()[0]); }
### Question: StructureRepository extends LocationRepository { public void markStructuresAsSynced(String structureId) { try { ContentValues values = new ContentValues(); values.put(ID, structureId); values.put(SYNC_STATUS, BaseRepository.TYPE_Synced); getWritableDatabase().update(STRUCTURE_TABLE, values, ID + " = ?", new String[]{structureId}); } catch (Exception e) { e.printStackTrace(); } } static void createTable(SQLiteDatabase database); @Override void deleteLocations(@NonNull Set<String> locationIdentifiers); @Override List<Location> getAllLocations(); List<Location> getAllUnsynchedCreatedStructures(); void markStructuresAsSynced(String structureId); void addOrUpdate(Location location); void setHelper(MappingHelper helper); boolean batchInsertStructures(JSONArray array); @Nullable JsonData getStructures(long lastRowId, int limit, String parentLocationId); int getUnsyncedStructuresCount(); static String STRUCTURE_TABLE; }### Answer: @Test public void testMarkStructureAsSynced() { String expectedStructureId = "41587456-b7c8-4c4e-b433-23a786f742fc"; structureRepository.markStructuresAsSynced(expectedStructureId); verifyMarkStructureAsSyncedTests(expectedStructureId); } @Test public void testMarkStructureAsSyncedShouldThrowException() { doThrow(new SQLiteException()).when(sqLiteDatabase).update(anyString(), any(), anyString(), any()); String expectedStructureId = "41587456-b7c8-4c4e-b433-23a786f742fc"; structureRepository.markStructuresAsSynced(expectedStructureId); verifyMarkStructureAsSyncedTests(expectedStructureId); }
### Question: StructureRepository extends LocationRepository { @Override public List<Location> getAllLocations() { throw new UnsupportedOperationException("getAllLocations not supported for Structures"); } static void createTable(SQLiteDatabase database); @Override void deleteLocations(@NonNull Set<String> locationIdentifiers); @Override List<Location> getAllLocations(); List<Location> getAllUnsynchedCreatedStructures(); void markStructuresAsSynced(String structureId); void addOrUpdate(Location location); void setHelper(MappingHelper helper); boolean batchInsertStructures(JSONArray array); @Nullable JsonData getStructures(long lastRowId, int limit, String parentLocationId); int getUnsyncedStructuresCount(); static String STRUCTURE_TABLE; }### Answer: @Test(expected = UnsupportedOperationException.class) public void testGetAllLocations() { structureRepository.getAllLocations(); }
### Question: StructureRepository extends LocationRepository { public static void createTable(SQLiteDatabase database) { database.execSQL(CREATE_LOCATION_TABLE); database.execSQL(CREATE_LOCATION_PARENT_INDEX); } static void createTable(SQLiteDatabase database); @Override void deleteLocations(@NonNull Set<String> locationIdentifiers); @Override List<Location> getAllLocations(); List<Location> getAllUnsynchedCreatedStructures(); void markStructuresAsSynced(String structureId); void addOrUpdate(Location location); void setHelper(MappingHelper helper); boolean batchInsertStructures(JSONArray array); @Nullable JsonData getStructures(long lastRowId, int limit, String parentLocationId); int getUnsyncedStructuresCount(); static String STRUCTURE_TABLE; }### Answer: @Test public void testCreateTable() { StructureRepository.createTable(sqLiteDatabase); verify(sqLiteDatabase, times(2)).execSQL(stringArgumentCaptor.capture()); assertEquals("CREATE TABLE structure (_id VARCHAR NOT NULL PRIMARY KEY,uuid VARCHAR , " + "parent_id VARCHAR , name VARCHAR , sync_status VARCHAR DEFAULT Synced, latitude FLOAT , " + "longitude FLOAT , geojson VARCHAR NOT NULL ) ", stringArgumentCaptor.getAllValues().get(0)); assertEquals("CREATE INDEX structure_parent_id_ind ON structure(parent_id)", stringArgumentCaptor.getAllValues().get(1)); }
### Question: FormsVersionRepository extends DrishtiRepository { @Override protected void onCreate(SQLiteDatabase database) { database.execSQL(FORM_VERSION_SQL); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertOnCreateCallsDatabaseExec() { formsVersionRepository.onCreate(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(1)).execSQL(Mockito.anyString()); }
### Question: FormsVersionRepository extends DrishtiRepository { public FormDefinitionVersion fetchVersionByFormName(String formName) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_VERSION_TABLE_NAME, FORM_VERSION_TABLE_COLUMNS, FORM_NAME_COLUMN + " " + "" + "= ?", new String[]{formName}, null, null, null); return readFormVersion(cursor).get(0); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertFetchVersionByFormName() { Assert.assertNotNull(formsVersionRepository.fetchVersionByFormName("")); }
### Question: FormsVersionRepository extends DrishtiRepository { public FormDefinitionVersion fetchVersionByFormDirName(String formDirName) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_VERSION_TABLE_NAME, FORM_VERSION_TABLE_COLUMNS, FORM_DIR_NAME_COLUMN + " = ?", new String[]{formDirName}, null, null, null); return readFormVersion(cursor).get(0); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertFetchVersionByFormDirName() { Assert.assertNotNull(formsVersionRepository.fetchVersionByFormDirName("")); }
### Question: FormsVersionRepository extends DrishtiRepository { public String getVersion(String formDirName) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_VERSION_TABLE_NAME, FORM_VERSION_TABLE_COLUMNS, FORM_DIR_NAME_COLUMN + " = ?", new String[]{formDirName}, null, null, null); return (readFormVersion(cursor).get(0)).getVersion(); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertGetVersion() { Assert.assertNotNull(formsVersionRepository.getVersion("")); }
### Question: FormsVersionRepository extends DrishtiRepository { public List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_VERSION_TABLE_NAME, FORM_VERSION_TABLE_COLUMNS, SYNC_STATUS_COLUMN + " = ?", new String[]{status.value()}, null, null, null); return readFormVersion(cursor); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertgetAllFormWithSyncStatus() { Assert.assertNotNull(formsVersionRepository.getAllFormWithSyncStatus(SyncStatus.PENDING)); }
### Question: FormsVersionRepository extends DrishtiRepository { public List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_VERSION_TABLE_NAME, FORM_VERSION_TABLE_COLUMNS, SYNC_STATUS_COLUMN + " = ?", new String[]{status.value()}, null, null, null); return readFormVersionToMap(cursor); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertgetAllFormWithSyncStatusAsMap() { Assert.assertNotNull(formsVersionRepository.getAllFormWithSyncStatusAsMap(SyncStatus.PENDING)); }
### Question: FormsVersionRepository extends DrishtiRepository { public FormDefinitionVersion getFormByFormDirName(String formDirName) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_VERSION_TABLE_NAME, FORM_VERSION_TABLE_COLUMNS, FORM_DIR_NAME_COLUMN + " = ?", new String[]{formDirName}, null, null, null); return (readFormVersion(cursor).get(0)); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertgetFormByFormDirName() { Assert.assertNotNull(formsVersionRepository.getFormByFormDirName("")); }
### Question: FormsVersionRepository extends DrishtiRepository { public void addFormVersion(Map<String, String> dataJSON) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.insert(FORM_VERSION_TABLE_NAME, null, createValuesFormVersions(dataJSON)); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertAddFormVersion() { HashMap<String, String> data = new HashMap<String, String>(); data.put(FORM_NAME_COLUMN, "form_name"); data.put(VERSION_COLUMN, "1.0"); data.put(FORM_DIR_NAME_COLUMN, "dir"); data.put(SYNC_STATUS_COLUMN, SyncStatus.PENDING.value()); formsVersionRepository.addFormVersion(data); Mockito.verify(sqLiteDatabase, Mockito.times(1)).insert(Mockito.anyString(), Mockito.isNull(String.class), Mockito.any(ContentValues.class)); }
### Question: FormsVersionRepository extends DrishtiRepository { public void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.insert(FORM_VERSION_TABLE_NAME, null, createValuesFromObject(formDefinitionVersion)); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertAddFormVersionFromObject() { FormDefinitionVersion fd = new FormDefinitionVersion("", "", ""); fd.setSyncStatus(SyncStatus.PENDING); formsVersionRepository.addFormVersionFromObject(fd); Mockito.verify(sqLiteDatabase, Mockito.times(1)).insert(Mockito.anyString(), Mockito.isNull(String.class), Mockito.any(ContentValues.class)); }
### Question: FormsVersionRepository extends DrishtiRepository { public boolean formExists(String formDirName) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(FORM_VERSION_TABLE_NAME, new String[]{FORM_DIR_NAME_COLUMN}, FORM_DIR_NAME_COLUMN + " = ?", new String[]{formDirName}, null, null, null); boolean isThere = cursor.moveToFirst(); cursor.close(); return isThere; } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertformExistsReturnsTrue() { Assert.assertEquals(formsVersionRepository.formExists(""), true); }
### Question: FormsVersionRepository extends DrishtiRepository { public void deleteAll() { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.delete(FORM_VERSION_TABLE_NAME, null, null); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertDeleteAllCallsDatabaseDelete() { formsVersionRepository.deleteAll(); Mockito.verify(sqLiteDatabase, Mockito.times(1)).delete(Mockito.anyString(), Mockito.isNull(String.class), Mockito.isNull(String[].class)); }
### Question: GenericInteractor implements CallableInteractor { @Override public <T> void execute(Callable<T> callable, CallableInteractorCallBack<T> callBack) { execute(callable, callBack, AppExecutors.Request.DISK_THREAD); } GenericInteractor(); @VisibleForTesting GenericInteractor(AppExecutors appExecutors); @Override void execute(Callable<T> callable, CallableInteractorCallBack<T> callBack); @Override void execute(Callable<T> callable, CallableInteractorCallBack<T> callBack, AppExecutors.Request request); }### Answer: @Test public void testDefaultExecuteFunction() { interactor = Mockito.spy(interactor); final String test = "Test String"; Callable<String> callable = () -> test; CallableInteractorCallBack<String> callBack = Mockito.mock(CallableInteractorCallBack.class); interactor.execute(callable, callBack); Mockito.verify(interactor).execute(callable, callBack, AppExecutors.Request.DISK_THREAD); Mockito.verify(callBack).onResult(test); Exception exception = new IllegalStateException("Exception"); Callable<String> errorCall = () -> { throw exception; }; interactor.execute(errorCall, callBack); Mockito.verify(callBack).onError(exception); }
### Question: FormsVersionRepository extends DrishtiRepository { public void updateServerVersion(String formDirName, String serverVersion) { SQLiteDatabase database = masterRepository.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(VERSION_COLUMN, serverVersion); database.update(FORM_VERSION_TABLE_NAME, values, FORM_DIR_NAME_COLUMN + " = ?", new String[]{formDirName}); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertupdateServerVersion() { formsVersionRepository.updateServerVersion("", ""); Mockito.verify(sqLiteDatabase, Mockito.times(1)).update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: FormsVersionRepository extends DrishtiRepository { public void updateFormName(String formDirName, String formName) { SQLiteDatabase database = masterRepository.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(FORM_NAME_COLUMN, formName); database.update(FORM_VERSION_TABLE_NAME, values, FORM_DIR_NAME_COLUMN + " = ?", new String[]{formDirName}); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertupdateFormName() { formsVersionRepository.updateFormName("", ""); Mockito.verify(sqLiteDatabase, Mockito.times(1)).update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: FormsVersionRepository extends DrishtiRepository { public void updateSyncStatus(String formDirName, SyncStatus status) { SQLiteDatabase database = masterRepository.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(SYNC_STATUS_COLUMN, status.value()); database.update(FORM_VERSION_TABLE_NAME, values, FORM_DIR_NAME_COLUMN + " = ?", new String[]{formDirName}); } FormDefinitionVersion fetchVersionByFormName(String formName); FormDefinitionVersion fetchVersionByFormDirName(String formDirName); String getVersion(String formDirName); FormDefinitionVersion getFormByFormDirName(String formDirName); List<FormDefinitionVersion> getAllFormWithSyncStatus(SyncStatus status); List<Map<String, String>> getAllFormWithSyncStatusAsMap(SyncStatus status); void addFormVersion(Map<String, String> dataJSON); void addFormVersionFromObject(FormDefinitionVersion formDefinitionVersion); void deleteAll(); void updateServerVersion(String formDirName, String serverVersion); void updateFormName(String formDirName, String formName); void updateSyncStatus(String formDirName, SyncStatus status); boolean formExists(String formDirName); ContentValues createValuesFormVersions(Map<String, String> params); ContentValues createValuesFromObject(FormDefinitionVersion formDefinitionVersion); long count(); static final String FORM_NAME_COLUMN; static final String VERSION_COLUMN; static final String FORM_DIR_NAME_COLUMN; static final String SYNC_STATUS_COLUMN; static final String[] FORM_VERSION_TABLE_COLUMNS; }### Answer: @Test public void assertupdateSyncStatus() { formsVersionRepository.updateSyncStatus("", SyncStatus.PENDING); Mockito.verify(sqLiteDatabase, Mockito.times(1)).update(Mockito.anyString(), Mockito.any(ContentValues.class), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: TimelineEventRepository extends DrishtiRepository { @Override protected void onCreate(SQLiteDatabase database) { database.execSQL(TIMELINEEVENT_SQL); database.execSQL(TIMELINEVENT_CASEID_INDEX_SQL); } void add(TimelineEvent timelineEvent); List<TimelineEvent> allFor(String caseId); void deleteAllTimelineEventsForEntity(String caseId); }### Answer: @Test public void assertOnCreateCallsDatabaseExec() { Mockito.doNothing().when(sqLiteDatabase).execSQL(Mockito.anyString()); timelineEventRepository.onCreate(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(2)).execSQL(Mockito.anyString()); }
### Question: TimelineEventRepository extends DrishtiRepository { public void add(TimelineEvent timelineEvent) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.insert(TIMELINEEVENT_TABLE_NAME, null, createValuesFor(timelineEvent)); } void add(TimelineEvent timelineEvent); List<TimelineEvent> allFor(String caseId); void deleteAllTimelineEventsForEntity(String caseId); }### Answer: @Test public void assertAddCallsDatabaseInsert() { TimelineEvent timelineEvent = new TimelineEvent("", "", new LocalDate(), "", "", ""); timelineEventRepository.add(timelineEvent); Mockito.verify(sqLiteDatabase, Mockito.times(1)).insert(Mockito.anyString(), Mockito.isNull(String.class), Mockito.any(ContentValues.class)); }
### Question: TimelineEventRepository extends DrishtiRepository { public List<TimelineEvent> allFor(String caseId) { SQLiteDatabase database = masterRepository.getReadableDatabase(); Cursor cursor = database.query(TIMELINEEVENT_TABLE_NAME, TIMELINEEVENT_TABLE_COLUMNS, CASEID_COLUMN + "= ?", new String[]{caseId}, null, null, null); return readAllTimelineEvents(cursor); } void add(TimelineEvent timelineEvent); List<TimelineEvent> allFor(String caseId); void deleteAllTimelineEventsForEntity(String caseId); }### Answer: @Test public void assertAllFor() { String[] columns = {"id", "name", "date", "a", "b", "c"}; MatrixCursor cursor = new MatrixCursor(columns); cursor.addRow(new Object[]{"", "", "2017-10-10", "", "", ""}); cursor.addRow(new Object[]{"", "", "2017-10-10", "", "", ""}); Mockito.when(sqLiteDatabase.query(Mockito.anyString(), Mockito.any(String[].class), Mockito.anyString(), Mockito.any(String[].class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class))).thenReturn(cursor); timelineEventRepository.allFor("0"); Mockito.verify(sqLiteDatabase, Mockito.times(1)).query(Mockito.anyString(), Mockito.any(String[].class), Mockito.anyString(), Mockito.any(String[].class), Mockito.isNull(String.class), Mockito.isNull(String.class), Mockito.isNull(String.class)); }
### Question: TimelineEventRepository extends DrishtiRepository { public void deleteAllTimelineEventsForEntity(String caseId) { SQLiteDatabase database = masterRepository.getWritableDatabase(); database.delete(TIMELINEEVENT_TABLE_NAME, CASEID_COLUMN + " = ?", new String[]{caseId}); } void add(TimelineEvent timelineEvent); List<TimelineEvent> allFor(String caseId); void deleteAllTimelineEventsForEntity(String caseId); }### Answer: @Test public void assertDeleteAllTimelineEventsForEntity() { timelineEventRepository.deleteAllTimelineEventsForEntity(""); Mockito.verify(sqLiteDatabase, Mockito.times(1)).delete(Mockito.anyString(), Mockito.anyString(), Mockito.any(String[].class)); }
### Question: ClientRepository extends SQLiteOpenHelper { @Override public void onCreate(SQLiteDatabase database) { database.execSQL(common_SQL); } ClientRepository(Context context, String[] columns); ClientRepository(Context context, String tableName, String[] columns); @Override void onOpen(SQLiteDatabase db); @Override void onCreate(SQLiteDatabase database); @Override void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1); ContentValues createValuesFor(Client common); void insertValues(ContentValues values); static final String ID_COLUMN; static final String Relational_ID; static final String propertyDETAILS_COLUMN; static final String attributeDETAILS_COLUMN; public String TABLE_NAME; public String[] additionalcolumns; }### Answer: @Test public void constructorNotNullCallsOnCreateDatabaseExec() { Assert.assertNotNull(clientRepository); clientRepository.onCreate(sqLiteDatabase); Mockito.verify(sqLiteDatabase, Mockito.times(1)).execSQL(Mockito.anyString()); }