| 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 MaybeContainsTest extends RxJavaTest { |
| 29 |
|
| 30 |
@Test |
| 31 |
public void doesContain() { |
| 32 |
Maybe.just(1).contains(1).test().assertResult(true); |
| 33 |
} |
| 34 |
|
| 35 |
@Test |
| 36 |
public void doesntContain() { |
| 37 |
Maybe.just(1).contains(2).test().assertResult(false); |
| 38 |
} |
| 39 |
|
| 40 |
@Test |
| 41 |
public void empty() { |
| 42 |
Maybe.empty().contains(2).test().assertResult(false); |
| 43 |
} |
| 44 |
|
| 45 |
@Test |
| 46 |
public void error() { |
| 47 |
Maybe.error(new TestException()).contains(2).test().assertFailure(TestException.class); |
| 48 |
} |
| 49 |
|
| 50 |
@Test |
| 51 |
public void dispose() { |
| 52 |
PublishProcessor<Integer> pp = PublishProcessor.create(); |
| 53 |
|
| 54 |
TestObserver<Boolean> to = pp.singleElement().contains(1).test(); |
| 55 |
|
| 56 |
assertTrue(pp.hasSubscribers()); |
| 57 |
|
| 58 |
to.dispose(); |
| 59 |
|
| 60 |
assertFalse(pp.hasSubscribers()); |
| 61 |
} |
| 62 |
|
| 63 |
@Test |
| 64 |
public void isDisposed() { |
| 65 |
PublishProcessor<Integer> pp = PublishProcessor.create(); |
| 66 |
|
| 67 |
TestHelper.checkDisposed(pp.singleElement().contains(1)); |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
public void doubleOnSubscribe() { |
| 72 |
TestHelper.checkDoubleOnSubscribeMaybeToSingle(new Function<Maybe<Object>, SingleSource<Boolean>>() { |
| 73 |
@Override |
| 74 |
public SingleSource<Boolean> apply(Maybe<Object> f) throws Exception { |
| 75 |
return f.contains(1); |
| 76 |
} |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
@SuppressWarnings("unchecked") |
| 81 |
@Test |
| 82 |
public void hasSource() { |
| 83 |
assertSame(Maybe.empty(), ((HasUpstreamMaybeSource<Object>)(Maybe.empty().contains(0))).source()); |
| 84 |
} |
| 85 |
} |