feat: added new tests and coverage report
This commit is contained in:
parent
e3393c8834
commit
a2e2395cc2
@ -2,6 +2,7 @@ plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.4.2'
|
||||
id 'io.spring.dependency-management' version '1.1.7'
|
||||
id 'jacoco'
|
||||
}
|
||||
|
||||
group = 'enseirb'
|
||||
@ -36,3 +37,22 @@ dependencies {
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
|
||||
test {
|
||||
finalizedBy jacocoTestReport // report is always generated after tests run
|
||||
}
|
||||
jacocoTestReport {
|
||||
dependsOn test // tests are required to run before generating the report
|
||||
reports {
|
||||
xml.required = false
|
||||
csv.required = false
|
||||
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jacoco {
|
||||
toolVersion = "0.8.12"
|
||||
reportsDirectory = layout.buildDirectory.dir('customJacocoReportDir')
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import enseirb.myinpulse.model.Administrator;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.service.AdminApiService;
|
||||
import enseirb.myinpulse.service.database.AdministratorService;
|
||||
import enseirb.myinpulse.service.database.ProjectService;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -15,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -24,22 +26,44 @@ public class AdminApiServiceTest {
|
||||
@Autowired private AdminApiService adminApiService;
|
||||
|
||||
@BeforeAll
|
||||
static void setup(@Autowired AdministratorService administratorService) {
|
||||
static void setup(
|
||||
@Autowired AdministratorService administratorService,
|
||||
@Autowired ProjectService projectService) {
|
||||
administratorService.addAdministrator(
|
||||
new Administrator(
|
||||
"admin", "admin", "testAdmin@example.com", "testAdmin@example.com", ""));
|
||||
"admin",
|
||||
"admin",
|
||||
"testAdminEmpty@example.com",
|
||||
"testAdmin@example.com",
|
||||
""));
|
||||
administratorService.addAdministrator(
|
||||
new Administrator(
|
||||
"admin2",
|
||||
"admin2",
|
||||
"testAdminFull@example.com",
|
||||
"testAdmin@example.com",
|
||||
""));
|
||||
projectService.addNewProject(
|
||||
new Project(
|
||||
"sampleProjectAdminApiService",
|
||||
null,
|
||||
LocalDate.now(),
|
||||
"ONGOING",
|
||||
administratorService.getAdministratorByPrimaryMain(
|
||||
"testAdminFull@example.com")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getProjectOfAdminIsEmpty() throws Exception {
|
||||
Iterable<Project> projects = adminApiService.getProjectsOfAdmin("testAdmin@example.com");
|
||||
void getProjectOfAdminIsEmpty() {
|
||||
Iterable<Project> projects =
|
||||
adminApiService.getProjectsOfAdmin("testAdminEmpty@example.com");
|
||||
List<Project> l = new ArrayList<>();
|
||||
projects.forEach(l::add);
|
||||
assertEquals(0, l.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getProjectOfInexistantAdminFails() throws Exception {
|
||||
void getProjectOfInexistantAdminFails() {
|
||||
String nonExistentAdminEmail = "testInexistantAdmin@example.com";
|
||||
|
||||
assertThrows(
|
||||
@ -48,4 +72,15 @@ public class AdminApiServiceTest {
|
||||
adminApiService.getProjectsOfAdmin(nonExistentAdminEmail);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void getProjectOfAdminNotEmpty() {
|
||||
Iterable<Project> projects =
|
||||
adminApiService.getProjectsOfAdmin("testAdminFull@example.com");
|
||||
List<Project> l = new ArrayList<>();
|
||||
projects.forEach(l::add);
|
||||
assertEquals(1, l.size());
|
||||
Project p = l.getFirst();
|
||||
assertEquals(p.getProjectName(), "sampleProjectAdminApiService");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user