IncidentService extends RecordService { public Incident update(ItemValuesMap itemValues) throws IOException { Gson gson = new Gson(); Blob blob = new Blob(gson.toJson(itemValues.getValues()).getBytes()); Incident incident = incidentDao.getIncidentByUniqueId(itemValues.getAsString(INCIDENT_ID)); incident.setLastUpdatedDate(new Date(Calendar.getInstance().getTimeInMillis())); incident.setContent(blob); incident.setName(getName(itemValues)); incident.setSurvivorCode(getSurvivorCode(itemValues)); incident.setTypeOfViolence(getTypeOfViolence(itemValues)); incident.setLocation(getLocation(itemValues)); int age = itemValues.getAsInt(AGE) != null ? itemValues.getAsInt(AGE) : EMPTY_AGE; incident.setAge(age); incident.setCaregiver(getCaregiverName(itemValues)); incident.setSynced(false); if (itemValues.has(DATE_OF_INTERVIEW)) { incident.setRegistrationDate(Utils.getRegisterDateByYyyyMmDd(itemValues.getAsString(DATE_OF_INTERVIEW))); } return incidentDao.update(incident); } IncidentService();  IncidentService(IncidentDao incidentDao); Incident getById(long incidentId); Incident getByUniqueId(String uniqueId); List<Incident> getAll(); List<Long> getAllOrderByDateASC(); List<Long> getAllOrderByDateDES(); List<Long> getAllOrderByAgeASC(); List<Long> getAllOrderByAgeDES(); List<Long> getSearchResult(String uniqueId, String survivorCode, int ageFrom, int ageTo, String
            typeOfViolence, String location); Incident saveOrUpdate(ItemValuesMap itemValues); Incident save(ItemValuesMap itemValues); Incident update(ItemValuesMap itemValues); Incident deleteByRecordId(long recordId); Incident getByInternalId(String id); boolean hasSameRev(String id, String rev); List<Long> getAllSyncedRecordsId(); static final String TAG; static final String INCIDENT_DISPLAY_ID; static final String INCIDENT_ID; static final String INCIDENT_PRIMARY_ID; static final String EMPTY_ID; }
@Test public void should_update_incident_when_give_item_values() throws Exception { ItemValuesMap itemValues = new ItemValuesMap(); itemValues.addStringItem(INCIDENT_ID, "existedUniqueId"); itemValues.addNumberItem(AGE, 18); itemValues.addStringItem(DATE_OF_INTERVIEW, "2016/12/25"); Incident expected = new Incident(); PowerMockito.when(incidentDao.getIncidentByUniqueId("existedUniqueId")).thenReturn (expected); expected.setContent(new Blob(new String("").getBytes())); PowerMockito.when(incidentDao.update(expected)).thenReturn(expected); Incident actual = incidentService.update(itemValues); verify(incidentDao, times(1)).update(actual); assertFalse("Sync status should be false", actual.isSynced()); assertThat("Age should be 18", actual.getAge(), is(18)); assertThat("Registration date should be 2016/12/25", actual.getRegistrationDate(), is (Utils.getRegisterDateByYyyyMmDd("2016/12/25"))); }