Skip to content

Commit

Permalink
Basic ViewAnimator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaarman committed Aug 13, 2014
1 parent 4c59e8a commit c91c2ad
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.nhaarman.listviewanimations.appearance;

import android.test.InstrumentationTestCase;
import android.view.View;

import com.nhaarman.listviewanimations.util.ListViewWrapper;
import com.nineoldandroids.animation.Animator;

import org.mockito.Mock;

import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.*;

@SuppressWarnings({"MagicNumber", "AnonymousInnerClass"})
public class ViewAnimatorTest extends InstrumentationTestCase {

private ViewAnimator mViewAnimator;

@Mock
private ListViewWrapper mListViewWrapper;

@Mock
private View mView;

@Mock
private Animator mAnimator;

@Override
protected void setUp() throws Exception {
super.setUp();

initMocks(this);

mViewAnimator = new ViewAnimator(mListViewWrapper);
}

public void testFirstViewAnimated() {
getInstrumentation().runOnMainSync(
new Runnable() {
@Override
public void run() {
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
}
}
);

verify(mAnimator, timeout(500)).start();
}

public void testSecondViewAnimated() throws InterruptedException {
mViewAnimator.setAnimationDelayMillis(500);

getInstrumentation().runOnMainSync(
new Runnable() {
@Override
public void run() {
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
mViewAnimator.animateViewIfNecessary(1, mView, new Animator[]{mAnimator});
}
}
);

verify(mAnimator, timeout(500)).start();
reset(mAnimator);
Thread.sleep(100);
verify(mAnimator, never()).start();
verify(mAnimator, timeout(500)).start();
}

public void testDisabledAnimations() throws InterruptedException {
mViewAnimator.disableAnimations();
getInstrumentation().runOnMainSync(
new Runnable() {
@Override
public void run() {
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
mViewAnimator.animateViewIfNecessary(1, mView, new Animator[]{mAnimator});
}
}
);

Thread.sleep(10000);

verify(mAnimator, never()).start();
}

public void testSetAnimationDuration() {
mViewAnimator.setAnimationDurationMillis(500);
getInstrumentation().runOnMainSync(
new Runnable() {
@Override
public void run() {
mViewAnimator.animateViewIfNecessary(0, mView, new Animator[]{mAnimator});
}
}
);

verify(mAnimator, timeout(1000)).setDuration(500);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
/**
* A class which decides whether given Views should be animated based on their position: each View should only be animated once.
* It also calculates proper animation delays for the views.
*
* @param the implementation of the ListView being used.
*/
public class ViewAnimator {

Expand Down

0 comments on commit c91c2ad

Please sign in to comment.