From ee123f55438fd4f896e0a95d903987a13025bc97 Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 2 Oct 2024 10:30:58 +0200
Subject: [PATCH] Satisfy Sonarqube Code Coverage
---
requests/updateProject.http | 14 +-------------
...ctActionTest.java => GetProjectActionTest.java} | 9 +++++++--
.../project/UpdateProjectActionTest.java | 9 ++++++++-
3 files changed, 16 insertions(+), 16 deletions(-)
rename src/test/java/de/szut/lf8_starter/integration/project/{FindProjectActionTest.java => GetProjectActionTest.java} (89%)
diff --git a/requests/updateProject.http b/requests/updateProject.http
index dfa5f0b..d1ae70c 100644
--- a/requests/updateProject.http
+++ b/requests/updateProject.http
@@ -1,15 +1,3 @@
### GET request to example server
PUT http://localhost:8080/projects/1
-Authorization: Bearer {{auth_token}}
-Content-Type: application/json
-
-{
- "name": "newName",
- "leading_employee": 2,
- "employees": [],
- "contractor": 9,
- "contractor_name": "New Contractor name",
- "comment": "new goal of project",
- "start_date": "01.01.2010",
- "planned_end_date": "01.01.2021"
-}
\ No newline at end of file
+Authorization: Bearer {{auth_token}}
\ No newline at end of file
diff --git a/src/test/java/de/szut/lf8_starter/integration/project/FindProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/GetProjectActionTest.java
similarity index 89%
rename from src/test/java/de/szut/lf8_starter/integration/project/FindProjectActionTest.java
rename to src/test/java/de/szut/lf8_starter/integration/project/GetProjectActionTest.java
index dacb171..c8e17cc 100644
--- a/src/test/java/de/szut/lf8_starter/integration/project/FindProjectActionTest.java
+++ b/src/test/java/de/szut/lf8_starter/integration/project/GetProjectActionTest.java
@@ -18,14 +18,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest
@AutoConfigureMockMvc(addFilters = false)
-class FindProjectActionTest {
+class GetProjectActionTest {
@Autowired
private MockMvc mockMvc;
@Autowired
private ProjectRepository projectRepository;
@Test
- void createProjectTest() throws Exception {
+ void getProjectTest() throws Exception {
var project = new ProjectEntity();
project.setId(1);
project.setComment("comment");
@@ -51,4 +51,9 @@ class FindProjectActionTest {
.andExpect(jsonPath("employees").isArray())
.andExpect(jsonPath("employees", hasSize(3)));
}
+
+ @Test
+ void getProjectShouldReturnNotFoundResponseWhenProjectIsNotFound() throws Exception {
+ this.mockMvc.perform(get("/projects/2")).andExpect(status().isNotFound());
+ }
}
diff --git a/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java
index b50c15d..5fb4c02 100644
--- a/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java
+++ b/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java
@@ -16,6 +16,8 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@@ -29,7 +31,7 @@ class UpdateProjectActionTest {
private ProjectRepository projectRepository;
@Test
- void updateProjectTest() throws Exception {
+ void updateProjectShouldUpdateProject() throws Exception {
ProjectEntity project = new ProjectEntity();
project.setId(1);
project.setComment("comment");
@@ -83,4 +85,9 @@ class UpdateProjectActionTest {
assertThat(existingProject.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2022, 1, 1));
}
+
+ @Test
+ void updateProjectShouldReturnNotFoundResponseWhenProjectIsNotFound() throws Exception {
+ this.mockMvc.perform(put("/projects/2").content("{}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());
+ }
}