### Question:
CookiePriorityComparator implements Comparator<Cookie> { @Override public int compare(final Cookie c1, final Cookie c2) { final int l1 = getPathLength(c1); final int l2 = getPathLength(c2); final int result = l2 - l1; if (result == 0) { final Date d1 = c1.getCreationDate(); final Date d2 = c2.getCreationDate(); if (d1 != null && d2 != null) { return (int) (d1.getTime() - d2.getTime()); } } return result; }  @Override int compare(final Cookie c1, final Cookie c2); static final CookiePriorityComparator INSTANCE; }### Answer:
@Test public void testUnequality() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/a/b/"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/a/"); Assert.assertTrue(comparator.compare(cookie1, cookie2) < 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) > 0); }
@Test public void testEquality() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/a"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/a"); Assert.assertTrue(comparator.compare(cookie1, cookie2) == 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) == 0); }
@Test public void testUnequalityTrailingSlash() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/a/"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/a"); Assert.assertTrue(comparator.compare(cookie1, cookie2) < 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) > 0); }
@Test public void testEqualityNullPath() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath(null); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/"); Assert.assertTrue(comparator.compare(cookie1, cookie2) == 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) == 0); }
@Test public void testEqualitySameLength() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/this"); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/that"); Assert.assertTrue(comparator.compare(cookie1, cookie2) == 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) == 0); }
@Test public void testUnequalityCreationDate() { final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value"); cookie1.setPath("/blah"); cookie1.setCreationDate(new Date(System.currentTimeMillis() - 200000)); final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value"); cookie2.setPath("/blah"); cookie2.setCreationDate(new Date(System.currentTimeMillis())); Assert.assertTrue(comparator.compare(cookie1, cookie2) < 0); Assert.assertTrue(comparator.compare(cookie2, cookie1) > 0); }