Cookie { @SuppressWarnings({ "StringEquality", "RedundantIfStatement" }) @Override public boolean equals(final Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Cookie other = (Cookie) obj; if (this.name != other.name && (this.name == null || !this.name.equals(other.name))) { return false; } if (this.value != other.value && (this.value == null || !this.value.equals(other.value))) { return false; } if (this.version != other.version) { return false; } if (this.path != other.path && (this.path == null || !this.path.equals(other.path))) { return false; } if (this.domain != other.domain && (this.domain == null || !this.domain.equals(other.domain))) { return false; } return true; } Cookie(final String name, final String value, final String path, final String domain, final int version);  Cookie(final String name, final String value, final String path, final String domain);  Cookie(final String name, final String value); @Deprecated static Cookie valueOf(final String value); String getName(); String getValue(); int getVersion(); String getDomain(); String getPath(); @Override @Deprecated String toString(); @Override int hashCode(); @SuppressWarnings({ "StringEquality", "RedundantIfStatement" }) @Override boolean equals(final Object obj); static final int DEFAULT_VERSION; }
@Test public void testEquals() { Object nullObj = null; Cookie cookie = new Cookie("name", "value"); Cookie cookie1 = new Cookie("name", "value"); Cookie cookie2 = new Cookie("name", "value2"); NewCookie newCookie = new NewCookie("name", "value"); NewCookie newCookie1 = new NewCookie("name", "value"); NewCookie newCookie2 = new NewCookie("name", "value2"); assertFalse(cookie.equals(nullObj)); assertFalse(cookie.equals(newCookie)); assertFalse(cookie.equals(cookie2)); assertTrue(cookie.equals(cookie1)); assertTrue(cookie.equals(newCookie.toCookie())); assertTrue(newCookie.equals(newCookie1)); assertFalse(newCookie.equals(newCookie2)); }