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 d8287e8
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.
* 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
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 d8287e8

Please sign in to comment.