Skip to content

Commit

Permalink
Fix test compilation to handle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj committed Jul 31, 2023
1 parent 0aebfe5 commit 096982e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import androidx.test.espresso.intent.matcher.IntentMatchers
import com.auth0.android.authentication.AuthenticationException
import com.auth0.android.callback.RunnableTask
import com.auth0.android.provider.AuthenticationActivity
import com.auth0.android.provider.CustomTabsOptions
import org.hamcrest.CoreMatchers
Expand Down Expand Up @@ -86,7 +88,11 @@ public class AuthenticationActivityTest {
createActivity(intentCaptor.value)
activityController.create().start().resume()
Mockito.verify(customTabsController).bindService()
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture())
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), object :
RunnableTask<AuthenticationException> {
override fun apply(error: AuthenticationException) {
}
})
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(Matchers.notNullValue()))
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(uri))
MatcherAssert.assertThat(activity.deliveredIntent, Is.`is`(Matchers.nullValue()))
Expand Down Expand Up @@ -117,7 +123,11 @@ public class AuthenticationActivityTest {
createActivity(intentCaptor.value)
activityController.create().start().resume()
Mockito.verify(customTabsController).bindService()
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture())
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), object :
RunnableTask<AuthenticationException> {
override fun apply(error: AuthenticationException) {
}
})
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(Matchers.notNullValue()))
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(uri))
MatcherAssert.assertThat(activity.deliveredIntent, Is.`is`(Matchers.nullValue()))
Expand Down Expand Up @@ -148,7 +158,11 @@ public class AuthenticationActivityTest {
createActivity(intentCaptor.value)
activityController.create().start().resume()
Mockito.verify(customTabsController).bindService()
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture())
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), object :
RunnableTask<AuthenticationException> {
override fun apply(error: AuthenticationException) {
}
})
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(Matchers.notNullValue()))
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(uri))
MatcherAssert.assertThat(launchAsTwaCaptor.value, Is.`is`(Matchers.notNullValue()))
Expand Down Expand Up @@ -178,7 +192,11 @@ public class AuthenticationActivityTest {
createActivity(intentCaptor.value)
activityController.create().start().resume()
Mockito.verify(customTabsController).bindService()
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture())
Mockito.verify(customTabsController).launchUri(uriCaptor.capture(), launchAsTwaCaptor.capture(), object :
RunnableTask<AuthenticationException> {
override fun apply(error: AuthenticationException) {
}
})
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(Matchers.notNullValue()))
MatcherAssert.assertThat(uriCaptor.value, Is.`is`(uri))
MatcherAssert.assertThat(launchAsTwaCaptor.value, Is.`is`(Matchers.notNullValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void shouldUnbindEvenIfNotBound() throws Exception {
@Test
public void shouldBindAndLaunchUri() throws Exception {
bindService(controller, true);
controller.launchUri(uri, false);
controller.launchUri(uri, false, (ex) -> {});
connectBoundService();

verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
Expand All @@ -146,7 +146,7 @@ public void shouldBindAndLaunchUri() throws Exception {
@Test
public void shouldBindAndLaunchUriAsTwa() throws Exception {
bindService(controller, true);
controller.launchUri(uri, true);
controller.launchUri(uri, true, (ex) -> {});
connectBoundService();
ArgumentCaptor<TrustedWebActivityIntentBuilder> trustedWebActivityIntentBuilderArgumentCaptor
= ArgumentCaptor.forClass(TrustedWebActivityIntentBuilder.class);
Expand Down Expand Up @@ -176,7 +176,7 @@ public void shouldLaunchUriUsingFallbackWhenNoCompatibleBrowserIsAvailable() {
when(browserPicker.getBestBrowserPackage(context.getPackageManager())).thenReturn(null);
CustomTabsOptions ctOptions = CustomTabsOptions.newBuilder().withBrowserPicker(browserPicker).build();
CustomTabsController controller = new CustomTabsController(context, ctOptions, twaLauncher);
controller.launchUri(uri, false);
controller.launchUri(uri, false, (ex) -> {});

verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
Intent intent = launchIntentCaptor.getValue();
Expand All @@ -199,7 +199,7 @@ public void shouldBindAndLaunchUriWithCustomization() throws Exception {
CustomTabsController controller = new CustomTabsController(context, ctOptions, twaLauncher);

bindService(controller, true);
controller.launchUri(uri, false);
controller.launchUri(uri, false, (ex) -> {});
connectBoundService();

verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
Expand Down Expand Up @@ -228,7 +228,7 @@ public void shouldBindAndLaunchUriWithCustomizationTwa() throws Exception {
CustomTabsController controller = new CustomTabsController(context, ctOptions, twaLauncher);

bindService(controller, true);
controller.launchUri(uri, true);
controller.launchUri(uri, true, (ex) -> {});
connectBoundService();


Expand Down Expand Up @@ -257,7 +257,7 @@ public void shouldBindAndLaunchUriWithCustomizationTwa() throws Exception {
@Test
public void shouldFailToBindButLaunchUri() {
bindService(controller, false);
controller.launchUri(uri, false);
controller.launchUri(uri, false, (ex) -> {});

verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
Intent intent = launchIntentCaptor.getValue();
Expand All @@ -271,7 +271,7 @@ public void shouldFailToBindButLaunchUri() {
public void shouldNotLaunchUriIfContextNoLongerValid() {
bindService(controller, true);
controller.clearContext();
controller.launchUri(uri, false);
controller.launchUri(uri, false, (ex) -> {});
verify(context, never()).startActivity(any(Intent.class));
}

Expand All @@ -280,7 +280,7 @@ public void shouldLaunchUriWithFallbackIfCustomTabIntentFails() {
doThrow(ActivityNotFoundException.class)
.doNothing()
.when(context).startActivity(any(Intent.class));
controller.launchUri(uri, false);
controller.launchUri(uri, false, (ex) -> {});

verify(context, timeout(MAX_TEST_WAIT_TIME_MS)).startActivity(launchIntentCaptor.capture());
List<Intent> intents = launchIntentCaptor.getAllValues();
Expand Down

0 comments on commit 096982e

Please sign in to comment.