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

feat: Add expectNextN to StreamTestKit for javadsl. #962

Merged
merged 1 commit into from
Jan 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ import scala.concurrent.duration._
import scala.reflect.ClassTag

import org.apache.pekko
import pekko.actor.ClassicActorSystemProvider
import org.reactivestreams.{ Publisher, Subscriber, Subscription }
import pekko.actor.{ ActorRef, ActorSystem, DeadLetterSuppression, NoSerializationVerificationNeeded }
import pekko.actor.ClassicActorSystemProvider
import pekko.stream._
import pekko.stream.impl._
import pekko.testkit.{ TestActor, TestProbe }
import pekko.testkit.TestActor.AutoPilot
import pekko.util.JavaDurationConverters
import pekko.util.ccompat._

import org.reactivestreams.{ Publisher, Subscriber, Subscription }

/**
* Provides factory methods for various Publishers.
*/
Expand Down Expand Up @@ -462,6 +463,16 @@ object TestSubscriber {
self
}

/**
* Fluent DSL
* Expect the given elements to be signalled in order.
* @since 1.1.0
*/
def expectNextN(elems: java.util.List[I]): Self = {
pjfanning marked this conversation as resolved.
Show resolved Hide resolved
elems.forEach(e => probe.expectMsg(OnNext(e)))
self
He-Pin marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Fluent DSL
* Expect the given elements to be signalled in any order.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
package org.apache.pekko.stream.testkit

import scala.concurrent.duration._

import org.apache.pekko
import pekko.stream.scaladsl.Source
import pekko.stream.testkit.scaladsl.TestSink

import pekko.testkit._

import pekko.testkit.TestEvent.Mute
import pekko.testkit.TestEvent.UnMute

import java.util

class StreamTestKitSpec extends PekkoSpec {

val ex = new Exception("Boom!")
Expand Down Expand Up @@ -199,5 +198,12 @@ class StreamTestKitSpec extends PekkoSpec {
"#expectNextN given specific elements" in {
Source(1 to 4).runWith(TestSink.probe).request(4).expectNextN(4) should ===(List(1, 2, 3, 4))
}

"#expectNextN given specific elements for java list" in {
Source(1 to 4).runWith(TestSink[Int]())
.request(4)
.expectNextN(util.Arrays.asList(1, 2, 3, 4))
.expectComplete()
}
}
}