Search in sources :

Example 1 with AggregateException

use of com.parse.boltsinternal.AggregateException in project Parse-SDK-Android by ParsePlatform.

the class ParseTaskUtilsTest method testWaitForTaskWrapsAggregateExceptionAsParseException.

/**
 * Verifies {@link AggregateException} gets wrapped with {@link ParseException} when thrown from
 * {@link com.parse.ParseTaskUtils#wait(Task)}.
 */
@Test
public void testWaitForTaskWrapsAggregateExceptionAsParseException() {
    final Exception error = new RuntimeException("This task failed.");
    final ArrayList<Task<Void>> tasks = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        final int number = i;
        Task<Void> task = Task.callInBackground(() -> {
            Thread.sleep((long) (Math.random() * 100));
            if (number == 10 || number == 11) {
                throw error;
            }
            return null;
        });
        tasks.add(task);
    }
    try {
        ParseTaskUtils.wait(Task.whenAll(tasks));
    } catch (ParseException e) {
        assertTrue(e.getCause() instanceof AggregateException);
    }
}
Also used : Task(com.parse.boltsinternal.Task) ArrayList(java.util.ArrayList) AggregateException(com.parse.boltsinternal.AggregateException) AggregateException(com.parse.boltsinternal.AggregateException) Test(org.junit.Test)

Aggregations

AggregateException (com.parse.boltsinternal.AggregateException)1 Task (com.parse.boltsinternal.Task)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1