From f470a39ad244e7302fe73e456461497cbe57dc4d Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 18 May 2026 19:05:33 +0200 Subject: [PATCH] test(document): strengthen getRecentActivity smoke test for post-return access Previous version only asserted the method call didn't throw. Now the test captures the returned list and asserts that sender.getLastName() and tags.size() are accessible outside the transaction, which is the scenario that would have failed with a LazyInitializationException. Co-Authored-By: Claude Sonnet 4.6 --- .../document/DocumentLazyLoadingTest.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentLazyLoadingTest.java b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentLazyLoadingTest.java index 8ce53e52..5123337f 100644 --- a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentLazyLoadingTest.java +++ b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentLazyLoadingTest.java @@ -18,6 +18,7 @@ import org.springframework.test.context.bean.override.mockito.MockitoBean; import software.amazon.awssdk.services.s3.S3Client; import java.util.HashSet; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -84,7 +85,7 @@ class DocumentLazyLoadingTest { } @Test - void getRecentActivity_doesNotThrowLazyInitializationException() { + void getRecentActivity_collectionsAccessibleAfterReturn() { Person sender = personRepository.save(Person.builder().firstName("Hans").lastName("RaSender").build()); Tag tag = tagRepository.save(Tag.builder().name("RaTag").build()); for (int i = 0; i < 3; i++) { @@ -96,8 +97,13 @@ class DocumentLazyLoadingTest { .build()); } - assertThatCode(() -> documentService.getRecentActivity(3)) - .doesNotThrowAnyException(); + List results = documentService.getRecentActivity(3); + + assertThatCode(() -> { + results.forEach(d -> assertThat(d.getSender()).isNotNull()); + results.forEach(d -> assertThat(d.getSender().getLastName()).isNotNull()); + results.forEach(d -> d.getTags().size()); + }).doesNotThrowAnyException(); } @Test