PersistenceUnitDescriptorLoader { public List<PersistenceUnitDescriptor> loadPersistenceUnitDescriptors(final Map<String, Object> properties) throws IOException { final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources("META-INF/persistence.xml"); final List<PersistenceUnitDescriptor> units = new ArrayList<>(); while (resources.hasMoreElements()) { final Document doc = loadDocument(resources.nextElement()); final NodeList children = doc.getDocumentElement().getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && "persistence-unit".equals(((Element) node).getTagName())) { units.add(new PersistenceUnitDescriptorImpl((Element) node, properties)); } } } return units; }  List<PersistenceUnitDescriptor> loadPersistenceUnitDescriptors(final Map<String, Object> properties);  }
@Test public void testPersistenceUnitDescriptorLoader() throws IOException { final PersistenceUnitDescriptorLoader loader = new PersistenceUnitDescriptorLoader(); final List<PersistenceUnitDescriptor> descriptors = loader.loadPersistenceUnitDescriptors(Collections.emptyMap()); assertThat(descriptors, notNullValue()); assertThat(descriptors.size(), equalTo(4)); assertThat(descriptors, not(hasItem(nullValue()))); }