Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeCountTest.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.operators.maybe;
15
16 import static org.junit.Assert.*;
17
18 import org.junit.Test;
19
20 import io.reactivex.rxjava3.core.*;
21 import io.reactivex.rxjava3.exceptions.TestException;
22 import io.reactivex.rxjava3.functions.Function;
23 import io.reactivex.rxjava3.internal.fuseable.HasUpstreamMaybeSource;
24 import io.reactivex.rxjava3.observers.TestObserver;
25 import io.reactivex.rxjava3.processors.PublishProcessor;
26 import io.reactivex.rxjava3.testsupport.TestHelper;
27
28 public class MaybeCountTest extends RxJavaTest {
29
30 @Test
31 public void one() {
32 Maybe.just(1).count().test().assertResult(1L);
33 }
34
35 @Test
36 public void empty() {
37 Maybe.empty().count().test().assertResult(0L);
38 }
39
40 @Test
41 public void error() {
42 Maybe.error(new TestException()).count().test().assertFailure(TestException.class);
43 }
44
45 @Test
46 public void dispose() {
47 PublishProcessor<Integer> pp = PublishProcessor.create();
48
49 TestObserver<Long> to = pp.singleElement().count().test();
50
51 assertTrue(pp.hasSubscribers());
52
53 to.dispose();
54
55 assertFalse(pp.hasSubscribers());
56 }
57
58 @Test
59 public void isDisposed() {
60 PublishProcessor<Integer> pp = PublishProcessor.create();
61
62 TestHelper.checkDisposed(pp.singleElement().count());
63 }
64
65 @Test
66 public void doubleOnSubscribe() {
67 TestHelper.checkDoubleOnSubscribeMaybeToSingle(new Function<Maybe<Object>, SingleSource<Long>>() {
68 @Override
69 public SingleSource<Long> apply(Maybe<Object> f) throws Exception {
70 return f.count();
71 }
72 });
73 }
74
75 @SuppressWarnings("unchecked")
76 @Test
77 public void hasSource() {
78 assertSame(Maybe.empty(), ((HasUpstreamMaybeSource<Object>)(Maybe.empty().count())).source());
79 }
80 }