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.apache;
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 import waffle.mock.MockWindowsAccount;
40 import waffle.windows.auth.WindowsAccount;
41
42
43
44
45 class WindowsAccountTest {
46
47
48 private final MockWindowsAccount mockWindowsAccount = new MockWindowsAccount("localhost\\Administrator");
49
50
51 private WindowsAccount windowsAccount;
52
53
54
55
56 @BeforeEach
57 void setUp() {
58 this.windowsAccount = new WindowsAccount(this.mockWindowsAccount);
59 }
60
61
62
63
64 @Test
65 void testEquals() {
66 Assertions.assertEquals(this.windowsAccount, new WindowsAccount(this.mockWindowsAccount));
67 final MockWindowsAccount mockWindowsAccount2 = new MockWindowsAccount("localhost\\Administrator2");
68 Assertions.assertNotEquals(this.windowsAccount, new WindowsAccount(mockWindowsAccount2));
69 }
70
71
72
73
74
75
76
77
78
79 @Test
80 void testIsSerializable() throws IOException, ClassNotFoundException {
81
82 final ByteArrayOutputStream out = new ByteArrayOutputStream();
83 try (ObjectOutputStream oos = new ObjectOutputStream(out)) {
84 oos.writeObject(this.windowsAccount);
85 }
86 assertThat(out.toByteArray()).isNotEmpty();
87
88 final InputStream in = new ByteArrayInputStream(out.toByteArray());
89 final ObjectInputStream ois = new ObjectInputStream(in);
90 final WindowsAccount copy = (WindowsAccount) ois.readObject();
91
92 Assertions.assertEquals(this.windowsAccount, copy);
93 Assertions.assertEquals(this.windowsAccount.getDomain(), copy.getDomain());
94 Assertions.assertEquals(this.windowsAccount.getFqn(), copy.getFqn());
95 Assertions.assertEquals(this.windowsAccount.getName(), copy.getName());
96 Assertions.assertEquals(this.windowsAccount.getSidString(), copy.getSidString());
97 }
98
99
100
101
102 @Test
103 void testProperties() {
104 Assertions.assertEquals("localhost", this.windowsAccount.getDomain());
105 Assertions.assertEquals("localhost\\Administrator", this.windowsAccount.getFqn());
106 Assertions.assertEquals("Administrator", this.windowsAccount.getName());
107 Assertions.assertTrue(this.windowsAccount.getSidString().startsWith("S-"));
108 }
109
110 }