Search in sources :

Example 96 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.

the class DistributeWarnUnknownSourcesTest method clickSettingsOnAndroidO.

@Test
@PrepareForTest(Build.class)
@SuppressLint("InlinedApi")
public void clickSettingsOnAndroidO() throws Exception {
    /* Click settings. */
    Intent intentSecuritySettings = mock(Intent.class);
    whenNew(Intent.class).withArguments(Settings.ACTION_SECURITY_SETTINGS).thenReturn(intentSecuritySettings);
    Intent intentManageUnknownAppSources = mock(Intent.class);
    whenNew(Intent.class).withArguments(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES).thenReturn(intentManageUnknownAppSources);
    ArgumentCaptor<DialogInterface.OnClickListener> clickListener = ArgumentCaptor.forClass(DialogInterface.OnClickListener.class);
    verify(mDialogBuilder).setPositiveButton(eq(R.string.appcenter_distribute_unknown_sources_dialog_settings), clickListener.capture());
    /* Verify behaviour on old version. */
    TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", BuildConfig.MIN_SDK_VERSION);
    clickListener.getValue().onClick(mUnknownSourcesDialog, DialogInterface.BUTTON_POSITIVE);
    verify(mFirstActivity).startActivity(intentSecuritySettings);
    verify(mFirstActivity, never()).startActivity(intentManageUnknownAppSources);
    reset(mFirstActivity);
    /* Verify behaviour on Android O. */
    TestUtils.setInternalState(Build.VERSION.class, "SDK_INT", Build.VERSION_CODES.O);
    clickListener.getValue().onClick(mUnknownSourcesDialog, DialogInterface.BUTTON_POSITIVE);
    verify(mFirstActivity, never()).startActivity(intentSecuritySettings);
    verify(mFirstActivity).startActivity(intentManageUnknownAppSources);
}
Also used : DialogInterface(android.content.DialogInterface) Build(android.os.Build) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) SuppressLint(android.annotation.SuppressLint)

Example 97 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.

the class CrashesTest method minidumpDeviceUserIdNotNull.

@Test
@PrepareForTest({ SessionContext.class, DeviceInfoHelper.class })
public void minidumpDeviceUserIdNotNull() throws Exception {
    long appStartTime = 95000L;
    long crashTime = 126000L;
    ManagedErrorLog crashLog = testNativeCrashLog(appStartTime, crashTime, true, false, true);
    assertNotNull(crashLog.getUserId());
}
Also used : ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 98 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.

the class CrashesTest method minidumpAppLaunchTimestampFromSessionContext.

@Test
@PrepareForTest({ SessionContext.class, DeviceInfoHelper.class })
public void minidumpAppLaunchTimestampFromSessionContext() throws Exception {
    long appStartTime = 99000L;
    long crashTime = 123000L;
    ManagedErrorLog crashLog = testNativeCrashLog(appStartTime, crashTime, true, true, true);
    assertEquals(new Date(crashTime), crashLog.getTimestamp());
    assertEquals(new Date(appStartTime), crashLog.getAppLaunchTimestamp());
}
Also used : ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Date(java.util.Date) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 99 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.

the class CrashesTest method minidumpDeviceUserIdNull.

@Test
@PrepareForTest({ SessionContext.class, DeviceInfoHelper.class })
public void minidumpDeviceUserIdNull() throws Exception {
    long appStartTime = 95000L;
    long crashTime = 126000L;
    ManagedErrorLog crashLog = testNativeCrashLog(appStartTime, crashTime, true, false, false);
    assertNull(crashLog.getUserId());
}
Also used : ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 100 with PrepareForTest

use of org.powermock.core.classloader.annotations.PrepareForTest in project mobile-center-sdk-android by Microsoft.

the class CrashesTest method minidumpDeviceInfoNull.

@Test
@PrepareForTest({ SessionContext.class, DeviceInfoHelper.class })
public void minidumpDeviceInfoNull() throws Exception {
    long appStartTime = 95000L;
    long crashTime = 126000L;
    ManagedErrorLog crashLog = testNativeCrashLog(appStartTime, crashTime, true, false, false);
    assertEquals(new Date(crashTime), crashLog.getTimestamp());
    assertEquals(new Date(appStartTime), crashLog.getAppLaunchTimestamp());
}
Also used : ManagedErrorLog(com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog) Date(java.util.Date) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)196 Test (org.junit.Test)194 HttpServletRequest (javax.servlet.http.HttpServletRequest)30 HttpServletResponse (javax.servlet.http.HttpServletResponse)30 StringWriter (java.io.StringWriter)28 PrintWriter (java.io.PrintWriter)27 File (java.io.File)24 ArrayList (java.util.ArrayList)16 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)14 Method (java.lang.reflect.Method)13 ManagedErrorLog (com.microsoft.appcenter.crashes.ingestion.models.ManagedErrorLog)12 Config (com.twitter.heron.spi.common.Config)12 Matchers.anyString (org.mockito.Matchers.anyString)12 DialogInterface (android.content.DialogInterface)11 Intent (android.content.Intent)11 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)11 Job (hudson.model.Job)11 IOException (java.io.IOException)11 Date (java.util.Date)10 HashMap (java.util.HashMap)10