/** - 内容: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 itDelegatesTaskToAsyncTaskWhenGetIsCalled()
      throws ExecutionException, InterruptedException {
    retryableAsyncTask.execute("foo");

    flushBackgroundThreadScheduler();

    assertThat(retryableAsyncTask.get(), is("bar"));
  }
  @Test
  public void itDoesNotExecutAsyncTaskIfThereIsNoConnectivity()
      throws ExecutionException, InterruptedException {
    when(connectivityCheckerMock.isConnected()).thenReturn(false);

    retryableAsyncTask.execute();

    flushBackgroundThreadScheduler();

    assertNull(retryableAsyncTask.get());
  }
  /** - 内容: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);
  }
  /** - 内容: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();
  }
  /** - 内容: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 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());
  }
  /** - 内容: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);
  }