1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.repository;
20
21 import org.eclipse.aether.RepositorySystemSession;
22 import org.eclipse.aether.internal.test.util.TestUtils;
23 import org.eclipse.aether.repository.Authentication;
24 import org.eclipse.aether.repository.AuthenticationContext;
25 import org.eclipse.aether.repository.AuthenticationDigest;
26 import org.eclipse.aether.repository.RemoteRepository;
27 import org.junit.jupiter.api.Test;
28
29 import static org.junit.jupiter.api.Assertions.*;
30
31 public class StringAuthenticationTest {
32
33 private RepositorySystemSession newSession() {
34 return TestUtils.newSession();
35 }
36
37 private RemoteRepository newRepo(Authentication auth) {
38 return new RemoteRepository.Builder("test", "default", "http://localhost")
39 .setAuthentication(auth)
40 .build();
41 }
42
43 private AuthenticationContext newContext(Authentication auth) {
44 return AuthenticationContext.forRepository(newSession(), newRepo(auth));
45 }
46
47 private String newDigest(Authentication auth) {
48 return AuthenticationDigest.forRepository(newSession(), newRepo(auth));
49 }
50
51 @Test
52 void testFill() {
53 Authentication auth = new StringAuthentication("key", "value");
54 try (AuthenticationContext context = newContext(auth)) {
55 assertNull(context.get("another-key"));
56 assertEquals("value", context.get("key"));
57 }
58 }
59
60 @Test
61 void testDigest() {
62 Authentication auth1 = new StringAuthentication("key", "value");
63 Authentication auth2 = new StringAuthentication("key", "value");
64 String digest1 = newDigest(auth1);
65 String digest2 = newDigest(auth2);
66 assertEquals(digest1, digest2);
67
68 Authentication auth3 = new StringAuthentication("key", "Value");
69 String digest3 = newDigest(auth3);
70 assertNotEquals(digest3, digest1);
71
72 Authentication auth4 = new StringAuthentication("Key", "value");
73 String digest4 = newDigest(auth4);
74 assertNotEquals(digest4, digest1);
75 }
76
77 @Test
78 void testEquals() {
79 Authentication auth1 = new StringAuthentication("key", "value");
80 Authentication auth2 = new StringAuthentication("key", "value");
81 Authentication auth3 = new StringAuthentication("key", "Value");
82 assertEquals(auth1, auth2);
83 assertNotEquals(auth1, auth3);
84 assertNotEquals(null, auth1);
85 }
86
87 @Test
88 void testHashCode() {
89 Authentication auth1 = new StringAuthentication("key", "value");
90 Authentication auth2 = new StringAuthentication("key", "value");
91 assertEquals(auth1.hashCode(), auth2.hashCode());
92 }
93 }