Skip to content

Commit

Permalink
Rename CartRepository.deleteById() to deleteByCustomerId()
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenWoltmann committed Jun 22, 2023
1 parent 56b8ff7 commit 7e59639
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Optional<Cart> findByCustomerId(CustomerId customerId) {
}

@Override
public void deleteById(CustomerId customerId) {
public void deleteByCustomerId(CustomerId customerId) {
carts.remove(customerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Optional<Cart> findByCustomerId(CustomerId customerId) {
}

@Override
public void deleteById(CustomerId customerId) {
public void deleteByCustomerId(CustomerId customerId) {
try (EntityManager entityManager = entityManagerFactory.createEntityManager()) {
entityManager.getTransaction().begin();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,25 @@ void givenExistingCartWithProduct_addProductAndSaveCart_updatesTheExistingCart()
}

@Test
void givenExistingCart_deleteById_deletesTheCart() {
void givenExistingCart_deleteByCustomerId_deletesTheCart() {
CustomerId customerId = createUniqueCustomerId();

Cart existingCart = new Cart(customerId);
cartRepository.save(existingCart);

assertThat(cartRepository.findByCustomerId(customerId)).isNotEmpty();

cartRepository.deleteById(customerId);
cartRepository.deleteByCustomerId(customerId);

assertThat(cartRepository.findByCustomerId(customerId)).isEmpty();
}

@Test
void givenNotExistingCart_deleteById_doesNothing() {
void givenNotExistingCart_deleteByCustomerId_doesNothing() {
CustomerId customerId = createUniqueCustomerId();
assertThat(cartRepository.findByCustomerId(customerId)).isEmpty();

cartRepository.deleteById(customerId);
cartRepository.deleteByCustomerId(customerId);

assertThat(cartRepository.findByCustomerId(customerId)).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface CartRepository {

Optional<Cart> findByCustomerId(CustomerId customerId);

void deleteById(CustomerId customerId);
void deleteByCustomerId(CustomerId customerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public EmptyCartService(CartRepository cartRepository) {
public void emptyCart(CustomerId customerId) {
Objects.requireNonNull(customerId, "'customerId' must not be null");

cartRepository.deleteById(customerId);
cartRepository.deleteByCustomerId(customerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class EmptyCartServiceTest {
void emptyCart_invokesDeleteOnThePersistencePort() {
emptyCartService.emptyCart(TEST_CUSTOMER_ID);

verify(cartRepository).deleteById(TEST_CUSTOMER_ID);
verify(cartRepository).deleteByCustomerId(TEST_CUSTOMER_ID);
}
}

0 comments on commit 7e59639

Please sign in to comment.