Source:
public void shouldCheckThatAMethodIsNotRolledBackInCaseOfAnErrorInAnotherInvokedInsideIt() throws Exception { PatientService patientService = Context.getPatientService(); EncounterService encounterService = Context.getEncounterService(); ProgramWorkflowService programService = Context.getProgramWorkflowService(); Patient prefPatient = patientService.getPatient(6); Patient notPrefPatient = patientService.getPatient(7); Collection<Program> programs = programService.getAllPrograms(false); int originalPrefEncounterCount = encounterService.getEncountersByPatient(prefPatient).size(); int originalNotPrefEncounterCount = encounterService.getEncountersByPatient(notPrefPatient).size(); Assert.assertTrue(originalNotPrefEncounterCount > 0); PatientProgram pp = new PatientProgram(); pp.setPatient(notPrefPatient); pp.setProgram(programs.iterator().next()); pp.setDateEnrolled(new Date()); pp.setCreator(Context.getAuthenticatedUser()); programService.savePatientProgram(pp); Cohort preferredCohort = new Cohort(prefPatient.getPatientId().toString()); int originalPrefProgramCount = programService.getPatientPrograms(preferredCohort, programs).size(); Cohort notPreferredCohort = new Cohort(notPrefPatient.getPatientId().toString()); List<PatientProgram> notPrefPrograms = programService.getPatientPrograms(notPreferredCohort, programs); int originalNotPrefProgramCount = notPrefPrograms.size(); Assert.assertTrue(originalNotPrefProgramCount > 1); notPrefPrograms.get(1).setProgram(null); boolean failed = false; try { patientService.mergePatients(prefPatient, notPrefPatient); } catch (APIException e) { failed = true; } Assert.assertTrue(failed); Assert.assertEquals(originalPrefEncounterCount + originalNotPrefEncounterCount, encounterService .getEncountersByPatient(prefPatient).size()); Assert.assertEquals(originalPrefProgramCount + originalNotPrefProgramCount - 1, programService.getPatientPrograms( preferredCohort, programs).size()); }

Target:
public void shouldCheckThatAMethodIsNotRolledBackInCaseOfAnErrorInAnotherInvokedInsideIt() throws Exception { PatientService patientService = Context.getPatientService(); EncounterService encounterService = Context.getEncounterService(); ProgramWorkflowService programService = Context.getProgramWorkflowService(); Patient prefPatient = patientService.getPatient(6); Patient notPrefPatient = patientService.getPatient(7); Collection<Program> programs = programService.getAllPrograms(false); int originalPrefEncounterCount = encounterService.getEncountersByPatient(prefPatient).size(); int originalNotPrefEncounterCount = encounterService.getEncountersByPatient(notPrefPatient).size(); Assert.assertTrue(originalNotPrefEncounterCount > 0); Cohort notPreferredCohort = new Cohort(notPrefPatient.getPatientId().toString()); List<PatientProgram> notPrefPrograms = programService.getPatientPrograms(notPreferredCohort, programs); Assert.assertTrue(notPrefPrograms.size() > 0); notPrefPrograms.get(0).setProgram(null); boolean failed = false; try { patientService.mergePatients(prefPatient, notPrefPatient); } catch (APIException e) { failed = true; } Assert.assertTrue(failed); Assert.assertEquals(originalPrefEncounterCount, encounterService.getEncountersByPatient(prefPatient).size()); }