Servlet { @Override public boolean equals(Object obj) { assertHostState(); if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof Servlet)) { return false; } Servlet other = (Servlet) obj; if (contextRoot == null) { if (other.contextRoot != null) { return false; } } else if (!contextRoot.equals(other.contextRoot)) { return false; } if (host == null) { if (other.host != null) { return false; } } else if (!host.equals(other.host)) { return false; } if (name == null) { if (other.name != null) { return false; } } else if (!name.equals(other.name)) { return false; } if (port != other.port) { return false; } return true; } Servlet(String name, String contextRoot); String getName(); String getContextRoot(); URI getBaseURI(); URI getFullURI(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test(expected = IllegalStateException.class) public void testEqualsObjectForNullHost() { servlet.equals(null); }
@Test public void testEqualsObjectForNonNullHost() { try { assertTrue(servletWithParent.equals(servletWithParent)); } catch (IllegalStateException e) { failOnUnexpectedException(e); } }