1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27
28 package org.apache.hc.client5.http.cookie;
29
30 import org.junit.jupiter.api.Assertions;
31 import org.junit.jupiter.api.Test;
32
33 /**
34 * Test cases for {@link CookieOrigin}.
35 */
36 class TestCookieOrigin {
37
38 @Test
39 void testConstructor() {
40 final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "/", false);
41 Assertions.assertEquals("www.apache.org", origin.getHost());
42 Assertions.assertEquals(80, origin.getPort());
43 Assertions.assertEquals("/", origin.getPath());
44 Assertions.assertFalse(origin.isSecure());
45 }
46
47 @Test
48 void testNullHost() {
49 Assertions.assertThrows(NullPointerException.class, () ->
50 new CookieOrigin(null, 80, "/", false));
51 }
52
53 @Test
54 void testEmptyHost() {
55 Assertions.assertThrows(IllegalArgumentException.class, () ->
56 new CookieOrigin(" ", 80, "/", false));
57 }
58
59 @Test
60 void testNegativePort() {
61 Assertions.assertThrows(IllegalArgumentException.class, () ->
62 new CookieOrigin("www.apache.org", -80, "/", false));
63 }
64
65 @Test
66 void testNullPath() {
67 Assertions.assertThrows(NullPointerException.class, () ->
68 new CookieOrigin("www.apache.org", 80, null, false));
69 }
70
71 @Test
72 void testEmptyPath() {
73 final CookieOrigin origin = new CookieOrigin("www.apache.org", 80, "", false);
74 Assertions.assertEquals("www.apache.org", origin.getHost());
75 Assertions.assertEquals(80, origin.getPort());
76 Assertions.assertEquals("/", origin.getPath());
77 Assertions.assertFalse(origin.isSecure());
78 }
79
80 }
81