use of bolts.Capture in project Parse-SDK-Android by ParsePlatform.
the class ParsePushTest method testSendDataInBackgroundWithCallback.
@Test
public void testSendDataInBackgroundWithCallback() throws Exception {
// Mock controller
ParsePushController controller = mock(ParsePushController.class);
when(controller.sendInBackground(any(ParsePush.State.class), anyString())).thenReturn(Task.<Void>forResult(null));
ParseCorePlugins.getInstance().registerPushController(controller);
// Make sample ParsePush data and call method
JSONObject data = new JSONObject();
data.put("key", "value");
data.put("keyAgain", "valueAgain");
ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
query.getBuilder().whereEqualTo("foo", "bar");
final Semaphore done = new Semaphore(0);
final Capture<Exception> exceptionCapture = new Capture<>();
ParsePush.sendDataInBackground(data, query, new SendCallback() {
@Override
public void done(ParseException e) {
exceptionCapture.set(e);
done.release();
}
});
// Make sure controller is executed and state parameter is correct
assertNull(exceptionCapture.get());
assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS));
ArgumentCaptor<ParsePush.State> stateCaptor = ArgumentCaptor.forClass(ParsePush.State.class);
verify(controller, times(1)).sendInBackground(stateCaptor.capture(), anyString());
ParsePush.State state = stateCaptor.getValue();
// Verify query state
ParseQuery.State<ParseInstallation> queryState = state.queryState();
JSONObject queryStateJson = queryState.toJSON(PointerEncoder.get());
assertEquals("bar", queryStateJson.getJSONObject("where").getString("foo"));
// Verify data
assertEquals(data, state.data(), JSONCompareMode.NON_EXTENSIBLE);
}
use of bolts.Capture in project Parse-SDK-Android by ParsePlatform.
the class ParsePushTest method testUnsubscribeInBackgroundWithCallbackFail.
@Test
public void testUnsubscribeInBackgroundWithCallbackFail() throws Exception {
ParsePushChannelsController controller = mock(ParsePushChannelsController.class);
final ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error");
when(controller.unsubscribeInBackground(anyString())).thenReturn(Task.<Void>forError(exception));
ParseCorePlugins.getInstance().registerPushChannelsController(controller);
ParsePush push = new ParsePush();
final Semaphore done = new Semaphore(0);
final Capture<Exception> exceptionCapture = new Capture<>();
push.unsubscribeInBackground("test", new SaveCallback() {
@Override
public void done(ParseException e) {
exceptionCapture.set(e);
done.release();
}
});
assertSame(exception, exceptionCapture.get());
assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS));
verify(controller, times(1)).unsubscribeInBackground("test");
}
use of bolts.Capture in project Parse-SDK-Android by ParsePlatform.
the class ParsePushTest method testSendInBackgroundWithCallbackFail.
@Test
public void testSendInBackgroundWithCallbackFail() throws Exception {
// Mock controller
ParsePushController controller = mock(ParsePushController.class);
final ParseException exception = new ParseException(ParseException.OTHER_CAUSE, "error");
when(controller.sendInBackground(any(ParsePush.State.class), anyString())).thenReturn(Task.<Void>forError(exception));
ParseCorePlugins.getInstance().registerPushController(controller);
// Make sample ParsePush data and call method
ParsePush push = new ParsePush();
JSONObject data = new JSONObject();
data.put("key", "value");
List<String> channels = new ArrayList<>();
channels.add("test");
channels.add("testAgain");
push.builder.expirationTime((long) 1000).data(data).pushToIOS(true).channelSet(channels);
final Semaphore done = new Semaphore(0);
final Capture<Exception> exceptionCapture = new Capture<>();
push.sendInBackground(new SendCallback() {
@Override
public void done(ParseException e) {
exceptionCapture.set(e);
done.release();
}
});
// Make sure controller is executed and state parameter is correct
assertSame(exception, exceptionCapture.get());
assertTrue(done.tryAcquire(1, 10, TimeUnit.SECONDS));
ArgumentCaptor<ParsePush.State> stateCaptor = ArgumentCaptor.forClass(ParsePush.State.class);
verify(controller, times(1)).sendInBackground(stateCaptor.capture(), anyString());
ParsePush.State state = stateCaptor.getValue();
assertTrue(state.pushToIOS());
assertEquals(data, state.data(), JSONCompareMode.NON_EXTENSIBLE);
assertEquals(2, state.channelSet().size());
assertTrue(state.channelSet().contains("test"));
assertTrue(state.channelSet().contains("testAgain"));
}
Aggregations