Search in sources :

Example 41 with ObservableSource

use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.

the class JavadocWording method singleDocRefersToSingleTypes.

@Test
public void singleDocRefersToSingleTypes() throws Exception {
    List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Single"), "Single");
    assertFalse(list.isEmpty());
    StringBuilder e = new StringBuilder();
    for (RxMethod m : list) {
        int jdx;
        if (m.javadoc != null) {
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("onNext", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Publisher") && !m.signature.contains("Flowable") && !m.signature.contains("Observable") && !m.signature.contains("ObservableSource")) {
                        e.append("java.lang.RuntimeException: Single doc mentions onNext but no Flowable/Observable in signature\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Subscriber", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Publisher") && !m.signature.contains("Flowable") && !m.signature.contains("TestSubscriber")) {
                        e.append("java.lang.RuntimeException: Single doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Subscription", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Flowable") && !m.signature.contains("Publisher")) {
                        e.append("java.lang.RuntimeException: Single doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Observer", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource") && !m.signature.contains("Observable") && !m.signature.contains("TestObserver")) {
                        if (idx < 6 || !m.javadoc.substring(idx - 6, idx + 8).equals("SingleObserver")) {
                            e.append("java.lang.RuntimeException: Single doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Publisher", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Publisher")) {
                        if (idx == 0 || !m.javadoc.substring(idx - 1, idx + 9).equals("(Publisher")) {
                            e.append("java.lang.RuntimeException: Single doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Flowable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Flowable")) {
                        e.append("java.lang.RuntimeException: Single doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Maybe", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Maybe")) {
                        e.append("java.lang.RuntimeException: Single doc mentions Maybe but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" MaybeSource", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("MaybeSource")) {
                        e.append("java.lang.RuntimeException: Single doc mentions SingleSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Maybe.method(Maybe.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Observable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Observable")) {
                        e.append("java.lang.RuntimeException: Single doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" ObservableSource", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource")) {
                        e.append("java.lang.RuntimeException: Single doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Single.method(Single.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            checkAtReturnAndSignatureMatch("Single", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
            aOrAn(e, m, "Single");
            missingClosingDD(e, m, "Single", "io.reactivex.rxjava3.core");
            backpressureMentionedWithoutAnnotation(e, m, "Single");
        }
    }
    if (e.length() != 0) {
        System.out.println(e);
        fail(e.toString());
    }
}
Also used : RxMethod(io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod) Test(org.junit.Test)

Example 42 with ObservableSource

use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.

the class JavadocWording method completableDocRefersToCompletableTypes.

@Test
public void completableDocRefersToCompletableTypes() throws Exception {
    List<RxMethod> list = BaseTypeParser.parse(TestHelper.findSource("Completable"), "Completable");
    assertFalse(list.isEmpty());
    StringBuilder e = new StringBuilder();
    for (RxMethod m : list) {
        int jdx;
        if (m.javadoc != null) {
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("onNext", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Publisher") && !m.signature.contains("Flowable") && !m.signature.contains("Observable") && !m.signature.contains("ObservableSource")) {
                        e.append("java.lang.RuntimeException: Completable doc mentions onNext but no Flowable/Observable in signature\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Subscriber", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Publisher") && !m.signature.contains("Flowable") && !m.signature.contains("TestSubscriber")) {
                        e.append("java.lang.RuntimeException: Completable doc mentions Subscriber but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Subscription", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Flowable") && !m.signature.contains("Publisher")) {
                        e.append("java.lang.RuntimeException: Completable doc mentions Subscription but not using Flowable\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Observer", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource") && !m.signature.contains("Observable") && !m.signature.contains("TestObserver")) {
                        if (idx < 11 || !m.javadoc.substring(idx - 11, idx + 8).equals("CompletableObserver")) {
                            e.append("java.lang.RuntimeException: Completable doc mentions Observer but not using Observable\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Publisher", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Publisher")) {
                        if (idx == 0 || !m.javadoc.substring(idx - 1, idx + 9).equals("(Publisher")) {
                            e.append("java.lang.RuntimeException: Completable doc mentions Publisher but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Flowable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Flowable")) {
                        Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Flowable");
                        if (!p.matcher(m.javadoc).find()) {
                            e.append("java.lang.RuntimeException: Completable doc mentions Flowable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("Single", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Single")) {
                        Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Single");
                        if (!p.matcher(m.javadoc).find()) {
                            e.append("java.lang.RuntimeException: Completable doc mentions Single but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("SingleSource", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("SingleSource")) {
                        Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*SingleSource");
                        if (!p.matcher(m.javadoc).find()) {
                            e.append("java.lang.RuntimeException: Completable doc mentions SingleSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf(" Observable", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("Observable")) {
                        Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*Observable");
                        if (!p.matcher(m.javadoc).find()) {
                            e.append("java.lang.RuntimeException: Completable doc mentions Observable but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            jdx = 0;
            for (; ; ) {
                int idx = m.javadoc.indexOf("ObservableSource", jdx);
                if (idx >= 0) {
                    if (!m.signature.contains("ObservableSource")) {
                        Pattern p = Pattern.compile("@see\\s+#[A-Za-z0-9 _.,()]*ObservableSource");
                        if (!p.matcher(m.javadoc).find()) {
                            e.append("java.lang.RuntimeException: Completable doc mentions ObservableSource but not in the signature\r\n at io.reactivex.rxjava3.core.").append("Completable.method(Completable.java:").append(m.javadocLine + lineNumber(m.javadoc, idx) - 1).append(")\r\n\r\n");
                        }
                    }
                    jdx = idx + 6;
                } else {
                    break;
                }
            }
            checkAtReturnAndSignatureMatch("Completable", m, e, "Flowable", "Observable", "Maybe", "Single", "Completable", "Disposable", "Iterable", "Stream", "Future", "CompletionStage");
            aOrAn(e, m, "Completable");
            missingClosingDD(e, m, "Completable", "io.reactivex.rxjava3.core");
            backpressureMentionedWithoutAnnotation(e, m, "Completable");
        }
    }
    if (e.length() != 0) {
        System.out.println(e);
        fail(e.toString());
    }
}
Also used : RxMethod(io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod) Pattern(java.util.regex.Pattern) Test(org.junit.Test)

Example 43 with ObservableSource

use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.

the class ObservableDoOnEachTest method onErrorAfterCrash.

@Test
public void onErrorAfterCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Observable.wrap(new ObservableSource<Object>() {

            @Override
            public void subscribe(Observer<? super Object> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onError(new TestException());
            }
        }).doAfterTerminate(new Action() {

            @Override
            public void run() throws Exception {
                throw new IOException();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) IOException(java.io.IOException)

Example 44 with ObservableSource

use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.

the class ObservableDoOnEachTest method ignoreCancel.

@Test
public void ignoreCancel() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Observable.wrap(new ObservableSource<Object>() {

            @Override
            public void subscribe(Observer<? super Object> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onError(new IOException());
                observer.onComplete();
            }
        }).doOnNext(new Consumer<Object>() {

            @Override
            public void accept(Object e) throws Exception {
                throw new TestException();
            }
        }).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) IOException(java.io.IOException)

Example 45 with ObservableSource

use of io.reactivex.rxjava3.core.ObservableSource in project RxJava by ReactiveX.

the class ObservableDistinctUntilChangedTest method ignoreCancel.

@Test
public void ignoreCancel() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Observable.wrap(new ObservableSource<Integer>() {

            @Override
            public void subscribe(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onNext(1);
                observer.onNext(2);
                observer.onNext(3);
                observer.onError(new IOException());
                observer.onComplete();
            }
        }).distinctUntilChanged(new BiPredicate<Integer, Integer>() {

            @Override
            public boolean test(Integer a, Integer b) throws Exception {
                throw new TestException();
            }
        }).test().assertFailure(TestException.class, 1);
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) IOException(java.io.IOException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)21 Observable (io.reactivex.rxjava3.core.Observable)20 TestException (io.reactivex.rxjava3.exceptions.TestException)12 InOrder (org.mockito.InOrder)12 TestObserver (io.reactivex.rxjava3.observers.TestObserver)9 IOException (java.io.IOException)8 Observer (io.reactivex.rxjava3.core.Observer)5 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ObservableSource (io.reactivex.rxjava3.core.ObservableSource)4 Function (io.reactivex.rxjava3.functions.Function)4 Intent (android.content.Intent)3 Disposable (io.reactivex.rxjava3.disposables.Disposable)3 File (java.io.File)3 View (android.view.View)2 RxPermissionTransformer (com.xxf.permission.transformer.RxPermissionTransformer)2 Supplier (io.reactivex.rxjava3.functions.Supplier)2 GroupedObservable (io.reactivex.rxjava3.observables.GroupedObservable)2 ArrayList (java.util.ArrayList)2 Callable (java.util.concurrent.Callable)2