|
18 | 18 |
|
19 | 19 | import java.io.ByteArrayOutputStream;
|
20 | 20 | import java.io.ObjectOutputStream;
|
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.Collection; |
21 | 23 | import java.util.HashSet;
|
22 | 24 | import java.util.List;
|
23 | 25 | import java.util.Set;
|
|
37 | 39 | * Tests {@link User}.
|
38 | 40 | *
|
39 | 41 | * @author Ben Alex
|
| 42 | + * @author Ilya Starchenko |
40 | 43 | */
|
41 | 44 | public class UserTests {
|
42 | 45 |
|
@@ -68,6 +71,33 @@ public void testNoArgConstructorDoesntExist() {
|
68 | 71 | .isThrownBy(() -> User.class.getDeclaredConstructor((Class[]) null));
|
69 | 72 | }
|
70 | 73 |
|
| 74 | + @Test |
| 75 | + public void testBuildUserWithNoAuthorities() { |
| 76 | + UserDetails user = User.builder().username("user").password("password").build(); |
| 77 | + assertThat(user.getAuthorities()).isEmpty(); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testNullWithinUserAuthoritiesIsRejected() { |
| 82 | + assertThatIllegalArgumentException().isThrownBy(() -> User.builder().username("user").password("password") |
| 83 | + .authorities((Collection<? extends GrantedAuthority>) null).build()); |
| 84 | + List<GrantedAuthority> authorities = new ArrayList<>(); |
| 85 | + authorities.add(null); |
| 86 | + authorities.add(null); |
| 87 | + assertThatIllegalArgumentException().isThrownBy( |
| 88 | + () -> User.builder().username("user").password("password").authorities(authorities).build()); |
| 89 | + |
| 90 | + assertThatIllegalArgumentException().isThrownBy(() -> User.builder().username("user").password("password") |
| 91 | + .authorities((GrantedAuthority[]) null).build()); |
| 92 | + assertThatIllegalArgumentException().isThrownBy(() -> User.builder().username("user").password("password") |
| 93 | + .authorities(new GrantedAuthority[] { null, null }).build()); |
| 94 | + |
| 95 | + assertThatIllegalArgumentException().isThrownBy( |
| 96 | + () -> User.builder().username("user").password("password").authorities((String[]) null).build()); |
| 97 | + assertThatIllegalArgumentException().isThrownBy(() -> User.builder().username("user").password("password") |
| 98 | + .authorities(new String[] { null, null }).build()); |
| 99 | + } |
| 100 | + |
71 | 101 | @Test
|
72 | 102 | public void testNullValuesRejected() {
|
73 | 103 | assertThatIllegalArgumentException().isThrownBy(() -> new User(null, "koala", true, true, true, true, ROLE_12));
|
|
0 commit comments