Skip to content

Commit e4cfd2f

Browse files
committed
Test UiThread task cancellation
1 parent 2cb859e commit e4cfd2f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/efragment/MyListFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class MyListFragment extends ListFragment {
3838

3939
boolean didExecute;
4040

41+
boolean uiThreadWithIdDidExecute;
42+
4143
@Override
4244
public void onActivityCreated(Bundle savedInstanceState) {
4345
super.onActivityCreated(savedInstanceState);
@@ -61,6 +63,11 @@ void uiThreadIgnored() {
6163
didExecute = true;
6264
}
6365

66+
@UiThread(id = "id")
67+
void uiThreadWithId() {
68+
uiThreadWithIdDidExecute = true;
69+
}
70+
6471
@Background
6572
void backgroundThread() {
6673
didExecute = true;

AndroidAnnotations/functional-test-1-5/src/test/java/org/androidannotations/test15/efragment/MyListFragmentTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
import java.util.concurrent.Executor;
2323

2424
import org.androidannotations.api.BackgroundExecutor;
25+
import org.androidannotations.api.UiThreadExecutor;
2526
import org.androidannotations.test15.R;
2627
import org.junit.Before;
2728
import org.junit.Test;
2829
import org.junit.runner.RunWith;
2930
import org.robolectric.Robolectric;
3031
import org.robolectric.RobolectricTestRunner;
32+
import org.robolectric.shadows.ShadowLooper;
3133

3234
import android.support.v4.app.Fragment;
3335
import android.support.v4.app.FragmentActivity;
@@ -75,6 +77,15 @@ public void uithreadMethodIsCalled() {
7577
assertTrue(myListFragment.didExecute);
7678
}
7779

80+
@Test
81+
public void uithreadMethodIsCanceled() {
82+
ShadowLooper.pauseMainLooper();
83+
myListFragment.uiThreadWithId();
84+
UiThreadExecutor.cancelAll("id");
85+
ShadowLooper.unPauseMainLooper();
86+
assertFalse(myListFragment.uiThreadWithIdDidExecute);
87+
}
88+
7889
@Test
7990
public void backgroundMethodIsCalled() {
8091
assertFalse(myListFragment.didExecute);

0 commit comments

Comments
 (0)