### Question:
ResourceDescriptor { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof ResourceDescriptor)) { return false; } final ResourceDescriptor resourceDescriptor = (ResourceDescriptor) o; if (name != null) { if (!name.equals(resourceDescriptor.name)) { return false; } } else if (pattern != null) { if (resourceDescriptor.pattern == null) { return false; } if (!pattern.toString().equals(resourceDescriptor.pattern.toString())) { return false; } } if (type == null) { if (resourceDescriptor.type != null) { return false; } } else { if (!type.equals(resourceDescriptor.type)) { return false; } } return true; } ResourceDescriptor(final Element element); String getType(); String getName(); String getLocation(); String getContent(); boolean doesTypeAndNameMatch(final String type, final String name); Map<String, String> getParameters(); String getParameter(final String key); @Override boolean equals(final Object o); @Override int hashCode(); ResourceLocation getResourceLocationForName(final String name);  }### Answer:
@Test public void testEquality() throws DocumentException { Document velViewDoc = DocumentHelper.parseText("<resource type=\"velocity\" name=\"view\">the content</resource>"); Document velViewDoc2 = DocumentHelper.parseText("<resource type=\"velocity\" name=\"view\" location=\"foo\" />"); Document velViewDoc3 = DocumentHelper.parseText("<resource type=\"velocity\" name=\"view\" location=\"foo\"><param name=\"narrator\">Tyler Durden</param></resource>"); Document velEditDoc = DocumentHelper.parseText("<resource type=\"velocity\" name=\"edit\">the content</resource>"); Document fooEditDoc = DocumentHelper.parseText("<resource type=\"foo\" name=\"edit\">the content</resource>"); ResourceDescriptor velViewResource = new ResourceDescriptor(velViewDoc.getRootElement()); ResourceDescriptor velViewResource2 = new ResourceDescriptor(velViewDoc2.getRootElement()); ResourceDescriptor velViewResource3 = new ResourceDescriptor(velViewDoc3.getRootElement()); ResourceDescriptor velEditResource = new ResourceDescriptor(velEditDoc.getRootElement()); ResourceDescriptor fooEditResource = new ResourceDescriptor(fooEditDoc.getRootElement()); assertEquals(velViewResource, velViewResource); assertEquals(velViewResource, velViewResource2); assertEquals(velViewResource, velViewResource3); assertEquals(velViewResource2, velViewResource); assertEquals(velViewResource3, velViewResource); assertFalse(velViewResource.equals(velEditResource)); assertFalse(velEditResource.equals(velViewResource)); assertFalse(fooEditResource.equals(velEditResource)); }
@Test public void testEquals() { Element desc = DocumentHelper.createElement("foo"); desc.addAttribute("name", "foo"); ResourceDescriptor descriptor = new ResourceDescriptor(desc); assertTrue(descriptor.equals(descriptor)); assertTrue(descriptor.equals(new ResourceDescriptor(desc))); }
@Test public void testEqualsWithNullNameAndType() { Element e = DocumentHelper.createElement("foo"); e.addAttribute("namePattern", "foo"); e.addAttribute("location", "/foo/"); ResourceDescriptor desc = new ResourceDescriptor(e); ResourceDescriptor desc2 = new ResourceDescriptor(e); assertTrue(desc.equals(desc2)); }
@Test public void testEqualsWithNullType() { Element e = DocumentHelper.createElement("foo"); e.addAttribute("name", "foo"); e.addAttribute("location", "/foo/"); ResourceDescriptor desc = new ResourceDescriptor(e); e.addAttribute("type", "foo"); ResourceDescriptor desc2 = new ResourceDescriptor(e); assertFalse(desc.equals(desc2)); desc = new ResourceDescriptor(e); e.addAttribute("type", null); desc2 = new ResourceDescriptor(e); assertFalse(desc.equals(desc2)); }