|
24 | 24 | import java.util.Optional;
|
25 | 25 | // tag::faq.entities.auditing.callbacks[]
|
26 | 26 | import java.util.UUID;
|
| 27 | +import java.util.stream.StreamSupport; |
27 | 28 |
|
28 | 29 | // end::faq.entities.auditing.callbacks[]
|
29 | 30 | import org.junit.jupiter.api.Test;
|
@@ -102,14 +103,24 @@ void onBeforeBindShouldBeCalledForAllEntities(@Autowired ThingRepository reposit
|
102 | 103 | thing1.setRandomValue("a");
|
103 | 104 | ThingWithAssignedId thing2 = new ThingWithAssignedId("id2", "Another name");
|
104 | 105 | thing2.setRandomValue("b");
|
105 |
| - Iterable<ThingWithAssignedId> savedThings = repository.saveAll(Arrays.asList(thing1, thing2)); |
| 106 | + |
| 107 | + var unsaved = Arrays.asList(thing1, thing2); |
| 108 | + Iterable<ThingWithAssignedId> savedThings = repository.saveAll(unsaved); |
| 109 | + |
| 110 | + assertThat(unsaved).allMatch(v -> v.getRandomValue() != null); |
| 111 | + assertThat(unsaved).noneMatch(v -> v.getAnotherRandomValue() != null); |
106 | 112 |
|
107 | 113 | assertThat(savedThings).extracting(ThingWithAssignedId::getName).containsExactlyInAnyOrder("A name (Edited)",
|
108 | 114 | "Another name (Edited)");
|
109 | 115 | assertThat(savedThings).hasSize(2)
|
110 | 116 | .extracting(ThingWithAssignedId::getRandomValue)
|
111 | 117 | .allMatch(Objects::isNull);
|
112 | 118 |
|
| 119 | + // Assert the onAfterConvert |
| 120 | + var ids = StreamSupport.stream(savedThings.spliterator(), false).map(ThingWithAssignedId::getTheId).toList(); |
| 121 | + var reloaded = repository.findAllById(ids); |
| 122 | + assertThat(reloaded).allMatch(v -> v.getRandomValue() != null); |
| 123 | + |
113 | 124 | verifyDatabase(savedThings);
|
114 | 125 | }
|
115 | 126 |
|
|
0 commit comments