Skip to content

Commit 0ba5b2b

Browse files
committed
Updated test
1 parent 54f9a8a commit 0ba5b2b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

services/identity/src/test/java/com/crapi/service/Impl/UserServiceImplTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.springframework.mock.web.MockHttpServletRequest;
6565
import org.springframework.security.authentication.AuthenticationManager;
6666
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
67+
import org.springframework.security.core.Authentication;
6768
import org.springframework.security.crypto.password.PasswordEncoder;
6869

6970
@RunWith(MockitoJUnitRunner.class)
@@ -152,6 +153,9 @@ public void testAuthenticateUserApiKey() throws UnsupportedEncodingException {
152153
LoginForm loginForm = getDummyLoginForm();
153154
User user = getDummyUser();
154155
user.setApiKey("sampleApiKey");
156+
Authentication mockAuth = Mockito.mock(Authentication.class);
157+
Mockito.when(authenticationManager.authenticate(Mockito.any(Authentication.class)))
158+
.thenReturn(mockAuth);
155159
Mockito.when(userRepository.findByEmail(Mockito.anyString())).thenReturn(user);
156160
ApiKeyResponse jwtResponse = userService.generateApiKey(getMockHttpRequest(), loginForm);
157161
Assertions.assertEquals(jwtResponse.getApiKey(), "sampleApiKey");

0 commit comments

Comments
 (0)