I'm using Scala 2.13.7 with Akka Streams 2.6.17.
I have this very basic Akka Stream. It takes what the user types (System.in), applies toUpperCase function and finally the string is printed using System.out:
val stdInSource: Source[ByteString, Future[IOResult]] = StreamConverters.fromInputStream(() => System.in)
val stdOutSink: Sink[ByteString, Future[IOResult]] = StreamConverters.fromOutputStream(() => System.out)
val dummyFlow: Flow[ByteString, ByteString, NotUsed] = {
Flow[ByteString].map(x => ByteString(x.utf8String.toUpperCase))
}
stdInSource
.via(dummyFlow)
.runWith(stdOutSink)
Let's say I want to wrap this code in a function something like this:
def myStream(input: () => InputStream)(implicit system: ActorSystem): Future[IOResult] = {
val stdOutSink: Sink[ByteString, Future[IOResult]] = StreamConverters.fromOutputStream(() => System.out)
val dummyFlow: Flow[ByteString, ByteString, NotUsed] = {
Flow[ByteString].map(x => ByteString(x.utf8String.toUpperCase))
}
StreamConverters
.fromInputStream(input)
.via(dummyFlow)
.runWith(stdOutSink)
}
Then I can invoke it like this:
myStream(() => System.in)
My question is: if I want to create unit tests, how can I pass a List[String] to myStream? I mean how can I convert the List[String] into the same type as myStream parameter? (() => InputStream)