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 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-18 19:05:33 +02:00
committed by marcel
parent e2f287d3d8
commit f470a39ad2

View File

@@ -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<Document> 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