File tree Expand file tree Collapse file tree 6 files changed +56
-42
lines changed
chapter-5/chapter-5-quarkus-kafka-streams
main/java/org/acme/service Expand file tree Collapse file tree 6 files changed +56
-42
lines changed Original file line number Diff line number Diff line change 1616 <quarkus .platform.group-id>io.quarkus</quarkus .platform.group-id>
1717 <quarkus .platform.version>2.0.3.Final</quarkus .platform.version>
1818 <surefire-plugin .version>3.0.0-M5</surefire-plugin .version>
19- <testcontainers .version>1.16.0</testcontainers .version>
2019 </properties >
2120 <dependencyManagement >
2221 <dependencies >
2726 <type >pom</type >
2827 <scope >import</scope >
2928 </dependency >
30- <dependency >
31- <groupId >org.testcontainers</groupId >
32- <artifactId >testcontainers-bom</artifactId >
33- <version >${testcontainers.version} </version >
34- <type >pom</type >
35- <scope >import</scope >
36- </dependency >
3729 </dependencies >
3830 </dependencyManagement >
3931 <dependencies >
7062 <scope >test</scope >
7163 </dependency >
7264 <dependency >
73- <groupId >org.testcontainers </groupId >
74- <artifactId >testcontainers </artifactId >
65+ <groupId >org.assertj </groupId >
66+ <artifactId >assertj-core </artifactId >
7567 <scope >test</scope >
7668 </dependency >
7769 </dependencies >
Original file line number Diff line number Diff line change 1313 */
1414@ ApplicationScoped
1515public class PriceConverter {
16- private static final double CONVERSION_RATE = 0.88 ;
16+ static final double CONVERSION_RATE = 0.88 ;
1717
1818 // Consume from the `prices` channel and produce to the `my-data-stream` channel
1919 @ Incoming ("prices" )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1212import javax .ws .rs .client .WebTarget ;
1313import javax .ws .rs .sse .SseEventSource ;
1414
15- import org .acme .DockerComposeResource ;
1615import org .junit .jupiter .api .Test ;
1716
18- import io .quarkus .test .common .QuarkusTestResource ;
1917import io .quarkus .test .common .http .TestHTTPEndpoint ;
2018import io .quarkus .test .common .http .TestHTTPResource ;
2119import io .quarkus .test .junit .QuarkusTest ;
2220
2321@ QuarkusTest
24- @ QuarkusTestResource (DockerComposeResource .class )
2522class PriceResourceTest {
2623 @ TestHTTPEndpoint (PriceResource .class )
2724 @ TestHTTPResource ("/stream" )
Original file line number Diff line number Diff line change 1+ package org .acme .service ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import org .junit .jupiter .api .DisplayName ;
6+ import org .junit .jupiter .params .ParameterizedTest ;
7+ import org .junit .jupiter .params .provider .ValueSource ;
8+
9+ class PriceConverterTests {
10+ PriceConverter priceConverter = new PriceConverter ();
11+
12+ @ ParameterizedTest (name = ParameterizedTest .DISPLAY_NAME_PLACEHOLDER + "[" + ParameterizedTest .INDEX_PLACEHOLDER + "] (" + ParameterizedTest .ARGUMENTS_WITH_NAMES_PLACEHOLDER + ")" )
13+ @ ValueSource (ints = { 1 , 2 })
14+ @ DisplayName ("process" )
15+ public void process (int price ) {
16+ assertThat (this .priceConverter .process (price ))
17+ .isEqualTo (price * PriceConverter .CONVERSION_RATE );
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package org .acme .service ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import java .time .Duration ;
6+ import java .util .List ;
7+ import java .util .function .Predicate ;
8+
9+ import org .junit .jupiter .api .Test ;
10+
11+ import io .smallrye .mutiny .helpers .test .AssertSubscriber ;
12+
13+ class PriceGeneratorTests {
14+ PriceGenerator priceGenerator = new PriceGenerator ();
15+
16+ private static final Predicate <Integer > VALUE_TEST =
17+ value -> (value >= 0 ) && (value < 100 );
18+
19+ @ Test
20+ public void generatesProperly () {
21+ List <Integer > prices = this .priceGenerator .generate ()
22+ .select ().first (2 )
23+ .subscribe ().withSubscriber (AssertSubscriber .create (2 ))
24+ .assertSubscribed ()
25+ .awaitItems (2 , Duration .ofSeconds (10 ))
26+ .awaitCompletion (Duration .ofSeconds (15 ))
27+ .assertCompleted ()
28+ .getItems ();
29+
30+ assertThat (prices )
31+ .hasSize (2 )
32+ .allMatch (VALUE_TEST );
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments