1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.client5.http.cookie;
29
30 import java.util.Comparator;
31
32 import org.apache.hc.client5.http.impl.cookie.BasicClientCookie;
33 import org.junit.jupiter.api.Assertions;
34 import org.junit.jupiter.api.Test;
35
36
37
38
39 class TestCookiePathComparator {
40
41 @Test
42 void testUnequality1() {
43 final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
44 cookie1.setPath("/a/b/");
45 final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
46 cookie2.setPath("/a/");
47 final Comparator<Cookie> comparator = new CookiePathComparator();
48 Assertions.assertTrue(comparator.compare(cookie1, cookie2) < 0);
49 Assertions.assertTrue(comparator.compare(cookie2, cookie1) > 0);
50 }
51
52 @Test
53 void testUnequality2() {
54 final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
55 cookie1.setPath("/a/b");
56 final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
57 cookie2.setPath("/a");
58 final Comparator<Cookie> comparator = new CookiePathComparator();
59 Assertions.assertTrue(comparator.compare(cookie1, cookie2) < 0);
60 Assertions.assertTrue(comparator.compare(cookie2, cookie1) > 0);
61 }
62
63 @Test
64 void testEquality1() {
65 final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
66 cookie1.setPath("/a");
67 final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
68 cookie2.setPath("/a");
69 final Comparator<Cookie> comparator = new CookiePathComparator();
70 Assertions.assertEquals(0, comparator.compare(cookie1, cookie2));
71 Assertions.assertEquals(0, comparator.compare(cookie2, cookie1));
72 }
73
74 @Test
75 void testEquality2() {
76 final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
77 cookie1.setPath("/a/");
78 final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
79 cookie2.setPath("/a");
80 final Comparator<Cookie> comparator = new CookiePathComparator();
81 Assertions.assertEquals(0, comparator.compare(cookie1, cookie2));
82 Assertions.assertEquals(0, comparator.compare(cookie2, cookie1));
83 }
84
85 @Test
86 void testEquality3() {
87 final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
88 cookie1.setPath(null);
89 final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
90 cookie2.setPath("/");
91 final Comparator<Cookie> comparator = new CookiePathComparator();
92 Assertions.assertEquals(0, comparator.compare(cookie1, cookie2));
93 Assertions.assertEquals(0, comparator.compare(cookie2, cookie1));
94 }
95
96 @Test
97 void testEquality4() {
98 final BasicClientCookie cookie1 = new BasicClientCookie("name1", "value");
99 cookie1.setPath("/this");
100 final BasicClientCookie cookie2 = new BasicClientCookie("name1", "value");
101 cookie2.setPath("/that");
102 final Comparator<Cookie> comparator = new CookiePathComparator();
103 Assertions.assertEquals(0, comparator.compare(cookie1, cookie2));
104 Assertions.assertEquals(0, comparator.compare(cookie2, cookie1));
105 }
106
107 }
108