Backend Test Report

Spring Boot 3.2 · JUnit 5 · Java 21 · 100 tests

100
Passed
0
Failed
3.0s
Duration
AppUserControllerTest 5/5 passed PASS
getUsers_returnsUsers
0.051s
@Test void getUsers_returnsUsers() throws Exception { AppUser user = AppUser.builder().id(UUID.randomUUID()).displayName("Alice").build(); when(service.findByListId(listId)).thenReturn(List.of(user)); mockMvc.perform(get("/api/lists/{listId}/users", listId)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].displayName").value("Alice")); }
joinList_nullName_returns400
0.008s
@Test void joinList_nullName_returns400() throws Exception { mockMvc.perform(post("/api/lists/{listId}/users", listId) .contentType(MediaType.APPLICATION_JSON) .content("{}")) .andExpect(status().isBadRequest()); verify(service, never()).joinList(any(), any()); }
joinList_returnsUser
0.008s
@Test void joinList_returnsUser() throws Exception { AppUser user = AppUser.builder().id(UUID.randomUUID()).displayName("Bob").build(); when(service.joinList(eq(listId), eq("Bob"))).thenReturn(user); mockMvc.perform(post("/api/lists/{listId}/users", listId) .contentType(MediaType.APPLICATION_JSON) .content("{\"displayName\":\"Bob\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.displayName").value("Bob")); }
getUsers_returnsEmptyList
0.016s
@Test void getUsers_returnsEmptyList() throws Exception { when(service.findByListId(listId)).thenReturn(List.of()); mockMvc.perform(get("/api/lists/{listId}/users", listId)) .andExpect(status().isOk()) .andExpect(jsonPath("$").isEmpty()); }
joinList_blankName_returns400
0.007s
@Test void joinList_blankName_returns400() throws Exception { mockMvc.perform(post("/api/lists/{listId}/users", listId) .contentType(MediaType.APPLICATION_JSON) .content("{\"displayName\":\"\"}")) .andExpect(status().isBadRequest()); verify(service, never()).joinList(any(), any()); }
AppUserServiceTest 4/4 passed PASS
joinList_throwsWhenListNotFound
0.102s
@Test void joinList_throwsWhenListNotFound() { UUID listId = UUID.randomUUID(); when(listRepository.findById(listId)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.joinList(listId, "Alice")) .isInstanceOf(RuntimeException.class) .hasMessage("Liste nicht gefunden"); }
joinList_associatesWithListAndSaves
0.003s
@Test void joinList_associatesWithListAndSaves() { UUID listId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Groceries").build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(userRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); AppUser result = service.joinList(listId, "Alice"); assertThat(result.getDisplayName()).isEqualTo("Alice"); assertThat(result.getShoppingList()).isEqualTo(list); verify(userRepository).save(any(AppUser.class)); }
findByListId_returnsUsers
0.002s
@Test void findByListId_returnsUsers() { UUID listId = UUID.randomUUID(); AppUser user = AppUser.builder().displayName("Alice").build(); when(userRepository.findByShoppingListId(listId)).thenReturn(List.of(user)); List<AppUser> result = service.findByListId(listId); assertThat(result).hasSize(1); assertThat(result.get(0).getDisplayName()).isEqualTo("Alice"); }
findByListId_returnsEmptyWhenNoUsers
0.001s
@Test void findByListId_returnsEmptyWhenNoUsers() { UUID listId = UUID.randomUUID(); when(userRepository.findByShoppingListId(listId)).thenReturn(List.of()); List<AppUser> result = service.findByListId(listId); assertThat(result).isEmpty(); }
ProductControllerTest 5/5 passed PASS
delete_returns204
0.061s
@Test void delete_returns204() throws Exception { UUID productId = UUID.randomUUID(); doNothing().when(service).softDelete(productId); mockMvc.perform(delete("/api/lists/{listId}/products/{id}", listId, productId)) .andExpect(status().isNoContent()); verify(service).softDelete(productId); }
create_returnsProduct
0.069s
@Test void create_returnsProduct() throws Exception { Product product = Product.builder() .id(UUID.randomUUID()).name("Milk").price(BigDecimal.valueOf(1.50)).build(); when(service.create(eq(listId), any())).thenReturn(product); mockMvc.perform(post("/api/lists/{listId}/products", listId) .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"Milk\",\"price\":1.50}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Milk")) .andExpect(jsonPath("$.price").value(1.50)); }
togglePurchase_returnsProduct
0.016s
@Test void togglePurchase_returnsProduct() throws Exception { UUID productId = UUID.randomUUID(); Product product = Product.builder() .id(productId).name("Milk").purchased(true).purchasedBy("Alice").build(); when(service.markPurchased(eq(productId), eq("Alice"))).thenReturn(product); mockMvc.perform(patch("/api/lists/{listId}/products/{id}/purchase", listId, productId) .contentType(MediaType.APPLICATION_JSON) .content("{\"purchasedBy\":\"Alice\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.purchased").value(true)) .andExpect(jsonPath("$.purchasedBy").value("Alice")); }
getAll_returnsProducts
0.016s
@Test void getAll_returnsProducts() throws Exception { Product product = Product.builder() .id(UUID.randomUUID()).name("Milk").build(); when(service.findByListId(listId)).thenReturn(List.of(product)); mockMvc.perform(get("/api/lists/{listId}/products", listId)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].name").value("Milk")); }
update_returnsProduct
0.018s
@Test void update_returnsProduct() throws Exception { UUID productId = UUID.randomUUID(); Product product = Product.builder() .id(productId).name("Oat Milk").version(2).build(); when(service.update(eq(productId), any())).thenReturn(product); mockMvc.perform(put("/api/lists/{listId}/products/{id}", listId, productId) .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"Oat Milk\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Oat Milk")) .andExpect(jsonPath("$.version").value(2)); }
ProductServiceTest 22/22 passed PASS
markPurchased_throwsWhenNotFound
1.76s
@Test void markPurchased_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(productRepository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.markPurchased(id, "Alice")) .isInstanceOf(RuntimeException.class) .hasMessage("Product not found"); }
markPurchased_togglesFromPurchasedToUnpurchased
0.034s
@Test void markPurchased_togglesFromPurchasedToUnpurchased() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(UUID.randomUUID()).name("Test").build(); Product product = Product.builder() .id(id).name("Milk").purchased(true).purchasedBy("Alice").version(1).shoppingList(list).build(); when(productRepository.findById(id)).thenReturn(Optional.of(product)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.markPurchased(id, "Bob"); assertThat(result.getPurchased()).isFalse(); assertThat(result.getPurchasedBy()).isNull(); assertThat(result.getPurchasedAt()).isNull(); assertThat(result.getVersion()).isEqualTo(2); }
create_throwsWhenListNotFound
0.005s
@Test void create_throwsWhenListNotFound() { UUID listId = UUID.randomUUID(); when(listRepository.findById(listId)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.create(listId, new Product())) .isInstanceOf(RuntimeException.class) .hasMessage("List not found"); }
findByListId_returnsNonDeletedProducts
0.011s
@Test void findByListId_returnsNonDeletedProducts() { UUID listId = UUID.randomUUID(); Product product = Product.builder().name("Milk").build(); when(productRepository.findByShoppingListIdAndDeletedAtIsNull(listId)) .thenReturn(List.of(product)); List<Product> result = service.findByListId(listId); assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo("Milk"); }
softDelete_throwsWhenNotFound
0.005s
@Test void softDelete_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(productRepository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.softDelete(id)) .isInstanceOf(RuntimeException.class) .hasMessage("Product not found"); }
update_throwsWhenNotFound
0.004s
@Test void update_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(productRepository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.update(id, new Product())) .isInstanceOf(RuntimeException.class) .hasMessage("Product not found"); }
findByListId_returnsEmptyWhenNoProducts
0.006s
@Test void findByListId_returnsEmptyWhenNoProducts() { UUID listId = UUID.randomUUID(); when(productRepository.findByShoppingListIdAndDeletedAtIsNull(listId)) .thenReturn(List.of()); List<Product> result = service.findByListId(listId); assertThat(result).isEmpty(); }
create_associatesWithListAndSaves
0.009s
@Test void create_associatesWithListAndSaves() { UUID listId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Groceries").build(); Product product = Product.builder().name("Milk").build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.create(listId, product); assertThat(result.getShoppingList()).isEqualTo(list); verify(productRepository).save(product); }
findDeletedByListId_returnsOnlyDeletedProducts
0.003s
@Test void findDeletedByListId_returnsOnlyDeletedProducts() { UUID listId = UUID.randomUUID(); Product deleted = Product.builder() .name("Old Milk").deletedAt(LocalDateTime.now()).build(); when(productRepository.findByShoppingListIdAndDeletedAtIsNotNull(listId)) .thenReturn(List.of(deleted)); List<Product> result = service.findDeletedByListId(listId); assertThat(result).hasSize(1); assertThat(result.get(0).getDeletedAt()).isNotNull(); verify(productRepository).findByShoppingListIdAndDeletedAtIsNotNull(listId); }
create_setsShoppingListOnProduct
0.005s
@Test void create_setsShoppingListOnProduct() { UUID listId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Groceries").build(); Product product = Product.builder().name("Milk").price(BigDecimal.ZERO).build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.create(listId, product); assertThat(result.getShoppingList()).isEqualTo(list); assertThat(result.getShoppingList().getId()).isEqualTo(listId); }
setTags_throwsWhenProductNotFound
0.004s
@Test void setTags_throwsWhenProductNotFound() { UUID productId = UUID.randomUUID(); when(productRepository.findById(productId)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.setTags(productId, Set.of(UUID.randomUUID()))) .isInstanceOf(RuntimeException.class) .hasMessage("Product not found"); }
restore_setsDeletedAtNullAndIncrementsVersion
0.005s
@Test void restore_setsDeletedAtNullAndIncrementsVersion() { UUID id = UUID.randomUUID(); Product product = Product.builder() .id(id).name("Milk").version(1).deletedAt(LocalDateTime.now()).build(); when(productRepository.findById(id)).thenReturn(Optional.of(product)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.restore(id); assertThat(result.getDeletedAt()).isNull(); assertThat(result.getVersion()).isEqualTo(2); verify(productRepository).save(product); }
update_withZeroVersion_skipsConflictCheck
0.004s
@Test void update_withZeroVersion_skipsConflictCheck() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(UUID.randomUUID()).name("Test").build(); Product existing = Product.builder() .id(id).name("Milk").version(5).shoppingList(list).build(); Product updated = Product.builder() .name("Oat Milk").price(BigDecimal.valueOf(2.99)).version(0).build(); when(productRepository.findById(id)).thenReturn(Optional.of(existing)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.update(id, updated); assertThat(result.getName()).isEqualTo("Oat Milk"); assertThat(result.getVersion()).isEqualTo(6); }
create_withNullPrice_savesSuccessfully
0.005s
@Test void create_withNullPrice_savesSuccessfully() { UUID listId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Groceries").build(); Product product = Product.builder().name("Milk").price(null).build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.create(listId, product); assertThat(result.getPrice()).isNull(); verify(productRepository).save(product); }
findDeletedByListId_returnsEmptyWhenNoneDeleted
0.003s
@Test void findDeletedByListId_returnsEmptyWhenNoneDeleted() { UUID listId = UUID.randomUUID(); when(productRepository.findByShoppingListIdAndDeletedAtIsNotNull(listId)) .thenReturn(List.of()); List<Product> result = service.findDeletedByListId(listId); assertThat(result).isEmpty(); }
softDelete_setsDeletedAt
0.004s
@Test void softDelete_setsDeletedAt() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(UUID.randomUUID()).name("Test").build(); Product product = Product.builder().id(id).name("Milk").shoppingList(list).build(); when(productRepository.findById(id)).thenReturn(Optional.of(product)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); service.softDelete(id); assertThat(product.getDeletedAt()).isNotNull(); verify(productRepository).save(product); }
reorder_updatesPositions
0.011s
@Test void reorder_updatesPositions() { UUID id1 = UUID.randomUUID(); UUID id2 = UUID.randomUUID(); UUID listId = UUID.randomUUID(); Product p1 = Product.builder().id(id1).name("Milk").position(0).build(); Product p2 = Product.builder().id(id2).name("Bread").position(1).build(); when(productRepository.findById(id1)).thenReturn(Optional.of(p1)); when(productRepository.findById(id2)).thenReturn(Optional.of(p2)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); List<Map<String, Object>> order = List.of( Map.of("id", id1.toString(), "position", 1), Map.of("id", id2.toString(), "position", 0) ); service.reorder(listId, order); assertThat(p1.getPosition()).isEqualTo(1); assertThat(p2.getPosition()).isEqualTo(0); verify(productRepository, times(2)).save(any(Product.class)); }
update_withVersionConflict_throwsConflictException
0.018s
@Test void update_withVersionConflict_throwsConflictException() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(UUID.randomUUID()).name("Test").build(); Product existing = Product.builder() .id(id).name("Milk").version(5).shoppingList(list).build(); Product updated = Product.builder() .name("Oat Milk").version(3).build(); when(productRepository.findById(id)).thenReturn(Optional.of(existing)); assertThatThrownBy(() -> service.update(id, updated)) .isInstanceOf(ConflictException.class); }
setTags_assignsTagsAndIncrementsVersion
0.005s
@Test void setTags_assignsTagsAndIncrementsVersion() { UUID productId = UUID.randomUUID(); UUID tagId1 = UUID.randomUUID(); UUID tagId2 = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(UUID.randomUUID()).name("Test").build(); Product product = Product.builder() .id(productId).name("Milk").version(1).shoppingList(list).build(); Tag tag1 = Tag.builder().id(tagId1).name("Fruit").build(); Tag tag2 = Tag.builder().id(tagId2).name("Dairy").build(); when(productRepository.findById(productId)).thenReturn(Optional.of(product)); when(tagRepository.findAllById(Set.of(tagId1, tagId2))).thenReturn(List.of(tag1, tag2)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.setTags(productId, Set.of(tagId1, tagId2)); assertThat(result.getTags()).hasSize(2); assertThat(result.getVersion()).isEqualTo(2); }
restore_throwsWhenNotFound
0.002s
@Test void restore_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(productRepository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.restore(id)) .isInstanceOf(RuntimeException.class) .hasMessage("Product not found"); }
update_updatesFieldsAndIncrementsVersion
0.003s
@Test void update_updatesFieldsAndIncrementsVersion() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(UUID.randomUUID()).name("Test").build(); Product existing = Product.builder() .id(id).name("Milk").price(BigDecimal.valueOf(1.50)).version(1).shoppingList(list).build(); Product updated = Product.builder() .name("Oat Milk").price(BigDecimal.valueOf(2.99)).build(); when(productRepository.findById(id)).thenReturn(Optional.of(existing)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.update(id, updated); assertThat(result.getName()).isEqualTo("Oat Milk"); assertThat(result.getPrice()).isEqualByComparingTo(BigDecimal.valueOf(2.99)); assertThat(result.getVersion()).isEqualTo(2); }
markPurchased_togglesFromUnpurchasedToPurchased
0.004s
@Test void markPurchased_togglesFromUnpurchasedToPurchased() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(UUID.randomUUID()).name("Test").build(); Product product = Product.builder() .id(id).name("Milk").purchased(false).version(1).shoppingList(list).build(); when(productRepository.findById(id)).thenReturn(Optional.of(product)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Product result = service.markPurchased(id, "Alice"); assertThat(result.getPurchased()).isTrue(); assertThat(result.getPurchasedBy()).isEqualTo("Alice"); assertThat(result.getPurchasedAt()).isNotNull(); assertThat(result.getVersion()).isEqualTo(2); }
ShoppingListControllerTest 14/14 passed PASS
getDeleted_returnsEmptyWhenNoneDeleted
0.064s
@Test void getDeleted_returnsEmptyWhenNoneDeleted() throws Exception { when(service.findDeleted()).thenReturn(List.of()); mockMvc.perform(get("/api/lists/deleted")) .andExpect(status().isOk()) .andExpect(jsonPath("$").isEmpty()); }
getById_returnsList
0.015s
@Test void getById_returnsList() throws Exception { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder() .id(id).name("Groceries").build(); when(service.findById(id)).thenReturn(Optional.of(list)); mockMvc.perform(get("/api/lists/{id}", id)) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Groceries")); }
restore_returnsList
0.013s
@Test void restore_returnsList() throws Exception { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder() .id(id).name("Restored List").version(2).build(); when(service.restore(id)).thenReturn(list); mockMvc.perform(patch("/api/lists/{id}/restore", id)) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Restored List")) .andExpect(jsonPath("$.version").value(2)); }
duplicate_returnsDuplicatedList
0.012s
@Test void duplicate_returnsDuplicatedList() throws Exception { UUID id = UUID.randomUUID(); ShoppingList copy = ShoppingList.builder() .id(UUID.randomUUID()).name("Groceries (Kopie)").accessCode("new12345").build(); when(service.duplicate(id)).thenReturn(copy); mockMvc.perform(post("/api/lists/{id}/duplicate", id)) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Groceries (Kopie)")) .andExpect(jsonPath("$.accessCode").value("new12345")); }
joinByCode_returns404WhenNotFound
0.013s
@Test void joinByCode_returns404WhenNotFound() throws Exception { when(service.findByAccessCode("nonexist")).thenReturn(Optional.empty()); mockMvc.perform(get("/api/lists/join/{accessCode}", "nonexist")) .andExpect(status().isNotFound()); }
create_returnsList
0.025s
@Test void create_returnsList() throws Exception { ShoppingList list = ShoppingList.builder() .id(UUID.randomUUID()).name("Groceries").accessCode("abc12345").build(); when(service.create(any())).thenReturn(list); mockMvc.perform(post("/api/lists") .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"Groceries\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Groceries")) .andExpect(jsonPath("$.accessCode").value("abc12345")); }
create_blankName_returns400
0.029s
@Test void create_blankName_returns400() throws Exception { mockMvc.perform(post("/api/lists") .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"\"}")) .andExpect(status().isBadRequest()); verify(service, never()).create(any()); }
getById_returns404WhenNotFound
0.012s
@Test void getById_returns404WhenNotFound() throws Exception { UUID id = UUID.randomUUID(); when(service.findById(id)).thenReturn(Optional.empty()); mockMvc.perform(get("/api/lists/{id}", id)) .andExpect(status().isNotFound()); }
joinByCode_returnsList
0.013s
@Test void joinByCode_returnsList() throws Exception { ShoppingList list = ShoppingList.builder() .id(UUID.randomUUID()).name("Groceries").accessCode("abc12345").build(); when(service.findByAccessCode("abc12345")).thenReturn(Optional.of(list)); mockMvc.perform(get("/api/lists/join/{accessCode}", "abc12345")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Groceries")) .andExpect(jsonPath("$.accessCode").value("abc12345")); }
delete_returns204
0.014s
@Test void delete_returns204() throws Exception { UUID id = UUID.randomUUID(); doNothing().when(service).softDelete(id); mockMvc.perform(delete("/api/lists/{id}", id)) .andExpect(status().isNoContent()); verify(service).softDelete(id); }
getAll_returnsLists
0.013s
@Test void getAll_returnsLists() throws Exception { ShoppingList list = ShoppingList.builder() .id(UUID.randomUUID()).name("Groceries").build(); when(service.findAll()).thenReturn(List.of(list)); mockMvc.perform(get("/api/lists")) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].name").value("Groceries")); }
update_returnsList
0.021s
@Test void update_returnsList() throws Exception { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder() .id(id).name("Updated").version(2).build(); when(service.update(eq(id), any())).thenReturn(list); mockMvc.perform(put("/api/lists/{id}", id) .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"Updated\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Updated")) .andExpect(jsonPath("$.version").value(2)); }
create_whitespaceName_returns400
0.018s
@Test void create_whitespaceName_returns400() throws Exception { mockMvc.perform(post("/api/lists") .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\" \"}")) .andExpect(status().isBadRequest()); verify(service, never()).create(any()); }
getDeleted_returnsDeletedLists
0.011s
@Test void getDeleted_returnsDeletedLists() throws Exception { ShoppingList deleted = ShoppingList.builder() .id(UUID.randomUUID()).name("Old List").build(); when(service.findDeleted()).thenReturn(List.of(deleted)); mockMvc.perform(get("/api/lists/deleted")) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].name").value("Old List")); }
ShoppingListServiceTest 19/19 passed PASS
findById_returnsListWhenFoundAndNotDeleted
0.005s
@Test void findById_returnsListWhenFoundAndNotDeleted() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(id).name("Groceries").build(); when(repository.findById(id)).thenReturn(Optional.of(list)); Optional<ShoppingList> result = service.findById(id); assertThat(result).isPresent(); assertThat(result.get().getName()).isEqualTo("Groceries"); }
findDeleted_returnsOnlyDeletedLists
0.003s
@Test void findDeleted_returnsOnlyDeletedLists() { ShoppingList deleted = ShoppingList.builder() .name("Old List").deletedAt(LocalDateTime.now()).build(); when(repository.findByDeletedAtIsNotNull()).thenReturn(List.of(deleted)); List<ShoppingList> result = service.findDeleted(); assertThat(result).hasSize(1); assertThat(result.get(0).getDeletedAt()).isNotNull(); verify(repository).findByDeletedAtIsNotNull(); }
findById_returnsEmptyWhenNotFound
0.005s
@Test void findById_returnsEmptyWhenNotFound() { UUID id = UUID.randomUUID(); when(repository.findById(id)).thenReturn(Optional.empty()); Optional<ShoppingList> result = service.findById(id); assertThat(result).isEmpty(); }
findByAccessCode_returnsEmptyWhenDeleted
0.006s
@Test void findByAccessCode_returnsEmptyWhenDeleted() { String code = "abc12345"; ShoppingList list = ShoppingList.builder() .name("Groceries").accessCode(code).deletedAt(LocalDateTime.now()).build(); when(repository.findByAccessCode(code)).thenReturn(Optional.of(list)); Optional<ShoppingList> result = service.findByAccessCode(code); assertThat(result).isEmpty(); }
create_setsAccessCodeAndSaves
0.007s
@Test void create_setsAccessCodeAndSaves() { ShoppingList list = ShoppingList.builder().name("Groceries").build(); when(repository.save(any())).thenAnswer(inv -> inv.getArgument(0)); ShoppingList result = service.create(list); assertThat(result.getAccessCode()).isNotNull(); assertThat(result.getAccessCode()).hasSize(8); verify(repository).save(list); }
findByAccessCode_returnsListWhenFoundAndNotDeleted
0.001s
@Test void findByAccessCode_returnsListWhenFoundAndNotDeleted() { String code = "abc12345"; ShoppingList list = ShoppingList.builder().name("Groceries").accessCode(code).build(); when(repository.findByAccessCode(code)).thenReturn(Optional.of(list)); Optional<ShoppingList> result = service.findByAccessCode(code); assertThat(result).isPresent(); assertThat(result.get().getAccessCode()).isEqualTo(code); }
softDelete_throwsWhenNotFound
0.002s
@Test void softDelete_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(repository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.softDelete(id)) .isInstanceOf(RuntimeException.class) .hasMessage("List not found"); }
update_throwsWhenNotFound
0.003s
@Test void update_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(repository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.update(id, new ShoppingList())) .isInstanceOf(RuntimeException.class) .hasMessage("List not found"); }
restore_setsDeletedAtNullAndIncrementsVersion
0.009s
@Test void restore_setsDeletedAtNullAndIncrementsVersion() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder() .id(id).name("Groceries").version(1).deletedAt(LocalDateTime.now()).build(); when(repository.findById(id)).thenReturn(Optional.of(list)); when(repository.save(any())).thenAnswer(inv -> inv.getArgument(0)); ShoppingList result = service.restore(id); assertThat(result.getDeletedAt()).isNull(); assertThat(result.getVersion()).isEqualTo(2); verify(repository).save(list); }
findByAccessCode_returnsEmptyWhenNotFound
0.005s
@Test void findByAccessCode_returnsEmptyWhenNotFound() { when(repository.findByAccessCode("nonexist")).thenReturn(Optional.empty()); Optional<ShoppingList> result = service.findByAccessCode("nonexist"); assertThat(result).isEmpty(); }
duplicate_throwsWhenNotFound
0.004s
@Test void duplicate_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(repository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.duplicate(id)) .isInstanceOf(RuntimeException.class) .hasMessage("List not found"); }
findAll_returnsNonDeletedLists
0.002s
@Test void findAll_returnsNonDeletedLists() { ShoppingList list = ShoppingList.builder().name("Groceries").build(); when(repository.findByDeletedAtIsNull()).thenReturn(List.of(list)); List<ShoppingList> result = service.findAll(); assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo("Groceries"); verify(repository).findByDeletedAtIsNull(); }
duplicate_createsCopyWithKopieNameAndNewAccessCode
0.003s
@Test void duplicate_createsCopyWithKopieNameAndNewAccessCode() { UUID originalId = UUID.randomUUID(); ShoppingList original = ShoppingList.builder() .id(originalId).name("Groceries").accessCode("orig1234").build(); when(repository.findById(originalId)).thenReturn(Optional.of(original)); when(repository.save(any())).thenAnswer(inv -> inv.getArgument(0)); when(productRepository.findByShoppingListIdAndDeletedAtIsNull(originalId)) .thenReturn(List.of()); ShoppingList result = service.duplicate(originalId); assertThat(result.getName()).isEqualTo("Groceries (Kopie)"); assertThat(result.getAccessCode()).isNotNull(); assertThat(result.getAccessCode()).hasSize(8); assertThat(result.getAccessCode()).isNotEqualTo("orig1234"); }
softDelete_setsDeletedAt
0.002s
@Test void softDelete_setsDeletedAt() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(id).name("Groceries").build(); when(repository.findById(id)).thenReturn(Optional.of(list)); when(repository.save(any())).thenAnswer(inv -> inv.getArgument(0)); service.softDelete(id); assertThat(list.getDeletedAt()).isNotNull(); verify(repository).save(list); }
duplicate_copiesProducts
0.004s
@Test void duplicate_copiesProducts() { UUID originalId = UUID.randomUUID(); ShoppingList original = ShoppingList.builder() .id(originalId).name("Groceries").accessCode("orig1234").build(); Product p1 = Product.builder().name("Milk").price(BigDecimal.valueOf(1.50)).position(0).build(); Product p2 = Product.builder().name("Bread").price(BigDecimal.valueOf(2.00)).position(1).build(); when(repository.findById(originalId)).thenReturn(Optional.of(original)); when(repository.save(any())).thenAnswer(inv -> inv.getArgument(0)); when(productRepository.findByShoppingListIdAndDeletedAtIsNull(originalId)) .thenReturn(List.of(p1, p2)); when(productRepository.save(any(Product.class))).thenAnswer(inv -> inv.getArgument(0)); service.duplicate(originalId); verify(productRepository, times(2)).save(any(Product.class)); }
restore_throwsWhenNotFound
0.002s
@Test void restore_throwsWhenNotFound() { UUID id = UUID.randomUUID(); when(repository.findById(id)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.restore(id)) .isInstanceOf(RuntimeException.class) .hasMessage("List not found"); }
findById_returnsEmptyWhenDeleted
0.002s
@Test void findById_returnsEmptyWhenDeleted() { UUID id = UUID.randomUUID(); ShoppingList list = ShoppingList.builder() .id(id).name("Groceries") .deletedAt(LocalDateTime.now()) .build(); when(repository.findById(id)).thenReturn(Optional.of(list)); Optional<ShoppingList> result = service.findById(id); assertThat(result).isEmpty(); }
update_updatesNameAndIncrementsVersion
0.002s
@Test void update_updatesNameAndIncrementsVersion() { UUID id = UUID.randomUUID(); ShoppingList existing = ShoppingList.builder() .id(id).name("Old").version(1).build(); ShoppingList updated = ShoppingList.builder().name("New").build(); when(repository.findById(id)).thenReturn(Optional.of(existing)); when(repository.save(any())).thenAnswer(inv -> inv.getArgument(0)); ShoppingList result = service.update(id, updated); assertThat(result.getName()).isEqualTo("New"); assertThat(result.getVersion()).isEqualTo(2); }
findAll_returnsEmptyWhenNoLists
0.001s
@Test void findAll_returnsEmptyWhenNoLists() { when(repository.findByDeletedAtIsNull()).thenReturn(List.of()); List<ShoppingList> result = service.findAll(); assertThat(result).isEmpty(); }
SirBuysALotApplicationTests 1/1 passed PASS
contextLoads
0.009s
SyncControllerTest 5/5 passed PASS
syncBatch_nullChanges_returnsZeroCounts
0.135s
@Test void syncBatch_nullChanges_returnsZeroCounts() throws Exception { String body = "{}"; mockMvc.perform(post("/api/lists/{listId}/sync", listId) .contentType(MediaType.APPLICATION_JSON) .content(body)) .andExpect(status().isOk()) .andExpect(jsonPath("$.synced").value(0)) .andExpect(jsonPath("$.failed").value(0)); }
syncBatch_withChanges_returnsResults
0.029s
@Test void syncBatch_withChanges_returnsResults() throws Exception { Map<String, Object> serviceResult = new HashMap<>(); serviceResult.put("results", List.of(Map.of("id", "c1", "status", "synced"))); serviceResult.put("synced", 1); serviceResult.put("failed", 0); when(syncService.processBatch(eq(listId), any())).thenReturn(serviceResult); String body = objectMapper.writeValueAsString(Map.of( "changes", List.of(Map.of( "id", "c1", "type", "create", "entity", "product", "payload", Map.of("name", "Milk") )) )); mockMvc.perform(post("/api/lists/{listId}/sync", listId) .contentType(MediaType.APPLICATION_JSON) .content(body)) .andExpect(status().isOk()) .andExpect(jsonPath("$.synced").value(1)) .andExpect(jsonPath("$.failed").value(0)); }
syncBatch_emptyChanges_returnsZeroCounts
0.009s
@Test void syncBatch_emptyChanges_returnsZeroCounts() throws Exception { String body = objectMapper.writeValueAsString(Map.of("changes", List.of())); mockMvc.perform(post("/api/lists/{listId}/sync", listId) .contentType(MediaType.APPLICATION_JSON) .content(body)) .andExpect(status().isOk()) .andExpect(jsonPath("$.synced").value(0)) .andExpect(jsonPath("$.failed").value(0)); verify(syncService, never()).processBatch(any(), any()); }
syncBatch_mixedResults_returnsCorrectCounts
0.011s
@Test void syncBatch_mixedResults_returnsCorrectCounts() throws Exception { Map<String, Object> serviceResult = new HashMap<>(); serviceResult.put("results", List.of( Map.of("id", "c1", "status", "synced"), Map.of("id", "c2", "status", "failed", "error", "Not found") )); serviceResult.put("synced", 1); serviceResult.put("failed", 1); when(syncService.processBatch(eq(listId), any())).thenReturn(serviceResult); String body = objectMapper.writeValueAsString(Map.of( "changes", List.of( Map.of("id", "c1", "type", "create", "entity", "product", "payload", Map.of("name", "Milk")), Map.of("id", "c2", "type", "update", "entity", "product", "entityId", UUID.randomUUID().toString(), "payload", Map.of("name", "Ghost")) ) )); mockMvc.perform(post("/api/lists/{listId}/sync", listId) .contentType(MediaType.APPLICATION_JSON) .content(body)) .andExpect(status().isOk()) .andExpect(jsonPath("$.synced").value(1)) .andExpect(jsonPath("$.failed").value(1)); }
syncBatch_multipleChanges_delegatesToService
0.012s
@Test void syncBatch_multipleChanges_delegatesToService() throws Exception { Map<String, Object> serviceResult = new HashMap<>(); serviceResult.put("results", List.of( Map.of("id", "c1", "status", "synced"), Map.of("id", "c2", "status", "synced") )); serviceResult.put("synced", 2); serviceResult.put("failed", 0); when(syncService.processBatch(eq(listId), any())).thenReturn(serviceResult); String body = objectMapper.writeValueAsString(Map.of( "changes", List.of( Map.of("id", "c1", "type", "create", "entity", "product", "payload", Map.of("name", "Milk")), Map.of("id", "c2", "type", "create", "entity", "product", "payload", Map.of("name", "Bread")) ) )); mockMvc.perform(post("/api/lists/{listId}/sync", listId) .contentType(MediaType.APPLICATION_JSON) .content(body)) .andExpect(status().isOk()) .andExpect(jsonPath("$.synced").value(2)); verify(syncService).processBatch(eq(listId), any()); }
SyncServiceTest 11/11 passed PASS
processBatch_updateList_updatesNameAndVersion
0.009s
@Test void processBatch_updateList_updatesNameAndVersion() { ShoppingList list = ShoppingList.builder() .id(listId).name("Old Name").version(1).build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(listRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Map<String, Object> change = new HashMap<>(); change.put("id", "change-5"); change.put("type", "update"); change.put("entity", "list"); change.put("payload", Map.of("name", "New Name")); service.processBatch(listId, List.of(change)); assertThat(list.getName()).isEqualTo("New Name"); assertThat(list.getVersion()).isEqualTo(2); }
processBatch_emptyChanges_returnsZeroCounts
0.005s
@Test void processBatch_emptyChanges_returnsZeroCounts() { Map<String, Object> result = service.processBatch(listId, List.of()); assertThat(result.get("synced")).isEqualTo(0); assertThat(result.get("failed")).isEqualTo(0); assertThat((List<?>) result.get("results")).isEmpty(); }
processBatch_broadcastsWebSocketMessage
0.005s
@Test void processBatch_broadcastsWebSocketMessage() { Map<String, Object> result = service.processBatch(listId, List.of()); verify(messagingTemplate).convertAndSend(eq("/topic/lists/" + listId), any(Map.class)); }
processBatch_mixedResults_countsSyncedAndFailed
0.004s
@Test void processBatch_mixedResults_countsSyncedAndFailed() { ShoppingList list = ShoppingList.builder().id(listId).name("Groceries").build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); when(productRepository.findById(any())).thenReturn(Optional.empty()); Map<String, Object> createChange = new HashMap<>(); createChange.put("id", "change-ok"); createChange.put("type", "create"); createChange.put("entity", "product"); createChange.put("payload", Map.of("name", "Milk")); Map<String, Object> updateChange = new HashMap<>(); updateChange.put("id", "change-fail"); updateChange.put("type", "update"); updateChange.put("entity", "product"); updateChange.put("entityId", UUID.randomUUID().toString()); updateChange.put("payload", Map.of("name", "Ghost")); Map<String, Object> result = service.processBatch(listId, List.of(createChange, updateChange)); assertThat(result.get("synced")).isEqualTo(1); assertThat(result.get("failed")).isEqualTo(1); }
processBatch_failedChange_incrementsFailedCount
0.002s
@Test void processBatch_failedChange_incrementsFailedCount() { when(listRepository.findById(listId)).thenReturn(Optional.empty()); Map<String, Object> change = new HashMap<>(); change.put("id", "change-7"); change.put("type", "create"); change.put("entity", "product"); change.put("payload", Map.of("name", "Milk")); Map<String, Object> result = service.processBatch(listId, List.of(change)); assertThat(result.get("synced")).isEqualTo(0); assertThat(result.get("failed")).isEqualTo(1); List<Map<String, Object>> results = (List<Map<String, Object>>) result.get("results"); assertThat(results.get(0).get("status")).isEqualTo("failed"); }
processBatch_updateProduct_updatesFieldsAndVersion
0.002s
@Test void processBatch_updateProduct_updatesFieldsAndVersion() { UUID productId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Test").build(); Product product = Product.builder() .id(productId).name("Milk").version(1).shoppingList(list).build(); when(productRepository.findById(productId)).thenReturn(Optional.of(product)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Map<String, Object> change = new HashMap<>(); change.put("id", "change-2"); change.put("type", "update"); change.put("entity", "product"); change.put("entityId", productId.toString()); change.put("payload", Map.of("name", "Oat Milk")); Map<String, Object> result = service.processBatch(listId, List.of(change)); assertThat(result.get("synced")).isEqualTo(1); assertThat(product.getName()).isEqualTo("Oat Milk"); assertThat(product.getVersion()).isEqualTo(2); }
broadcastChange_sendsToCorrectTopic
0.001s
@Test void broadcastChange_sendsToCorrectTopic() { service.broadcastChange(listId, "test_event", Map.of("key", "value")); verify(messagingTemplate).convertAndSend(eq("/topic/lists/" + listId), any(Map.class)); }
processBatch_toggleProduct_togglesPurchased
0.002s
@Test void processBatch_toggleProduct_togglesPurchased() { UUID productId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Test").build(); Product product = Product.builder() .id(productId).name("Milk").purchased(false).version(1).shoppingList(list).build(); when(productRepository.findById(productId)).thenReturn(Optional.of(product)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Map<String, Object> change = new HashMap<>(); change.put("id", "change-3"); change.put("type", "toggle"); change.put("entity", "product"); change.put("entityId", productId.toString()); change.put("payload", Map.of("purchasedBy", "Alice")); service.processBatch(listId, List.of(change)); assertThat(product.getPurchased()).isTrue(); assertThat(product.getPurchasedBy()).isEqualTo("Alice"); assertThat(product.getVersion()).isEqualTo(2); }
processBatch_createProduct_savesProduct
0.002s
@Test void processBatch_createProduct_savesProduct() { ShoppingList list = ShoppingList.builder().id(listId).name("Groceries").build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Map<String, Object> change = new HashMap<>(); change.put("id", "change-1"); change.put("type", "create"); change.put("entity", "product"); change.put("payload", Map.of("name", "Milk", "price", 1.50)); Map<String, Object> result = service.processBatch(listId, List.of(change)); assertThat(result.get("synced")).isEqualTo(1); assertThat(result.get("failed")).isEqualTo(0); verify(productRepository).save(any(Product.class)); }
processBatch_deleteProduct_setsDeletedAt
0.003s
@Test void processBatch_deleteProduct_setsDeletedAt() { UUID productId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Test").build(); Product product = Product.builder() .id(productId).name("Milk").shoppingList(list).build(); when(productRepository.findById(productId)).thenReturn(Optional.of(product)); when(productRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Map<String, Object> change = new HashMap<>(); change.put("id", "change-4"); change.put("type", "delete"); change.put("entity", "product"); change.put("entityId", productId.toString()); change.put("payload", Map.of()); service.processBatch(listId, List.of(change)); assertThat(product.getDeletedAt()).isNotNull(); }
processBatch_deleteList_setsDeletedAt
0.002s
@Test void processBatch_deleteList_setsDeletedAt() { ShoppingList list = ShoppingList.builder() .id(listId).name("Groceries").build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(listRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Map<String, Object> change = new HashMap<>(); change.put("id", "change-6"); change.put("type", "delete"); change.put("entity", "list"); change.put("payload", Map.of()); service.processBatch(listId, List.of(change)); assertThat(list.getDeletedAt()).isNotNull(); }
TagControllerTest 8/8 passed PASS
create_nullName_returns400
0.05s
@Test void create_nullName_returns400() throws Exception { mockMvc.perform(post("/api/lists/{listId}/tags", listId) .contentType(MediaType.APPLICATION_JSON) .content("{}")) .andExpect(status().isBadRequest()); verify(service, never()).create(any(), any()); }
getAll_returnsEmptyList
0.009s
@Test void getAll_returnsEmptyList() throws Exception { when(service.findByListId(listId)).thenReturn(List.of()); mockMvc.perform(get("/api/lists/{listId}/tags", listId)) .andExpect(status().isOk()) .andExpect(jsonPath("$").isEmpty()); }
update_returnsTag
0.01s
@Test void update_returnsTag() throws Exception { UUID tagId = UUID.randomUUID(); Tag tag = Tag.builder().id(tagId).name("Vegetables").build(); when(service.update(eq(tagId), eq("Vegetables"))).thenReturn(tag); mockMvc.perform(put("/api/lists/{listId}/tags/{id}", listId, tagId) .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"Vegetables\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Vegetables")); }
create_blankName_returns400
0.008s
@Test void create_blankName_returns400() throws Exception { mockMvc.perform(post("/api/lists/{listId}/tags", listId) .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"\"}")) .andExpect(status().isBadRequest()); verify(service, never()).create(any(), any()); }
delete_returns204
0.007s
@Test void delete_returns204() throws Exception { UUID tagId = UUID.randomUUID(); doNothing().when(service).delete(tagId); mockMvc.perform(delete("/api/lists/{listId}/tags/{id}", listId, tagId)) .andExpect(status().isNoContent()); verify(service).delete(tagId); }
create_whitespaceName_returns400
0.008s
@Test void create_whitespaceName_returns400() throws Exception { mockMvc.perform(post("/api/lists/{listId}/tags", listId) .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\" \"}")) .andExpect(status().isBadRequest()); verify(service, never()).create(any(), any()); }
create_returnsTag
0.008s
@Test void create_returnsTag() throws Exception { Tag tag = Tag.builder().id(UUID.randomUUID()).name("Fruit").build(); when(service.create(eq(listId), eq("Fruit"))).thenReturn(tag); mockMvc.perform(post("/api/lists/{listId}/tags", listId) .contentType(MediaType.APPLICATION_JSON) .content("{\"name\":\"Fruit\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("Fruit")); }
getAll_returnsTags
0.008s
@Test void getAll_returnsTags() throws Exception { Tag tag = Tag.builder().id(UUID.randomUUID()).name("Fruit").build(); when(service.findByListId(listId)).thenReturn(List.of(tag)); mockMvc.perform(get("/api/lists/{listId}/tags", listId)) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].name").value("Fruit")); }
TagServiceTest 6/6 passed PASS
create_throwsWhenListNotFound
0.004s
@Test void create_throwsWhenListNotFound() { UUID listId = UUID.randomUUID(); when(listRepository.findById(listId)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.create(listId, "Fruit")) .isInstanceOf(RuntimeException.class) .hasMessage("Liste nicht gefunden"); }
update_throwsWhenNotFound
0.003s
@Test void update_throwsWhenNotFound() { UUID tagId = UUID.randomUUID(); when(tagRepository.findById(tagId)).thenReturn(Optional.empty()); assertThatThrownBy(() -> service.update(tagId, "Vegetables")) .isInstanceOf(RuntimeException.class) .hasMessage("Tag nicht gefunden"); }
create_associatesWithListAndSaves
0.005s
@Test void create_associatesWithListAndSaves() { UUID listId = UUID.randomUUID(); ShoppingList list = ShoppingList.builder().id(listId).name("Groceries").build(); when(listRepository.findById(listId)).thenReturn(Optional.of(list)); when(tagRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Tag result = service.create(listId, "Fruit"); assertThat(result.getName()).isEqualTo("Fruit"); assertThat(result.getShoppingList()).isEqualTo(list); verify(tagRepository).save(any(Tag.class)); }
findByListId_returnsTags
0.004s
@Test void findByListId_returnsTags() { UUID listId = UUID.randomUUID(); Tag tag = Tag.builder().name("Fruit").build(); when(tagRepository.findByShoppingListId(listId)).thenReturn(List.of(tag)); List<Tag> result = service.findByListId(listId); assertThat(result).hasSize(1); assertThat(result.get(0).getName()).isEqualTo("Fruit"); }
update_updatesNameAndSaves
0.006s
@Test void update_updatesNameAndSaves() { UUID tagId = UUID.randomUUID(); Tag tag = Tag.builder().id(tagId).name("Fruit").build(); when(tagRepository.findById(tagId)).thenReturn(Optional.of(tag)); when(tagRepository.save(any())).thenAnswer(inv -> inv.getArgument(0)); Tag result = service.update(tagId, "Vegetables"); assertThat(result.getName()).isEqualTo("Vegetables"); verify(tagRepository).save(tag); }
delete_deletesById
0.004s
@Test void delete_deletesById() { UUID tagId = UUID.randomUUID(); service.delete(tagId); verify(tagRepository).deleteById(tagId); }