File tree Expand file tree Collapse file tree
services/identity/src/test/java/com/crapi/service/Impl Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6464import org .springframework .mock .web .MockHttpServletRequest ;
6565import org .springframework .security .authentication .AuthenticationManager ;
6666import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
67+ import org .springframework .security .core .Authentication ;
6768import 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" );
You can’t perform that action at this time.
0 commit comments