ContentFragmentUtils { public static Map<String, ComponentExporter> getComponentExporters(Iterator<Resource> resourceIterator, ModelFactory modelFactory, SlingHttpServletRequest slingHttpServletRequest) { final Map<String, ComponentExporter> componentExporterMap = new LinkedHashMap<>(); while (resourceIterator.hasNext()) { Resource resource = resourceIterator.next(); ComponentExporter exporter = modelFactory.getModelFromWrappedRequest(slingHttpServletRequest, resource, ComponentExporter.class); if (exporter != null) { String name = resource.getName(); if (componentExporterMap.put(name, exporter) != null) { throw new IllegalStateException(String.format("Duplicate key '%s'", name)); } } } return componentExporterMap; } private  ContentFragmentUtils(); static String getType(ContentFragment contentFragment); static Iterator<ContentElement> filterElements(final ContentFragment contentFragment,
                                                          final String[] elementNames); static String getEditorJSON(final ContentFragment contentFragment,
                                       final String variationName,
                                       final String[] elementNames); static String getGridResourceType(Resource fragmentResource); static String[] getItemsOrder(Map<String, ?> itemsMap); static Map<String, ComponentExporter> getComponentExporters(Iterator<Resource> resourceIterator,
                                                                       ModelFactory modelFactory,
                                                                       SlingHttpServletRequest slingHttpServletRequest);  }
@Test public void getComponentExport() { AemContext slingContext = CoreComponentTestContext.newAemContext(); slingContext.load().json(this.getClass().getResourceAsStream("foo.json"), "/foo"); MockSlingHttpServletRequest slingHttpServletRequest = new MockSlingHttpServletRequest(slingContext.bundleContext()); ComponentExporter componentExporter = new TestComponentExporter(); ModelFactory modelFactory = Mockito.mock(ModelFactory.class); Mockito.when(modelFactory.getModelFromWrappedRequest( Mockito.any(), Mockito.any(), Mockito.eq(ComponentExporter.class) )).thenReturn(componentExporter); Map<String, ComponentExporter> exporterMap = ContentFragmentUtils.getComponentExporters(slingContext.resourceResolver() .getResource("/foo").listChildren(), modelFactory, slingHttpServletRequest); Assertions.assertEquals(componentExporter, exporterMap.get("bar")); Assertions.assertEquals(componentExporter, exporterMap.get("qux")); }