MappingProcessor implements Mapper { static void removeOrphans(Collection<?> mappedElements, List<Object> result) { for (Iterator<?> iterator = result.iterator(); iterator.hasNext();) { Object object = iterator.next(); if (!mappedElements.contains(object)) { iterator.remove(); } } for (Object object : mappedElements) { if (!result.contains(object)) { result.add(object); } } } protected  MappingProcessor(ClassMappings classMappings, Configuration globalConfiguration, CacheManager cacheMgr,
                               List<CustomConverter> customConverterObjects,
                               EventManager eventManager, CustomFieldMapper customFieldMapper,
                               Map<String, CustomConverter> customConverterObjectsWithId, BeanContainer beanContainer,
                               DestBeanCreator destBeanCreator, DestBeanBuilderCreator destBeanBuilderCreator,
                               BeanMappingGenerator beanMappingGenerator, PropertyDescriptorFactory propertyDescriptorFactory); T map(final Object srcObj, final Class<T> destClass); T map(final Object srcObj, final Class<T> destClass, final String mapId); void map(final Object srcObj, final Object destObj); void map(final Object srcObj, final Object destObj, final String mapId); @Override MapperModelContext getMapperModelContext();  }
@Test public void testRemoveOrphans_OK() { destinationList.add("A"); MappingProcessor.removeOrphans(sourceList, destinationList); assertTrue(destinationList.isEmpty()); }
@Test public void testRemoveOrphans_Many() { destinationList.add("A"); destinationList.add("B"); destinationList.add("C"); sourceList.add("B"); sourceList.add("D"); MappingProcessor.removeOrphans(sourceList, destinationList); assertEquals(2, destinationList.size()); assertEquals("B", destinationList.get(0)); assertEquals("D", destinationList.get(1)); }
@Test public void testRemoveOrphans_Ordering() { destinationList.add(new Ordered(1)); destinationList.add(new Ordered(2)); destinationList.add(new Ordered(3)); sourceList.add(new Ordered(0)); sourceList.add(new Ordered(3)); sourceList.add(new Ordered(2)); sourceList.add(new Ordered(1)); MappingProcessor.removeOrphans(sourceList, destinationList); assertEquals(4, destinationList.size()); assertEquals(new Ordered(1), destinationList.get(0)); assertEquals(new Ordered(2), destinationList.get(1)); assertEquals(new Ordered(3), destinationList.get(2)); assertEquals(new Ordered(0), destinationList.get(3)); }