From cda04fa8a23087b919c02d2f4acc700b5b457720 Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 23 Oct 2024 10:34:24 +0200 Subject: [PATCH] Remove var --- .../project/AddEmployeeToProjectTest.java | 11 +++----- .../project/CreateProjectActionTest.java | 28 +++++++++---------- .../project/GetProjectActionTest.java | 2 +- .../project/ProjectFindAllSuccessTest.java | 4 +-- .../project/RemoveProjectActionTest.java | 2 +- .../project/UpdateProjectActionTest.java | 15 +++++----- 6 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java b/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java index 570687a..4193e77 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java @@ -6,10 +6,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; +import org.springframework.http.*; import org.springframework.test.web.servlet.MockMvc; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -37,7 +34,7 @@ class AddEmployeeToProjectActionIntegrationTest { @Test void addEmployeeToProjectTest() throws Exception { - var project = new ProjectEntity(); + ProjectEntity project = new ProjectEntity(); project.setComment("comment"); project.setContractor(1); project.setContractorName("contractorName"); @@ -54,7 +51,7 @@ class AddEmployeeToProjectActionIntegrationTest { .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isNoContent()); - var updatedProject = projectRepository.findById(1L).get(); + ProjectEntity updatedProject = projectRepository.findById(1L).get(); assert updatedProject.getEmployees().contains(312L); } @@ -73,7 +70,7 @@ class AddEmployeeToProjectActionIntegrationTest { HttpEntity> request = new HttpEntity<>(map, headers); - var response = this.restTemplate.exchange(url, HttpMethod.POST, request, Map.class); + ResponseEntity response = this.restTemplate.exchange(url, HttpMethod.POST, request, Map.class); return Objects.requireNonNull(response.getBody()).get("access_token").toString(); } diff --git a/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java index af10c64..6a340ca 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java @@ -1,5 +1,6 @@ package de.szut.lf8_starter.integration.project; +import de.szut.lf8_starter.project.ProjectEntity; import de.szut.lf8_starter.project.ProjectRepository; import org.json.JSONObject; import org.junit.jupiter.api.Test; @@ -12,10 +13,9 @@ import org.springframework.test.web.servlet.MockMvc; import java.time.LocalDate; import java.util.Arrays; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest @@ -41,9 +41,9 @@ class CreateProjectActionTest { } """; - final var contentAsString = this.mockMvc.perform( - post("/projects").content(content).contentType(MediaType.APPLICATION_JSON) - ) + final String contentAsString = this.mockMvc.perform( + post("/projects").content(content).contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().isCreated()) .andExpect(jsonPath("name", is("name"))) .andExpect(jsonPath("leading_employee", is(1))) @@ -57,15 +57,15 @@ class CreateProjectActionTest { .getResponse() .getContentAsString(); - final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString()); + final long id = Long.parseLong(new JSONObject(contentAsString).get("id").toString()); - final var project = this.projectRepository.findById(id); - assertThat(project.get().getName()).isEqualTo("name"); - assertThat(project.get().getLeadingEmployee()).isEqualTo(1); - assertThat(project.get().getContractor()).isEqualTo(4); - assertThat(project.get().getContractorName()).isEqualTo("Peter File"); - assertThat(project.get().getComment()).isEqualTo("goal of project"); - assertThat(project.get().getStartDate()).isEqualTo(LocalDate.of(2000, 1, 1)); - assertThat(project.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2001, 1, 1)); + final ProjectEntity project = this.projectRepository.findById(id); + assertThat(project.get().getName()).isEqualTo("name"); + assertThat(project.get().getLeadingEmployee()).isEqualTo(1); + assertThat(project.get().getContractor()).isEqualTo(4); + assertThat(project.get().getContractorName()).isEqualTo("Peter File"); + assertThat(project.get().getComment()).isEqualTo("goal of project"); + assertThat(project.get().getStartDate()).isEqualTo(LocalDate.of(2000, 1, 1)); + assertThat(project.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2001, 1, 1)); } } diff --git a/src/test/java/de/szut/lf8_starter/integration/project/GetProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/GetProjectActionTest.java index 0b9eb83..1b6ed3f 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/GetProjectActionTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/GetProjectActionTest.java @@ -26,7 +26,7 @@ class GetProjectActionTest { @Test void getProjectTest() throws Exception { - var project = new ProjectEntity(); + ProjectEntity project = new ProjectEntity(); project.setId(1); project.setComment("comment"); project.setContractor(1); diff --git a/src/test/java/de/szut/lf8_starter/integration/project/ProjectFindAllSuccessTest.java b/src/test/java/de/szut/lf8_starter/integration/project/ProjectFindAllSuccessTest.java index 3fa8bd8..ff3a642 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/ProjectFindAllSuccessTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/ProjectFindAllSuccessTest.java @@ -27,7 +27,7 @@ class ProjectFindAllSuccessTest { @Test void findAllProjectsTest() throws Exception { - var project = new ProjectEntity(); + ProjectEntity project = new ProjectEntity(); project.setId(1); project.setComment("comment"); project.setContractor(1); @@ -36,7 +36,7 @@ class ProjectFindAllSuccessTest { project.setLeadingEmployee(1); project.setName("name"); project.setStartDate(LocalDate.of(2021, 1, 1)); - project.setEmployees(List.of(1L,2L,3L)); + project.setEmployees(List.of(1L, 2L, 3L)); this.projectRepository.save(project); this.mockMvc.perform(get("/projects")) diff --git a/src/test/java/de/szut/lf8_starter/integration/project/RemoveProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/RemoveProjectActionTest.java index 93285ab..c2c47dd 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/RemoveProjectActionTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/RemoveProjectActionTest.java @@ -25,7 +25,7 @@ class RemoveProjectActionTest { @Test void deleteProjectTest() throws Exception { - var project = new ProjectEntity(); + ProjectEntity project = new ProjectEntity(); project.setComment("comment"); project.setContractor(1); project.setContractorName("contractorName"); 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 4e53c8c..e03a680 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 @@ -13,6 +13,7 @@ import org.springframework.test.web.servlet.MockMvc; import java.time.LocalDate; import java.util.Arrays; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.is; @@ -55,7 +56,7 @@ class UpdateProjectActionTest { } """; - final var contentAsString = this.mockMvc.perform( + final String contentAsString = this.mockMvc.perform( put("/projects/1").content(content).contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) @@ -71,9 +72,9 @@ class UpdateProjectActionTest { .getResponse() .getContentAsString(); - final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString()); + final long id = Long.parseLong(new JSONObject(contentAsString).get("id").toString()); - final var existingProject = this.projectRepository.findById(id); + final Optional existingProject = this.projectRepository.findById(id); assertThat(existingProject.get().getName()).isEqualTo("updatedName"); assertThat(existingProject.get().getLeadingEmployee()).isEqualTo(2); assertThat(existingProject.get().getContractor()).isEqualTo(6); @@ -103,13 +104,13 @@ class UpdateProjectActionTest { {} """; - final var contentAsString = this.mockMvc.perform( + final String contentAsString = this.mockMvc.perform( put("/projects/1").content(content).contentType(MediaType.APPLICATION_JSON) ) .andExpect(status().isOk()) .andExpect(jsonPath("name", is("name"))) .andExpect(jsonPath("leading_employee", is(1))) - .andExpect(jsonPath("employees", is(List.of(1,2,3)))) + .andExpect(jsonPath("employees", is(List.of(1, 2, 3)))) .andExpect(jsonPath("contractor", is(1))) .andExpect(jsonPath("contractor_name", is("contractorName"))) .andExpect(jsonPath("comment", is("comment"))) @@ -120,9 +121,9 @@ class UpdateProjectActionTest { .getResponse() .getContentAsString(); - final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString()); + final long id = Long.parseLong(new JSONObject(contentAsString).get("id").toString()); - final var existingProject = this.projectRepository.findById(id); + final Optional existingProject = this.projectRepository.findById(id); assertThat(existingProject.get().getName()).isEqualTo("name"); assertThat(existingProject.get().getLeadingEmployee()).isEqualTo(1); assertThat(existingProject.get().getContractor()).isEqualTo(1);