Search in sources :

Example 21 with Action

use of io.reactivex.functions.Action in project requery by requery.

the class ReactiveTest method testQueryEmpty.

@Test
public void testQueryEmpty() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    data.select(Person.class).get().observable().subscribe(new Consumer<Person>() {

        @Override
        public void accept(Person person) throws Exception {
            Assert.fail();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            Assert.fail();
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            latch.countDown();
        }
    });
    if (!latch.await(1, TimeUnit.SECONDS)) {
        Assert.fail();
    }
}
Also used : Action(io.reactivex.functions.Action) CountDownLatch(java.util.concurrent.CountDownLatch) Person(io.requery.test.model.Person) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 22 with Action

use of io.reactivex.functions.Action in project RxJava by ReactiveX.

the class CompletableTimeoutTest method timeoutContinueOther.

@Test
public void timeoutContinueOther() throws Exception {
    final int[] call = { 0 };
    Completable other = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            call[0]++;
        }
    });
    Completable.never().timeout(100, TimeUnit.MILLISECONDS, Schedulers.io(), other).test().awaitDone(5, TimeUnit.SECONDS).assertResult();
    assertEquals(1, call[0]);
}
Also used : Action(io.reactivex.functions.Action) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 23 with Action

use of io.reactivex.functions.Action in project RxJava by ReactiveX.

the class CompletableFromActionTest method fromActionInvokesLazy.

@Test
public void fromActionInvokesLazy() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable completable = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            atomicInteger.incrementAndGet();
        }
    });
    assertEquals(0, atomicInteger.get());
    completable.test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : Completable(io.reactivex.Completable) Action(io.reactivex.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 24 with Action

use of io.reactivex.functions.Action in project RxJava by ReactiveX.

the class CompletableFromActionTest method fromAction.

@Test
public void fromAction() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            atomicInteger.incrementAndGet();
        }
    }).test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : Action(io.reactivex.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 25 with Action

use of io.reactivex.functions.Action in project RxJava by ReactiveX.

the class FlowableUnsubscribeOnTest method error.

@Test
public void error() {
    final int[] calls = { 0 };
    Flowable.error(new TestException()).doOnCancel(new Action() {

        @Override
        public void run() throws Exception {
            calls[0]++;
        }
    }).unsubscribeOn(Schedulers.single()).test().assertFailure(TestException.class);
    assertEquals(0, calls[0]);
}
Also used : Action(io.reactivex.functions.Action) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Aggregations

Action (io.reactivex.functions.Action)31 Test (org.junit.Test)19 TestException (io.reactivex.exceptions.TestException)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Consumer (io.reactivex.functions.Consumer)5 Disposable (io.reactivex.disposables.Disposable)4 TestScheduler (io.reactivex.schedulers.TestScheduler)3 View (android.view.View)2 NonNull (io.reactivex.annotations.NonNull)2 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 Toolbar (android.support.v7.widget.Toolbar)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 ActionBarProvider (com.bluelinelabs.conductor.demo.ActionBarProvider)1 ActionBarOwner (com.example.mortar.android.ActionBarOwner)1 ChatListScreen (com.example.mortar.screen.ChatListScreen)1