/** * Convenience method. Passes through to userContext.hasPrivilege(String) * * @should give daemon user full privileges */ public static boolean hasPrivilege(String privilege) { // the daemon threads have access to all things if (Daemon.isDaemonThread()) { return true; } return getUserContext().hasPrivilege(privilege); }
@Test public void processDeath_shouldMapValuesAndSavePatient() throws Exception { // given final Date dateDied = new Date(); final Concept causeOfDeath = new Concept(2); when(conceptService.getConcept(anyString())).thenReturn(new Concept()); when(locationService.getDefaultLocation()).thenReturn(new Location()); UserContext userContext = mock(UserContext.class); this.contextMockHelper.setUserContext(userContext); when(userContext.hasPrivilege(anyString())).thenReturn(true); ArgumentCaptor<Patient> argumentCaptor = ArgumentCaptor.forClass(Patient.class); when(patientDaoMock.savePatient(argumentCaptor.capture())).thenReturn(new Patient()); // when final Patient patient = new Patient(); patient.addIdentifier(new PatientIdentifier("an identifier", new PatientIdentifierType(1234), new Location())); patientService.processDeath(patient, dateDied, causeOfDeath, "unknown"); // then final Patient savedPatient = argumentCaptor.getValue(); assertEquals(true, savedPatient.getDead()); assertEquals(dateDied, savedPatient.getDeathDate()); assertEquals(causeOfDeath, savedPatient.getCauseOfDeath()); }