|
9 | 9 | import java.util.ArrayList; |
10 | 10 | import java.util.Arrays; |
11 | 11 | import java.util.List; |
| 12 | +import java.util.UUID; |
| 13 | +import java.util.concurrent.atomic.AtomicInteger; |
12 | 14 |
|
13 | 15 | class InMemoryBackingStoreTest { |
14 | 16 | @Test |
@@ -392,4 +394,32 @@ void TestsBackingStoreEmbeddedInModelWithByUpdatingNestedIBackedModelCollectionP |
392 | 394 | (List<String>) colleaguesList.get(0).getBackingStore().get("businessPhones"); |
393 | 395 | assertEquals(1, businessPhones.size()); |
394 | 396 | } |
| 397 | + |
| 398 | + @Test |
| 399 | + void TestsBackingStoreEmbeddedWithMultipleNestedModelsCollectionsAndAdditionalData() { |
| 400 | + // Arrange dummy user with initialized backing store |
| 401 | + AtomicInteger invocationCount = new AtomicInteger(); |
| 402 | + var testUser = new TestEntity(); |
| 403 | + testUser.getBackingStore() |
| 404 | + .subscribe( |
| 405 | + "testSubscription", |
| 406 | + (keyString, oldObject, newObject) -> { |
| 407 | + invocationCount.getAndIncrement(); |
| 408 | + }); |
| 409 | + testUser.setId("84c747c1-d2c0-410d-ba50-fc23e0b4abbe"); // invocation 1 |
| 410 | + |
| 411 | + var colleagues = new ArrayList<TestEntity>(); |
| 412 | + for (int i = 0; i < 10; i++) { |
| 413 | + var colleague = new TestEntity(); |
| 414 | + colleague.setId(UUID.randomUUID().toString()); |
| 415 | + colleague.setBusinessPhones(Arrays.asList(new String[] {"+1 234 567 891"})); |
| 416 | + colleague.getAdditionalData().put("count", i); |
| 417 | + colleagues.add(colleague); |
| 418 | + } |
| 419 | + testUser.setColleagues(colleagues); // invocation 2 |
| 420 | + |
| 421 | + testUser.getBackingStore().setIsInitializationCompleted(true); // initialize |
| 422 | + |
| 423 | + assertEquals(2, invocationCount.get()); // only for setting the id and the colleagues |
| 424 | + } |
395 | 425 | } |
0 commit comments