### Question:
Resources implements Resourced { public static Resources fromXml(final Element element) throws PluginParseException, IllegalArgumentException { if (element == null) { throw new IllegalArgumentException("Cannot parse resources from null XML element"); } @SuppressWarnings("unchecked") final List<Element> elements = element.elements("resource"); final List<ResourceDescriptor> templates = new ArrayList<ResourceDescriptor>(elements.size()); for (final Element e : elements) { final ResourceDescriptor resourceDescriptor = new ResourceDescriptor(e); if (templates.contains(resourceDescriptor)) { throw new PluginParseException("Duplicate resource with type '" + resourceDescriptor.getType() + "' and name '" + resourceDescriptor.getName() + "' found"); } templates.add(resourceDescriptor); } return new Resources(templates); } Resources(final Iterable<ResourceDescriptor> resourceDescriptors); static Resources fromXml(final Element element); List<ResourceDescriptor> getResourceDescriptors(); @Deprecated List<ResourceDescriptor> getResourceDescriptors(final String type); ResourceLocation getResourceLocation(final String type, final String name); ResourceDescriptor getResourceDescriptor(final String type, final String name); static final Resources EMPTY_RESOURCES; }### Answer:
@Test public void testMultipleResourceWithClashingKeysFail() throws DocumentException { final Document document = DocumentHelper.parseText("<foo>" + "<resource type=\"velocity\" name=\"view\">the content</resource>" + "<resource type=\"velocity\" name=\"view\" />" + "</foo>"); try { Resources.fromXml(document.getRootElement()); fail("Should have thrown exception about duplicate resources."); } catch (final PluginParseException e) { assertEquals("Duplicate resource with type 'velocity' and name 'view' found", e.getMessage()); } }
@Test(expected = IllegalArgumentException.class) public void testParsingNullElementThrowsException() throws Exception { Resources.fromXml(null); }