|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
27 | 27 | import org.springframework.security.core.userdetails.PasswordEncodedUser;
|
28 | 28 | import org.springframework.security.core.userdetails.User;
|
29 | 29 | import org.springframework.security.core.userdetails.UserDetails;
|
| 30 | +import org.springframework.security.core.userdetails.UsernameNotFoundException; |
30 | 31 |
|
31 | 32 | import static org.assertj.core.api.Assertions.assertThat;
|
| 33 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
32 | 34 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
33 | 35 | import static org.mockito.BDDMockito.given;
|
34 | 36 | import static org.mockito.Mockito.mock;
|
@@ -97,4 +99,24 @@ public void changePasswordWhenCustomSecurityContextHolderStrategyThenUses() {
|
97 | 99 | verify(strategy).getContext();
|
98 | 100 | }
|
99 | 101 |
|
| 102 | + @Test |
| 103 | + public void createUserWhenUserAlreadyExistsThenException() { |
| 104 | + assertThatIllegalArgumentException().isThrownBy(() -> this.manager.createUser(this.user)) |
| 105 | + .withMessage("user should not exist"); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void updateUserWhenUserDoesNotExistThenException() { |
| 110 | + InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); |
| 111 | + assertThatIllegalArgumentException().isThrownBy(() -> manager.updateUser(this.user)) |
| 112 | + .withMessage("user should exist"); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + public void loadUserByUsernameWhenUserNullThenException() { |
| 117 | + InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); |
| 118 | + assertThatExceptionOfType(UsernameNotFoundException.class) |
| 119 | + .isThrownBy(() -> manager.loadUserByUsername(this.user.getUsername())); |
| 120 | + } |
| 121 | + |
100 | 122 | }
|
0 commit comments