rewrite FlatSpec tests using WordSpec #24186
This commit is contained in:
parent
6d6e96179d
commit
0c0bf91661
4 changed files with 145 additions and 135 deletions
|
|
@ -3,12 +3,9 @@
|
||||||
*/
|
*/
|
||||||
package akka.util
|
package akka.util
|
||||||
|
|
||||||
import org.scalatest.FlatSpec
|
import org.scalatest.{ Matchers, WordSpec }
|
||||||
import org.scalatest.Matchers
|
|
||||||
|
|
||||||
class PrettyDurationSpec extends FlatSpec with Matchers {
|
class PrettyDurationSpec extends WordSpec with Matchers {
|
||||||
|
|
||||||
behavior of "PrettyDuration"
|
|
||||||
|
|
||||||
import akka.util.PrettyDuration._
|
import akka.util.PrettyDuration._
|
||||||
|
|
||||||
|
|
@ -27,22 +24,25 @@ class PrettyDurationSpec extends FlatSpec with Matchers {
|
||||||
95.hours → "3.958 d" ::
|
95.hours → "3.958 d" ::
|
||||||
Nil
|
Nil
|
||||||
|
|
||||||
|
"PrettyDuration" should {
|
||||||
|
|
||||||
cases foreach {
|
cases foreach {
|
||||||
case (d, expectedValue) ⇒
|
case (d, expectedValue) ⇒
|
||||||
it should s"print $d nanos as $expectedValue" in {
|
s"print $d nanos as $expectedValue" in {
|
||||||
d.pretty should ===(expectedValue)
|
d.pretty should ===(expectedValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "work with infinity" in {
|
"work with infinity" in {
|
||||||
Duration.Inf.pretty should include("infinity")
|
Duration.Inf.pretty should include("infinity")
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "work with -infinity" in {
|
"work with -infinity" in {
|
||||||
Duration.MinusInf.pretty should include("minus infinity")
|
Duration.MinusInf.pretty should include("minus infinity")
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "work with undefined" in {
|
"work with undefined" in {
|
||||||
Duration.Undefined.pretty should include("undefined")
|
Duration.Undefined.pretty should include("undefined")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@
|
||||||
package docs.actor
|
package docs.actor
|
||||||
|
|
||||||
import language.postfixOps
|
import language.postfixOps
|
||||||
import akka.actor.{ ActorSystem, ActorRef, Props, Terminated }
|
import akka.actor.{ ActorRef, ActorSystem, Props, Terminated }
|
||||||
import FaultHandlingDocSpec._
|
import FaultHandlingDocSpec._
|
||||||
|
import org.scalatest.{ WordSpec, WordSpecLike }
|
||||||
|
|
||||||
//#testkit
|
//#testkit
|
||||||
import com.typesafe.config.{ Config, ConfigFactory }
|
import com.typesafe.config.{ Config, ConfigFactory }
|
||||||
import org.scalatest.{ FlatSpecLike, Matchers, BeforeAndAfterAll }
|
import org.scalatest.{ Matchers, BeforeAndAfterAll }
|
||||||
import akka.testkit.{ TestActors, TestKit, ImplicitSender, EventFilter }
|
import akka.testkit.{ TestActors, TestKit, ImplicitSender, EventFilter }
|
||||||
|
|
||||||
//#testkit
|
//#testkit
|
||||||
|
|
@ -100,7 +101,7 @@ object FaultHandlingDocSpec {
|
||||||
}
|
}
|
||||||
//#testkit
|
//#testkit
|
||||||
class FaultHandlingDocSpec(_system: ActorSystem) extends TestKit(_system)
|
class FaultHandlingDocSpec(_system: ActorSystem) extends TestKit(_system)
|
||||||
with ImplicitSender with FlatSpecLike with Matchers with BeforeAndAfterAll {
|
with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll {
|
||||||
|
|
||||||
def this() = this(ActorSystem(
|
def this() = this(ActorSystem(
|
||||||
"FaultHandlingDocSpec",
|
"FaultHandlingDocSpec",
|
||||||
|
|
@ -115,7 +116,8 @@ class FaultHandlingDocSpec(_system: ActorSystem) extends TestKit(_system)
|
||||||
TestKit.shutdownActorSystem(system)
|
TestKit.shutdownActorSystem(system)
|
||||||
}
|
}
|
||||||
|
|
||||||
"A supervisor" must "apply the chosen strategy for its child" in {
|
"A supervisor" must {
|
||||||
|
"apply the chosen strategy for its child" in {
|
||||||
//#testkit
|
//#testkit
|
||||||
|
|
||||||
//#create
|
//#create
|
||||||
|
|
@ -181,4 +183,5 @@ class FaultHandlingDocSpec(_system: ActorSystem) extends TestKit(_system)
|
||||||
// code here
|
// code here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//#testkit
|
//#testkit
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ package akka.remote
|
||||||
|
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
import org.scalatest.FlatSpec
|
|
||||||
import org.scalatest.Matchers
|
|
||||||
import org.scalatest.concurrent.Eventually._
|
import org.scalatest.concurrent.Eventually._
|
||||||
|
import org.scalatest.{ Matchers, WordSpec }
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import scala.collection.mutable.Set
|
import scala.collection.mutable.Set
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
|
|
@ -19,7 +19,7 @@ import scala.util.control.NonFatal
|
||||||
* by any network node. Therefore we assume here that the initialization of
|
* by any network node. Therefore we assume here that the initialization of
|
||||||
* the ActorSystem with the use of remoting will intentionally fail.
|
* the ActorSystem with the use of remoting will intentionally fail.
|
||||||
*/
|
*/
|
||||||
class RemoteInitErrorSpec extends FlatSpec with Matchers {
|
class RemoteInitErrorSpec extends WordSpec with Matchers {
|
||||||
val conf = ConfigFactory.parseString(
|
val conf = ConfigFactory.parseString(
|
||||||
"""
|
"""
|
||||||
akka {
|
akka {
|
||||||
|
|
@ -41,7 +41,8 @@ class RemoteInitErrorSpec extends FlatSpec with Matchers {
|
||||||
threads.asScala.collect({ case t: Thread if (!t.isDaemon()) ⇒ t.getId() })
|
threads.asScala.collect({ case t: Thread if (!t.isDaemon()) ⇒ t.getId() })
|
||||||
}
|
}
|
||||||
|
|
||||||
"Remoting" must "shut down properly on RemoteActorRefProvider initialization failure" in {
|
"Remoting" must {
|
||||||
|
"shut down properly on RemoteActorRefProvider initialization failure" in {
|
||||||
val start = currentThreadIds()
|
val start = currentThreadIds()
|
||||||
try {
|
try {
|
||||||
ActorSystem("duplicate", ConfigFactory.parseString("akka.loglevel=OFF").withFallback(conf))
|
ActorSystem("duplicate", ConfigFactory.parseString("akka.loglevel=OFF").withFallback(conf))
|
||||||
|
|
@ -57,3 +58,4 @@ class RemoteInitErrorSpec extends FlatSpec with Matchers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
package akka.testkit.typed
|
package akka.testkit.typed
|
||||||
|
|
||||||
import akka.actor.typed.scaladsl.Actor
|
import akka.actor.typed.scaladsl.Actor
|
||||||
import akka.testkit.typed.Effect.{ Spawned, SpawnedAdapter, SpawnedAnonymous }
|
|
||||||
import akka.testkit.typed.BehaviorTestkitSpec.{ Child, Father }
|
|
||||||
import akka.testkit.typed.BehaviorTestkitSpec.Father._
|
|
||||||
import akka.actor.typed.{ Behavior, Props }
|
import akka.actor.typed.{ Behavior, Props }
|
||||||
import org.scalatest.{ FlatSpec, Matchers }
|
import akka.testkit.typed.BehaviorTestkitSpec.Father._
|
||||||
|
import akka.testkit.typed.BehaviorTestkitSpec.{ Child, Father }
|
||||||
|
import akka.testkit.typed.Effect.{ Spawned, SpawnedAdapter, SpawnedAnonymous }
|
||||||
|
import org.scalatest.{ Matchers, WordSpec }
|
||||||
|
|
||||||
object BehaviorTestkitSpec {
|
object BehaviorTestkitSpec {
|
||||||
object Father {
|
object Father {
|
||||||
|
|
@ -78,12 +78,12 @@ object BehaviorTestkitSpec {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO WordSpec
|
class BehaviorTestkitSpec extends WordSpec with Matchers {
|
||||||
class BehaviorTestkitSpec extends FlatSpec with Matchers {
|
|
||||||
|
|
||||||
private val props = Props.empty
|
private val props = Props.empty
|
||||||
|
|
||||||
"BehaviourTestkit's spawn" should "create children when no props specified" in {
|
"BehaviourTestkit's spawn" should {
|
||||||
|
"create children when no props specified" in {
|
||||||
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
||||||
|
|
||||||
ctx.run(SpawnChildren(2))
|
ctx.run(SpawnChildren(2))
|
||||||
|
|
@ -91,15 +91,17 @@ class BehaviorTestkitSpec extends FlatSpec with Matchers {
|
||||||
effects should contain only (Spawned(Child.initial, "child0"), Spawned(Child.initial, "child1", Props.empty))
|
effects should contain only (Spawned(Child.initial, "child0"), Spawned(Child.initial, "child1", Props.empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "create children when props specified and record effects" in {
|
"create children when props specified and record effects" in {
|
||||||
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
||||||
|
|
||||||
ctx.run(SpawnChildrenWithProps(2, props))
|
ctx.run(SpawnChildrenWithProps(2, props))
|
||||||
val effects = ctx.retrieveAllEffects()
|
val effects = ctx.retrieveAllEffects()
|
||||||
effects should contain only (Spawned(Child.initial, "child0", props), Spawned(Child.initial, "child1", props))
|
effects should contain only (Spawned(Child.initial, "child0", props), Spawned(Child.initial, "child1", props))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"BehaviourTestkit's spawnAnonymous" should "create children when no props specified and record effects" in {
|
"BehaviourTestkit's spawnAnonymous" should {
|
||||||
|
"create children when no props specified and record effects" in {
|
||||||
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
||||||
|
|
||||||
ctx.run(SpawnAnonymous(2))
|
ctx.run(SpawnAnonymous(2))
|
||||||
|
|
@ -107,15 +109,17 @@ class BehaviorTestkitSpec extends FlatSpec with Matchers {
|
||||||
effects shouldBe Seq(SpawnedAnonymous(Child.initial, Props.empty), SpawnedAnonymous(Child.initial, Props.empty))
|
effects shouldBe Seq(SpawnedAnonymous(Child.initial, Props.empty), SpawnedAnonymous(Child.initial, Props.empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "create children when props specified and record effects" in {
|
"create children when props specified and record effects" in {
|
||||||
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
||||||
|
|
||||||
ctx.run(SpawnAnonymousWithProps(2, props))
|
ctx.run(SpawnAnonymousWithProps(2, props))
|
||||||
val effects = ctx.retrieveAllEffects()
|
val effects = ctx.retrieveAllEffects()
|
||||||
effects shouldBe Seq(SpawnedAnonymous(Child.initial, props), SpawnedAnonymous(Child.initial, props))
|
effects shouldBe Seq(SpawnedAnonymous(Child.initial, props), SpawnedAnonymous(Child.initial, props))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"BehaviourTestkit's spawnAdapter" should "create adapters without name and record effects" in {
|
"BehaviourTestkit's spawnAdapter" should {
|
||||||
|
"create adapters without name and record effects" in {
|
||||||
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
||||||
|
|
||||||
ctx.run(SpawnAdapter)
|
ctx.run(SpawnAdapter)
|
||||||
|
|
@ -123,7 +127,7 @@ class BehaviorTestkitSpec extends FlatSpec with Matchers {
|
||||||
effects shouldBe Seq(SpawnedAdapter)
|
effects shouldBe Seq(SpawnedAdapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "create adapters with name and record effects" in {
|
"create adapters with name and record effects" in {
|
||||||
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
val ctx = BehaviorTestkit[Father.Command](Father.init())
|
||||||
|
|
||||||
ctx.run(SpawnAdapterWithName("adapter"))
|
ctx.run(SpawnAdapterWithName("adapter"))
|
||||||
|
|
@ -131,3 +135,4 @@ class BehaviorTestkitSpec extends FlatSpec with Matchers {
|
||||||
effects shouldBe Seq(SpawnedAdapter)
|
effects shouldBe Seq(SpawnedAdapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue