Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit c91c2ad

Browse files
committed
Basic ViewAnimator tests
1 parent 4c59e8a commit c91c2ad

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.nhaarman.listviewanimations.appearance;
2+
3+
import android.test.InstrumentationTestCase;
4+
import android.view.View;
5+
6+
import com.nhaarman.listviewanimations.util.ListViewWrapper;
7+
import com.nineoldandroids.animation.Animator;
8+
9+
import org.mockito.Mock;
10+
11+
import static org.mockito.Mockito.*;
12+
import static org.mockito.MockitoAnnotations.*;
13+
14+
@SuppressWarnings({"MagicNumber", "AnonymousInnerClass"})
15+
public class ViewAnimatorTest extends InstrumentationTestCase {
16+
17+
private ViewAnimator mViewAnimator;
18+
19+
@Mock
20+
private ListViewWrapper mListViewWrapper;
21+
22+
@Mock
23+
private View mView;
24+
25+
@Mock
26+
private Animator mAnimator;
27+
28+
@Override
29+
protected void setUp() throws Exception {
30+
super.setUp();
31+
32+
initMocks(this);
33+
34+
mViewAnimator = new ViewAnimator(mListViewWrapper);
35+
}
36+
37+
public void testFirstViewAnimated() {
38+
getInstrumentation().runOnMainSync(
39+
new Runnable() {
40+
@Override
41+
public void run() {
42+
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
43+
}
44+
}
45+
);
46+
47+
verify(mAnimator, timeout(500)).start();
48+
}
49+
50+
public void testSecondViewAnimated() throws InterruptedException {
51+
mViewAnimator.setAnimationDelayMillis(500);
52+
53+
getInstrumentation().runOnMainSync(
54+
new Runnable() {
55+
@Override
56+
public void run() {
57+
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
58+
mViewAnimator.animateViewIfNecessary(1, mView, new Animator[]{mAnimator});
59+
}
60+
}
61+
);
62+
63+
verify(mAnimator, timeout(500)).start();
64+
reset(mAnimator);
65+
Thread.sleep(100);
66+
verify(mAnimator, never()).start();
67+
verify(mAnimator, timeout(500)).start();
68+
}
69+
70+
public void testDisabledAnimations() throws InterruptedException {
71+
mViewAnimator.disableAnimations();
72+
getInstrumentation().runOnMainSync(
73+
new Runnable() {
74+
@Override
75+
public void run() {
76+
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
77+
mViewAnimator.animateViewIfNecessary(1, mView, new Animator[]{mAnimator});
78+
}
79+
}
80+
);
81+
82+
Thread.sleep(10000);
83+
84+
verify(mAnimator, never()).start();
85+
}
86+
87+
public void testSetAnimationDuration() {
88+
mViewAnimator.setAnimationDurationMillis(500);
89+
getInstrumentation().runOnMainSync(
90+
new Runnable() {
91+
@Override
92+
public void run() {
93+
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
94+
}
95+
}
96+
);
97+
98+
verify(mAnimator, timeout(1000)).setDuration(500);
99+
100+
}
101+
102+
}

lib-core/src/main/java/com/nhaarman/listviewanimations/appearance/ViewAnimator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
/**
3636
* A class which decides whether given Views should be animated based on their position: each View should only be animated once.
3737
* It also calculates proper animation delays for the views.
38-
*
39-
* @param the implementation of the ListView being used.
4038
*/
4139
public class ViewAnimator {
4240

0 commit comments

Comments
 (0)