📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@@ -23,6 +23,18 @@
|
||||
|
||||
package com.iluwatar.transactionscript;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
@@ -31,15 +43,6 @@ import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Tests {@link HotelDaoImpl}.
|
||||
*/
|
||||
@@ -90,7 +93,7 @@ public class HotelDaoImplTest {
|
||||
public class NonExistingRoom {
|
||||
|
||||
@Test
|
||||
public void addingShouldResultInSuccess() throws Exception {
|
||||
void addingShouldResultInSuccess() throws Exception {
|
||||
try (var allRooms = dao.getAll()) {
|
||||
assumeTrue(allRooms.count() == 1);
|
||||
}
|
||||
@@ -104,7 +107,7 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletionShouldBeFailureAndNotAffectExistingRooms() throws Exception {
|
||||
void deletionShouldBeFailureAndNotAffectExistingRooms() throws Exception {
|
||||
final var nonExistingRoom = new Room(2, "Double", 80, false);
|
||||
var result = dao.delete(nonExistingRoom);
|
||||
|
||||
@@ -113,7 +116,7 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updationShouldBeFailureAndNotAffectExistingRooms() throws Exception {
|
||||
void updationShouldBeFailureAndNotAffectExistingRooms() throws Exception {
|
||||
final var nonExistingId = getNonExistingRoomId();
|
||||
final var newRoomType = "Double";
|
||||
final var newPrice = 80;
|
||||
@@ -125,7 +128,7 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrieveShouldReturnNoRoom() throws Exception {
|
||||
void retrieveShouldReturnNoRoom() throws Exception {
|
||||
assertFalse(dao.getById(getNonExistingRoomId()).isPresent());
|
||||
}
|
||||
}
|
||||
@@ -138,7 +141,7 @@ public class HotelDaoImplTest {
|
||||
public class ExistingRoom {
|
||||
|
||||
@Test
|
||||
public void addingShouldResultInFailureAndNotAffectExistingRooms() throws Exception {
|
||||
void addingShouldResultInFailureAndNotAffectExistingRooms() throws Exception {
|
||||
var existingRoom = new Room(1, "Single", 50, false);
|
||||
var result = dao.add(existingRoom);
|
||||
|
||||
@@ -148,7 +151,7 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletionShouldBeSuccessAndRoomShouldBeNonAccessible() throws Exception {
|
||||
void deletionShouldBeSuccessAndRoomShouldBeNonAccessible() throws Exception {
|
||||
var result = dao.delete(existingRoom);
|
||||
|
||||
Assertions.assertTrue(result);
|
||||
@@ -157,7 +160,7 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updationShouldBeSuccessAndAccessingTheSameRoomShouldReturnUpdatedInformation() throws
|
||||
void updationShouldBeSuccessAndAccessingTheSameRoomShouldReturnUpdatedInformation() throws
|
||||
Exception {
|
||||
final var newRoomType = "Double";
|
||||
final var newPrice = 80;
|
||||
@@ -204,21 +207,21 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addingARoomFailsWithExceptionAsFeedbackToClient() {
|
||||
void addingARoomFailsWithExceptionAsFeedbackToClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.add(new Room(2, "Double", 80, false));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletingARoomFailsWithExceptionAsFeedbackToTheClient() {
|
||||
void deletingARoomFailsWithExceptionAsFeedbackToTheClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.delete(existingRoom);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatingARoomFailsWithFeedbackToTheClient() {
|
||||
void updatingARoomFailsWithFeedbackToTheClient() {
|
||||
final var newRoomType = "Double";
|
||||
final var newPrice = 80;
|
||||
final var newBookingStatus = false;
|
||||
@@ -228,14 +231,14 @@ public class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrievingARoomByIdFailsWithExceptionAsFeedbackToClient() {
|
||||
void retrievingARoomByIdFailsWithExceptionAsFeedbackToClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.getById(existingRoom.getId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void retrievingAllRoomsFailsWithExceptionAsFeedbackToClient() {
|
||||
void retrievingAllRoomsFailsWithExceptionAsFeedbackToClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.getAll();
|
||||
});
|
||||
|
@@ -23,19 +23,20 @@
|
||||
|
||||
package com.iluwatar.transactionscript;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import javax.sql.DataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests {@link Hotel}
|
||||
*/
|
||||
public class HotelTest {
|
||||
class HotelTest {
|
||||
|
||||
private static final String H2_DB_URL = "jdbc:h2:~/test";
|
||||
|
||||
@@ -54,20 +55,20 @@ public class HotelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bookingRoomShouldChangeBookedStatusToTrue() throws Exception {
|
||||
void bookingRoomShouldChangeBookedStatusToTrue() throws Exception {
|
||||
hotel.bookRoom(1);
|
||||
assertTrue(dao.getById(1).get().isBooked());
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void bookingRoomWithInvalidIdShouldRaiseException() {
|
||||
void bookingRoomWithInvalidIdShouldRaiseException() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
hotel.bookRoom(getNonExistingRoomId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void bookingRoomAgainShouldRaiseException() {
|
||||
void bookingRoomAgainShouldRaiseException() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
hotel.bookRoom(1);
|
||||
hotel.bookRoom(1);
|
||||
@@ -75,12 +76,12 @@ public class HotelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void NotBookingRoomShouldNotChangeBookedStatus() throws Exception {
|
||||
void NotBookingRoomShouldNotChangeBookedStatus() throws Exception {
|
||||
assertFalse(dao.getById(1).get().isBooked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cancelRoomBookingShouldChangeBookedStatus() throws Exception {
|
||||
void cancelRoomBookingShouldChangeBookedStatus() throws Exception {
|
||||
hotel.bookRoom(1);
|
||||
assertTrue(dao.getById(1).get().isBooked());
|
||||
hotel.cancelRoomBooking(1);
|
||||
@@ -88,14 +89,14 @@ public class HotelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cancelRoomBookingWithInvalidIdShouldRaiseException() {
|
||||
void cancelRoomBookingWithInvalidIdShouldRaiseException() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
hotel.cancelRoomBooking(getNonExistingRoomId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cancelRoomBookingForUnbookedRoomShouldRaiseException() {
|
||||
void cancelRoomBookingForUnbookedRoomShouldRaiseException() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
hotel.cancelRoomBooking(1);
|
||||
});
|
||||
|
@@ -23,16 +23,16 @@
|
||||
|
||||
package com.iluwatar.transactionscript;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link Room}.
|
||||
*/
|
||||
public class RoomTest {
|
||||
class RoomTest {
|
||||
|
||||
private Room room;
|
||||
private static final int ID = 1;
|
||||
@@ -41,33 +41,33 @@ public class RoomTest {
|
||||
private static final boolean BOOKED = false;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
room = new Room(ID, ROOMTYPE, PRICE, BOOKED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAndSetId() {
|
||||
void getAndSetId() {
|
||||
final var newId = 2;
|
||||
room.setId(newId);
|
||||
assertEquals(newId, room.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAndSetRoomType() {
|
||||
void getAndSetRoomType() {
|
||||
final var newRoomType = "Double";
|
||||
room.setRoomType(newRoomType);
|
||||
assertEquals(newRoomType, room.getRoomType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAndSetLastName() {
|
||||
void getAndSetLastName() {
|
||||
final var newPrice = 60;
|
||||
room.setPrice(newPrice);
|
||||
assertEquals(newPrice, room.getPrice());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEqualWithDifferentId() {
|
||||
void notEqualWithDifferentId() {
|
||||
final var newId = 2;
|
||||
final var otherRoom = new Room(newId, ROOMTYPE, PRICE, BOOKED);
|
||||
assertNotEquals(room, otherRoom);
|
||||
@@ -75,21 +75,21 @@ public class RoomTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithSameObjectValues() {
|
||||
void equalsWithSameObjectValues() {
|
||||
final var otherRoom = new Room(ID, ROOMTYPE, PRICE, BOOKED);
|
||||
assertEquals(room, otherRoom);
|
||||
assertEquals(room.hashCode(), otherRoom.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWithSameObjects() {
|
||||
void equalsWithSameObjects() {
|
||||
assertEquals(room, room);
|
||||
assertEquals(room.hashCode(), room.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals(String.format("Room{id=%s, roomType=%s, price=%s, booked=%s}",
|
||||
void testToString() {
|
||||
assertEquals(String.format("Room(id=%s, roomType=%s, price=%s, booked=%s)",
|
||||
room.getId(), room.getRoomType(), room.getPrice(), room.isBooked()), room.toString());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user