Skip to content

Commit

Permalink
More unit tests to meet the new code coverage.
Browse files Browse the repository at this point in the history
More unit tests to meet the new code coverage.
  • Loading branch information
infstar committed Dec 20, 2024
1 parent bb708cc commit 3db475c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class StudentSearchRequest implements Serializable {
private List<String> programs = new ArrayList<>();
private List<UUID> studentIDs = new ArrayList<>();
private List<String> statuses = new ArrayList<>();
private List<String> reportTypes = new ArrayList();
private List<String> reportTypes = new ArrayList<>();

private String user;
private Address address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,6 @@ public SchoolClob getSchoolClob(String schoolId) {
return restService.get(String.format(constants.getSchoolClobBySchoolId(), schoolId), SchoolClob.class);
}

public ca.bc.gov.educ.api.batchgraduation.model.institute.School getSchool(String schoolId) {
return restService.get(String.format(constants.getSchoolBySchoolId(), schoolId), ca.bc.gov.educ.api.batchgraduation.model.institute.School.class);
}

public List<UUID> getDeceasedStudentIDs(List<UUID> studentIDs) {
var response = restService.post(constants.getDeceasedStudentIDList(), studentIDs, List.class);
return jsonTransformer.convertValue(response, new TypeReference<>(){});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,14 @@ public void testGetDistrictsBySchoolCategoryCode() {
assertThat(res).isNotNull();
}

@Test
public void testGetDistrictsBySchoolCategoryCode_whenException_isThrown() {
when(this.restService.get(String.format(constants.getDistricstBySchoolCategory(), "02"), List.class)).thenThrow(new RuntimeException("Test Exception"));

List<ca.bc.gov.educ.api.batchgraduation.model.institute.District> res = this.restUtils.getDistrictsBySchoolCategoryCode("02");
assertThat(res).isEmpty();
}

@Test
public void testGetSchoolsBySchoolCategoryCode() {
ca.bc.gov.educ.api.batchgraduation.model.institute.School school = new ca.bc.gov.educ.api.batchgraduation.model.institute.School();
Expand All @@ -1124,6 +1132,14 @@ public void testGetSchoolsBySchoolCategoryCode() {
assertThat(res).isNotNull();
}

@Test
public void testGetSchoolsBySchoolCategoryCode_whenException_isThrown() {
when(this.restService.get(String.format(constants.getSchoolsBySchoolCategory(), "02"), List.class)).thenThrow(new RuntimeException("Test Exception"));

List<ca.bc.gov.educ.api.batchgraduation.model.institute.School> res = this.restUtils.getSchoolsBySchoolCategoryCode("02");
assertThat(res).isEmpty();
}

@Test
public void testSearchSchoolsByDistrictId() {
UUID schoolId = UUID.randomUUID();
Expand All @@ -1140,6 +1156,54 @@ public void testSearchSchoolsByDistrictId() {
assertThat(res).isNotNull();
}

@Test
public void testSearchSchoolsByDistrictId_whenException_isThrown() {
UUID districtId = UUID.randomUUID();
when(this.restService.get(String.format(constants.getSearchSchoolsByDistrictId(), districtId), List.class)).thenThrow(new RuntimeException("Test Exception"));

List<ca.bc.gov.educ.api.batchgraduation.model.institute.School> res = this.restUtils.getSchoolsByDistrictId(districtId);
assertThat(res).isEmpty();
}

@Test
public void testSearchSchoolsByDistrictNumber() {
UUID schoolId = UUID.randomUUID();
UUID districtId = UUID.randomUUID();
String districtNumber = "039";

ca.bc.gov.educ.api.batchgraduation.model.institute.School school = new ca.bc.gov.educ.api.batchgraduation.model.institute.School();
school.setSchoolId(schoolId.toString());
school.setDistrictId(districtId.toString());
school.setMincode("1234567");

when(this.restService.get(String.format(constants.getSearchSchoolsByDistrictNumber(), districtNumber), List.class)).thenReturn(List.of(school));

List<ca.bc.gov.educ.api.batchgraduation.model.institute.School> res = this.restUtils.getSchoolsByDistrictNumber(districtNumber);
assertThat(res).isNotNull();
}

@Test
public void testSearchSchoolsByDistrictNumber_whenException_isThrown() {
String districtNumber = "039";
when(this.restService.get(String.format(constants.getSearchSchoolsByDistrictNumber(), districtNumber), List.class)).thenThrow(new RuntimeException("Test Exception"));

List<ca.bc.gov.educ.api.batchgraduation.model.institute.School> res = this.restUtils.getSchoolsByDistrictNumber(districtNumber);
assertThat(res).isEmpty();
}

public void testGetSchoolClob() {
UUID schoolId = UUID.randomUUID();

SchoolClob school = new SchoolClob();
school.setSchoolId(schoolId.toString());
school.setMinCode("1234567");

when(this.restService.get(String.format(constants.getSchoolClobBySchoolId(), schoolId), List.class)).thenReturn(List.of(school));

val res = this.restUtils.getSchoolClob(schoolId.toString());
assertThat(res).isNotNull();
}

@Test
public void testExecutePostDistribution() {
DistributionResponse distributionResponse = new DistributionResponse();
Expand Down

0 comments on commit 3db475c

Please sign in to comment.