/**
* Copyright 2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/
package io.reactivex.observers;
import io.reactivex.Observable;
import io.reactivex.functions.*;
import io.reactivex.internal.fuseable.*;
/**
* Utility methods that return functional interfaces to support assertions regarding fusion
* in a TestObserver.
*
Don't move this class as it needs package-private access to TestObserver's internals.
*/
public enum ObserverFusion {
;
/**
* Returns a function that takes a Flowable and returns a TestObserver that
* is set up according to the parameters and is subscribed to the Flowable.
*
* @param the value type
* @param mode the fusion mode to request, see {@link QueueDisposable} constants.
* @param cancelled should the TestObserver cancelled before the subscription even happens?
* @return the new Function instance
*/
public static Function, TestObserver> test(
final int mode, final boolean cancelled) {
return new Function, TestObserver>() {
@Override
public TestObserver apply(Observable t) throws Exception {
TestObserver ts = new TestObserver();
ts.setInitialFusionMode(mode);
if (cancelled) {
ts.cancel();
}
t.subscribe(ts);
return ts;
}
};
}
/**
* Returns a Consumer that asserts on its TestObserver parameter that
* the upstream is Fuseable (sent a QueueDisposable subclass in onSubscribe).
*
* @param the value type
* @return the new Consumer instance
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Consumer> assertFuseable() {
return (Consumer)AssertFuseable.INSTANCE;
}
enum AssertFuseable implements Consumer> {
INSTANCE;
@Override
public void accept(TestObserver