1
2
3
4
5
6
7 package waffle.windows.auth;
8
9 import mockit.Expectations;
10 import mockit.Mocked;
11
12 import org.junit.jupiter.api.Assertions;
13 import org.junit.jupiter.api.BeforeEach;
14 import org.junit.jupiter.api.Test;
15
16
17
18
19 class WindowsAccountValueTest {
20
21
22 @Mocked
23 private IWindowsAccount mockAccount;
24
25
26 private WindowsAccount windowsAccount;
27
28
29
30
31 @BeforeEach
32 void setUp() {
33 Assertions.assertNotNull(new Expectations() {
34 {
35 WindowsAccountValueTest.this.mockAccount.getSidString();
36 this.result = "S-1-5-21-12345";
37 WindowsAccountValueTest.this.mockAccount.getFqn();
38 this.result = "DOMAIN\\testuser";
39 WindowsAccountValueTest.this.mockAccount.getName();
40 this.result = "testuser";
41 WindowsAccountValueTest.this.mockAccount.getDomain();
42 this.result = "DOMAIN";
43 }
44 });
45 this.windowsAccount = new WindowsAccount(this.mockAccount);
46 }
47
48
49
50
51 @Test
52 void testGetSidString() {
53 Assertions.assertEquals("S-1-5-21-12345", this.windowsAccount.getSidString());
54 }
55
56
57
58
59 @Test
60 void testGetFqn() {
61 Assertions.assertEquals("DOMAIN\\testuser", this.windowsAccount.getFqn());
62 }
63
64
65
66
67 @Test
68 void testGetName() {
69 Assertions.assertEquals("testuser", this.windowsAccount.getName());
70 }
71
72
73
74
75 @Test
76 void testGetDomain() {
77 Assertions.assertEquals("DOMAIN", this.windowsAccount.getDomain());
78 }
79
80
81
82
83 @Test
84 void testEqualsSameSid() {
85 Assertions.assertNotNull(new Expectations() {
86 {
87 WindowsAccountValueTest.this.mockAccount.getSidString();
88 this.result = "S-1-5-21-12345";
89 WindowsAccountValueTest.this.mockAccount.getFqn();
90 this.result = "DOMAIN\\other";
91 WindowsAccountValueTest.this.mockAccount.getName();
92 this.result = "other";
93 WindowsAccountValueTest.this.mockAccount.getDomain();
94 this.result = "DOMAIN";
95 }
96 });
97 final WindowsAccount other = new WindowsAccount(this.mockAccount);
98 Assertions.assertEquals(this.windowsAccount, other);
99 Assertions.assertEquals(this.windowsAccount.hashCode(), other.hashCode());
100 }
101
102
103
104
105 @Test
106 void testEqualsSelf() {
107 Assertions.assertEquals(this.windowsAccount, this.windowsAccount);
108 }
109
110
111
112
113 @Test
114 void testNotEqualsNull() {
115 Assertions.assertNotEquals(null, this.windowsAccount);
116 }
117
118
119
120
121 @Test
122 void testNotEqualsDifferentType() {
123 Assertions.assertNotEquals("string", this.windowsAccount);
124 }
125 }