use of org.mockito.ArgumentMatcher in project mobile-center-sdk-android by Microsoft.
the class CrashesTest method trackExceptionForWrapperSdk.
@Test
public void trackExceptionForWrapperSdk() {
StackFrame frame = new StackFrame();
frame.setClassName("1");
frame.setFileName("2");
frame.setLineNumber(3);
frame.setMethodName("4");
final com.microsoft.azure.mobile.crashes.ingestion.models.Exception exception = new com.microsoft.azure.mobile.crashes.ingestion.models.Exception();
exception.setType("5");
exception.setMessage("6");
exception.setFrames(singletonList(frame));
Crashes crashes = Crashes.getInstance();
Channel mockChannel = mock(Channel.class);
Crashes.getInstance().trackException(exception);
verify(mockChannel, never()).enqueue(any(Log.class), eq(crashes.getGroupName()));
crashes.onStarted(mock(Context.class), "", mockChannel);
Crashes.getInstance().trackException(exception);
verify(mockChannel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
return item instanceof ManagedErrorLog && exception.equals(((ManagedErrorLog) item).getException());
}
}), eq(crashes.getGroupName()));
}
use of org.mockito.ArgumentMatcher in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method shutdownInterrupted.
@Test
public void shutdownInterrupted() throws Exception {
Persistence mockPersistence = mock(Persistence.class);
IngestionHttp mockIngestion = mock(IngestionHttp.class);
Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
DatabasePersistenceAsync mockPersistenceAsync = spy(new DatabasePersistenceAsync(mockPersistence));
whenNew(DatabasePersistenceAsync.class).withArguments(mockPersistence).thenReturn(mockPersistenceAsync);
when(mockPersistence.getLogs(any(String.class), anyInt(), Matchers.<List<Log>>any())).then(getGetLogsAnswer(1));
doThrow(new InterruptedException()).when(mockPersistenceAsync).waitForCurrentTasksToComplete(anyLong());
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUIDUtils.randomUUID().toString(), mockPersistence, mockIngestion);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, mockListener);
/* Enqueuing 1 event. */
channel.enqueue(mock(Log.class), TEST_GROUP);
verify(mockListener).onBeforeSending(notNull(Log.class));
channel.shutdown();
verify(mockListener, never()).onFailure(any(Log.class), any(Exception.class));
verify(mockPersistence).clearPendingLogState();
verify(mockPersistenceAsync).waitForCurrentTasksToComplete(DefaultChannel.SHUTDOWN_TIMEOUT);
verifyStatic();
MobileCenterLog.warn(eq(MobileCenterLog.LOG_TAG), anyString(), argThat(new ArgumentMatcher<Throwable>() {
@Override
public boolean matches(Object argument) {
return argument instanceof InterruptedException;
}
}));
}
use of org.mockito.ArgumentMatcher in project mobile-center-sdk-android by Microsoft.
the class BrowserUtilsTest method twoBrowsersAndNoDefault.
@Test
public void twoBrowsersAndNoDefault() throws Exception {
/* Mock no browser. */
Activity activity = mock(Activity.class);
doThrow(new ActivityNotFoundException()).when(activity).startActivity(argThat(CHROME_MATCHER));
PackageManager packageManager = mock(PackageManager.class);
when(activity.getPackageManager()).thenReturn(packageManager);
{
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = "system";
activityInfo.name = "picker";
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = activityInfo;
when(packageManager.resolveActivity(any(Intent.class), eq(PackageManager.MATCH_DEFAULT_ONLY))).thenReturn(resolveInfo);
}
{
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = "system";
activityInfo.name = "browser";
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = activityInfo;
ActivityInfo activityInfo2 = new ActivityInfo();
activityInfo2.packageName = "mozilla";
activityInfo2.name = "firefox";
ResolveInfo resolveInfo2 = new ResolveInfo();
resolveInfo2.activityInfo = activityInfo;
when(packageManager.queryIntentActivities(any(Intent.class), anyInt())).thenReturn(asList(resolveInfo, resolveInfo2));
}
/* Open Chrome then abort. */
BrowserUtils.openBrowser(TEST_URL, activity);
InOrder order = inOrder(activity);
order.verify(activity).startActivity(argThat(CHROME_MATCHER));
order.verify(activity).startActivity(argThat(new ArgumentMatcher<Intent>() {
@Override
public boolean matches(Object o) {
Intent intent = (Intent) o;
return Intent.ACTION_VIEW.equals(intent.getAction()) && Uri.parse(TEST_URL).equals(intent.getData()) && intent.getComponent().getClassName().equals("browser");
}
}));
order.verifyNoMoreInteractions();
}
use of org.mockito.ArgumentMatcher in project mobile-center-sdk-android by Microsoft.
the class BrowserUtilsTest method secondBrowserIsDefault.
@Test
public void secondBrowserIsDefault() throws Exception {
/* Mock no browser. */
Activity activity = mock(Activity.class);
doThrow(new ActivityNotFoundException()).when(activity).startActivity(argThat(CHROME_MATCHER));
PackageManager packageManager = mock(PackageManager.class);
when(activity.getPackageManager()).thenReturn(packageManager);
{
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = "mozilla";
activityInfo.name = "firefox";
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = activityInfo;
when(packageManager.resolveActivity(any(Intent.class), eq(PackageManager.MATCH_DEFAULT_ONLY))).thenReturn(resolveInfo);
}
{
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = "system";
activityInfo.name = "browser";
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = activityInfo;
ActivityInfo activityInfo2 = new ActivityInfo();
activityInfo2.packageName = "mozilla";
activityInfo2.name = "firefox";
ResolveInfo resolveInfo2 = new ResolveInfo();
resolveInfo2.activityInfo = activityInfo2;
when(packageManager.queryIntentActivities(any(Intent.class), anyInt())).thenReturn(asList(resolveInfo, resolveInfo2));
}
/* Open Chrome then abort. */
BrowserUtils.openBrowser(TEST_URL, activity);
InOrder order = inOrder(activity);
order.verify(activity).startActivity(argThat(CHROME_MATCHER));
order.verify(activity).startActivity(argThat(new ArgumentMatcher<Intent>() {
@Override
public boolean matches(Object o) {
Intent intent = (Intent) o;
return Intent.ACTION_VIEW.equals(intent.getAction()) && Uri.parse(TEST_URL).equals(intent.getData()) && intent.getComponent().getClassName().equals("firefox");
}
}));
order.verifyNoMoreInteractions();
}
use of org.mockito.ArgumentMatcher in project mobile-center-sdk-android by Microsoft.
the class BrowserUtilsTest method onlySystemBrowserNoDefaultAsPicker.
@Test
public void onlySystemBrowserNoDefaultAsPicker() throws Exception {
/* Mock no browser. */
Activity activity = mock(Activity.class);
doThrow(new ActivityNotFoundException()).when(activity).startActivity(argThat(CHROME_MATCHER));
PackageManager packageManager = mock(PackageManager.class);
when(activity.getPackageManager()).thenReturn(packageManager);
{
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = "system";
activityInfo.name = "picker";
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = activityInfo;
when(packageManager.resolveActivity(any(Intent.class), eq(PackageManager.MATCH_DEFAULT_ONLY))).thenReturn(resolveInfo);
}
{
ActivityInfo activityInfo = new ActivityInfo();
activityInfo.packageName = "system";
activityInfo.name = "browser";
ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.activityInfo = activityInfo;
when(packageManager.queryIntentActivities(any(Intent.class), anyInt())).thenReturn(Collections.singletonList(resolveInfo));
}
/* Open Chrome then abort. */
BrowserUtils.openBrowser(TEST_URL, activity);
InOrder order = inOrder(activity);
order.verify(activity).startActivity(argThat(CHROME_MATCHER));
order.verify(activity).startActivity(argThat(new ArgumentMatcher<Intent>() {
@Override
public boolean matches(Object o) {
Intent intent = (Intent) o;
return Intent.ACTION_VIEW.equals(intent.getAction()) && Uri.parse(TEST_URL).equals(intent.getData()) && intent.getComponent().getClassName().equals("browser");
}
}));
order.verifyNoMoreInteractions();
}
Aggregations