Search in sources :

Example 1 with Nullable

use of io.reactivex.annotations.Nullable in project RxJava by ReactiveX.

the class FlowableObserveOnTest method asycFusedPollThrows.

@Test
public void asycFusedPollThrows() {
    new Flowable<Integer>() {

        @Override
        protected void subscribeActual(Subscriber<? super Integer> observer) {
            observer.onSubscribe(new BooleanSubscription());
            @SuppressWarnings("unchecked") BaseObserveOnSubscriber<Integer> oo = (BaseObserveOnSubscriber<Integer>) observer;
            oo.sourceMode = QueueFuseable.ASYNC;
            oo.requested.lazySet(1);
            oo.queue = new SimpleQueue<Integer>() {

                @Override
                public boolean offer(Integer value) {
                    return false;
                }

                @Override
                public boolean offer(Integer v1, Integer v2) {
                    return false;
                }

                @Nullable
                @Override
                public Integer poll() throws Exception {
                    throw new TestException();
                }

                @Override
                public boolean isEmpty() {
                    return false;
                }

                @Override
                public void clear() {
                }
            };
            oo.clear();
            oo.trySchedule();
        }
    }.observeOn(Schedulers.single()).test(0L).awaitDone(5, TimeUnit.SECONDS).assertFailure(TestException.class);
}
Also used : BaseObserveOnSubscriber(io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) BaseObserveOnSubscriber(io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber) Nullable(io.reactivex.annotations.Nullable) Test(org.junit.Test)

Example 2 with Nullable

use of io.reactivex.annotations.Nullable in project RxJava by ReactiveX.

the class FlowableObserveOnTest method nonFusedPollThrows.

@Test
public void nonFusedPollThrows() {
    new Flowable<Integer>() {

        @Override
        protected void subscribeActual(Subscriber<? super Integer> observer) {
            observer.onSubscribe(new BooleanSubscription());
            @SuppressWarnings("unchecked") BaseObserveOnSubscriber<Integer> oo = (BaseObserveOnSubscriber<Integer>) observer;
            oo.sourceMode = QueueFuseable.SYNC;
            oo.requested.lazySet(1);
            oo.queue = new SimpleQueue<Integer>() {

                @Override
                public boolean offer(Integer value) {
                    return false;
                }

                @Override
                public boolean offer(Integer v1, Integer v2) {
                    return false;
                }

                @Nullable
                @Override
                public Integer poll() throws Exception {
                    throw new TestException();
                }

                @Override
                public boolean isEmpty() {
                    return false;
                }

                @Override
                public void clear() {
                }
            };
            oo.clear();
            oo.trySchedule();
        }
    }.observeOn(Schedulers.single()).test(0L).awaitDone(5, TimeUnit.SECONDS).assertFailure(TestException.class);
}
Also used : BaseObserveOnSubscriber(io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) BaseObserveOnSubscriber(io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber) Nullable(io.reactivex.annotations.Nullable) Test(org.junit.Test)

Example 3 with Nullable

use of io.reactivex.annotations.Nullable in project collect by opendatakit.

the class AuditEventLogger method getMostAccurateLocation.

@Nullable
private Location getMostAccurateLocation(long currentTime) {
    removeExpiredLocations(currentTime);
    Location bestLocation = null;
    if (!locations.isEmpty()) {
        for (Location location : locations) {
            if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) {
                bestLocation = location;
            }
        }
    }
    return bestLocation;
}
Also used : Location(android.location.Location) Nullable(io.reactivex.annotations.Nullable)

Example 4 with Nullable

use of io.reactivex.annotations.Nullable in project RxJava by ReactiveX.

the class ObservableObserveOnTest method nonFusedPollThrows.

@Test
public void nonFusedPollThrows() {
    new Observable<Integer>() {

        @Override
        protected void subscribeActual(Observer<? super Integer> observer) {
            observer.onSubscribe(Disposables.empty());
            @SuppressWarnings("unchecked") ObserveOnObserver<Integer> oo = (ObserveOnObserver<Integer>) observer;
            oo.queue = new SimpleQueue<Integer>() {

                @Override
                public boolean offer(Integer value) {
                    return false;
                }

                @Override
                public boolean offer(Integer v1, Integer v2) {
                    return false;
                }

                @Nullable
                @Override
                public Integer poll() throws Exception {
                    throw new TestException();
                }

                @Override
                public boolean isEmpty() {
                    return false;
                }

                @Override
                public void clear() {
                }
            };
            oo.clear();
            oo.schedule();
        }
    }.observeOn(Schedulers.single()).test().awaitDone(5, TimeUnit.SECONDS).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.exceptions.TestException) ObserveOnObserver(io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver) Observer(io.reactivex.Observer) ObserveOnObserver(io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver) Observable(io.reactivex.Observable) Nullable(io.reactivex.annotations.Nullable) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 5 with Nullable

use of io.reactivex.annotations.Nullable in project Alarmio by TheAndroidMaster.

the class Alarmio method getSunsetCalculator.

@Nullable
private SunriseSunsetCalculator getSunsetCalculator() {
    if (sunsetCalculator == null && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        try {
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            android.location.Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(new Criteria(), false));
            sunsetCalculator = new SunriseSunsetCalculator(new Location(location.getLatitude(), location.getLongitude()), TimeZone.getDefault().getID());
        } catch (NullPointerException ignored) {
        }
    }
    return sunsetCalculator;
}
Also used : LocationManager(android.location.LocationManager) SunriseSunsetCalculator(com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator) Criteria(android.location.Criteria) Location(com.luckycatlabs.sunrisesunset.dto.Location) Nullable(io.reactivex.annotations.Nullable)

Aggregations

Nullable (io.reactivex.annotations.Nullable)6 Test (org.junit.Test)3 BaseObserveOnSubscriber (io.reactivex.internal.operators.flowable.FlowableObserveOn.BaseObserveOnSubscriber)2 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)2 Criteria (android.location.Criteria)1 Location (android.location.Location)1 LocationManager (android.location.LocationManager)1 SunriseSunsetCalculator (com.luckycatlabs.sunrisesunset.SunriseSunsetCalculator)1 Location (com.luckycatlabs.sunrisesunset.dto.Location)1 Observable (io.reactivex.Observable)1 Observer (io.reactivex.Observer)1 TestException (io.reactivex.exceptions.TestException)1 ObserveOnObserver (io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver)1 Calendar (java.util.Calendar)1