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
+ }
0 commit comments