From 63b996bd623ac226b60e89c26944a2a8e1516521 Mon Sep 17 00:00:00 2001 From: Hsbalazs Date: Tue, 10 Sep 2024 18:48:41 +0200 Subject: [PATCH] fix: repair reviewdog finding --- .../services/mail/EmailServiceImpl.java | 1 - .../services/user/owner/OwnerServiceImpl.java | 2 -- .../{Pet => pet}/PetServiceImplTest.java | 30 ++++++++++++++----- 3 files changed, 22 insertions(+), 11 deletions(-) rename backend/src/test/java/com/greenfoxacademy/backend/services/{Pet => pet}/PetServiceImplTest.java (71%) diff --git a/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java b/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java index b2044b9e..48b59fc7 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/services/mail/EmailServiceImpl.java @@ -6,7 +6,6 @@ import jakarta.mail.internet.MimeMessage; import java.util.UUID; import lombok.RequiredArgsConstructor; - import org.springframework.core.io.ClassPathResource; import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSender; diff --git a/backend/src/main/java/com/greenfoxacademy/backend/services/user/owner/OwnerServiceImpl.java b/backend/src/main/java/com/greenfoxacademy/backend/services/user/owner/OwnerServiceImpl.java index 293efde7..7c6fd4d0 100644 --- a/backend/src/main/java/com/greenfoxacademy/backend/services/user/owner/OwnerServiceImpl.java +++ b/backend/src/main/java/com/greenfoxacademy/backend/services/user/owner/OwnerServiceImpl.java @@ -14,9 +14,7 @@ import com.greenfoxacademy.backend.services.auth.AuthService; import com.greenfoxacademy.backend.services.mail.EmailService; import jakarta.transaction.Transactional; - import java.util.UUID; - import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; diff --git a/backend/src/test/java/com/greenfoxacademy/backend/services/Pet/PetServiceImplTest.java b/backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java similarity index 71% rename from backend/src/test/java/com/greenfoxacademy/backend/services/Pet/PetServiceImplTest.java rename to backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java index 0ffa5c45..c9a48258 100644 --- a/backend/src/test/java/com/greenfoxacademy/backend/services/Pet/PetServiceImplTest.java +++ b/backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java @@ -1,7 +1,7 @@ -package com.greenfoxacademy.backend.services.Pet; +package com.greenfoxacademy.backend.services.pet; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.greenfoxacademy.backend.models.Owner; @@ -19,6 +19,15 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; +/** + * Integration test class for PetServiceImpl. + * + * This class uses the following annotations: + * + * - {@link SpringBootTest}: Indicates that the class is a Spring Boot test that will start the full application context. + * - {@link AutoConfigureMockMvc}: Automatically configures MockMvc for testing web layer. + * - {@link Transactional}: Ensures that each test method runs within a transaction that is rolled back after the test completes. + */ @SpringBootTest @AutoConfigureMockMvc @Transactional @@ -33,6 +42,11 @@ public class PetServiceImplTest { @Autowired private OwnerRepository ownerRepository; + /** + * Sets up mock data before each test. + * This method is executed before each test method in the current test class. + * It initializes mock data for owners and pets and saves them to the repository. + */ @BeforeEach public void setUp() { // Set up mock data @@ -60,9 +74,9 @@ public void setUp() { public void testCorrectEmailWithExistingPets() throws Exception { mockMvc.perform(get("/pets") .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.pets[0].name").value("Morzsi")) - .andExpect(jsonPath("$.pets[1].name").value("Rusty")); + .andExpect(status().isOk()) + .andExpect(jsonPath("$.pets[0].name").value("Morzsi")) + .andExpect(jsonPath("$.pets[1].name").value("Rusty")); } @Test @@ -70,8 +84,8 @@ public void testCorrectEmailWithExistingPets() throws Exception { public void testCorrectEmailWithNoExistingPets() throws Exception { mockMvc.perform(get("/pets") .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.pets").isEmpty()); + .andExpect(status().isOk()) + .andExpect(jsonPath("$.pets").isEmpty()); } @Test @@ -79,6 +93,6 @@ public void testCorrectEmailWithNoExistingPets() throws Exception { public void testIncorrectEmail() throws Exception { mockMvc.perform(get("/pets") .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().is4xxClientError()); + .andExpect(status().is4xxClientError()); } }