28
28
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
29
29
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
30
30
import static org .assertj .core .api .Assertions .assertThatNoException ;
31
+ import static org .springframework .security .access .hierarchicalroles .HierarchicalRolesTestHelper .assertHierarchy ;
31
32
32
33
/**
33
34
* Tests for {@link RoleHierarchyImpl}.
@@ -252,20 +253,12 @@ public void testBuilderWithDefaultRolePrefix() {
252
253
.authority ("C" )
253
254
.implies ("E" , "F" , "B" )
254
255
.build ();
255
- List <GrantedAuthority > flatAuthorities1 = AuthorityUtils .createAuthorityList ("ROLE_A" );
256
- List <GrantedAuthority > allAuthorities1 = AuthorityUtils .createAuthorityList ("ROLE_A" , "ROLE_B" , "ROLE_C" ,
257
- "ROLE_D" );
258
-
259
- assertThat (roleHierarchyImpl ).isNotNull ();
260
- assertThat (roleHierarchyImpl .getReachableGrantedAuthorities (flatAuthorities1 ))
261
- .containsExactlyInAnyOrderElementsOf (allAuthorities1 );
262
256
263
- List <GrantedAuthority > flatAuthorities2 = AuthorityUtils .createAuthorityList ("C" );
264
- List <GrantedAuthority > allAuthorities2 = AuthorityUtils .createAuthorityList ("C" , "ROLE_B" , "ROLE_C" , "ROLE_D" ,
265
- "ROLE_E" , "ROLE_F" );
266
- assertThat (roleHierarchyImpl .getReachableGrantedAuthorities (flatAuthorities2 ))
267
- .containsExactlyInAnyOrderElementsOf (allAuthorities2 );
257
+ assertHierarchy (roleHierarchyImpl ).givesToAuthorities ("ROLE_A" )
258
+ .theseAuthorities ("ROLE_A" , "ROLE_B" , "ROLE_C" , "ROLE_D" );
268
259
260
+ assertHierarchy (roleHierarchyImpl ).givesToAuthorities ("C" )
261
+ .theseAuthorities ("C" , "ROLE_B" , "ROLE_C" , "ROLE_D" , "ROLE_E" , "ROLE_F" );
269
262
}
270
263
271
264
@ Test
@@ -278,19 +271,13 @@ public void testBuilderWithRolePrefix() {
278
271
.authority ("C" )
279
272
.implies ("E" , "F" , "B" )
280
273
.build ();
281
- List <GrantedAuthority > flatAuthorities1 = AuthorityUtils .createAuthorityList ("CUSTOM_PREFIX_A" );
282
- List <GrantedAuthority > allAuthorities1 = AuthorityUtils .createAuthorityList ("CUSTOM_PREFIX_A" ,
283
- "CUSTOM_PREFIX_B" , "CUSTOM_PREFIX_C" , "CUSTOM_PREFIX_D" );
284
274
285
- assertThat (roleHierarchyImpl ).isNotNull ();
286
- assertThat (roleHierarchyImpl .getReachableGrantedAuthorities (flatAuthorities1 ))
287
- .containsExactlyInAnyOrderElementsOf (allAuthorities1 );
288
-
289
- List <GrantedAuthority > flatAuthorities2 = AuthorityUtils .createAuthorityList ("C" );
290
- List <GrantedAuthority > allAuthorities2 = AuthorityUtils .createAuthorityList ("C" , "CUSTOM_PREFIX_B" ,
291
- "CUSTOM_PREFIX_C" , "CUSTOM_PREFIX_D" , "CUSTOM_PREFIX_E" , "CUSTOM_PREFIX_F" );
292
- assertThat (roleHierarchyImpl .getReachableGrantedAuthorities (flatAuthorities2 ))
293
- .containsExactlyInAnyOrderElementsOf (allAuthorities2 );
275
+ assertHierarchy (roleHierarchyImpl ).givesToAuthorities ("CUSTOM_PREFIX_A" )
276
+ .theseAuthorities ("CUSTOM_PREFIX_A" , "CUSTOM_PREFIX_B" , "CUSTOM_PREFIX_C" , "CUSTOM_PREFIX_D" );
277
+
278
+ assertHierarchy (roleHierarchyImpl ).givesToAuthorities ("C" )
279
+ .theseAuthorities ("C" , "CUSTOM_PREFIX_B" , "CUSTOM_PREFIX_C" , "CUSTOM_PREFIX_D" , "CUSTOM_PREFIX_E" ,
280
+ "CUSTOM_PREFIX_F" );
294
281
}
295
282
296
283
@ Test
0 commit comments