package com.pspdfkit.vangogh.api;

import android.app.Activity;
import android.graphics.Color;
import android.support.test.InstrumentationRegistry;
import android.support.test.annotation.UiThreadTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import com.pspdfkit.vangogh.R;
import com.pspdfkit.vangogh.view.TestActivity;
import io.reactivex.observers.TestObserver;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.TimeUnit;

@RunWith(AndroidJUnit4.class)
public class FadeAnimationsTest {

    @Rule
    public ActivityTestRule<TestActivity> activityRule = new ActivityTestRule<>(TestActivity.class);

    private View view;

    @Before
    public void setUp() {
        view = activityRule.getActivity().findViewById(com.pspdfkit.vangogh.test.R.id.view);
    }

    @Test
    public void testFadeIn() {
        // Init test observer.
        TestObserver o = new TestObserver();
        o.assertNotComplete();

        // Set view to visible and then fade out.
        view.setAlpha(0f);
        FadeAnimations.fadeIn(view).subscribe(o);

        // Wait for onComplete().
        o.awaitDone(2, TimeUnit.SECONDS);
        o.assertComplete();

        // Assert view invisible.
        Assert.assertEquals(1f, view.getAlpha(), 0f);
    }

    @Test
    public void testFadeOut() {
        // Init test observer.
        TestObserver o = new TestObserver();
        o.assertNotComplete();

        // Set view to visible and then fade out.
        view.setAlpha(1f);
        FadeAnimations.fadeOut(view).subscribe(o);

        // Wait for onComplete().
        o.awaitDone(2, TimeUnit.SECONDS);
        o.assertComplete();

        // Assert view invisible.
        Assert.assertEquals(0f, view.getAlpha(), 0f);
    }

}

@@ -1420,32 +1420,988 @@
 (), 0f);%0A    %7D%0A%0A
+    @Test%0A    public void testFadeInWithDuration() throws InterruptedException %7B%0A        final long duration = 1500L;%0A%0A        // Init test observer.%0A        TestObserver o = new TestObserver();%0A        o.assertNotComplete();%0A%0A        // Set view to visible and then fade out.%0A        view.setAlpha(0f);%0A        FadeAnimations.fadeIn(view, duration).subscribe(o);%0A%0A        // Wait one second and make sure it's not completed.%0A        o.await(1, TimeUnit.SECONDS);%0A        o.assertNotComplete();%0A%0A        // Wait another second and make sure it's completed.%0A        o.await(1, TimeUnit.SECONDS);%0A        o.assertComplete();%0A%0A        // Assert view invisible.%0A        Assert.assertEquals(1f, view.getAlpha(), 0f);%0A    %7D%0A%0A    @Test%0A    public void testFadeInWithInterpolator() %7B%0A        // TODO Find a way to test interpolator.%0A    %7D%0A%0A    @Test%0A    public void testFadeInWithDurationAndInterpolator() %7B%0A        // TODO Find a way to test interpolator.%0A    %7D%0A%0A
     @Test%0A    pu

Add fade in tests