@Test void testPopulate() { when(existingDecorator.getId()).thenReturn("id1"); when(removedDecorator.getId()).thenReturn("id2"); when(newDecorator.getId()).thenReturn("id3"); when(newDecorator.setLabel(any())).thenReturn(newDecorator); when(newDecorator.setDescription(any())).thenReturn(newDecorator); when(newDecorator.setSchema(any())).thenReturn(newDecorator); when(registry.getFactoryIds()).thenAnswer(invocation -> Stream.of("id1", "id3")); when(registry.getFactory("id3")).thenReturn(dynamicRepositoryDecoratorFactory); when(dataService.findAll(DYNAMIC_DECORATOR, DynamicDecorator.class)) .thenAnswer(invocation -> Stream.of(existingDecorator, removedDecorator)); when(dataService.findOneById(DYNAMIC_DECORATOR, "id1", DynamicDecorator.class)) .thenReturn(existingDecorator); when(dynamicDecoratorFactory.create("id3")).thenReturn(newDecorator); when(dynamicRepositoryDecoratorFactory.getLabel()).thenReturn("label3"); when(dynamicRepositoryDecoratorFactory.getDescription()).thenReturn("desc3"); populator.populate(); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<DynamicDecorator>> decoratorCaptor = forClass(Stream.class); @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Object>> stringCaptor = forClass(Stream.class); verify(dataService).add(eq(DYNAMIC_DECORATOR), decoratorCaptor.capture()); verify(dataService).deleteAll(eq(DYNAMIC_DECORATOR), stringCaptor.capture()); List<DynamicDecorator> addedDecorators = decoratorCaptor.getValue().collect(toList()); List<Object> deletedDecorators = stringCaptor.getValue().collect(toList()); assertEquals(1, addedDecorators.size()); assertEquals("id3", addedDecorators.get(0).getId()); assertEquals(1, deletedDecorators.size()); assertEquals("id2", deletedDecorators.get(0)); }
public void populate() { addNewDecorators(); removeNonExistingDecorators(); }
DynamicDecoratorPopulator { public void populate() { addNewDecorators(); removeNonExistingDecorators(); } }
DynamicDecoratorPopulator { public void populate() { addNewDecorators(); removeNonExistingDecorators(); } DynamicDecoratorPopulator(
      DataService dataService,
      DynamicRepositoryDecoratorRegistry dynamicRepositoryDecoratorRegistry,
      DynamicDecoratorFactory dynamicDecoratorFactory); }
DynamicDecoratorPopulator { public void populate() { addNewDecorators(); removeNonExistingDecorators(); } DynamicDecoratorPopulator(
      DataService dataService,
      DynamicRepositoryDecoratorRegistry dynamicRepositoryDecoratorRegistry,
      DynamicDecoratorFactory dynamicDecoratorFactory); void populate(); }
DynamicDecoratorPopulator { public void populate() { addNewDecorators(); removeNonExistingDecorators(); } DynamicDecoratorPopulator(
      DataService dataService,
      DynamicRepositoryDecoratorRegistry dynamicRepositoryDecoratorRegistry,
      DynamicDecoratorFactory dynamicDecoratorFactory); void populate();  }