mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 10:58:51 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -24,17 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.transactionscript;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Tests that Transaction script example runs without errors.
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Tests that Transaction script example runs without errors. */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-17
@@ -44,9 +44,7 @@ import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
* Tests {@link HotelDaoImpl}.
|
||||
*/
|
||||
/** Tests {@link HotelDaoImpl}. */
|
||||
class HotelDaoImplTest {
|
||||
|
||||
private static final String DB_URL = "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1";
|
||||
@@ -61,15 +59,13 @@ class HotelDaoImplTest {
|
||||
@BeforeEach
|
||||
void createSchema() throws SQLException {
|
||||
try (var connection = DriverManager.getConnection(DB_URL);
|
||||
var statement = connection.createStatement()) {
|
||||
var statement = connection.createStatement()) {
|
||||
statement.execute(RoomSchemaSql.DELETE_SCHEMA_SQL);
|
||||
statement.execute(RoomSchemaSql.CREATE_SCHEMA_SQL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the scenario where DB connectivity is present.
|
||||
*/
|
||||
/** Represents the scenario where DB connectivity is present. */
|
||||
@Nested
|
||||
class ConnectionSuccess {
|
||||
|
||||
@@ -87,9 +83,7 @@ class HotelDaoImplTest {
|
||||
Assertions.assertTrue(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the scenario when DAO operations are being performed on a non-existing room.
|
||||
*/
|
||||
/** Represents the scenario when DAO operations are being performed on a non-existing room. */
|
||||
@Nested
|
||||
class NonExistingRoom {
|
||||
|
||||
@@ -135,8 +129,7 @@ class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a scenario where DAO operations are being performed on an already existing
|
||||
* room.
|
||||
* Represents a scenario where DAO operations are being performed on an already existing room.
|
||||
*/
|
||||
@Nested
|
||||
class ExistingRoom {
|
||||
@@ -161,8 +154,8 @@ class HotelDaoImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void updationShouldBeSuccessAndAccessingTheSameRoomShouldReturnUpdatedInformation() throws
|
||||
Exception {
|
||||
void updationShouldBeSuccessAndAccessingTheSameRoomShouldReturnUpdatedInformation()
|
||||
throws Exception {
|
||||
final var newRoomType = "Double";
|
||||
final var newPrice = 80;
|
||||
final var newBookingStatus = false;
|
||||
@@ -222,7 +215,10 @@ class HotelDaoImplTest {
|
||||
final var newRoomType = "Double";
|
||||
final var newPrice = 80;
|
||||
final var newBookingStatus = false;
|
||||
assertThrows(Exception.class, () -> dao.update(new Room(existingRoom.getId(), newRoomType, newPrice, newBookingStatus)));
|
||||
assertThrows(
|
||||
Exception.class,
|
||||
() ->
|
||||
dao.update(new Room(existingRoom.getId(), newRoomType, newPrice, newBookingStatus)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,7 +230,6 @@ class HotelDaoImplTest {
|
||||
void retrievingAllRoomsFailsWithExceptionAsFeedbackToClient() {
|
||||
assertThrows(Exception.class, () -> dao.getAll());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +240,7 @@ class HotelDaoImplTest {
|
||||
@AfterEach
|
||||
void deleteSchema() throws SQLException {
|
||||
try (var connection = DriverManager.getConnection(DB_URL);
|
||||
var statement = connection.createStatement()) {
|
||||
var statement = connection.createStatement()) {
|
||||
statement.execute(RoomSchemaSql.DELETE_SCHEMA_SQL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,7 @@ import org.h2.jdbcx.JdbcDataSource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link Hotel}
|
||||
*/
|
||||
/** Tests {@link Hotel} */
|
||||
class HotelTest {
|
||||
|
||||
private static final String H2_DB_URL = "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1";
|
||||
@@ -53,7 +51,6 @@ class HotelTest {
|
||||
dao = new HotelDaoImpl(dataSource);
|
||||
addRooms(dao);
|
||||
hotel = new Hotel(dao);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +65,6 @@ class HotelTest {
|
||||
assertThrows(Exception.class, () -> hotel.bookRoom(getNonExistingRoomId()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
void bookingRoomAgainShouldRaiseException() {
|
||||
@@ -103,17 +99,16 @@ class HotelTest {
|
||||
assertThrows(Exception.class, () -> hotel.cancelRoomBooking(1));
|
||||
}
|
||||
|
||||
|
||||
private static void deleteSchema(DataSource dataSource) throws java.sql.SQLException {
|
||||
try (var connection = dataSource.getConnection();
|
||||
var statement = connection.createStatement()) {
|
||||
var statement = connection.createStatement()) {
|
||||
statement.execute(RoomSchemaSql.DELETE_SCHEMA_SQL);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createSchema(DataSource dataSource) throws Exception {
|
||||
try (var connection = dataSource.getConnection();
|
||||
var statement = connection.createStatement()) {
|
||||
var statement = connection.createStatement()) {
|
||||
statement.execute(RoomSchemaSql.CREATE_SCHEMA_SQL);
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e.getMessage(), e);
|
||||
@@ -150,4 +145,4 @@ class HotelTest {
|
||||
private int getNonExistingRoomId() {
|
||||
return 999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests {@link Room}.
|
||||
*/
|
||||
/** Tests {@link Room}. */
|
||||
class RoomTest {
|
||||
|
||||
private Room room;
|
||||
@@ -90,7 +88,10 @@ class RoomTest {
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
assertEquals(String.format("Room(id=%s, roomType=%s, price=%s, booked=%s)",
|
||||
room.getId(), room.getRoomType(), room.getPrice(), room.isBooked()), room.toString());
|
||||
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