public void testReRegisterNative() throws Throwable {
    try {

      Context context = getInstrumentation().getTargetContext();
      final SharedPreferences sharedPreferences =
          PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

      final Container container = new Container();
      final String handle = "handle";

      String registrationId1 = "registrationId1";
      String registrationId2 = "registrationId2";

      String[] tags1 = new String[] {"tag1"};
      final String[] tags2 = new String[] {"tag2"};

      MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context);

      MobileServiceClient registrationclient =
          client.withFilter(getUpsertTestFilter(registrationId1));
      MobileServiceClient reRegistrationclient =
          client.withFilter(getUpsertTestFilter(registrationId2));

      final MobileServicePush registrationPush = registrationclient.getPush();
      final MobileServicePush reRegistrationPush = reRegistrationclient.getPush();

      forceRefreshSync(registrationPush, handle);
      forceRefreshSync(reRegistrationPush, handle);

      try {
        registrationPush.register(handle, tags1).get();

        Registration registration2 = reRegistrationPush.register(handle, tags2).get();

        container.storedRegistrationId =
            sharedPreferences.getString(
                STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + DEFAULT_REGISTRATION_NAME, null);
        container.tags = registration2.getTags();

      } catch (Exception exception) {
        container.exception = exception;
      }

      // Asserts
      Exception exception = container.exception;

      if (exception != null) {
        fail(exception.getMessage());
      } else {
        Assert.assertEquals(registrationId2, container.storedRegistrationId);
        Assert.assertTrue(matchTags(tags2, container.tags));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void testRegisterUnregisterNative() throws Throwable {
    Context context = getInstrumentation().getTargetContext();
    final SharedPreferences sharedPreferences =
        PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

    final Container container = new Container();
    final String handle = "handle";

    String registrationId = "registrationId";

    MobileServiceClient client = new MobileServiceClient(appUrl, appKey, context);

    client = client.withFilter(getUpsertTestFilter(registrationId));

    final MobileServicePush push = client.getPush();

    forceRefreshSync(push, handle);

    try {

      Registration registration = push.register(handle, new String[] {"tag1"}).get();

      container.registrationId = registration.getRegistrationId();

      container.storedRegistrationId =
          sharedPreferences.getString(
              STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + DEFAULT_REGISTRATION_NAME, null);

      push.unregister().get();

      container.unregister =
          sharedPreferences.getString(
              STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + DEFAULT_REGISTRATION_NAME, null);

    } catch (Exception exception) {

      if (exception instanceof ExecutionException) {
        container.exception = (Exception) exception.getCause();
      } else {
        container.exception = exception;
      }

      fail(container.exception.getMessage());
    }

    Assert.assertEquals(registrationId, container.storedRegistrationId);
    Assert.assertEquals(registrationId, container.registrationId);
    Assert.assertNull(container.unregister);
  }