Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/observable/ObservableCastTest.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.observable;
15
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.*;
18
19 import org.junit.Test;
20
21 import io.reactivex.rxjava3.core.*;
22 import io.reactivex.rxjava3.testsupport.TestHelper;
23
24 public class ObservableCastTest extends RxJavaTest {
25
26 @Test
27 public void cast() {
28 Observable<?> source = Observable.just(1, 2);
29 Observable<Integer> observable = source.cast(Integer.class);
30
31 Observer<Integer> observer = TestHelper.mockObserver();
32
33 observable.subscribe(observer);
34
35 verify(observer, times(1)).onNext(1);
36 verify(observer, times(1)).onNext(1);
37 verify(observer, never()).onError(
38 any(Throwable.class));
39 verify(observer, times(1)).onComplete();
40 }
41
42 @Test
43 public void castWithWrongType() {
44 Observable<?> source = Observable.just(1, 2);
45 Observable<Boolean> observable = source.cast(Boolean.class);
46
47 Observer<Boolean> observer = TestHelper.mockObserver();
48
49 observable.subscribe(observer);
50
51 verify(observer, times(1)).onError(
52 any(ClassCastException.class));
53 }
54 }