Like other Pekko libraries, Projections ships with a @ref:TestKit that a user can include to assert the correctness of their Projection handler implementation. Add the Projections TestKit dependency to your project:
@@dependency [sbt,Maven,Gradle] { group=org.apache.pekko artifact=pekko-projection-testkit_$scala.binary.version$ version=$project.version$ }
Import the @apidoc[pekko.projection.testkit.(javadsl|scaladsl).ProjectionTestKit] and other utilities into a new @scala:[ScalaTest test spec] @java:[JUnit test].
Scala : @@snip ShoppingCartAppSpec.scala { #testKitImports }
Java : @@snip ShoppingCartAppTest.java { #testKitImports }
The TestKit includes several utilities to run the Projection handler in isolation so that a full projection implementation and source provider are not required.
Envelopes that will be processed by the Projection Handler.Using these tools we can assert that our Projection handler meets the following requirements of the ItemPopularityProjectionHandler.
Scala : @@snip ShoppingCartAppSpec.scala { #testKitSpec }
Java : @@snip ShoppingCartAppTest.java { #testKitSpec }