From 807e84ed7dce912f4e1fccfc3b9398de86623a0c Mon Sep 17 00:00:00 2001 From: Gituser010 Date: Wed, 26 Jun 2024 14:36:41 +0200 Subject: [PATCH] code reformated --- .../APIExceptionHandler.java | 21 +- .../DTOs/ActuatorDTO.java | 1 + .../virtualsmarthomeplus/DTOs/SensorDTO.java | 1 + .../Mapper/DTOMapper.java | 7 +- .../controllers/DeviceController.java | 1 + .../controllers/DoorController.java | 12 +- .../controllers/FinalDeviceHandling.java | 1 - .../controllers/FireplaceController.java | 10 +- .../controllers/RGBLightController.java | 10 +- .../controllers/ThermometerController.java | 10 +- .../factory/DeviceFactory.java | 2 +- .../virtualsmarthomeplus/house/House.java | 2 +- .../house/devices/Actuator.java | 2 +- .../house/devices/Device.java | 2 +- .../house/devices/finalDevices/Door.java | 1 + .../house/devices/finalDevices/Fireplace.java | 1 + .../house/devices/finalDevices/RGBLight.java | 2 +- .../devices/finalDevices/Thermometer.java | 21 +- src/main/resources/application.properties | 1 - src/main/resources/application.yaml | 2 +- .../Mapper/DTOMapperTest.java | 35 +- .../controllers/DoorApiTest.java | 3 +- .../controllers/FireplaceApiTest.java | 7 +- .../controllers/HouseApiTest.java | 12 +- .../controllers/RGBLightApiTest.java | 3 +- .../controllers/ThermometerApiTest.java | 354 +++++++++--------- .../house/DeviceFactoryTest.java | 7 +- .../virtualsmarthomeplus/house/HouseTest.java | 14 +- .../house/devices/DoorTest.java | 13 +- .../house/devices/FireplaceTest.java | 14 +- .../house/devices/RGBLightTest.java | 1 - 31 files changed, 272 insertions(+), 301 deletions(-) diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/APIExceptionHandler.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/APIExceptionHandler.java index 4e7a2b0..f38baa5 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/APIExceptionHandler.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/APIExceptionHandler.java @@ -44,10 +44,11 @@ protected ResponseEntity handleMethodArgumentNotValid( return new ResponseEntity<>(apiError, status); } + /** * Returns proper response entity on NoSuchElementException. * - * @param ex exception which caused this method call + * @param ex exception which caused this method call * @return {@link io.patriotframework.virtualsmarthomeplus.APIErrors.APIError APIError} instance whith list of * {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which * informs about specific validity violations @@ -55,13 +56,14 @@ protected ResponseEntity handleMethodArgumentNotValid( @ExceptionHandler(value = NoSuchElementException.class) protected ResponseEntity handleNotFound(NoSuchElementException ex) { final String message = "Device not found"; - final APIError apiError = new APIError(HttpStatus.NOT_FOUND,message); - return new ResponseEntity<>(apiError,HttpStatus.NOT_FOUND); + final APIError apiError = new APIError(HttpStatus.NOT_FOUND, message); + return new ResponseEntity<>(apiError, HttpStatus.NOT_FOUND); } + /** * Returns proper response entity on IllegalArgumentException. * - * @param ex exception which caused this method call + * @param ex exception which caused this method call * @return {@link io.patriotframework.virtualsmarthomeplus.APIErrors.APIError APIError} instance whith list of * {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which * informs about specific validity violations @@ -69,13 +71,14 @@ protected ResponseEntity handleNotFound(NoSuchElementException ex) { @ExceptionHandler(value = IllegalArgumentException.class) protected ResponseEntity handleWrongArgument(IllegalArgumentException ex) { final String message = "Wrong label"; - final APIError apiError = new APIError(HttpStatus.BAD_REQUEST,message); - return new ResponseEntity<>(apiError,HttpStatus.BAD_REQUEST); + final APIError apiError = new APIError(HttpStatus.BAD_REQUEST, message); + return new ResponseEntity<>(apiError, HttpStatus.BAD_REQUEST); } + /** * Returns proper response entity on KeyAlreadyExistException. * - * @param ex exception which caused this method call + * @param ex exception which caused this method call * @return {@link io.patriotframework.virtualsmarthomeplus.APIErrors.APIError APIError} instance whith list of * {@link io.patriotframework.virtualsmarthomeplus.APIErrors.NotValidSubError NotValidSubError} instances, which * informs about specific validity violations @@ -83,8 +86,8 @@ protected ResponseEntity handleWrongArgument(IllegalArgumentException ex @ExceptionHandler(value = KeyAlreadyExistsException.class) protected ResponseEntity handleExistingDevice(IllegalArgumentException ex) { final String message = "Device already exists"; - final APIError apiError = new APIError(HttpStatus.CONFLICT,message); - return new ResponseEntity<>(apiError,HttpStatus.CONFLICT); + final APIError apiError = new APIError(HttpStatus.CONFLICT, message); + return new ResponseEntity<>(apiError, HttpStatus.CONFLICT); } diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/ActuatorDTO.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/ActuatorDTO.java index c16a001..8b2b1c3 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/ActuatorDTO.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/ActuatorDTO.java @@ -5,6 +5,7 @@ import lombok.Setter; import java.util.Objects; + /** * Base class for actuator devices */ diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/SensorDTO.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/SensorDTO.java index 7330b8e..04e915a 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/SensorDTO.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/DTOs/SensorDTO.java @@ -1,4 +1,5 @@ package io.patriotframework.virtualsmarthomeplus.DTOs; + /** * Base class for sensor devices DTOs */ diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java index 4d40394..788300b 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapper.java @@ -1,11 +1,6 @@ package io.patriotframework.virtualsmarthomeplus.Mapper; -import io.patriotframework.virtualsmarthomeplus.DTOs.ThermometerDTO; -import io.patriotframework.virtualsmarthomeplus.DTOs.HouseDTO; -import io.patriotframework.virtualsmarthomeplus.DTOs.RGBLightDTO; -import io.patriotframework.virtualsmarthomeplus.DTOs.DeviceDTO; -import io.patriotframework.virtualsmarthomeplus.DTOs.DoorDTO; -import io.patriotframework.virtualsmarthomeplus.DTOs.FireplaceDTO; +import io.patriotframework.virtualsmarthomeplus.DTOs.*; import io.patriotframework.virtualsmarthomeplus.house.House; import io.patriotframework.virtualsmarthomeplus.house.devices.Device; import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door; diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DeviceController.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DeviceController.java index daabd63..011b163 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DeviceController.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DeviceController.java @@ -28,6 +28,7 @@ public class DeviceController { private static final String DEVICE_ID_ROUTE = APIRoutes.DEVICE_ROUTE + "/{label}"; private final House house; private final DTOMapper dtoMapper; + @Autowired public DeviceController(House house) { this.house = house; diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorController.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorController.java index 8694113..6f637e4 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorController.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorController.java @@ -8,15 +8,7 @@ import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - +import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; import javax.validation.Valid; @@ -78,7 +70,7 @@ public ResponseEntity postDoor( * * @param device updated door * @param apiVersion api version specified in route - * @param label label of the new device + * @param label label of the new device * @return door updated or added to the house */ @PutMapping(DOOR_ID_ROUTE) diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FinalDeviceHandling.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FinalDeviceHandling.java index c0936a3..33f5c6e 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FinalDeviceHandling.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FinalDeviceHandling.java @@ -91,7 +91,6 @@ public DeviceDTO handlePut(String label, DeviceDTO device) deviceToUpdate.update(device); - return dtoMapper.map(deviceToUpdate); } diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceController.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceController.java index dcad41c..29cfd1d 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceController.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceController.java @@ -8,13 +8,7 @@ import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Fireplace; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; import javax.validation.Valid; @@ -72,7 +66,7 @@ public DeviceDTO postFireplace(@Valid @RequestBody FireplaceDTO device, @PathVar * * @param device updated fireplace DTO * @param apiVersion api version specified in route - * @param label label of the device to be created + * @param label label of the device to be created * @return fireplace updated or added to the house */ @PutMapping(FIREPLACE_ID_ROUTE) diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/RGBLightController.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/RGBLightController.java index 64e138f..a446869 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/RGBLightController.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/RGBLightController.java @@ -8,13 +8,7 @@ import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.RGBLight; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; import javax.validation.Valid; @@ -68,7 +62,7 @@ public ResponseEntity getLed(@PathVariable @NotNull String label, @Pa * * @param device updated RGBLight DTO * @param apiVersion api version specified in route - * @param label label of the RGBLight to be created + * @param label label of the RGBLight to be created * @return RGBLight updated or added to the house */ @PutMapping(RGB_LIGHT_ID_ROUTE) diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/ThermometerController.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/ThermometerController.java index f16c72a..7d9d7b4 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/ThermometerController.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/controllers/ThermometerController.java @@ -9,13 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.server.ResponseStatusException; import javax.validation.constraints.NotNull; @@ -76,7 +70,7 @@ public DeviceDTO postThermometer( * * @param thermometer updated thermometer DTO * @param apiVersion api version specified in route - * @param label label of the thermometer to be updated + * @param label label of the thermometer to be updated * @return thermometer updated or added to the house */ @PutMapping(THERMOMETER_ID_ROUTE) diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/factory/DeviceFactory.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/factory/DeviceFactory.java index 44ea2a1..0c358b4 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/factory/DeviceFactory.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/factory/DeviceFactory.java @@ -20,7 +20,7 @@ public DeviceFactory() { * @param device DTO of device to be created * @return devices of certain type */ - public Device createDevice( DeviceDTO device) throws IllegalArgumentException { + public Device createDevice(DeviceDTO device) throws IllegalArgumentException { final String deviceType = device.getClass().getSimpleName(); return switch (deviceType) { case "RGBLightDTO" -> new RGBLight(device.getLabel()); diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/House.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/House.java index 679e480..942a592 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/House.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/House.java @@ -83,7 +83,7 @@ public void removeDevice(String label) throws IllegalArgumentException, NoSuchEl * Provide device of certain type which is stored in house. * * @param deviceType type of requested device - * @param label label of requested device + * @param label label of requested device * @return device of requested type */ public Device getDeviceOfType(Class deviceType, String label) throws IllegalArgumentException { diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Actuator.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Actuator.java index 6612f0a..c561a41 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Actuator.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Actuator.java @@ -28,7 +28,7 @@ public Actuator(String label) { * Creates new Actuator with the same values of the attributes as given Actuator except label. * Label of the new Actuator is given by parameter. * - * @param newLabel label creates identity of the thermometer and is compared in the equals method + * @param newLabel label creates identity of the thermometer and is compared in the equals method * @param origDevice template for the new Actuator * @throws IllegalArgumentException if given label is null or blank */ diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Device.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Device.java index cbce1c2..fbf9bc3 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Device.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/Device.java @@ -103,8 +103,8 @@ public void setEnabled(Boolean enabled) { * Method responsible for check whether two Devices has the same values of attributes * * @param device device to which this object will be compared - * @throws IllegalArgumentException if parameter device is null * @return return true if objects have same attributes and false otherwise + * @throws IllegalArgumentException if parameter device is null */ public abstract boolean hasSameAttributes(Device device) throws IllegalArgumentException; diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Door.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Door.java index 005e199..0f4b377 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Door.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Door.java @@ -100,6 +100,7 @@ public boolean hasSameAttributes(Device door) throws IllegalArgumentException { } return typedDoor.opened == opened; } + /** * Updates the door object with the values from provided DTO. * diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Fireplace.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Fireplace.java index 651f8bc..26a6344 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Fireplace.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Fireplace.java @@ -101,6 +101,7 @@ public boolean hasSameAttributes(Device fireplace) throws IllegalArgumentExcepti } return typedFireplace.onFire == onFire; } + /** * Updates the fireplace object with the values from provided DTO. * diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/RGBLight.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/RGBLight.java index b6bb05d..acf3a8a 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/RGBLight.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/RGBLight.java @@ -10,7 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.awt.Color; +import java.awt.*; @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) diff --git a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Thermometer.java b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Thermometer.java index 6e3c717..3cb7c78 100644 --- a/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Thermometer.java +++ b/src/main/java/io/patriotframework/virtualsmarthomeplus/house/devices/finalDevices/Thermometer.java @@ -33,7 +33,7 @@ public Thermometer(String label) { /** * Creates new thermometer with given label and given unit. * - * @param unit measuring unit + * @param unit measuring unit * @param label label of the new thermometer * @throws IllegalArgumentException if given label is null or blank */ @@ -85,22 +85,22 @@ public Float getTemperature() { } /** - * Method sets new measuring unit + * Method gets type of measuring unit * - * @param unit change measuring unit to unit + * @return measuring unit */ - public void setUnit(String unit) { - Thermometer.this.unit = unit; - LOGGER.debug(String.format("Measuring unit changed to %s", unit)); + public String getUnit() { + return unit; } /** - * Method gets type of measuring unit + * Method sets new measuring unit * - * @return measuring unit + * @param unit change measuring unit to unit */ - public String getUnit() { - return unit; + public void setUnit(String unit) { + Thermometer.this.unit = unit; + LOGGER.debug(String.format("Measuring unit changed to %s", unit)); } /** @@ -130,6 +130,7 @@ public boolean hasSameAttributes(Device thermometer) throws IllegalArgumentExcep } return typedThermometer.unit.equals(unit); } + /** * Updates the thermometer object with the values from provided DTO. * diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 583ab48..d9c0f55 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,2 @@ - server.error.whitelabel.enabled=false server.error.include-message=always diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 41d525d..54b155f 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,2 +1,2 @@ server: - port : 8081 \ No newline at end of file + port: 8081 \ No newline at end of file diff --git a/src/test/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapperTest.java b/src/test/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapperTest.java index d7cf514..f96ab39 100644 --- a/src/test/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapperTest.java +++ b/src/test/java/io/patriotframework/virtualsmarthomeplus/Mapper/DTOMapperTest.java @@ -31,6 +31,7 @@ public class DTOMapperTest { public DTOMapperTest() { this.dtoMapper = new DTOMapper(new ModelMapper()); } + @Test public void unknownDeviceToDeviceDTO() { DeviceMock deviceMock = new DeviceMock("deviceMock"); @@ -50,11 +51,11 @@ public void thermometerToThermometerDTO() { thermometerDTO.setEnabled(true); thermometerDTO.setUnit("F"); - assertEquals(dtoMapper.map(thermometer),thermometerDTO); + assertEquals(dtoMapper.map(thermometer), thermometerDTO); } @Test - public void rgbToRgbDTO(){ + public void rgbToRgbDTO() { RGBLight rgbLight = new RGBLight("rgb1"); rgbLight.setEnabled(true); rgbLight.switchOn(); @@ -70,12 +71,12 @@ public void rgbToRgbDTO(){ rgbLightDTO.setGreen(21); rgbLightDTO.setBlue(22); - assertEquals(dtoMapper.map(rgbLight),rgbLightDTO); + assertEquals(dtoMapper.map(rgbLight), rgbLightDTO); rgbLight.switchOf(); rgbLightDTO.setSwitchedOn(false); - assertEquals(dtoMapper.map(rgbLight),rgbLightDTO); + assertEquals(dtoMapper.map(rgbLight), rgbLightDTO); } @Test @@ -89,12 +90,12 @@ public void fireplaceToFireplaceDTO() { fireplaceDTO.setStatus(ON_FIRE); fireplaceDTO.setEnabled(true); - assertEquals(dtoMapper.map(fireplace),fireplaceDTO); + assertEquals(dtoMapper.map(fireplace), fireplaceDTO); fireplace.extinguish(); fireplaceDTO.setStatus(EXTINGUISHED); - assertEquals(dtoMapper.map(fireplace),fireplaceDTO); + assertEquals(dtoMapper.map(fireplace), fireplaceDTO); } @Test @@ -108,30 +109,30 @@ public void doorToDoorDTO() { doorDTO.setEnabled(true); doorDTO.setStatus(OPENED); - assertEquals(dtoMapper.map(door),doorDTO); + assertEquals(dtoMapper.map(door), doorDTO); door.close(); doorDTO.setStatus(CLOSED); - assertEquals(dtoMapper.map(door),doorDTO); + assertEquals(dtoMapper.map(door), doorDTO); } @Test public void classDTOToClass() { - assertEquals(RGBLight.class,dtoMapper.mapDtoClassType(RGBLightDTO.class)); - assertEquals(Door.class,dtoMapper.mapDtoClassType(DoorDTO.class)); - assertEquals(Fireplace.class,dtoMapper.mapDtoClassType(FireplaceDTO.class)); - assertEquals(Thermometer.class,dtoMapper.mapDtoClassType(ThermometerDTO.class)); + assertEquals(RGBLight.class, dtoMapper.mapDtoClassType(RGBLightDTO.class)); + assertEquals(Door.class, dtoMapper.mapDtoClassType(DoorDTO.class)); + assertEquals(Fireplace.class, dtoMapper.mapDtoClassType(FireplaceDTO.class)); + assertEquals(Thermometer.class, dtoMapper.mapDtoClassType(ThermometerDTO.class)); assertThrows(DeviceMappingNotSupportedException.class, () -> dtoMapper.mapDtoClassType(MockDTO.class)); } @Test public void classToClassDTO() { - assertEquals(RGBLightDTO.class,dtoMapper.mapDeviceClassType(RGBLight.class)); - assertEquals(DoorDTO.class,dtoMapper.mapDeviceClassType(Door.class)); - assertEquals(FireplaceDTO.class,dtoMapper.mapDeviceClassType(Fireplace.class)); - assertEquals(ThermometerDTO.class,dtoMapper.mapDeviceClassType(Thermometer.class)); + assertEquals(RGBLightDTO.class, dtoMapper.mapDeviceClassType(RGBLight.class)); + assertEquals(DoorDTO.class, dtoMapper.mapDeviceClassType(Door.class)); + assertEquals(FireplaceDTO.class, dtoMapper.mapDeviceClassType(Fireplace.class)); + assertEquals(ThermometerDTO.class, dtoMapper.mapDeviceClassType(Thermometer.class)); assertThrows(DeviceMappingNotSupportedException.class, () -> dtoMapper.mapDeviceClassType(DeviceMock.class)); } @@ -150,7 +151,7 @@ public void houseToHouseDTO() { houseDTO.setDevices(list); HouseDTO houseDTO1 = dtoMapper.map(house); - assertEquals(houseDTO1,houseDTO); + assertEquals(houseDTO1, houseDTO); } } diff --git a/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorApiTest.java b/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorApiTest.java index d2430bc..270306f 100644 --- a/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorApiTest.java +++ b/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/DoorApiTest.java @@ -8,7 +8,6 @@ import io.patriotframework.virtualsmarthomeplus.house.House; import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.modelmapper.ModelMapper; @@ -24,12 +23,12 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import static io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door.CLOSED; import static io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door.OPENED; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + @ContextConfiguration(classes = VirtualSmartHomePlusApplication.class) @SpringBootTest @TestInstance(TestInstance.Lifecycle.PER_CLASS) diff --git a/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceApiTest.java b/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceApiTest.java index ffef822..2002d45 100644 --- a/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceApiTest.java +++ b/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/FireplaceApiTest.java @@ -27,6 +27,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + @ContextConfiguration(classes = VirtualSmartHomePlusApplication.class) @SpringBootTest @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -106,7 +107,7 @@ public void shouldUpdateFireplace() throws Exception { ) .andExpect(status().isOk()); FireplaceDTO fireplaceDTO2 = (FireplaceDTO) dtoMapper.map(house.getDevice("fireplace1")); - assertEquals(fireplaceDTO2.getStatus(),ON_FIRE); + assertEquals(fireplaceDTO2.getStatus(), ON_FIRE); fireplace.setLabel("newFireplace1"); fireplace.setStatus(ON_FIRE); @@ -117,7 +118,7 @@ public void shouldUpdateFireplace() throws Exception { ) .andExpect(status().isOk()); fireplaceDTO2 = (FireplaceDTO) dtoMapper.map(house.getDevice("newFireplace1")); - assertEquals(fireplaceDTO2.getStatus(),ON_FIRE); + assertEquals(fireplaceDTO2.getStatus(), ON_FIRE); fireplace = new FireplaceDTO(); fireplace.setLabel("fireplace1"); @@ -130,7 +131,7 @@ public void shouldUpdateFireplace() throws Exception { ) .andExpect(status().isOk()); fireplaceDTO2 = (FireplaceDTO) dtoMapper.map(house.getDevice("fireplace1")); - assertEquals(fireplaceDTO2.getStatus(),EXTINGUISHED); + assertEquals(fireplaceDTO2.getStatus(), EXTINGUISHED); assertEquals(fireplaceDTO2.getEnabled(), true); fireplace = new FireplaceDTO(); diff --git a/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/HouseApiTest.java b/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/HouseApiTest.java index e497024..a73787b 100644 --- a/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/HouseApiTest.java +++ b/src/test/java/io/patriotframework/virtualsmarthomeplus/controllers/HouseApiTest.java @@ -31,15 +31,17 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class HouseApiTest { private final DTOMapper dtoMapper = new DTOMapper(new ModelMapper()); - private MockMvc mockMvc; @Autowired public House house = new House(); + private MockMvc mockMvc; @Autowired private WebApplicationContext wac; + @BeforeAll public void setUp() { this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } + @Test @Order(1) public void shouldFetchHouse() throws Exception { @@ -52,12 +54,12 @@ public void shouldFetchHouse() throws Exception { .andExpect(status().is(200)) .andReturn(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String responseBody = result.getResponse().getContentAsString(); - HouseDTO responseDTO = objectMapper.readValue(responseBody,HouseDTO.class); + HouseDTO responseDTO = objectMapper.readValue(responseBody, HouseDTO.class); - for (int i=0;i house.removeDevice(null)); assertThrows(IllegalArgumentException.class, () -> house.getDevice(null)); assertThrows(IllegalArgumentException.class, () -> house.addDevice(null)); - assertThrows(IllegalArgumentException.class, () -> house.getDeviceOfType(Door.class,null)); + assertThrows(IllegalArgumentException.class, () -> house.getDeviceOfType(Door.class, null)); } @Test diff --git a/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/DoorTest.java b/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/DoorTest.java index e26235d..53eb82c 100644 --- a/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/DoorTest.java +++ b/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/DoorTest.java @@ -1,9 +1,6 @@ package io.patriotframework.virtualsmarthomeplus.house.devices; -import io.patriotframework.virtualsmarthomeplus.DTOs.RGBLightDTO; -import io.patriotframework.virtualsmarthomeplus.Mapper.DTOMapper; import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door; -import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.RGBLight; import org.junit.jupiter.api.Test; import static io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door.CLOSED; @@ -28,18 +25,18 @@ public void constructorTest() { @Test public void OpenCloseTest() { door1.setEnabled(true); - assertEquals(door1.getStatus(),CLOSED); + assertEquals(door1.getStatus(), CLOSED); door1.open(); - assertEquals(door1.getStatus(),OPENED); + assertEquals(door1.getStatus(), OPENED); door1.close(); - assertEquals(door1.getStatus(),CLOSED); + assertEquals(door1.getStatus(), CLOSED); door1.open(); door1.open(); - assertEquals(door1.getStatus(),OPENED); + assertEquals(door1.getStatus(), OPENED); door1.close(); door1.close(); - assertEquals(door1.getStatus(),CLOSED); + assertEquals(door1.getStatus(), CLOSED); } @Test diff --git a/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/FireplaceTest.java b/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/FireplaceTest.java index 5b7bea9..239c4c4 100644 --- a/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/FireplaceTest.java +++ b/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/FireplaceTest.java @@ -1,12 +1,8 @@ package io.patriotframework.virtualsmarthomeplus.house.devices; -import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door; -import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Fireplace; import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Fireplace; import org.junit.jupiter.api.Test; -import static io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door.CLOSED; -import static io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Door.OPENED; import static io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Fireplace.EXTINGUISHED; import static io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.Fireplace.ON_FIRE; import static org.junit.jupiter.api.Assertions.*; @@ -29,18 +25,18 @@ public void constructorTest() { @Test public void fireUpExtinguishTest() { fireplace1.setEnabled(true); - assertEquals(fireplace1.getStatus(),EXTINGUISHED); + assertEquals(fireplace1.getStatus(), EXTINGUISHED); fireplace1.fireUp(); - assertEquals(fireplace1.getStatus(),ON_FIRE); + assertEquals(fireplace1.getStatus(), ON_FIRE); fireplace1.extinguish(); - assertEquals(fireplace1.getStatus(),EXTINGUISHED); + assertEquals(fireplace1.getStatus(), EXTINGUISHED); fireplace1.fireUp(); fireplace1.fireUp(); - assertEquals(fireplace1.getStatus(),ON_FIRE); + assertEquals(fireplace1.getStatus(), ON_FIRE); fireplace1.extinguish(); fireplace1.extinguish(); - assertEquals(fireplace1.getStatus(),EXTINGUISHED); + assertEquals(fireplace1.getStatus(), EXTINGUISHED); } @Test diff --git a/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/RGBLightTest.java b/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/RGBLightTest.java index 8807a0e..b0c9721 100644 --- a/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/RGBLightTest.java +++ b/src/test/java/io/patriotframework/virtualsmarthomeplus/house/devices/RGBLightTest.java @@ -1,7 +1,6 @@ package io.patriotframework.virtualsmarthomeplus.house.devices; import io.patriotframework.virtualsmarthomeplus.DTOs.RGBLightDTO; -import io.patriotframework.virtualsmarthomeplus.Mapper.DTOMapper; import io.patriotframework.virtualsmarthomeplus.house.devices.finalDevices.RGBLight; import org.junit.jupiter.api.Test; import org.modelmapper.ModelMapper;