1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package waffle.jaas;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.ObjectInputStream;
33 import java.io.ObjectOutputStream;
34
35 import org.junit.jupiter.api.Assertions;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38
39
40
41
42
43
44 class GroupPrincipalTest {
45
46
47 private GroupPrincipal groupPrincipal;
48
49
50
51
52 @Test
53 void equals_otherObject() {
54 Assertions.assertNotEquals("", this.groupPrincipal);
55 }
56
57
58
59
60 @Test
61 void equals_sameObject() {
62 Assertions.assertEquals(this.groupPrincipal, this.groupPrincipal);
63 }
64
65
66
67
68 @BeforeEach
69 void setUp() {
70 this.groupPrincipal = new GroupPrincipal("localhost\\Administrator");
71 }
72
73
74
75
76 @Test
77 void testEquals_Symmetric() {
78 final GroupPrincipal x = new GroupPrincipal("localhost\\Administrator");
79 final GroupPrincipal y = new GroupPrincipal("localhost\\Administrator");
80 Assertions.assertEquals(x, y);
81 Assertions.assertEquals(x.hashCode(), y.hashCode());
82 }
83
84
85
86
87
88
89
90
91
92 @Test
93 void testIsSerializable() throws IOException, ClassNotFoundException {
94
95 final ByteArrayOutputStream out = new ByteArrayOutputStream();
96 try (final ObjectOutputStream oos = new ObjectOutputStream(out)) {
97 oos.writeObject(this.groupPrincipal);
98 }
99 assertThat(out.toByteArray()).isNotEmpty();
100
101 final InputStream in = new ByteArrayInputStream(out.toByteArray());
102 final ObjectInputStream ois = new ObjectInputStream(in);
103 final GroupPrincipal copy = (GroupPrincipal) ois.readObject();
104
105 Assertions.assertEquals(this.groupPrincipal, copy);
106 Assertions.assertEquals(this.groupPrincipal.getName(), copy.getName());
107 }
108
109 }