Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate servicetalk-concurrent-reactivestreams tests to Junit 5 (#1568) #1628

Merged
merged 1 commit into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion servicetalk-concurrent-reactivestreams/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ dependencies {
testImplementation testFixtures(project(":servicetalk-concurrent-api"))
testImplementation testFixtures(project(":servicetalk-concurrent-internal"))
testImplementation project(":servicetalk-test-resources")
testImplementation "junit:junit:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit5Version"
testImplementation "org.mockito:mockito-core:$mockitoCoreVersion"
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
testImplementation "org.reactivestreams:reactive-streams-tck:$reactiveStreamsVersion"
testImplementation "org.testng:testng:$testngVersion"

testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit5Version"
}

// We need testng for the reactive-streams-tck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import io.servicetalk.concurrent.api.TestSubscription;
import io.servicetalk.concurrent.internal.ScalarValueSubscription;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
Expand All @@ -49,24 +47,21 @@
import static io.servicetalk.concurrent.reactivestreams.ReactiveStreamsAdapters.fromReactiveStreamsPublisher;
import static io.servicetalk.concurrent.reactivestreams.ReactiveStreamsAdapters.toReactiveStreamsPublisher;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

public class ReactiveStreamsAdaptersTest {

@Rule
public final ExpectedException expectedException = ExpectedException.none();
class ReactiveStreamsAdaptersTest {

@Test
public void fromRSSuccess() throws Exception {
void fromRSSuccess() throws Exception {
Publisher<Integer> rsPublisher = newMockRsPublisher((subscriber, __) -> {
subscriber.onNext(1);
subscriber.onComplete();
Expand All @@ -76,17 +71,16 @@ public void fromRSSuccess() throws Exception {
}

@Test
public void fromRSError() throws Exception {
void fromRSError() {
Publisher<Integer> rsPublisher = newMockRsPublisher((subscriber, __) ->
subscriber.onError(DELIBERATE_EXCEPTION));
Future<Integer> future = fromReactiveStreamsPublisher(rsPublisher).firstOrElse(() -> null).toFuture();
expectedException.expect(instanceOf(ExecutionException.class));
expectedException.expectCause(sameInstance(DELIBERATE_EXCEPTION));
future.get();
ExecutionException ex = assertThrows(ExecutionException.class, future::get);
assertThat(ex.getCause(), sameInstance(DELIBERATE_EXCEPTION));
}

@Test
public void fromRSCancel() {
void fromRSCancel() {
AtomicReference<Subscription> receivedSubscription = new AtomicReference<>();
Publisher<Integer> rsPublisher = newMockRsPublisher((__, subscription) ->
receivedSubscription.set(subscription));
Expand All @@ -97,12 +91,12 @@ public void fromRSCancel() {
}

@Test
public void singleToRSSuccess() {
void singleToRSSuccess() {
verifyRSSuccess(toRSPublisherAndSubscribe(succeeded(1)), true);
}

@Test
public void singleToRSFromSourceSuccess() {
void singleToRSFromSourceSuccess() {
SingleSource<Integer> source = s -> {
s.onSubscribe(IGNORE_CANCEL);
s.onSuccess(1);
Expand All @@ -111,12 +105,12 @@ public void singleToRSFromSourceSuccess() {
}

@Test
public void completableToRSSuccess() {
void completableToRSSuccess() {
verifyRSSuccess(toRSPublisherAndSubscribe(Completable.completed()), false);
}

@Test
public void completableToRSFromSourceSuccess() {
void completableToRSFromSourceSuccess() {
CompletableSource source = s -> {
s.onSubscribe(IGNORE_CANCEL);
s.onComplete();
Expand All @@ -125,12 +119,12 @@ public void completableToRSFromSourceSuccess() {
}

@Test
public void toRSSuccess() {
void toRSSuccess() {
verifyRSSuccess(toRSPublisherAndSubscribe(from(1)), true);
}

@Test
public void toRSFromSourceSuccess() {
void toRSFromSourceSuccess() {
PublisherSource<Integer> source = s -> s.onSubscribe(new ScalarValueSubscription<>(1, s));
verifyRSSuccess(toRSPublisherFromSourceAndSubscribe(source), true);
}
Expand All @@ -145,22 +139,22 @@ private void verifyRSSuccess(final Subscriber<Integer> subscriber, boolean onNex
}

@Test
public void singleToRSError() {
void singleToRSError() {
verifyRSError(toRSPublisherAndSubscribe(Single.failed(DELIBERATE_EXCEPTION)));
}

@Test
public void completableToRSError() {
void completableToRSError() {
verifyRSError(toRSPublisherAndSubscribe(Completable.failed(DELIBERATE_EXCEPTION)));
}

@Test
public void toRSError() {
void toRSError() {
verifyRSError(toRSPublisherAndSubscribe(failed(DELIBERATE_EXCEPTION)));
}

@Test
public void singleToRSFromSourceError() {
void singleToRSFromSourceError() {
SingleSource<Integer> source = s -> {
s.onSubscribe(IGNORE_CANCEL);
s.onError(DELIBERATE_EXCEPTION);
Expand All @@ -169,7 +163,7 @@ public void singleToRSFromSourceError() {
}

@Test
public void completableToRSFromSourceError() {
void completableToRSFromSourceError() {
CompletableSource source = s -> {
s.onSubscribe(EMPTY_SUBSCRIPTION);
s.onError(DELIBERATE_EXCEPTION);
Expand All @@ -178,7 +172,7 @@ public void completableToRSFromSourceError() {
}

@Test
public void toRSFromSourceError() {
void toRSFromSourceError() {
PublisherSource<Integer> source = s -> {
s.onSubscribe(EMPTY_SUBSCRIPTION);
s.onError(DELIBERATE_EXCEPTION);
Expand All @@ -193,7 +187,7 @@ private void verifyRSError(final Subscriber<Integer> subscriber) {
}

@Test
public void singleToRSCancel() {
void singleToRSCancel() {
TestSingle<Integer> stSingle = new TestSingle<>();
Subscriber<Integer> subscriber = toRSPublisherAndSubscribe(stSingle);
TestSubscription subscription = new TestSubscription();
Expand All @@ -206,7 +200,7 @@ public void singleToRSCancel() {
}

@Test
public void completableToRSCancel() {
void completableToRSCancel() {
TestCompletable stCompletable = new TestCompletable();
Subscriber<Integer> subscriber = toRSPublisherAndSubscribe(stCompletable);
TestSubscription subscription = new TestSubscription();
Expand All @@ -219,7 +213,7 @@ public void completableToRSCancel() {
}

@Test
public void toRSCancel() {
void toRSCancel() {
TestPublisher<Integer> stPublisher = new TestPublisher<>();
Subscriber<Integer> subscriber = toRSPublisherAndSubscribe(stPublisher);
TestSubscription subscription = new TestSubscription();
Expand All @@ -232,7 +226,7 @@ public void toRSCancel() {
}

@Test
public void singleToRSFromSourceCancel() {
void singleToRSFromSourceCancel() {
Cancellable srcCancellable = mock(Cancellable.class);
SingleSource<Integer> source = s -> s.onSubscribe(srcCancellable);
Subscriber<Integer> subscriber = toRSPublisherFromSourceAndSubscribe(source);
Expand All @@ -243,7 +237,7 @@ public void singleToRSFromSourceCancel() {
}

@Test
public void completableToRSFromSourceCancel() {
void completableToRSFromSourceCancel() {
Cancellable srcCancellable = mock(Cancellable.class);
CompletableSource source = s -> s.onSubscribe(srcCancellable);
Subscriber<Integer> subscriber = toRSPublisherFromSourceAndSubscribe(source);
Expand All @@ -254,7 +248,7 @@ public void completableToRSFromSourceCancel() {
}

@Test
public void toRSFromSourceCancel() {
void toRSFromSourceCancel() {
PublisherSource.Subscription srcSubscription = mock(PublisherSource.Subscription.class);
PublisherSource<Integer> source = s -> s.onSubscribe(srcSubscription);
Subscriber<Integer> subscriber = toRSPublisherFromSourceAndSubscribe(source);
Expand Down