@Test
  public void generateUniqueId_withMultipleInvocations_shouldReturnUniqueValues() throws Exception {
    final int expectedIdCount = 100;

    Set<Long> ids = new HashSet<Long>(expectedIdCount);
    for (int i = 0; i < expectedIdCount; i++) {
      final long id = Utils.generateUniqueId();
      ids.add(id);
    }

    assertThat(ids).hasSize(expectedIdCount);
  }
  @Test
  public void deviceCanHandleIntent_whenActivityCanResolveIntent_shouldReturnTrue()
      throws Exception {
    Context context = mock(Context.class);
    PackageManager packageManager = mock(PackageManager.class);

    List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>();
    resolveInfos.add(new ResolveInfo());

    stub(context.getPackageManager()).toReturn(packageManager);
    Intent specificIntent = new Intent();
    specificIntent.setData(Uri.parse("specificIntent:"));

    stub(packageManager.queryIntentActivities(eq(specificIntent), eq(0))).toReturn(resolveInfos);

    assertThat(Utils.deviceCanHandleIntent(context, specificIntent)).isTrue();
  }
  public CustomEventInterstitialAdapter(
      MoPubInterstitial moPubInterstitial, String className, String jsonParams) {
    mHandler = new Handler();
    mServerExtras = new HashMap<String, String>();
    mLocalExtras = new HashMap<String, Object>();
    mContext = moPubInterstitial.getActivity();
    mTimeout =
        new Runnable() {
          @Override
          public void run() {
            Log.d("MoPub", "Third-party network timed out.");
            onInterstitialFailed(NETWORK_TIMEOUT);
            invalidate();
          }
        };

    Log.d("MoPub", "Attempting to invoke custom event: " + className);
    try {
      mCustomEventInterstitial = CustomEventInterstitialFactory.create(className);
    } catch (Exception exception) {
      Log.d("MoPub", "Couldn't locate or instantiate custom event: " + className + ".");
      if (mCustomEventInterstitialAdapterListener != null)
        mCustomEventInterstitialAdapterListener.onCustomEventInterstitialFailed(ADAPTER_NOT_FOUND);
    }

    // Attempt to load the JSON extras into mServerExtras.
    try {
      mServerExtras = Utils.jsonStringToMap(jsonParams);
    } catch (Exception exception) {
      Log.d("MoPub", "Failed to create Map from JSON: " + jsonParams);
    }

    mLocalExtras = moPubInterstitial.getLocalExtras();
    if (moPubInterstitial.getLocation() != null)
      mLocalExtras.put("location", moPubInterstitial.getLocation());
  }