All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdeferred.android.test.AndroidDeferredManagerTest Maven / Gradle / Ivy

There is a newer version: 1.2.4
Show newest version
package org.jdeferred.android.test;

import junit.framework.Assert;

import org.jdeferred.DoneCallback;
import org.jdeferred.android.AndroidDeferredManager;
import org.jdeferred.android.DeferredAsyncTask;

import android.test.AndroidTestCase;

public class AndroidDeferredManagerTest extends AndroidTestCase {
	protected AndroidDeferredManager dm = new AndroidDeferredManager();

	public void testDeferredAsyncTask() {
		final ValueHolder backgroundThreadGroupName = new ValueHolder();
		final ValueHolder doneThreadGroupName = new ValueHolder();

		try {
			dm.when(new DeferredAsyncTask() {
				@Override
				protected String doInBackgroundSafe(Void... nil)
						throws Exception {
					backgroundThreadGroupName.set(Thread.currentThread()
							.getThreadGroup().getName());
					return "Done";
				}
			}).done(new DoneCallback() {

				@Override
				public void onDone(String result) {
					doneThreadGroupName.set(Thread.currentThread()
							.getThreadGroup().getName());
				}

			}).waitSafely();
		} catch (InterruptedException e) {
			// Do nothing
		}

		doneThreadGroupName.assertEquals("main");
		Assert.assertFalse(
				String.format(
						"Background Thread Group [%s] shouldn't be the same as Thread Group in Done [%s]",
						backgroundThreadGroupName.get(),
						doneThreadGroupName.get()), backgroundThreadGroupName
						.equals(doneThreadGroupName));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy