@@ -9,6 +9,9 @@ import androidx.test.espresso.intent.matcher.IntentMatchers
99import com.auth0.android.authentication.AuthenticationException
1010import com.auth0.android.callback.RunnableTask
1111import com.auth0.android.provider.AuthenticationActivity
12+ import com.auth0.android.provider.AuthenticationActivity.Companion.EXTRA_AUTHORIZE_URI
13+ import com.auth0.android.provider.AuthenticationActivity.Companion.EXTRA_CT_OPTIONS
14+ import com.auth0.android.provider.AuthenticationActivity.Companion.EXTRA_LAUNCH_AS_TWA
1215import com.auth0.android.provider.CustomTabsOptions
1316import com.nhaarman.mockitokotlin2.any
1417import org.hamcrest.CoreMatchers
@@ -92,7 +95,12 @@ public class AuthenticationActivityTest {
9295 createActivity(intentCaptor.value)
9396 activityController.create().start().resume()
9497 Mockito .verify(customTabsController).bindService()
95- Mockito .verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), any(), failureCallbackCaptor.capture())
98+ Mockito .verify(customTabsController).launchUri(
99+ uriCaptor.capture(),
100+ launchAsTwaCaptor.capture(),
101+ any(),
102+ failureCallbackCaptor.capture()
103+ )
96104 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(Matchers .notNullValue()))
97105 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(uri))
98106 MatcherAssert .assertThat(activity.deliveredIntent, Is .`is `(Matchers .nullValue()))
@@ -123,7 +131,12 @@ public class AuthenticationActivityTest {
123131 createActivity(intentCaptor.value)
124132 activityController.create().start().resume()
125133 Mockito .verify(customTabsController).bindService()
126- Mockito .verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), any(), failureCallbackCaptor.capture())
134+ Mockito .verify(customTabsController).launchUri(
135+ uriCaptor.capture(),
136+ launchAsTwaCaptor.capture(),
137+ any(),
138+ failureCallbackCaptor.capture()
139+ )
127140 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(Matchers .notNullValue()))
128141 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(uri))
129142 MatcherAssert .assertThat(activity.deliveredIntent, Is .`is `(Matchers .nullValue()))
@@ -154,7 +167,12 @@ public class AuthenticationActivityTest {
154167 createActivity(intentCaptor.value)
155168 activityController.create().start().resume()
156169 Mockito .verify(customTabsController).bindService()
157- Mockito .verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), any(), failureCallbackCaptor.capture())
170+ Mockito .verify(customTabsController).launchUri(
171+ uriCaptor.capture(),
172+ launchAsTwaCaptor.capture(),
173+ any(),
174+ failureCallbackCaptor.capture()
175+ )
158176 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(Matchers .notNullValue()))
159177 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(uri))
160178 MatcherAssert .assertThat(launchAsTwaCaptor.value, Is .`is `(Matchers .notNullValue()))
@@ -184,7 +202,12 @@ public class AuthenticationActivityTest {
184202 createActivity(intentCaptor.value)
185203 activityController.create().start().resume()
186204 Mockito .verify(customTabsController).bindService()
187- Mockito .verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), any(), failureCallbackCaptor.capture())
205+ Mockito .verify(customTabsController).launchUri(
206+ uriCaptor.capture(),
207+ launchAsTwaCaptor.capture(),
208+ any(),
209+ failureCallbackCaptor.capture()
210+ )
188211 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(Matchers .notNullValue()))
189212 MatcherAssert .assertThat(uriCaptor.value, Is .`is `(uri))
190213 MatcherAssert .assertThat(launchAsTwaCaptor.value, Is .`is `(Matchers .notNullValue()))
@@ -243,6 +266,47 @@ public class AuthenticationActivityTest {
243266 MatcherAssert .assertThat(controller, Is .`is `(Matchers .notNullValue()))
244267 }
245268
269+
270+ @Test
271+ public fun shouldThrowExceptionIfAuthorizeUriIsNullInIntent () {
272+ AuthenticationActivity .authenticateUsingBrowser(
273+ callerActivity,
274+ uri,
275+ false ,
276+ customTabsOptions
277+ )
278+ Mockito .verify(callerActivity).startActivity(intentCaptor.capture())
279+ createActivity(intentCaptor.value)
280+ activity.intent = Intent ().apply {
281+ putExtra(EXTRA_LAUNCH_AS_TWA , false )
282+ putExtra(EXTRA_CT_OPTIONS , customTabsOptions)
283+ }
284+ activityController.create().start().resume()
285+ MatcherAssert .assertThat(activity.deliveredException, Is .`is `(Matchers .notNullValue()))
286+ MatcherAssert .assertThat(activity.isFinishing, Is .`is `(true ))
287+ activityController.destroy()
288+ }
289+
290+ @Test
291+ public fun shouldThrowExceptionIfCustomTabsIsNullInIntent () {
292+ AuthenticationActivity .authenticateUsingBrowser(
293+ callerActivity,
294+ uri,
295+ false ,
296+ customTabsOptions
297+ )
298+ Mockito .verify(callerActivity).startActivity(intentCaptor.capture())
299+ createActivity(intentCaptor.value)
300+ activity.intent = Intent ().apply {
301+ putExtra(EXTRA_LAUNCH_AS_TWA , false )
302+ putExtra(EXTRA_AUTHORIZE_URI , uri)
303+ }
304+ activityController.create().start().resume()
305+ MatcherAssert .assertThat(activity.deliveredException, Is .`is `(Matchers .notNullValue()))
306+ MatcherAssert .assertThat(activity.isFinishing, Is .`is `(true ))
307+ activityController.destroy()
308+ }
309+
246310 private fun recreateAndCallNewIntent (data : Intent ) {
247311 val outState = Bundle ()
248312 activityController.saveInstanceState(outState)
0 commit comments