|
60 | 60 | import org.junit.jupiter.api.Test; |
61 | 61 | import org.mockito.Mock; |
62 | 62 | import org.mockito.junit.jupiter.MockitoSettings; |
63 | | -import org.xmldb.api.security.AclEntry.Builder; |
64 | 63 |
|
65 | 64 | @MockitoSettings |
66 | 65 | class AclEntryTest { |
67 | 66 | @Mock |
68 | 67 | UserPrincipal principal; |
69 | 68 |
|
70 | | - Builder builder; |
| 69 | + AclEntry.Builder builder; |
71 | 70 |
|
72 | 71 | @BeforeEach |
73 | 72 | void prepare() { |
@@ -162,37 +161,36 @@ void testBuildWithFlagsVarargs() { |
162 | 161 | .containsExactlyInAnyOrder(RESOURCE_INHERIT, INHERIT_ONLY).isInstanceOf(EnumSet.class)); |
163 | 162 | } |
164 | 163 |
|
165 | | - @Test |
166 | | - void testBuilderFromExistingEntry() { |
167 | | - UserPrincipal principal2 = mock(UserPrincipal.class); |
168 | | - AclEntry aclEntry = builder.setType(ALLOW).setPrincipal(principal).setPermissions(READ, EXECUTE) |
169 | | - .setFlags(RESOURCE_INHERIT, INHERIT_ONLY).build(); |
170 | | - assertThat(aclEntry).isNotEqualTo(null); |
171 | | - |
172 | | - AclEntry aclEntry1 = AclEntry.newBuilder(aclEntry).setPrincipal(principal2).build(); |
173 | | - assertThat(aclEntry1).isNotEqualTo(aclEntry); |
174 | | - assertThat(aclEntry1).doesNotHaveSameHashCodeAs(aclEntry); |
175 | | - |
176 | | - AclEntry aclEntry2 = AclEntry.newBuilder(aclEntry).setType(DENY).build(); |
177 | | - assertThat(aclEntry2).isNotEqualTo(aclEntry); |
178 | | - assertThat(aclEntry2).doesNotHaveSameHashCodeAs(aclEntry); |
179 | | - |
180 | | - AclEntry aclEntry3 = AclEntry.newBuilder(aclEntry).setPermissions(READ).build(); |
181 | | - assertThat(aclEntry3).isNotEqualTo(aclEntry); |
182 | | - assertThat(aclEntry3).doesNotHaveSameHashCodeAs(aclEntry); |
183 | | - |
184 | | - AclEntry aclEntry4 = AclEntry.newBuilder(aclEntry).setFlags(INHERIT_ONLY).build(); |
185 | | - assertThat(aclEntry4).isNotEqualTo(aclEntry); |
186 | | - assertThat(aclEntry4).doesNotHaveSameHashCodeAs(aclEntry); |
187 | | - |
188 | | - AclEntry aclEntry5 = AclEntry.newBuilder(aclEntry).build(); |
189 | | - assertThat(aclEntry5).isEqualTo(aclEntry).isNotSameAs(aclEntry); |
190 | | - assertThat(aclEntry4).doesNotHaveSameHashCodeAs(aclEntry); |
191 | | - } |
192 | | - |
193 | 164 | @Test |
194 | 165 | void testToString() { |
195 | 166 | AclEntry aclEntry = builder.setType(DENY).setPrincipal(principal).build(); |
196 | 167 | assertThat(aclEntry).hasToString("org.xmldb.api.security.AclEntry(principal)"); |
197 | 168 | } |
| 169 | + |
| 170 | + @Test |
| 171 | + void testBuilderFromExistingEntry() { |
| 172 | + final AclEntry aclEntry = builder.setType(ALLOW).setPrincipal(principal) |
| 173 | + .setPermissions(READ, EXECUTE).setFlags(RESOURCE_INHERIT, INHERIT_ONLY).build(); |
| 174 | + assertThat(aclEntry).isNotNull(); |
| 175 | + |
| 176 | + final UserPrincipal principal2 = mock(UserPrincipal.class); |
| 177 | + assertThat(AclEntry.newBuilder(aclEntry).setPrincipal(principal2).build()) |
| 178 | + .satisfies(tested -> nonEquals(tested, aclEntry)); |
| 179 | + assertThat(AclEntry.newBuilder(aclEntry).setType(DENY).build()) |
| 180 | + .satisfies(tested -> nonEquals(tested, aclEntry)); |
| 181 | + assertThat(AclEntry.newBuilder(aclEntry).setPermissions(READ).build()) |
| 182 | + .satisfies(tested -> nonEquals(tested, aclEntry)); |
| 183 | + assertThat(AclEntry.newBuilder(aclEntry).setFlags(INHERIT_ONLY).build()) |
| 184 | + .satisfies(tested -> nonEquals(tested, aclEntry)); |
| 185 | + |
| 186 | + assertThat(AclEntry.newBuilder(aclEntry).build()).satisfies(tested -> { |
| 187 | + assertThat(tested).isEqualTo(aclEntry); |
| 188 | + assertThat(tested).hasSameHashCodeAs(aclEntry); |
| 189 | + }); |
| 190 | + } |
| 191 | + |
| 192 | + static void nonEquals(AclEntry tested, AclEntry aclEntry) { |
| 193 | + assertThat(tested).isNotEqualTo(aclEntry); |
| 194 | + assertThat(tested).doesNotHaveSameHashCodeAs(aclEntry); |
| 195 | + } |
198 | 196 | } |
0 commit comments