Search in sources :

Example 26 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method dynamicRealmResults_emittedOnSubscribe.

@Test
@UiThreadTest
public void dynamicRealmResults_emittedOnSubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<DynamicRealmObject> results = dynamicRealm.where(AllTypes.CLASS_NAME).findAll();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<DynamicRealmObject>>() {

        @Override
        public void call(RealmResults<DynamicRealmObject> rxResults) {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    dynamicRealm.close();
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 27 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method realmResults_emittedOnSubscribe.

@Test
@UiThreadTest
public void realmResults_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<AllTypes>>() {

        @Override
        public void call(RealmResults<AllTypes> rxResults) {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 28 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method findFirst_emittedOnSubscribe.

@Test
@UiThreadTest
public void findFirst_emittedOnSubscribe() {
    realm.beginTransaction();
    realm.createObject(AllTypes.class).setColumnLong(42);
    realm.commitTransaction();
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = realm.where(AllTypes.class).equalTo(AllTypes.FIELD_LONG, 42).findFirst().<AllTypes>asObservable().subscribe(new Action1<AllTypes>() {

        @Override
        public void call(AllTypes rxObject) {
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 29 with Action1

use of rx.functions.Action1 in project realm-java by realm.

the class RxJavaTests method findFirstAsync_emittedOnDelete.

@Test
@RunTestInLooperThread
public void findFirstAsync_emittedOnDelete() {
    final AtomicInteger subscriberCalled = new AtomicInteger(0);
    final Realm realm = looperThread.realm;
    realm.beginTransaction();
    final AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();
    subscription = realm.where(AllTypes.class).findFirstAsync().<AllTypes>asObservable().subscribe(new Action1<AllTypes>() {

        @Override
        public void call(final AllTypes rxObject) {
            switch(subscriberCalled.incrementAndGet()) {
                case 1:
                    assertFalse(rxObject.isLoaded());
                    break;
                case 2:
                    assertTrue(rxObject.isLoaded());
                    assertTrue(rxObject.isValid());
                    realm.executeTransactionAsync(new Realm.Transaction() {

                        @Override
                        public void execute(Realm realm) {
                            realm.delete(AllTypes.class);
                        }
                    });
                    break;
                case 3:
                    assertTrue(rxObject.isLoaded());
                    assertFalse(rxObject.isValid());
                    looperThread.testComplete();
                    break;
                default:
                    fail();
            }
        }
    });
}
Also used : Action1(rx.functions.Action1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AllTypes(io.realm.entities.AllTypes) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Example 30 with Action1

use of rx.functions.Action1 in project SongkickInterview by pakoito.

the class SongkickDetailsActivity method navigateToUrl.

@Override
public Action1<String> navigateToUrl() {
    return new Action1<String>() {

        @Override
        public void call(String url) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(browserIntent);
        }
    };
}
Also used : Action1(rx.functions.Action1) Intent(android.content.Intent)

Aggregations

Action1 (rx.functions.Action1)108 Test (org.junit.Test)33 Action0 (rx.functions.Action0)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 UiThreadTest (android.support.test.annotation.UiThreadTest)20 Observable (rx.Observable)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)11 ArrayList (java.util.ArrayList)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 TestSubscriber (rx.observers.TestSubscriber)10 AllTypes (io.realm.entities.AllTypes)9 List (java.util.List)9 TestCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreakerTest.TestCircuitBreaker)7 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)6 IOException (java.io.IOException)6 Func1 (rx.functions.Func1)6 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)5 Method (java.lang.reflect.Method)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5