forked from reactor/lite-rx-api-hands-on
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from reactor/master
Update with base
- Loading branch information
Showing
16 changed files
with
517 additions
and
1,525 deletions.
There are no files selected for viewing
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
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
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,97 @@ | ||
/* | ||
* Copyright 2002-2016 the original author or authors. | ||
* | ||
* 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.pivotal.literx; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Supplier; | ||
|
||
import io.pivotal.literx.domain.User; | ||
import static org.junit.Assert.fail; | ||
import org.junit.Test; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
|
||
/** | ||
* Learn how to use StepVerifier to test Mono, Flux or any other kind of Reactive Streams Publisher. | ||
* | ||
* @author Sebastien Deleuze | ||
* @see <a href="http://next.projectreactor.io/ext/docs/api/reactor/test/StepVerifier.html">StepVerifier Javadoc</a> | ||
*/ | ||
public class Part03StepVerifier { | ||
|
||
//======================================================================================== | ||
|
||
@Test | ||
public void expectElementsThenComplete() { | ||
expectFooBarComplete(Flux.just("foo", "bar")); | ||
} | ||
|
||
// TODO Use StepVerifier to check that the flux parameter emits "foo" and "bar" elements then completes successfully. | ||
void expectFooBarComplete(Flux<String> flux) { | ||
fail(); | ||
} | ||
|
||
//======================================================================================== | ||
|
||
@Test | ||
public void expect2ElementsThenError() { | ||
expectFooBarError(Flux.just("foo", "bar").concatWith(Mono.error(new RuntimeException()))); | ||
} | ||
|
||
// TODO Use StepVerifier to check that the flux parameter emits "foo" and "bar" elements then a RuntimeException error. | ||
void expectFooBarError(Flux<String> flux) { | ||
fail(); | ||
} | ||
|
||
//======================================================================================== | ||
|
||
@Test | ||
public void expectElementsWithThenComplete() { | ||
expectSkylerJesseComplete(Flux.just(new User("swhite", null, null), new User("jpinkman", null, null))); | ||
} | ||
|
||
// TODO Use StepVerifier to check that the flux parameter emits a User with "swhite" username and another one with "jpinkman" then completes successfully. | ||
void expectSkylerJesseComplete(Flux<User> flux) { | ||
fail(); | ||
} | ||
|
||
//======================================================================================== | ||
|
||
@Test | ||
public void count() { | ||
expect10Elements(Flux.interval(Duration.ofSeconds(1)).take(10)); | ||
} | ||
|
||
// TODO Expect 10 elements then complete and notice how long it takes for running the test | ||
void expect10Elements(Flux<Long> flux) { | ||
fail(); | ||
} | ||
|
||
//======================================================================================== | ||
|
||
@Test | ||
public void countWithVirtualTime() { | ||
expect3600Elements(() -> Flux.interval(Duration.ofSeconds(1)).take(3600)); | ||
} | ||
|
||
// TODO Expect 3600 elements then complete using the virtual time capabilities provided via StepVerifier.with() and notice how long it takes for running the test | ||
void expect3600Elements(Supplier<Flux<Long>> supplier) { | ||
fail(); | ||
} | ||
|
||
} |
Oops, something went wrong.