From aed44aedc935ab70f9bcd3b57edd2f4d2d636fd4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Diana=20Gul=C4=8D=C3=ADkov=C3=A1?= <xgulcik@fi.muni.cz>
Date: Mon, 17 Apr 2023 01:50:15 +0200
Subject: [PATCH] checkstyle fix

---
 .../car/rest/CarComponentPairController.java  | 13 +++---
 .../service/CarComponentPairServiceImpl.java  |  4 +-
 .../car/service/CarDriverPairServiceImpl.java |  5 +--
 .../data/repository/CarRepositoryTest.java    | 10 ++---
 .../rest/CarComponentPairControllerTest.java  | 25 ++++++-----
 .../pa165/car/rest/CarControllerTest.java     |  2 +-
 .../car/rest/CarDriverPairControllerTest.java | 32 ++++++-------
 .../service/CarComponentPairServiceTests.java |  2 +-
 .../service/CarDriverPairServiceTests.java    |  2 +-
 .../pa165/car/service/CarServiceTests.java    | 45 +++++++++++--------
 10 files changed, 72 insertions(+), 68 deletions(-)

diff --git a/car/src/main/java/cz/muni/pa165/car/rest/CarComponentPairController.java b/car/src/main/java/cz/muni/pa165/car/rest/CarComponentPairController.java
index 1b242046..006e9668 100644
--- a/car/src/main/java/cz/muni/pa165/car/rest/CarComponentPairController.java
+++ b/car/src/main/java/cz/muni/pa165/car/rest/CarComponentPairController.java
@@ -7,7 +7,6 @@ import cz.muni.pa165.common_library.dtos.CarResponseDto;
 import io.swagger.v3.oas.annotations.Operation;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
@@ -61,7 +60,7 @@ public class CarComponentPairController {
   @PutMapping(path = "/removecomponent",
       produces = MediaType.APPLICATION_JSON_VALUE)
   public ResponseEntity<CarResponseDto> removeComponent(@RequestParam Long componentId,
-                                                       @RequestParam Long carId) {
+                                                        @RequestParam Long carId) {
     return ResponseEntity.ok(carComponentService.removeComponent(componentId, carId));
   }
 
@@ -74,8 +73,8 @@ public class CarComponentPairController {
   @Operation(summary = "Get all components of a car")
   @GetMapping(path = "/getcomponents",
       produces = MediaType.APPLICATION_JSON_VALUE)
-  public ResponseEntity<List<CarComponentResponseDto>>
-      getAllComponentsOfCar(@RequestParam Long carId) {
+  public ResponseEntity<List<CarComponentResponseDto>> getAllComponentsOfCar(
+      @RequestParam Long carId) {
     return ResponseEntity.ok(carComponentService.getAllComponentsOfCar(carId));
   }
 
@@ -89,9 +88,9 @@ public class CarComponentPairController {
    */
   @Operation(summary = "Get all components from component repo")
   @GetMapping(path = "/getsparecomponents",
-          produces = MediaType.APPLICATION_JSON_VALUE)
-  public ResponseEntity<List<CarComponentResponseDto>>
-      getAllCarComponents(@RequestParam Long carId, @RequestParam Long componentId) {
+      produces = MediaType.APPLICATION_JSON_VALUE)
+  public ResponseEntity<List<CarComponentResponseDto>> getAllCarComponents(@RequestParam Long carId,
+                      @RequestParam Long componentId) {
     List<CarComponentResponseDto> allComponents = dbGetter.getAllComponentsFromDb();
     var carComponentsResponse = getAllComponentsOfCar(carId);
     var carComponents = carComponentsResponse.getBody();
diff --git a/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java b/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java
index f18115ff..ae8139f9 100644
--- a/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java
+++ b/car/src/main/java/cz/muni/pa165/car/service/CarComponentPairServiceImpl.java
@@ -1,10 +1,9 @@
 package cz.muni.pa165.car.service;
 
-import cz.muni.pa165.car.restemplate.DbGetter;
-
 import cz.muni.pa165.car.data.model.Car;
 import cz.muni.pa165.car.data.repository.CarRepository;
 import cz.muni.pa165.car.mapper.CarMapper;
+import cz.muni.pa165.car.restemplate.DbGetter;
 import cz.muni.pa165.common_library.dtos.CarComponentResponseDto;
 import cz.muni.pa165.common_library.dtos.CarResponseDto;
 import cz.muni.pa165.common_library.exception.DatabaseException;
@@ -12,7 +11,6 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
diff --git a/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java b/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java
index 06ff7817..0b72660e 100644
--- a/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java
+++ b/car/src/main/java/cz/muni/pa165/car/service/CarDriverPairServiceImpl.java
@@ -8,13 +8,12 @@ import cz.muni.pa165.common_library.dtos.CarResponseDto;
 import cz.muni.pa165.common_library.dtos.DriverDto;
 import cz.muni.pa165.common_library.dtos.DriverInsightDto;
 import cz.muni.pa165.common_library.exception.DatabaseException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
diff --git a/car/src/test/java/cz/muni/pa165/car/data/repository/CarRepositoryTest.java b/car/src/test/java/cz/muni/pa165/car/data/repository/CarRepositoryTest.java
index 52d5cb08..98ba4a8d 100644
--- a/car/src/test/java/cz/muni/pa165/car/data/repository/CarRepositoryTest.java
+++ b/car/src/test/java/cz/muni/pa165/car/data/repository/CarRepositoryTest.java
@@ -1,19 +1,17 @@
 package cz.muni.pa165.car.data.repository;
 
-import cz.muni.pa165.car.data.model.Car;
-import org.junit.jupiter.api.Assertions;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import cz.muni.pa165.car.data.model.Car;
+import java.util.Set;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
-import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
 import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import java.util.Set;
 
 @DataJpaTest
 class CarRepositoryTest {
diff --git a/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java b/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java
index c214cf06..6a35e26d 100644
--- a/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java
+++ b/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java
@@ -1,14 +1,20 @@
 package cz.muni.pa165.car.rest;
 
+import static org.mockito.BDDMockito.given;
+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.status;
+
 import com.fasterxml.jackson.databind.ObjectMapper;
 import cz.muni.pa165.car.restemplate.DbGetter;
 import cz.muni.pa165.car.service.CarComponentPairService;
 import cz.muni.pa165.common_library.dtos.CarComponentResponseDto;
 import cz.muni.pa165.common_library.dtos.CarResponseDto;
+import java.math.BigDecimal;
+import java.util.List;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import static org.mockito.BDDMockito.given;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
 import org.springframework.boot.test.context.TestConfiguration;
@@ -16,15 +22,9 @@ import org.springframework.boot.test.mock.mockito.MockBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.http.MediaType;
 import org.springframework.test.web.servlet.MockMvc;
-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.status;
-
-import java.math.BigDecimal;
-import java.util.List;
 
 @WebMvcTest(CarComponentPairController.class)
-public class CarComponentPairControllerTest {
+class CarComponentPairControllerTest {
 
   private static CarResponseDto carResponseDto;
   private static CarResponseDto carResponseDto2;
@@ -115,14 +115,17 @@ public class CarComponentPairControllerTest {
 
   @Test
   void getAllComponentsOfCar() throws Exception {
-    given(carComponentPairServiceMock.getAllComponentsOfCar(1L)).willReturn(List.of(carComponentResponseDto, carComponentResponseDto2));
+    given(carComponentPairServiceMock.getAllComponentsOfCar(1L)).willReturn(
+        List.of(carComponentResponseDto, carComponentResponseDto2));
 
     String response = mockMvc.perform(get("/carcomponent/getcomponents")
             .param("carId", String.valueOf(1L))
             .contentType(MediaType.APPLICATION_JSON)
         )
         .andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
-    List<CarComponentResponseDto> carComponentListResponse = List.of(objectMapper.readValue(response, CarComponentResponseDto[].class));
-    Assertions.assertEquals(List.of(carComponentResponseDto, carComponentResponseDto2), carComponentListResponse);
+    List<CarComponentResponseDto> carComponentListResponse =
+        List.of(objectMapper.readValue(response, CarComponentResponseDto[].class));
+    Assertions.assertEquals(List.of(carComponentResponseDto, carComponentResponseDto2),
+        carComponentListResponse);
   }
 }
\ No newline at end of file
diff --git a/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java b/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java
index dbe05c1b..b3ed4d6c 100644
--- a/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java
+++ b/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java
@@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.MockMvc;
 
 
 @WebMvcTest(CarController.class)
-public class CarControllerTest {
+class CarControllerTest {
 
   @Autowired
   private MockMvc mockMvc;
diff --git a/car/src/test/java/cz/muni/pa165/car/rest/CarDriverPairControllerTest.java b/car/src/test/java/cz/muni/pa165/car/rest/CarDriverPairControllerTest.java
index 84696b2c..b466a5d2 100644
--- a/car/src/test/java/cz/muni/pa165/car/rest/CarDriverPairControllerTest.java
+++ b/car/src/test/java/cz/muni/pa165/car/rest/CarDriverPairControllerTest.java
@@ -1,27 +1,25 @@
 package cz.muni.pa165.car.rest;
 
+import static org.mockito.BDDMockito.given;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
 import com.fasterxml.jackson.databind.ObjectMapper;
-import cz.muni.pa165.car.rest.CarDriverPairController;
 import cz.muni.pa165.car.service.CarDriverPairService;
 import cz.muni.pa165.common_library.dtos.CarResponseDto;
 import cz.muni.pa165.common_library.dtos.DriverDto;
+import java.util.List;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import static org.mockito.BDDMockito.given;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
 import org.springframework.boot.test.mock.mockito.MockBean;
 import org.springframework.http.MediaType;
 import org.springframework.test.web.servlet.MockMvc;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
-import java.util.ArrayList;
-import java.util.List;
 
 @WebMvcTest(CarDriverPairController.class)
-public class CarDriverPairControllerTest {
+class CarDriverPairControllerTest {
 
   @Autowired
   private MockMvc mockMvc;
@@ -85,7 +83,7 @@ public class CarDriverPairControllerTest {
   }
 
   @Test
-  public void nonExistingPathPostTest() throws Exception {
+  void nonExistingPathPostTest() throws Exception {
     given(carDriverPairServiceMock.assignDriverToCar(1L, 1L)).willReturn(carResponseDto);
 
     mockMvc.perform(put("/cardriver/invalidpath"))
@@ -93,7 +91,7 @@ public class CarDriverPairControllerTest {
   }
 
   @Test
-  public void assignDriverToCar() throws Exception {
+  void assignDriverToCar() throws Exception {
     given(carDriverPairServiceMock.assignDriverToCar(1L, 1L)).willReturn(carResponseDto);
 
     String response = mockMvc.perform(put("/cardriver/assign")
@@ -109,7 +107,7 @@ public class CarDriverPairControllerTest {
   }
 
   @Test
-  public void unassignDriverFromCar() throws Exception {
+  void unassignDriverFromCar() throws Exception {
     given(carDriverPairServiceMock.unassignDriverFromCar(1L, 1L)).willReturn(carResponseDto4);
 
     String response = mockMvc.perform(put("/cardriver/unassign")
@@ -125,20 +123,22 @@ public class CarDriverPairControllerTest {
   }
 
   @Test
-  public void getAllDriversOfCar() throws Exception {
-    given(carDriverPairServiceMock.getAllDriversOfCar(3L)).willReturn(List.of(driverDto, driverDto2));
+  void getAllDriversOfCar() throws Exception {
+    given(carDriverPairServiceMock.getAllDriversOfCar(3L)).willReturn(
+        List.of(driverDto, driverDto2));
 
     String response = mockMvc.perform(put("/cardriver/alldrivers")
             .param("carId", String.valueOf(3L))
             .contentType(MediaType.APPLICATION_JSON))
         .andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
 
-    List<DriverDto> driverDtoListResponse = List.of(objectMapper.readValue(response, DriverDto[].class));
+    List<DriverDto> driverDtoListResponse =
+        List.of(objectMapper.readValue(response, DriverDto[].class));
     Assertions.assertEquals(List.of(driverDto, driverDto2), driverDtoListResponse);
   }
 
   @Test
-  public void setMainDriver() throws Exception {
+  void setMainDriver() throws Exception {
     given(carDriverPairServiceMock.setMainDriver(3L, 1L)).willReturn(carResponseDto3);
 
     String response = mockMvc.perform(put("/cardriver/setmain")
@@ -151,7 +151,7 @@ public class CarDriverPairControllerTest {
   }
 
   @Test
-  public void removeMainDriver() throws Exception {
+  void removeMainDriver() throws Exception {
     given(carDriverPairServiceMock.removeMainDriver(1L)).willReturn(carResponseDto);
 
     String response = mockMvc.perform(put("/cardriver/removemain")
diff --git a/car/src/test/java/cz/muni/pa165/car/service/CarComponentPairServiceTests.java b/car/src/test/java/cz/muni/pa165/car/service/CarComponentPairServiceTests.java
index 852b8fc4..f338505e 100644
--- a/car/src/test/java/cz/muni/pa165/car/service/CarComponentPairServiceTests.java
+++ b/car/src/test/java/cz/muni/pa165/car/service/CarComponentPairServiceTests.java
@@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.MockMvc;
 
 @SpringBootTest
 @AutoConfigureMockMvc
-public class CarComponentPairServiceTests {
+class CarComponentPairServiceTests {
   @Autowired
   private MockMvc mockMvc;
 
diff --git a/car/src/test/java/cz/muni/pa165/car/service/CarDriverPairServiceTests.java b/car/src/test/java/cz/muni/pa165/car/service/CarDriverPairServiceTests.java
index c2ebe418..4bf73d32 100644
--- a/car/src/test/java/cz/muni/pa165/car/service/CarDriverPairServiceTests.java
+++ b/car/src/test/java/cz/muni/pa165/car/service/CarDriverPairServiceTests.java
@@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.MockMvc;
 
 @SpringBootTest
 @AutoConfigureMockMvc
-public class CarDriverPairServiceTests {
+class CarDriverPairServiceTests {
 
   @Autowired
   private MockMvc mockMvc;
diff --git a/car/src/test/java/cz/muni/pa165/car/service/CarServiceTests.java b/car/src/test/java/cz/muni/pa165/car/service/CarServiceTests.java
index 5b588258..0c085a41 100644
--- a/car/src/test/java/cz/muni/pa165/car/service/CarServiceTests.java
+++ b/car/src/test/java/cz/muni/pa165/car/service/CarServiceTests.java
@@ -1,5 +1,12 @@
 package cz.muni.pa165.car.service;
 
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
 import com.fasterxml.jackson.databind.ObjectMapper;
 import cz.muni.pa165.car.data.model.Car;
 import cz.muni.pa165.car.data.repository.CarRepository;
@@ -8,30 +15,23 @@ import cz.muni.pa165.common_library.dtos.CarComponentResponseDto;
 import cz.muni.pa165.common_library.dtos.CarRequestDto;
 import cz.muni.pa165.common_library.dtos.CarResponseDto;
 import cz.muni.pa165.common_library.dtos.DriverInsightDto;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.BDDMockito.given;
 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.boot.test.mock.mockito.MockBean;
 import org.springframework.http.MediaType;
 import org.springframework.test.web.servlet.MockMvc;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
 
 @SpringBootTest()
 @AutoConfigureMockMvc()
-public class CarServiceTests {
+class CarServiceTests {
 
   @Autowired
   private MockMvc mockMvc;
@@ -88,7 +88,8 @@ public class CarServiceTests {
     given(carRepository.save(car)).willReturn(car1);
     given(carRepository.findById(1L)).willReturn(
         Optional.of(car1));
-    DriverInsightDto driverInsightDto = new DriverInsightDto(1L, "name", "surname", "nationality", Map.of());
+    DriverInsightDto driverInsightDto =
+        new DriverInsightDto(1L, "name", "surname", "nationality", Map.of());
     CarComponentResponseDto carComponentDto = CarComponentResponseDto.builder().build();
 
     given(dbGetter.getDriverFromDb(anyLong())).willReturn(driverInsightDto);
@@ -101,8 +102,10 @@ public class CarServiceTests {
     var carResponse = objectMapper.readValue(response, CarResponseDto.class);
     Assertions.assertAll(
         () -> Assertions.assertEquals(carResponse.getId(), car1.getId()),
-        () -> Assertions.assertEquals(carResponse.getComponentIdsNames(), car1.getComponents().stream().toList()),
-        () -> Assertions.assertEquals(carResponse.getDriverIdsNames(), car1.getDrivers().stream().toList()),
+        () -> Assertions.assertEquals(carResponse.getComponentIdsNames(),
+            car1.getComponents().stream().toList()),
+        () -> Assertions.assertEquals(carResponse.getDriverIdsNames(),
+            car1.getDrivers().stream().toList()),
         () -> Assertions.assertEquals(carResponse.getMainDriverId(), car1.getMainDriverId())
     );
   }
@@ -117,8 +120,10 @@ public class CarServiceTests {
     var carResponse = List.of(objectMapper.readValue(response, CarResponseDto[].class));
     Assertions.assertAll(
         () -> Assertions.assertEquals(carResponse.get(0).getId(), car1.getId()),
-        () -> Assertions.assertEquals(carResponse.get(0).getComponentIdsNames(), car1.getComponents().stream().toList()),
-        () -> Assertions.assertEquals(carResponse.get(0).getDriverIdsNames(), car1.getDrivers().stream().toList()),
+        () -> Assertions.assertEquals(carResponse.get(0).getComponentIdsNames(),
+            car1.getComponents().stream().toList()),
+        () -> Assertions.assertEquals(carResponse.get(0).getDriverIdsNames(),
+            car1.getDrivers().stream().toList()),
         () -> Assertions.assertEquals(carResponse.get(0).getMainDriverId(), car1.getMainDriverId())
     );
   }
@@ -135,8 +140,10 @@ public class CarServiceTests {
     var carResponse = objectMapper.readValue(response, CarResponseDto.class);
     Assertions.assertAll(
         () -> Assertions.assertEquals(carResponse.getId(), car1.getId()),
-        () -> Assertions.assertEquals(carResponse.getComponentIdsNames(), car1.getComponents().stream().toList()),
-        () -> Assertions.assertEquals(carResponse.getDriverIdsNames(), car1.getDrivers().stream().toList()),
+        () -> Assertions.assertEquals(carResponse.getComponentIdsNames(),
+            car1.getComponents().stream().toList()),
+        () -> Assertions.assertEquals(carResponse.getDriverIdsNames(),
+            car1.getDrivers().stream().toList()),
         () -> Assertions.assertEquals(carResponse.getMainDriverId(), car1.getMainDriverId())
     );
   }
-- 
GitLab