@Test(expected = NullPointerException.class) public void composeNull() { just1.compose(null); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_compose_operator_example); /* Compose for reusable code. */ Observable.just(1, 2, 3, 4, 5) .compose(schedulers.<Integer>applyObservableAsync()) .subscribe(/* */); Flowable.just(1, 2, 3, 4, 5) .compose(schedulers.<Integer>applyFlowableAsysnc()) .subscribe(/* */); } }
@SuppressWarnings("unused") @Test public void testCovarianceOfCompose() { Flowable<HorrorMovie> movie = Flowable.just(new HorrorMovie()); Flowable<Movie> movie2 = movie.compose(new FlowableTransformer<HorrorMovie, Movie>() { @Override public Publisher<Movie> apply(Flowable<HorrorMovie> t) { return Flowable.just(new Movie()); } }); }
@Test public void flowableGenericsSignatureTest() { A<String, Integer> a = new A<String, Integer>() { }; Flowable.just(a).compose(TransformerTest.<String>testFlowableTransformerCreator()); }
@SuppressWarnings("unused") @Test public void testCovarianceOfCompose4() { Flowable<HorrorMovie> movie = Flowable.just(new HorrorMovie()); Flowable<HorrorMovie> movie2 = movie.compose(new FlowableTransformer<HorrorMovie, HorrorMovie>() { @Override public Publisher<HorrorMovie> apply(Flowable<HorrorMovie> t1) { return t1.map(new Function<HorrorMovie, HorrorMovie>() { @Override public HorrorMovie apply(HorrorMovie v) { return v; } }); } }); }
@SuppressWarnings("unused") @Test public void testCovarianceOfCompose2() { Flowable<Movie> movie = Flowable.<Movie> just(new HorrorMovie()); Flowable<HorrorMovie> movie2 = movie.compose(new FlowableTransformer<Movie, HorrorMovie>() { @Override public Publisher<HorrorMovie> apply(Flowable<Movie> t) { return Flowable.just(new HorrorMovie()); } }); }
@SuppressWarnings("unused") @Test public void testCovarianceOfCompose3() { Flowable<Movie> movie = Flowable.<Movie>just(new HorrorMovie()); Flowable<HorrorMovie> movie2 = movie.compose(new FlowableTransformer<Movie, HorrorMovie>() { @Override public Publisher<HorrorMovie> apply(Flowable<Movie> t) { return Flowable.just(new HorrorMovie()).map(new Function<HorrorMovie, HorrorMovie>() { @Override public HorrorMovie apply(HorrorMovie v) { return v; } }); } } ); }
@Test public void testComposeWithDeltaLogic() { List<Movie> list1 = Arrays.asList(new Movie(), new HorrorMovie(), new ActionMovie()); List<Movie> list2 = Arrays.asList(new ActionMovie(), new Movie(), new HorrorMovie(), new ActionMovie()); Flowable<List<Movie>> movies = Flowable.just(list1, list2); movies.compose(deltaTransformer); }
@Test public void flowableTransformerThrows() { try { Flowable.just(1).compose(new FlowableTransformer<Integer, Integer>() { @Override public Publisher<Integer> apply(Flowable<Integer> v) { throw new TestException("Forced failure"); } }); fail("Should have thrown!"); } catch (TestException ex) { assertEquals("Forced failure", ex.getMessage()); } }
@Test public void testCompose() { TestSubscriber<String> ts = new TestSubscriber<String>(); Flowable.just(1, 2, 3).compose(new FlowableTransformer<Integer, String>() { @Override public Publisher<String> apply(Flowable<Integer> t1) { return t1.map(new Function<Integer, String>() { @Override public String apply(Integer v) { return String.valueOf(v); } }); } }) .subscribe(ts); ts.assertTerminated(); ts.assertNoErrors(); ts.assertValues("1", "2", "3"); }
@Test public void pollThrowsDelayError() { Flowable.just(1) .map(new Function<Integer, Integer>() { @Override public Integer apply(Integer v) throws Exception { throw new TestException(); } }) .compose(TestHelper.<Integer>flowableStripBoundary()) .concatMapDelayError(new Function<Integer, Publisher<Integer>>() { @Override public Publisher<Integer> apply(Integer v) throws Exception { return Flowable.just(v); } }) .test() .assertFailure(TestException.class); }
@Test public void syncFusedMapCrash() { Flowable.just(1) .map(new Function<Integer, Object>() { @Override public Object apply(Integer v) throws Exception { throw new TestException(); } }) .compose(new StripBoundary<Object>(null)) .parallel() .sequential() .test() .assertFailure(TestException.class); }
@Test public void pollThrows() { Flowable.just(1) .map(new Function<Integer, Object>() { @Override public Object apply(Integer v) throws Exception { throw new TestException(); } }) .compose(TestHelper.flowableStripBoundary()) .publish() .autoConnect() .test() .assertFailure(TestException.class); }
@Test public void pollThrows() { Flowable.just(1) .map(new Function<Integer, Integer>() { @Override public Integer apply(Integer v) throws Exception { throw new TestException(); } }) .compose(TestHelper.<Integer>flowableStripBoundary()) .concatMap(new Function<Integer, Publisher<Integer>>() { @Override public Publisher<Integer> apply(Integer v) throws Exception { return Flowable.just(v); } }) .test() .assertFailure(TestException.class); }
@Test public void pollThrowsNoSubscribers() { ConnectableFlowable<Integer> cf = Flowable.just(1, 2) .map(new Function<Integer, Integer>() { @Override public Integer apply(Integer v) throws Exception { if (v == 2) { throw new TestException(); } return v; } }) .compose(TestHelper.<Integer>flowableStripBoundary()) .publish(); TestSubscriber<Integer> ts = cf.take(1) .test(); cf.connect(); ts.assertResult(1); }
@Test public void fusedInnerCrash() { Flowable.just(1).hide() .switchMap(Functions.justFunction(Flowable.just(1) .map(new Function<Integer, Object>() { @Override public Object apply(Integer v) throws Exception { throw new TestException(); } }) .compose(TestHelper.<Object>flowableStripBoundary()) ) ) .test() .assertFailure(TestException.class); }
@Test public void doOnNextDoOnErrorCombinedFused() { ConnectableFlowable<Integer> cf = Flowable.just(1) .compose(new FlowableTransformer<Integer, Integer>() { @Override public Publisher<Integer> apply(Flowable<Integer> v) {
@Test public void asyncFusedMapCrash() { UnicastProcessor<Integer> up = UnicastProcessor.create(); up.onNext(1); up .map(new Function<Integer, Object>() { @Override public Object apply(Integer v) throws Exception { throw new TestException(); } }) .compose(new StripBoundary<Object>(null)) .parallel() .sequential() .test() .assertFailure(TestException.class); assertFalse(up.hasSubscribers()); }
@Test public void doOnNextDoOnErrorCombinedFusedConditional() { ConnectableFlowable<Integer> cf = Flowable.just(1) .compose(new FlowableTransformer<Integer, Integer>() { @Override public Publisher<Integer> apply(Flowable<Integer> v) {
@Test public void shouldNotRetryFromPredicateUsingFlowable() { //Given RetryConfig config = RetryConfig.custom() .retryOnException(t -> t instanceof IOException) .maxAttempts(3).build(); Retry retry = Retry.of("testName", config); given(helloWorldService.returnHelloWorld()) .willThrow(new WebServiceException("BAM!")); //When Flowable.fromCallable(helloWorldService::returnHelloWorld) .compose(RetryTransformer.of(retry)) .test() .assertError(WebServiceException.class) .assertNotComplete() .assertSubscribed(); //Then BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnHelloWorld(); Retry.Metrics metrics = retry.getMetrics(); assertThat(metrics.getNumberOfFailedCallsWithoutRetryAttempt()).isEqualTo(1); assertThat(metrics.getNumberOfFailedCallsWithRetryAttempt()).isEqualTo(0); }