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.impl.auth;
29
30 import org.apache.hc.client5.http.auth.AuthScheme;
31 import org.apache.hc.core5.http.HttpHost;
32 import org.junit.jupiter.api.Assertions;
33 import org.junit.jupiter.api.Test;
34
35
36
37
38 @SuppressWarnings("boxing")
39 class TestBasicAuthCache {
40
41 @Test
42 void testBasicStoreRestore() {
43 final BasicAuthCache cache = new BasicAuthCache();
44 final AuthScheme authScheme = new BasicScheme();
45 cache.put(new HttpHost("localhost", 80), authScheme);
46 Assertions.assertNotNull(cache.get(new HttpHost("localhost", 80)));
47 cache.remove(new HttpHost("localhost", 80));
48 Assertions.assertNull(cache.get(new HttpHost("localhost", 80)));
49 cache.put(new HttpHost("localhost", 80), authScheme);
50 cache.clear();
51 Assertions.assertNull(cache.get(new HttpHost("localhost", 80)));
52 }
53
54 @Test
55 void testNullKey() {
56 final BasicAuthCache cache = new BasicAuthCache();
57 final AuthScheme authScheme = new BasicScheme();
58 Assertions.assertThrows(NullPointerException.class, () ->
59 cache.put(null, authScheme));
60 }
61
62 @Test
63 void testNullAuthScheme() {
64 final BasicAuthCache cache = new BasicAuthCache();
65 cache.put(new HttpHost("localhost", 80), null);
66 Assertions.assertNull(cache.get(new HttpHost("localhost", 80)));
67 }
68
69 }