11package com .auth0 .android .authentication .request ;
22
3+ import static org .hamcrest .MatcherAssert .assertThat ;
4+ import static org .hamcrest .Matchers .instanceOf ;
5+ import static org .hamcrest .Matchers .is ;
6+ import static org .hamcrest .Matchers .notNullValue ;
7+ import static org .junit .Assert .assertFalse ;
8+ import static org .junit .Assert .assertTrue ;
9+ import static org .mockito .ArgumentMatchers .anyString ;
10+ import static org .mockito .Matchers .eq ;
11+ import static org .mockito .Mockito .mock ;
12+ import static org .mockito .Mockito .verify ;
13+ import static org .mockito .Mockito .when ;
14+
315import com .auth0 .android .authentication .AuthenticationException ;
416import com .auth0 .android .callback .Callback ;
517import com .auth0 .android .request .AuthenticationRequest ;
18+ import com .auth0 .android .request .HttpMethod ;
619import com .auth0 .android .request .ProfileRequest ;
720import com .auth0 .android .request .Request ;
821import com .auth0 .android .result .Authentication ;
922import com .auth0 .android .result .Credentials ;
23+ import com .auth0 .android .result .CredentialsMock ;
1024import com .auth0 .android .result .UserProfile ;
1125
1226import org .junit .Before ;
1529import org .mockito .ArgumentCaptor ;
1630import org .robolectric .RobolectricTestRunner ;
1731
32+ import java .util .Date ;
1833import java .util .Map ;
1934
20- import static org .hamcrest .MatcherAssert .assertThat ;
21- import static org .hamcrest .Matchers .instanceOf ;
22- import static org .hamcrest .Matchers .is ;
23- import static org .hamcrest .Matchers .notNullValue ;
24- import static org .junit .Assert .assertFalse ;
25- import static org .junit .Assert .assertTrue ;
26- import static org .mockito .ArgumentMatchers .anyString ;
27- import static org .mockito .Matchers .eq ;
28- import static org .mockito .Mockito .mock ;
29- import static org .mockito .Mockito .verify ;
30- import static org .mockito .Mockito .when ;
31-
3235@ RunWith (RobolectricTestRunner .class )
3336public class ProfileRequestTest {
3437
3538 private AuthenticationRequest authenticationMockRequest ;
3639 private Request userInfoMockRequest ;
3740 private ProfileRequest profileRequest ;
3841
42+ private Credentials dummyCredentials = CredentialsMock .Companion .create ("idToken" , "accessToken" , "Bearer" , null , new Date (), null );
43+
3944 @ Before
4045 public void setUp () {
4146 userInfoMockRequest = mock (Request .class );
47+ when (userInfoMockRequest .getHttpMethod ()).thenReturn (HttpMethod .GET .INSTANCE );
48+ when (userInfoMockRequest .getUrl ()).thenReturn ("www.api.com/example" );
4249 authenticationMockRequest = mock (AuthenticationRequest .class );
4350 profileRequest = new ProfileRequest (authenticationMockRequest , userInfoMockRequest );
4451 }
@@ -87,7 +94,7 @@ public void shouldSetConnection() {
8794 @ Test
8895 public void shouldReturnAuthenticationAfterStartingTheRequest () {
8996 final UserProfile userProfile = mock (UserProfile .class );
90- final Credentials credentials = mock ( Credentials . class ) ;
97+ final Credentials credentials = dummyCredentials ;
9198
9299 final AuthenticationRequestMock authenticationRequestMock = new AuthenticationRequestMock (credentials , null );
93100 final RequestMock tokenInfoRequestMock = new RequestMock (userProfile , null );
@@ -130,7 +137,7 @@ public void shouldReturnErrorAfterStartingTheRequestIfAuthenticationRequestFails
130137
131138 @ Test
132139 public void shouldReturnErrorAfterStartingTheRequestIfTokenInfoRequestFails () {
133- final Credentials credentials = mock ( Credentials . class ) ;
140+ final Credentials credentials = dummyCredentials ;
134141 final AuthenticationException error = mock (AuthenticationException .class );
135142
136143 final AuthenticationRequestMock authenticationRequestMock = new AuthenticationRequestMock (credentials , null );
@@ -148,7 +155,7 @@ public void shouldReturnErrorAfterStartingTheRequestIfTokenInfoRequestFails() {
148155
149156 @ Test
150157 public void shouldExecuteTheRequest () {
151- final Credentials credentials = mock ( Credentials . class ) ;
158+ final Credentials credentials = dummyCredentials ;
152159 when (authenticationMockRequest .execute ()).thenAnswer (invocation -> credentials );
153160 final UserProfile userProfile = mock (UserProfile .class );
154161 when (userInfoMockRequest .addParameter (anyString (), anyString ())).thenReturn (userInfoMockRequest );
0 commit comments