-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.x: Add concatMapX operators (aliases) (#6879)
- Loading branch information
Showing
10 changed files
with
1,063 additions
and
241 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...est/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeConcatMapCompletableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* 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.rxjava3.internal.operators.maybe; | ||
|
||
import org.junit.Test; | ||
|
||
import io.reactivex.rxjava3.core.*; | ||
import io.reactivex.rxjava3.exceptions.TestException; | ||
import io.reactivex.rxjava3.functions.Function; | ||
import io.reactivex.rxjava3.testsupport.TestHelper; | ||
|
||
public class MaybeConcatMapCompletableTest extends RxJavaTest { | ||
|
||
@Test | ||
public void dispose() { | ||
TestHelper.checkDisposed(Maybe.just(1).concatMapCompletable(new Function<Integer, Completable>() { | ||
@Override | ||
public Completable apply(Integer v) throws Exception { | ||
return Completable.complete(); | ||
} | ||
})); | ||
} | ||
|
||
@Test | ||
public void mapperThrows() { | ||
Maybe.just(1) | ||
.concatMapCompletable(new Function<Integer, Completable>() { | ||
@Override | ||
public Completable apply(Integer v) throws Exception { | ||
throw new TestException(); | ||
} | ||
}) | ||
.test() | ||
.assertFailure(TestException.class); | ||
} | ||
|
||
@Test | ||
public void mapperReturnsNull() { | ||
Maybe.just(1) | ||
.concatMapCompletable(new Function<Integer, Completable>() { | ||
@Override | ||
public Completable apply(Integer v) throws Exception { | ||
return null; | ||
} | ||
}) | ||
.test() | ||
.assertFailure(NullPointerException.class); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
src/test/java/io/reactivex/rxjava3/internal/operators/maybe/MaybeConcatMapSingleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* 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.rxjava3.internal.operators.maybe; | ||
|
||
import org.junit.Test; | ||
|
||
import io.reactivex.rxjava3.core.*; | ||
import io.reactivex.rxjava3.exceptions.TestException; | ||
import io.reactivex.rxjava3.functions.Function; | ||
import io.reactivex.rxjava3.testsupport.TestHelper; | ||
|
||
public class MaybeConcatMapSingleTest extends RxJavaTest { | ||
@Test | ||
public void flatMapSingleElementValue() { | ||
Maybe.just(1).concatMapSingle(new Function<Integer, SingleSource<Integer>>() { | ||
@Override public SingleSource<Integer> apply(final Integer integer) throws Exception { | ||
if (integer == 1) { | ||
return Single.just(2); | ||
} | ||
|
||
return Single.just(1); | ||
} | ||
}) | ||
.test() | ||
.assertResult(2); | ||
} | ||
|
||
@Test | ||
public void flatMapSingleElementValueDifferentType() { | ||
Maybe.just(1).concatMapSingle(new Function<Integer, SingleSource<String>>() { | ||
@Override public SingleSource<String> apply(final Integer integer) throws Exception { | ||
if (integer == 1) { | ||
return Single.just("2"); | ||
} | ||
|
||
return Single.just("1"); | ||
} | ||
}) | ||
.test() | ||
.assertResult("2"); | ||
} | ||
|
||
@Test | ||
public void flatMapSingleElementValueNull() { | ||
Maybe.just(1).concatMapSingle(new Function<Integer, SingleSource<Integer>>() { | ||
@Override public SingleSource<Integer> apply(final Integer integer) throws Exception { | ||
return null; | ||
} | ||
}) | ||
.to(TestHelper.<Integer>testConsumer()) | ||
.assertNoValues() | ||
.assertError(NullPointerException.class) | ||
.assertErrorMessage("The mapper returned a null SingleSource"); | ||
} | ||
|
||
@Test | ||
public void flatMapSingleElementValueErrorThrown() { | ||
Maybe.just(1).concatMapSingle(new Function<Integer, SingleSource<Integer>>() { | ||
@Override public SingleSource<Integer> apply(final Integer integer) throws Exception { | ||
throw new RuntimeException("something went terribly wrong!"); | ||
} | ||
}) | ||
.to(TestHelper.<Integer>testConsumer()) | ||
.assertNoValues() | ||
.assertError(RuntimeException.class) | ||
.assertErrorMessage("something went terribly wrong!"); | ||
} | ||
|
||
@Test | ||
public void flatMapSingleElementError() { | ||
RuntimeException exception = new RuntimeException("test"); | ||
|
||
Maybe.error(exception).concatMapSingle(new Function<Object, SingleSource<Object>>() { | ||
@Override public SingleSource<Object> apply(final Object integer) throws Exception { | ||
return Single.just(new Object()); | ||
} | ||
}) | ||
.test() | ||
.assertError(exception); | ||
} | ||
|
||
@Test | ||
public void flatMapSingleElementEmpty() { | ||
Maybe.<Integer>empty().concatMapSingle(new Function<Integer, SingleSource<Integer>>() { | ||
@Override public SingleSource<Integer> apply(final Integer integer) throws Exception { | ||
return Single.just(2); | ||
} | ||
}) | ||
.test() | ||
.assertNoValues() | ||
.assertResult(); | ||
} | ||
|
||
@Test | ||
public void dispose() { | ||
TestHelper.checkDisposed(Maybe.just(1).concatMapSingle(new Function<Integer, SingleSource<Integer>>() { | ||
@Override | ||
public SingleSource<Integer> apply(final Integer integer) throws Exception { | ||
return Single.just(2); | ||
} | ||
})); | ||
} | ||
|
||
@Test | ||
public void doubleOnSubscribe() { | ||
TestHelper.checkDoubleOnSubscribeMaybe(new Function<Maybe<Integer>, Maybe<Integer>>() { | ||
@Override | ||
public Maybe<Integer> apply(Maybe<Integer> m) throws Exception { | ||
return m.concatMapSingle(new Function<Integer, SingleSource<Integer>>() { | ||
@Override | ||
public SingleSource<Integer> apply(final Integer integer) throws Exception { | ||
return Single.just(2); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void singleErrors() { | ||
Maybe.just(1) | ||
.concatMapSingle(new Function<Integer, SingleSource<Integer>>() { | ||
@Override | ||
public SingleSource<Integer> apply(final Integer integer) throws Exception { | ||
return Single.error(new TestException()); | ||
} | ||
}) | ||
.test() | ||
.assertFailure(TestException.class); | ||
} | ||
} |
Oops, something went wrong.