Skip to content

Commit

Permalink
fix: repair reviewdog finding
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsbalazs committed Sep 10, 2024
1 parent ae4d1b0 commit 63b996b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,6 +19,15 @@
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;

/**
* Integration test class for PetServiceImpl.
*

Check warning on line 24 in backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Empty line should be followed by <p> tag on the next line. Raw Output: /github/workspace/backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java:24:0: warning: Empty line should be followed by <p> tag on the next line. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck)
* This class uses the following annotations:
*

Check warning on line 26 in backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Empty line should be followed by <p> tag on the next line. Raw Output: /github/workspace/backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java:26:0: warning: Empty line should be followed by <p> tag on the next line. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck)
* - {@link SpringBootTest}: Indicates that the class is a Spring Boot test that will start the full application context.

Check warning on line 27 in backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Line is longer than 100 characters (found 121). Raw Output: /github/workspace/backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java:27:0: warning: Line is longer than 100 characters (found 121). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
* - {@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.

Check warning on line 29 in backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Line is longer than 100 characters (found 129). Raw Output: /github/workspace/backend/src/test/java/com/greenfoxacademy/backend/services/pet/PetServiceImplTest.java:29:0: warning: Line is longer than 100 characters (found 129). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
*/
@SpringBootTest
@AutoConfigureMockMvc
@Transactional
Expand All @@ -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
Expand Down Expand Up @@ -60,25 +74,25 @@ 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
@WithMockUser(username = "userWithNoPets@example.com")
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
@WithMockUser(username = "nonExistingUser@example.com")
public void testIncorrectEmail() throws Exception {
mockMvc.perform(get("/pets")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError());
.andExpect(status().is4xxClientError());
}
}

0 comments on commit 63b996b

Please sign in to comment.