### Question:
CookiePathComparator implements Serializable, Comparator<Cookie> { @Override public int compare(final Cookie c1, final Cookie c2) { final String path1 = normalizePath(c1); final String path2 = normalizePath(c2); if (path1.equals(path2)) { return 0; } else if (path1.startsWith(path2)) { return -1; } else if (path2.startsWith(path1)) { return 1; } else { return 0; } }  @Override int compare(final Cookie c1, final Cookie c2); static final CookiePathComparator INSTANCE; }### Answer:
@Test public void testUnequality1() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/a/b/"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/a/"); final Comparator<Cookie> comparator = new CookiePathComparator(); Assert.assertTrue(comparator.compare(cookie1, cookie2) < 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) > 0); }
@Test public void testUnequality2() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/a/b"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/a"); final Comparator<Cookie> comparator = new CookiePathComparator(); Assert.assertTrue(comparator.compare(cookie1, cookie2) < 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) > 0); }
@Test public void testEquality1() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/a"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/a"); final Comparator<Cookie> comparator = new CookiePathComparator(); Assert.assertTrue(comparator.compare(cookie1, cookie2) == 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) == 0); }
@Test public void testEquality2() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/a/"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/a"); final Comparator<Cookie> comparator = new CookiePathComparator(); Assert.assertTrue(comparator.compare(cookie1, cookie2) == 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) == 0); }
@Test public void testEquality3() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath(null); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/"); final Comparator<Cookie> comparator = new CookiePathComparator(); Assert.assertTrue(comparator.compare(cookie1, cookie2) == 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) == 0); }
@Test public void testEquality4() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/this"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/that"); final Comparator<Cookie> comparator = new CookiePathComparator(); Assert.assertTrue(comparator.compare(cookie1, cookie2) == 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) == 0); }