Skip to content

Commit

Permalink
[fix]: delete patient test
Browse files Browse the repository at this point in the history
  • Loading branch information
valens200 committed Mar 18, 2024
1 parent 234b1d1 commit f5af882
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/test/java/org/openelisglobal/patient/PatientServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.ObjectNotFoundException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -20,6 +22,8 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertThrows;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { BaseTestConfig.class, PatientTestConfig.class })
@TestPropertySource("classpath:common.properties")
Expand All @@ -37,6 +41,24 @@ public void init() throws Exception {

}

@Test
public void getAllPatients_shouldGetAllPatients() throws Exception {
Assert.assertEquals(1, patientService.getAllPatients().size());
}
@Test
public void deletePatient_shouldDeleteNewPatient() throws Exception {
String firstName = "Peter";
String lastname = "Master";
String dob = "9/12/1993";
String gender = "M";
Patient pat = createPatient(firstName, lastname, dob, gender);
String patientId = patientService.insert(pat);
Patient savedPatient = patientService.get(patientId);
patientService.delete(savedPatient);
assertThrows(ObjectNotFoundException.class, () -> {
patientService.get(patientId);
});
}
@Test
public void createPatient_shouldCreateNewPatient() throws Exception {
String firstName = "John";
Expand All @@ -57,23 +79,8 @@ public void createPatient_shouldCreateNewPatient() throws Exception {
Assert.assertEquals(gender, savedPatient.getGender());
}

@Test
public void deletePatient_shouldDeleteNewPatient() throws Exception {
String firstName = "Peter";
String lastname = "Master";
String dob = "9/12/1993";
String gender = "M";
Patient pat = createPatient(firstName, lastname, dob, gender);
String patientId = patientService.insert(pat);
Patient savedPatient = patientService.get(patientId);
patientService.delete(savedPatient);
Assert.assertEquals(0, patientService.getAllPatients().size());
}

@Test
public void getAllPatients_shouldGetAllPatients() throws Exception {
Assert.assertEquals(0, patientService.getAllPatients().size());
}


private Patient createPatient(String firstName, String LastName, String birthDate, String gender)
throws ParseException {
Expand Down

0 comments on commit f5af882

Please sign in to comment.