Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

add unit testing for create grocery list, delete account, add grocery item, and remove grocery item - #35

Merged
itsreverence merged 5 commits into
masterfrom
grocery-list-account-tests
Apr 29, 2026
Merged

add unit testing for create grocery list, delete account, add grocery item, and remove grocery item#35
itsreverence merged 5 commits into
masterfrom
grocery-list-account-tests

Conversation

@itsreverence

Copy link
Copy Markdown
Owner

No description provided.

@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds unit tests for four service-layer use cases: create grocery list, delete account, add grocery item, and remove grocery item. The tests are well-structured using JUnit 5 nested classes, Mockito mocks, and ArgumentCaptor, and they cover both failure paths (user/list/item not found, wrong owner) and success paths with appropriate verification of repository interactions.

Confidence Score: 5/5

Safe to merge — all findings are P2 suggestions with no blocking correctness issues.

Both files add test-only code with no changes to production logic. All identified issues are minor gaps in coverage (untested deleteUser(Integer id) overload, missing duplicate-item edge case) rather than defects in the tests themselves. Existing test assertions correctly reflect service behaviour.

No files require special attention.

Important Files Changed

Filename Overview
src/test/java/com/groceryrun/app/services/GroceryListServiceTest.java New test file covering create-grocery-list, add-item, and remove-item use cases; all happy/sad paths exercised with correct Mockito setup, but the duplicate-item edge case is unaddressed.
src/test/java/com/groceryrun/app/services/UserServiceTest.java New test file covering the delete-account use case via the String-username overload; the Integer-id overload of deleteUser is untested.

Sequence Diagram

sequenceDiagram
    participant Test
    participant GroceryListService
    participant UserRepository
    participant GroceryListRepository
    participant ItemRepository

    Note over Test,ItemRepository: addGroceryList (success path)
    Test->>GroceryListService: addGroceryList(username, dto)
    GroceryListService->>UserRepository: findByUsername(username)
    UserRepository-->>GroceryListService: Optional<User>
    GroceryListService->>GroceryListRepository: save(groceryList)
    GroceryListService->>UserRepository: save(user)

    Note over Test,ItemRepository: addItemToGroceryList (success path)
    Test->>GroceryListService: addItemToGroceryList(username, listId, itemId)
    GroceryListService->>UserRepository: findByUsername(username)
    UserRepository-->>GroceryListService: Optional<User>
    GroceryListService->>GroceryListRepository: findById(listId)
    GroceryListRepository-->>GroceryListService: Optional<GroceryList>
    GroceryListService->>ItemRepository: findById(itemId)
    ItemRepository-->>GroceryListService: Optional<Item>
    GroceryListService->>GroceryListRepository: save(groceryList)

    Note over Test,ItemRepository: removeItemFromGroceryList (success path)
    Test->>GroceryListService: removeItemFromGroceryList(username, listId, itemId)
    GroceryListService->>UserRepository: findByUsername(username)
    UserRepository-->>GroceryListService: Optional<User>
    GroceryListService->>GroceryListRepository: findById(listId)
    GroceryListRepository-->>GroceryListService: Optional<GroceryList>
    GroceryListService->>ItemRepository: findById(itemId)
    ItemRepository-->>GroceryListService: Optional<Item>
    GroceryListService->>GroceryListRepository: save(groceryList)
Loading

Reviews (1): Last reviewed commit: "Add remove grocery item tests" | Re-trigger Greptile

Comment thread src/test/java/com/groceryrun/app/services/UserServiceTest.java
@itsreverence
itsreverence merged commit 0756653 into master Apr 29, 2026
2 checks passed
@itsreverence
itsreverence deleted the grocery-list-account-tests branch April 29, 2026 21:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants