Skip to content

Commit

Permalink
add CompatibleBrowser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Sep 25, 2020
1 parent 0df6395 commit 18dc928
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Parcel;
import android.support.customtabs.CustomTabsIntent;
import android.support.v4.content.ContextCompat;
Expand All @@ -18,7 +19,11 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 21)
Expand All @@ -37,6 +42,34 @@ public void shouldCreateNewBuilder() {
assertThat(builder, is(notNullValue()));
}

@Test
public void shouldHaveCompatibleBrowser() {
PackageManager pm = mock(PackageManager.class);
BrowserPicker browserPicker = mock(BrowserPicker.class);
when(browserPicker.getBestBrowserPackage(any(PackageManager.class))).thenReturn("something");

CustomTabsOptions options = CustomTabsOptions.newBuilder()
.withBrowserPicker(browserPicker).build();


assertThat(options.getPreferredPackage(pm), is("something"));
assertThat(options.hasCompatibleBrowser(pm), is(true));
}

@Test
public void shouldNotHaveCompatibleBrowser() {
PackageManager pm = mock(PackageManager.class);
BrowserPicker browserPicker = mock(BrowserPicker.class);
when(browserPicker.getBestBrowserPackage(any(PackageManager.class))).thenReturn(null);

CustomTabsOptions options = CustomTabsOptions.newBuilder()
.withBrowserPicker(browserPicker).build();


assertThat(options.getPreferredPackage(pm), is(nullValue()));
assertThat(options.hasCompatibleBrowser(pm), is(false));
}

@Test
public void shouldHaveDefaultValues() {
CustomTabsOptions options = CustomTabsOptions.newBuilder().build();
Expand Down

0 comments on commit 18dc928

Please sign in to comment.