1
2
3
4
5
6
7 package waffle.apache;
8
9 import static org.assertj.core.api.Assertions.assertThat;
10
11 import java.io.ByteArrayInputStream;
12 import java.io.ByteArrayOutputStream;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.io.ObjectInputStream;
16 import java.io.ObjectOutputStream;
17
18 import org.junit.jupiter.api.Assertions;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21
22 import waffle.mock.MockWindowsAccount;
23 import waffle.windows.auth.WindowsAccount;
24
25
26
27
28 class WindowsAccountTest {
29
30
31 private final MockWindowsAccount mockWindowsAccount = new MockWindowsAccount("localhost\\Administrator");
32
33
34 private WindowsAccount windowsAccount;
35
36
37
38
39 @BeforeEach
40 void setUp() {
41 this.windowsAccount = new WindowsAccount(this.mockWindowsAccount);
42 }
43
44
45
46
47 @Test
48 void testEquals() {
49 Assertions.assertEquals(this.windowsAccount, new WindowsAccount(this.mockWindowsAccount));
50 final MockWindowsAccount mockWindowsAccount2 = new MockWindowsAccount("localhost\\Administrator2");
51 Assertions.assertNotEquals(this.windowsAccount, new WindowsAccount(mockWindowsAccount2));
52 }
53
54
55
56
57
58
59
60
61
62 @Test
63 void testIsSerializable() throws IOException, ClassNotFoundException {
64
65 final ByteArrayOutputStream out = new ByteArrayOutputStream();
66 try (ObjectOutputStream oos = new ObjectOutputStream(out)) {
67 oos.writeObject(this.windowsAccount);
68 }
69 assertThat(out.toByteArray()).isNotEmpty();
70
71 final InputStream in = new ByteArrayInputStream(out.toByteArray());
72 final ObjectInputStream ois = new ObjectInputStream(in);
73 final WindowsAccount copy = (WindowsAccount) ois.readObject();
74
75 Assertions.assertEquals(this.windowsAccount, copy);
76 Assertions.assertEquals(this.windowsAccount.getDomain(), copy.getDomain());
77 Assertions.assertEquals(this.windowsAccount.getFqn(), copy.getFqn());
78 Assertions.assertEquals(this.windowsAccount.getName(), copy.getName());
79 Assertions.assertEquals(this.windowsAccount.getSidString(), copy.getSidString());
80 }
81
82
83
84
85 @Test
86 void testProperties() {
87 Assertions.assertEquals("localhost", this.windowsAccount.getDomain());
88 Assertions.assertEquals("localhost\\Administrator", this.windowsAccount.getFqn());
89 Assertions.assertEquals("Administrator", this.windowsAccount.getName());
90 Assertions.assertTrue(this.windowsAccount.getSidString().startsWith("S-"));
91 }
92
93 }