mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-17 08:24:38 +00:00
docs: update dao
This commit is contained in:
@@ -24,20 +24,16 @@
|
||||
*/
|
||||
package com.iluwatar.dao;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* Custom exception.
|
||||
*/
|
||||
public class CustomException extends Exception {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CustomException() {
|
||||
}
|
||||
|
||||
public CustomException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CustomException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ class AppTest {
|
||||
|
||||
/**
|
||||
* Issue: Add at least one assertion to this test case.
|
||||
*
|
||||
* Solution: Inserted assertion to check whether the execution of the main method in {@link App#main(String[])}
|
||||
* throws an exception.
|
||||
*/
|
||||
|
||||
@@ -87,7 +87,7 @@ class DbCustomerDaoTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the scenario when DAO operations are being performed on a non existing customer.
|
||||
* Represents the scenario when DAO operations are being performed on a non-existing customer.
|
||||
*/
|
||||
@Nested
|
||||
class NonExistingCustomer {
|
||||
@@ -206,39 +206,29 @@ class DbCustomerDaoTest {
|
||||
|
||||
@Test
|
||||
void addingACustomerFailsWithExceptionAsFeedbackToClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.add(new Customer(2, "Bernard", "Montgomery"));
|
||||
});
|
||||
assertThrows(Exception.class, () -> dao.add(new Customer(2, "Bernard", "Montgomery")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingACustomerFailsWithExceptionAsFeedbackToTheClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.delete(existingCustomer);
|
||||
});
|
||||
assertThrows(Exception.class, () -> dao.delete(existingCustomer));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingACustomerFailsWithFeedbackToTheClient() {
|
||||
final var newFirstname = "Bernard";
|
||||
final var newLastname = "Montgomery";
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.update(new Customer(existingCustomer.getId(), newFirstname, newLastname));
|
||||
});
|
||||
assertThrows(Exception.class, () -> dao.update(new Customer(existingCustomer.getId(), newFirstname, newLastname)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void retrievingACustomerByIdFailsWithExceptionAsFeedbackToClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.getById(existingCustomer.getId());
|
||||
});
|
||||
assertThrows(Exception.class, () -> dao.getById(existingCustomer.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void retrievingAllCustomersFailsWithExceptionAsFeedbackToClient() {
|
||||
assertThrows(Exception.class, () -> {
|
||||
dao.getAll();
|
||||
});
|
||||
assertThrows(Exception.class, () -> dao.getAll());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class InMemoryCustomerDaoTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the scenario when the DAO operations are being performed on a non existent
|
||||
* Represents the scenario when the DAO operations are being performed on a non-existent
|
||||
* customer.
|
||||
*/
|
||||
@Nested
|
||||
@@ -78,7 +78,7 @@ class InMemoryCustomerDaoTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void updationShouldBeFailureAndNotAffectExistingCustomers() throws Exception {
|
||||
void updateShouldBeFailureAndNotAffectExistingCustomers() {
|
||||
final var nonExistingId = getNonExistingCustomerId();
|
||||
final var newFirstname = "Douglas";
|
||||
final var newLastname = "MacArthur";
|
||||
|
||||
Reference in New Issue
Block a user