@Test
  @Feature({"GCore"})
  public void lifecycleManagementDelayTest() {
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    Activity mockActivity = mock(Activity.class);
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
    helper.setDisconnectionDelay(5000);

    // We have a connected client
    when(mMockClient.isConnected()).thenReturn(true);

    // Should not be disconnected when we go in the background
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
    ShadowLooper.runUiThreadTasks();
    verify(mMockClient, times(0)).disconnect();

    // Should be disconnected when we wait.
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    verify(mMockClient, times(1)).disconnect();

    // Should be reconnected when we come in the foreground
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
    verify(mMockClient).connect();

    // Should not disconnect when we became visible during the delay
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
    ShadowLooper.runUiThreadTasks();
    verify(mMockClient, times(1)).disconnect();
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    verify(mMockClient, times(1)).disconnect();
  }
  /** Tests that the connection handler gives up after a number of connection attempts. */
  @Test
  @Feature({"GCore"})
  public void connectionFailureTest() {
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);

    helper.onConnectionFailed(new ConnectionResult(ConnectionResult.DEVELOPER_ERROR));
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    // Should not retry on unrecoverable errors
    verify(mMockClient, never()).connect();

    // Connection attempts
    for (int i = 0; i < ConnectedTask.RETRY_NUMBER_LIMIT; i++) {
      helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
      ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    }

    // Should have tried to connect every time.
    verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT)).connect();

    // Try again
    helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    // The connection handler should have given up, no new call.
    verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT)).connect();
  }
  /** Tests that when a connection succeeds, the retry limit is reset. */
  @Test
  @Feature({"GCore"})
  public void connectionAttemptsResetTest() {
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);

    // Connection attempts
    for (int i = 0; i < ConnectedTask.RETRY_NUMBER_LIMIT - 1; i++) {
      helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
      ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    }

    // Should have tried to connect every time.
    verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT - 1)).connect();

    // Connection successful now
    helper.onConnected(null);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    for (int i = 0; i < ConnectedTask.RETRY_NUMBER_LIMIT; i++) {
      helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
      ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    }

    // A success should allow for more connection attempts.
    verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT * 2 - 1)).connect();

    // This should not result in a connection attempt, the limit is still there.
    helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    // The connection handler should have given up, no new call.
    verify(mMockClient, times(ConnectedTask.RETRY_NUMBER_LIMIT * 2 - 1)).connect();
  }
  @Test
  @Feature({"GCore"})
  public void willUseConnectionBackgroundTest() {
    int disconnectionTimeout = 5000;
    int arbitraryNumberOfSeconds = 42;
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    Activity mockActivity = mock(Activity.class);
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
    helper.setDisconnectionDelay(disconnectionTimeout);

    // We have a connected client
    when(mMockClient.isConnected()).thenReturn(true);

    // We go in the background and extend the delay
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
    ShadowLooper.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds);
    helper.willUseConnection();

    // The client should not have been disconnected.
    ShadowLooper.idleMainLooper(disconnectionTimeout - arbitraryNumberOfSeconds);
    verify(mMockClient, never()).disconnect();

    // After the full timeout it should still disconnect though
    ShadowLooper.idleMainLooper(arbitraryNumberOfSeconds);
    verify(mMockClient).disconnect();

    // The client is now disconnected then
    when(mMockClient.isConnected()).thenReturn(false);

    // The call should reconnect a disconnected client
    helper.willUseConnection();
    verify(mMockClient).connect();
  }
  @Test
  public void testInitializeOptOut() {
    ShadowLooper looper = Shadows.shadowOf(amplitude.logThread.getLooper());

    String sourceName = Constants.PACKAGE_NAME + "." + context.getPackageName();
    SharedPreferences prefs = context.getSharedPreferences(sourceName, Context.MODE_PRIVATE);
    prefs.edit().putBoolean(Constants.PREFKEY_OPT_OUT, true).commit();

    DatabaseHelper dbHelper = DatabaseHelper.getDatabaseHelper(context);
    assertNull(dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY));

    amplitude.initialize(context, apiKey);
    looper.runOneTask();

    assertTrue(amplitude.isOptedOut());
    assertEquals((long) dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY), 1L);

    amplitude.setOptOut(false);
    looper.runOneTask();
    assertFalse(amplitude.isOptedOut());
    assertEquals((long) dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY), 0L);

    // verify shared prefs deleted
    assertFalse(prefs.getBoolean(Constants.PREFKEY_OPT_OUT, false));
  }
 @Test
 public void disable_shouldCancelTraceReplay() throws Exception {
   mockEngine.setTrace(getTestGpxTrace());
   mockEngine.setRequest(LocationRequest.create().setFastestInterval(100));
   Thread.sleep(100);
   ShadowLooper.runUiThreadTasks();
   assertThat(callback.locations).hasSize(1);
   mockEngine.disable();
   Thread.sleep(100);
   ShadowLooper.runUiThreadTasks();
   assertThat(callback.locations).hasSize(1);
 }
  /** Tests that connection attempts are delayed. */
  @Test
  @Feature({"GCore"})
  public void connectionAttemptDelayTest() {
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);

    ShadowLooper.pauseMainLooper();
    helper.onConnectionFailed(new ConnectionResult(ConnectionResult.SERVICE_UPDATING));
    verify(mMockClient, times(0)).connect();
    ShadowLooper.unPauseMainLooper();

    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    verify(mMockClient, times(1)).connect();
  }
  /** - 内容:sendInBackground(POST)が成功することを確認する - 結果:非同期でプッシュの送信が出来る事 */
  @Test
  public void sendInBackground_post() throws Exception {
    Assert.assertFalse(callbackFlag);
    // post
    NCMBPush push = new NCMBPush();
    push.setMessage("message");
    push.setTitle("title");
    push.sendInBackground(
        new DoneCallback() {

          @Override
          public void done(NCMBException e) {
            Assert.assertNull(e);
            callbackFlag = true;
          }
        });

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();

    Assert.assertTrue(callbackFlag);

    // check
    Assert.assertEquals("message", push.getMessage());
    Assert.assertEquals("title", push.getTitle());
    Assert.assertEquals("7FrmPTBKSNtVjajm", push.getObjectId());
    DateFormat format = NCMBDateFormat.getIso8601();
    Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getCreateDate());
  }
  /** - 内容:executeScriptInBackgroundが成功することを確認する - 結果:エラーが発生しないこと */
  @Test
  public void executeScriptInBackground() throws Exception {
    NCMBScriptService scriptService = (NCMBScriptService) NCMB.factory(NCMB.ServiceType.SCRIPT);
    scriptService.executeScriptInBackground(
        "testScript.js",
        NCMBScript.MethodType.GET,
        null,
        null,
        null,
        mScriptUrl,
        new ExecuteScriptCallback() {
          @Override
          public void done(byte[] result, NCMBException e) {
            if (e != null) {
              Assert.fail(e.getMessage());
            } else {
              try {
                Assert.assertEquals("hello", new String(result, "UTF-8"));
              } catch (UnsupportedEncodingException error) {
                Assert.fail(error.getMessage());
              }
            }
            mCallbackFlag = true;
          }
        });

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();

    Assert.assertTrue(mCallbackFlag);
  }
  @Test
  public void shouldNotCallOnSubscribeWhenSubscriptionUnsubscribedBeforeDelay() {
    Observable.OnSubscribe<Integer> onSubscribe = mock(Observable.OnSubscribe.class);
    Handler handler = spy(new Handler());

    final Worker worker = spy(new HandlerScheduler.HandlerWorker(handler));
    Scheduler scheduler =
        new Scheduler() {
          @Override
          public Worker createWorker() {
            return worker;
          }
        };

    Subscription subscription =
        Observable.create(onSubscribe).delaySubscription(1, MINUTES, scheduler).subscribe();

    verify(worker).schedule(any(Action0.class), eq(1L), eq(MINUTES));
    verify(handler).postDelayed(any(Runnable.class), eq(MINUTES.toMillis(1)));

    subscription.unsubscribe();

    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    verify(onSubscribe, never()).call(any(Subscriber.class));
    verify(handler).removeCallbacks(any(Runnable.class));
  }
Exemple #11
0
 @Test
 public void setTrace_shouldReportSpeed() throws Exception {
   mockEngine.setTrace(getTestGpxTrace());
   mockEngine.setRequest(LocationRequest.create().setFastestInterval(0));
   Thread.sleep(100);
   ShadowLooper.runUiThreadTasks();
   assertThat(callback.locations.get(0).getSpeed()).isEqualTo(10f);
   assertThat(callback.locations.get(1).getSpeed()).isEqualTo(20f);
   assertThat(callback.locations.get(2).getSpeed()).isEqualTo(30f);
 }
Exemple #12
0
 @Test
 public void setTrace_shouldSetHasBearing() throws Exception {
   mockEngine.setTrace(getTestGpxTrace());
   mockEngine.setRequest(LocationRequest.create().setFastestInterval(0));
   Thread.sleep(100);
   ShadowLooper.runUiThreadTasks();
   assertThat(callback.locations.get(0).hasBearing()).isFalse();
   assertThat(callback.locations.get(1).hasBearing()).isTrue();
   assertThat(callback.locations.get(2).hasBearing()).isTrue();
 }
  @Test
  public void testSkipSharedPrefsToDb() {
    DatabaseHelper dbHelper = DatabaseHelper.getDatabaseHelper(context);
    dbHelper.insertOrReplaceKeyValue(AmplitudeClient.DEVICE_ID_KEY, "testDeviceId");
    dbHelper.insertOrReplaceKeyLongValue(AmplitudeClient.PREVIOUS_SESSION_ID_KEY, 1000L);
    dbHelper.insertOrReplaceKeyLongValue(AmplitudeClient.LAST_EVENT_TIME_KEY, 2000L);

    assertNull(dbHelper.getValue(AmplitudeClient.USER_ID_KEY));
    assertNull(dbHelper.getLongValue(AmplitudeClient.LAST_EVENT_ID_KEY));
    assertNull(dbHelper.getLongValue(AmplitudeClient.LAST_IDENTIFY_ID_KEY));
    assertNull(dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY));

    String sourceName = Constants.PACKAGE_NAME + "." + context.getPackageName();
    SharedPreferences prefs = context.getSharedPreferences(sourceName, Context.MODE_PRIVATE);
    prefs.edit().putString(Constants.PREFKEY_DEVICE_ID, "otherDeviceId").commit();
    prefs.edit().putString(Constants.PREFKEY_USER_ID, "testUserId").commit();
    prefs.edit().putBoolean(Constants.PREFKEY_OPT_OUT, true).commit();
    prefs.edit().putLong(Constants.PREFKEY_LAST_IDENTIFY_ID, 3000L).commit();

    amplitude.initialize(context, apiKey);
    ShadowLooper looper = Shadows.shadowOf(amplitude.logThread.getLooper());
    looper.runOneTask();
    looper.runToEndOfTasks();

    assertEquals(dbHelper.getValue(AmplitudeClient.DEVICE_ID_KEY), "testDeviceId");
    assertEquals((long) dbHelper.getLongValue(AmplitudeClient.PREVIOUS_SESSION_ID_KEY), 1000L);
    assertEquals((long) dbHelper.getLongValue(AmplitudeClient.LAST_EVENT_TIME_KEY), 2000L);
    assertNull(dbHelper.getValue(AmplitudeClient.USER_ID_KEY));
    assertNull(dbHelper.getLongValue(AmplitudeClient.LAST_EVENT_ID_KEY));
    assertNull(dbHelper.getLongValue(AmplitudeClient.LAST_IDENTIFY_ID_KEY));
    assertNull(dbHelper.getLongValue(AmplitudeClient.OPT_OUT_KEY));

    assertEquals(prefs.getString(Constants.PREFKEY_DEVICE_ID, null), "otherDeviceId");
    assertEquals(prefs.getString(Constants.PREFKEY_USER_ID, null), "testUserId");
    assertTrue(prefs.getBoolean(Constants.PREFKEY_OPT_OUT, false));
    assertEquals(prefs.getLong(Constants.PREFKEY_LAST_IDENTIFY_ID, -1), 3000L);

    // after upgrade, pref values still there since they weren't deleted
    assertEquals(amplitude.deviceId, "testDeviceId");
    assertEquals(amplitude.previousSessionId, 1000L);
    assertEquals(amplitude.lastEventTime, 2000L);
    assertNull(amplitude.userId);
  }
  @Test
  public void testInitializePreviousSessionIdLastEventTime() {
    // set a previous session id & last event time
    // log an event with timestamp such that same session is continued
    // log second event with timestamp such that new session is started

    amplitude.setSessionTimeoutMillis(5000); // 5s

    String sourceName = Constants.PACKAGE_NAME + "." + context.getPackageName();
    SharedPreferences prefs = context.getSharedPreferences(sourceName, Context.MODE_PRIVATE);
    prefs.edit().putString(Constants.PREFKEY_DEVICE_ID, "testDeviceId").commit();
    prefs.edit().putLong(Constants.PREFKEY_PREVIOUS_SESSION_ID, 6000L).commit();
    prefs.edit().putLong(Constants.PREFKEY_LAST_EVENT_TIME, 6000L).commit();

    DatabaseHelper dbHelper = DatabaseHelper.getDatabaseHelper(context);
    dbHelper.insertOrReplaceKeyLongValue(AmplitudeClient.LAST_EVENT_TIME_KEY, 7000L);

    long[] timestamps = {8000, 14000};
    clock.setTimestamps(timestamps);

    amplitude.initialize(context, apiKey);
    ShadowLooper looper = Shadows.shadowOf(amplitude.logThread.getLooper());
    looper.runOneTask();
    looper.runToEndOfTasks();

    assertEquals(amplitude.deviceId, "testDeviceId");
    assertEquals(amplitude.previousSessionId, 6000L);
    assertEquals(amplitude.lastEventTime, 7000L);
    assertNull(amplitude.userId);

    // log first event
    amplitude.logEvent("testEvent1");
    looper.runToEndOfTasks();
    assertEquals(amplitude.previousSessionId, 6000L);
    assertEquals(amplitude.lastEventTime, 8000L);

    // log second event
    amplitude.logEvent("testEvent2");
    looper.runToEndOfTasks();
    assertEquals(amplitude.previousSessionId, 14000L);
    assertEquals(amplitude.lastEventTime, 14000L);
  }
Exemple #15
0
 @Test
 public void setTrace_shouldCalculateBearing() throws Exception {
   mockEngine.setTrace(getTestGpxTrace());
   mockEngine.setRequest(LocationRequest.create().setFastestInterval(0));
   Thread.sleep(100);
   ShadowLooper.runUiThreadTasks();
   assertThat(callback.locations.get(0).getBearing()).isEqualTo(0.0f);
   assertThat(callback.locations.get(1).getBearing())
       .isEqualTo(callback.locations.get(0).bearingTo(callback.locations.get(1)));
   assertThat(callback.locations.get(2).getBearing())
       .isEqualTo(callback.locations.get(1).bearingTo(callback.locations.get(2)));
 }
  @Test
  @Feature({"GCore"})
  public void willUseConnectionForegroundTest() {
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    Activity mockActivity = mock(Activity.class);
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
    helper.setDisconnectionDelay(5000);

    // We have a connected client
    when(mMockClient.isConnected()).thenReturn(true);

    // We are in the foreground
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    // Disconnections should not be scheduled when in the foreground.
    helper.willUseConnection();
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    verify(mMockClient, never()).disconnect();
  }
  /** - 内容:deleteInBackground(callback無し)が成功することを確認する - 結果:非同期でプッシュ情報が削除出来る事 */
  @Test
  public void deleteInBackground_none_callback() throws Exception {
    // delete
    NCMBPush push = new NCMBPush();
    push.setObjectId("7FrmPTBKSNtVjajm");
    push.deleteInBackground();

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();

    // check
    Assert.assertNull(push.getObjectId());
  }
  /** - 内容:fetchInBackground(callback無し)が成功することを確認する - 結果:非同期でプッシュ情報が取得出来る事 */
  @Test
  public void fetchInBackground_none_callback() throws Exception {
    // get
    NCMBPush push = new NCMBPush();
    push.setObjectId("7FrmPTBKSNtVjajm");
    push.fetchInBackground();

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();

    // check
    checkGetResponse(push);
  }
  @Test
  @Feature({"GCore"})
  public void disconnectionCancellingTest() {
    int disconnectionTimeout = 5000;
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    Activity mockActivity = mock(Activity.class);
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);
    helper.setDisconnectionDelay(disconnectionTimeout);

    // We have a connected client
    when(mMockClient.isConnected()).thenReturn(true);

    // We go in the background and come back before the end of the timeout.
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
    ShadowLooper.idleMainLooper(disconnectionTimeout - 42);
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    // The client should not have been disconnected, which would drop requests otherwise.
    verify(mMockClient, never()).disconnect();
  }
  // Should pass
  @Test
  public void testButtonOneClick_shouldShowToast() {
    MainActivity activity = Robolectric.setupActivity(MainActivity.class);
    activity.findViewById(R.id.button_1).performClick();

    ShadowLooper.idleMainLooper();
    // Check toast correctness
    Assert.assertTrue(ShadowToast.getTextOfLatestToast().equals("Button #1 Clicked"));

    // Check textView text
    TextView textView = (TextView) activity.findViewById(R.id.test_text);
    Assert.assertTrue("Button 1 Clicked".equals(textView.getText()));
  }
  @Test
  @Feature({"GCore"})
  public void lifecycleManagementTest() {
    GoogleApiClientHelper helper = new GoogleApiClientHelper(mMockClient);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    Activity mockActivity = mock(Activity.class);
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.CREATED);

    // The helper should have been registered to handle connectivity issues.
    verify(mMockClient).registerConnectionCallbacks(helper);
    verify(mMockClient).registerConnectionFailedListener(helper);

    // Client was not connected. Coming in the foreground should not change that.
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
    verify(mMockClient, never()).connect();

    // We now say we are connected
    when(mMockClient.isConnected()).thenReturn(true);

    // Should be disconnected when we go in the background
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
    verify(mMockClient, times(1)).disconnect();

    // Should be reconnected when we come in the foreground
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STARTED);
    verify(mMockClient).connect();

    helper.disable();

    // The helper should have been unregistered from handling connectivity issues.
    verify(mMockClient).unregisterConnectionCallbacks(helper);
    verify(mMockClient).unregisterConnectionFailedListener(helper);

    // Should not be interacted with anymore when we stop managing it.
    ApplicationStatus.onStateChangeForTesting(mockActivity, ActivityState.STOPPED);
    verify(mMockClient).disconnect();
  }
Exemple #22
0
 @Test
 public void setTrace_shouldReportEachLocation() throws Exception {
   mockEngine.setTrace(getTestGpxTrace());
   mockEngine.setRequest(LocationRequest.create().setFastestInterval(0));
   Thread.sleep(100);
   ShadowLooper.runUiThreadTasks();
   assertThat(callback.locations).hasSize(3);
   assertThat(callback.locations.get(0).getLatitude()).isEqualTo(0.0);
   assertThat(callback.locations.get(0).getLongitude()).isEqualTo(0.1);
   assertThat(callback.locations.get(1).getLatitude()).isEqualTo(1.0);
   assertThat(callback.locations.get(1).getLongitude()).isEqualTo(1.1);
   assertThat(callback.locations.get(2).getLatitude()).isEqualTo(2.0);
   assertThat(callback.locations.get(2).getLongitude()).isEqualTo(2.1);
 }
  /** - 内容:sendInBackground(callback無し)が成功することを確認する - 結果:非同期でプッシュの送信が出来る事 */
  @Test
  public void sendInBackground_none_callback() throws Exception {
    // post
    NCMBPush push = new NCMBPush();
    push.setMessage("message");
    push.setTitle("title");
    push.sendInBackground();

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();

    // check
    Assert.assertEquals("message", push.getMessage());
    Assert.assertEquals("title", push.getTitle());
    Assert.assertEquals("7FrmPTBKSNtVjajm", push.getObjectId());
    DateFormat format = NCMBDateFormat.getIso8601();
    Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getCreateDate());
    Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getUpdateDate());
  }
  /** - 内容:fetchInBackgroundが成功することを確認する - 結果:非同期でプッシュ通知が取得できること */
  @Test
  public void fetchInBackground_with_callback() throws Exception {
    NCMBPush push = new NCMBPush();
    push.setObjectId("7FrmPTBKSNtVjajm");
    push.fetchInBackground(
        new FetchCallback<NCMBPush>() {
          @Override
          public void done(NCMBPush fetchedPush, NCMBException e) {
            try {
              checkGetResponse(fetchedPush);
            } catch (Exception e1) {
              Assert.fail(e1.getMessage());
            }
          }
        });

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();
  }
  /** - 内容:fetchInBackgroundが成功することを確認する - 結果:非同期でプッシュ情報が取得出来る事 */
  @Test
  public void fetchInBackground() throws Exception {
    Assert.assertFalse(callbackFlag);
    // get
    NCMBPush push = new NCMBPush();
    push.setObjectId("7FrmPTBKSNtVjajm");
    push.fetchInBackground(
        new FetchCallback<NCMBPush>() {
          @Override
          public void done(NCMBPush fetchedPush, NCMBException e) {
            Assert.assertNull(e);
            callbackFlag = true;
          }
        });

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();

    Assert.assertTrue(callbackFlag);

    // check
    checkGetResponse(push);
  }
  /** - 内容:fetchInBackgroundが成功することを確認する - 結果:非同期でプッシュ情報が削除出来る事 */
  @Test
  public void deleteInBackground() throws Exception {
    Assert.assertFalse(callbackFlag);
    // delete
    NCMBPush push = new NCMBPush();
    push.setObjectId("7FrmPTBKSNtVjajm");
    push.deleteInBackground(
        new DoneCallback() {
          @Override
          public void done(NCMBException e) {
            Assert.assertNull(e);
            callbackFlag = true;
          }
        });

    Robolectric.flushBackgroundThreadScheduler();
    ShadowLooper.runUiThreadTasks();

    Assert.assertTrue(callbackFlag);

    // check
    Assert.assertNull(push.getObjectId());
  }