Skip to content

Commit 75a4241

Browse files
committed
Fixed the remaining failing errors
1 parent a701dbf commit 75a4241

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

auth0/src/test/java/com/auth0/android/authentication/request/ProfileRequestTest.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
package 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+
315
import com.auth0.android.authentication.AuthenticationException;
416
import com.auth0.android.callback.Callback;
517
import com.auth0.android.request.AuthenticationRequest;
18+
import com.auth0.android.request.HttpMethod;
619
import com.auth0.android.request.ProfileRequest;
720
import com.auth0.android.request.Request;
821
import com.auth0.android.result.Authentication;
922
import com.auth0.android.result.Credentials;
23+
import com.auth0.android.result.CredentialsMock;
1024
import com.auth0.android.result.UserProfile;
1125

1226
import org.junit.Before;
@@ -15,30 +29,23 @@
1529
import org.mockito.ArgumentCaptor;
1630
import org.robolectric.RobolectricTestRunner;
1731

32+
import java.util.Date;
1833
import 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)
3336
public 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);

auth0/src/test/java/com/auth0/android/dpop/DPoPProviderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public class DPoPProviderTest {
339339

340340
@Test
341341
public fun `isNonceRequiredError should return true for 400 response with nonce required error`() {
342-
whenever(mockResponse.body).thenReturn("{\"error\":\"use_dpop_nonce\"}".toResponseBody())
342+
whenever(mockResponse.peekBody(Long.MAX_VALUE)).thenReturn("{\"error\":\"use_dpop_nonce\"}".toResponseBody())
343343
whenever(mockResponse.code).thenReturn(400)
344344

345345
val result = DPoPProvider.isNonceRequiredError(mockResponse)
@@ -358,7 +358,7 @@ public class DPoPProviderTest {
358358

359359
@Test
360360
public fun `isNonceRequiredError should return false for 400 response with different error`() {
361-
whenever(mockResponse.body).thenReturn("{\"error\":\"different_error\"}".toResponseBody())
361+
whenever(mockResponse.peekBody(Long.MAX_VALUE)).thenReturn("{\"error\":\"different_error\"}".toResponseBody())
362362
whenever(mockResponse.code).thenReturn(400)
363363

364364
val result = DPoPProvider.isNonceRequiredError(mockResponse)

auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import androidx.test.espresso.intent.matcher.UriMatchers
99
import com.auth0.android.Auth0
1010
import com.auth0.android.authentication.AuthenticationException
1111
import com.auth0.android.callback.Callback
12+
import com.auth0.android.dpop.DPoPKeyStore
13+
import com.auth0.android.dpop.DPoPProvider
1214
import com.auth0.android.provider.WebAuthProvider.login
1315
import com.auth0.android.provider.WebAuthProvider.logout
1416
import com.auth0.android.provider.WebAuthProvider.resume
@@ -65,6 +67,7 @@ public class WebAuthProviderTest {
6567
private lateinit var voidCallback: Callback<Void?, AuthenticationException>
6668
private lateinit var activity: Activity
6769
private lateinit var account: Auth0
70+
private lateinit var mockKeyStore: DPoPKeyStore
6871

6972
private val authExceptionCaptor: KArgumentCaptor<AuthenticationException> = argumentCaptor()
7073
private val intentCaptor: KArgumentCaptor<Intent> = argumentCaptor()
@@ -83,6 +86,10 @@ public class WebAuthProviderTest {
8386
Auth0.getInstance(JwtTestUtils.EXPECTED_AUDIENCE, JwtTestUtils.EXPECTED_BASE_DOMAIN)
8487
account.networkingClient = SSLTestUtils.testClient
8588

89+
mockKeyStore = mock()
90+
91+
DPoPProvider.keyStore = mockKeyStore
92+
8693
//Next line is needed to avoid CustomTabService from being bound to Test environment
8794
Mockito.doReturn(false).`when`(activity).bindService(
8895
any(),
@@ -95,8 +102,11 @@ public class WebAuthProviderTest {
95102
null,
96103
null
97104
)
105+
106+
`when`(mockKeyStore.hasKeyPair()).thenReturn(false)
98107
}
99108

109+
100110
//** ** ** ** ** ** **//
101111
//** ** ** ** ** ** **//
102112
//** LOG IN FEATURE **//
@@ -107,6 +117,7 @@ public class WebAuthProviderTest {
107117
login(account)
108118
.start(activity, callback)
109119
Assert.assertNotNull(WebAuthProvider.managerInstance)
120+
110121
}
111122

112123
@Test

auth0/src/test/java/com/auth0/android/request/DefaultClientTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public class DefaultClientTest {
8282

8383
@Test
8484
public fun shouldHaveLoggingDisabledByDefault() {
85-
assertThat(DefaultClient().okHttpClient.interceptors, empty())
85+
assertThat(DefaultClient().okHttpClient.interceptors, hasSize(1))
8686
}
8787

8888
@Test
8989
public fun shouldHaveLoggingEnabledIfSpecified() {
9090
val netClient = DefaultClient(enableLogging = true)
91-
assertThat(netClient.okHttpClient.interceptors, hasSize(1))
91+
assertThat(netClient.okHttpClient.interceptors, hasSize(2))
9292

93-
val interceptor: Interceptor = netClient.okHttpClient.interceptors[0]
93+
val interceptor: Interceptor = netClient.okHttpClient.interceptors[1]
9494
assertThat(
9595
(interceptor as HttpLoggingInterceptor).level,
9696
equalTo(HttpLoggingInterceptor.Level.BODY)

0 commit comments

Comments
 (0)