1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.authc;
20
21 import static org.junit.Assert.assertEquals;
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashSet;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Set;
29
30 import org.apache.shiro.subject.PrincipalCollection;
31 import org.junit.Test;
32
33
34
35
36
37 public class SimpleAuthenticationInfoTest {
38
39 @Test
40 public void testMergeWithEmptyInstances() {
41 SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
42 SimpleAuthenticationInfo local = new SimpleAuthenticationInfo();
43 aggregate.merge(local);
44 }
45
46
47
48
49 @Test
50 public void testMergeWithAggregateNullCredentials() {
51 SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
52 SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
53 aggregate.merge(local);
54 }
55
56 @SuppressWarnings("serial")
57 @Test
58 public void testMergeWithImmutablePrincipalCollection() {
59 SimpleAuthenticationInfo aggregate = new SimpleAuthenticationInfo();
60
61 PrincipalCollection principalCollection = new PrincipalCollection() {
62 @SuppressWarnings("unchecked")
63 public List asList() { return null;}
64 @SuppressWarnings("unchecked")
65 public Set asSet() {return null;}
66 public <T> Collection<T> byType(Class<T> type) {return null;}
67 @SuppressWarnings("unchecked")
68 public Collection fromRealm(String realmName) {
69 Collection<Object> principals = new HashSet<Object>();
70 principals.add("testprincipal");
71 return principals;
72 }
73 public Object getPrimaryPrincipal() {return null;}
74 public Set<String> getRealmNames() {
75 Set<String> realms = new HashSet<String>();
76 realms.add("testrealm");
77 return realms;
78 }
79 public boolean isEmpty() {return false;}
80 public <T> T oneByType(Class<T> type) {return null;}
81 @SuppressWarnings("unchecked")
82 public Iterator iterator() {return null;}
83
84 };
85 aggregate.setPrincipals(principalCollection);
86 SimpleAuthenticationInfo local = new SimpleAuthenticationInfo("username", "password", "testRealm");
87 aggregate.merge(local);
88 assertEquals(2, aggregate.getPrincipals().asList().size());
89 }
90
91 }