rewrite FlatSpec tests using WordSpec #24186

This commit is contained in:
Łukasz Drygała 2018-01-03 12:51:27 +01:00 committed by Johan Andrén
parent 6d6e96179d
commit 0c0bf91661
4 changed files with 145 additions and 135 deletions

View file

@ -3,12 +3,9 @@
*/
package akka.util
import org.scalatest.FlatSpec
import org.scalatest.Matchers
import org.scalatest.{ Matchers, WordSpec }
class PrettyDurationSpec extends FlatSpec with Matchers {
behavior of "PrettyDuration"
class PrettyDurationSpec extends WordSpec with Matchers {
import akka.util.PrettyDuration._
@ -27,22 +24,25 @@ class PrettyDurationSpec extends FlatSpec with Matchers {
95.hours "3.958 d" ::
Nil
"PrettyDuration" should {
cases foreach {
case (d, expectedValue)
it should s"print $d nanos as $expectedValue" in {
s"print $d nanos as $expectedValue" in {
d.pretty should ===(expectedValue)
}
}
it should "work with infinity" in {
"work with infinity" in {
Duration.Inf.pretty should include("infinity")
}
it should "work with -infinity" in {
"work with -infinity" in {
Duration.MinusInf.pretty should include("minus infinity")
}
it should "work with undefined" in {
"work with undefined" in {
Duration.Undefined.pretty should include("undefined")
}
}
}

View file

@ -4,12 +4,13 @@
package docs.actor
import language.postfixOps
import akka.actor.{ ActorSystem, ActorRef, Props, Terminated }
import akka.actor.{ ActorRef, ActorSystem, Props, Terminated }
import FaultHandlingDocSpec._
import org.scalatest.{ WordSpec, WordSpecLike }
//#testkit
import com.typesafe.config.{ Config, ConfigFactory }
import org.scalatest.{ FlatSpecLike, Matchers, BeforeAndAfterAll }
import org.scalatest.{ Matchers, BeforeAndAfterAll }
import akka.testkit.{ TestActors, TestKit, ImplicitSender, EventFilter }
//#testkit
@ -100,7 +101,7 @@ object FaultHandlingDocSpec {
}
//#testkit
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(
"FaultHandlingDocSpec",
@ -115,7 +116,8 @@ class FaultHandlingDocSpec(_system: ActorSystem) extends TestKit(_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
//#create
@ -181,4 +183,5 @@ class FaultHandlingDocSpec(_system: ActorSystem) extends TestKit(_system)
// code here
}
}
}
//#testkit

View file

@ -5,9 +5,9 @@ package akka.remote
import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
import org.scalatest.FlatSpec
import org.scalatest.Matchers
import org.scalatest.concurrent.Eventually._
import org.scalatest.{ Matchers, WordSpec }
import scala.collection.JavaConverters._
import scala.collection.mutable.Set
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
* 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(
"""
akka {
@ -41,7 +41,8 @@ class RemoteInitErrorSpec extends FlatSpec with Matchers {
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()
try {
ActorSystem("duplicate", ConfigFactory.parseString("akka.loglevel=OFF").withFallback(conf))
@ -57,3 +58,4 @@ class RemoteInitErrorSpec extends FlatSpec with Matchers {
}
}
}
}

View file

@ -5,11 +5,11 @@
package akka.testkit.typed
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 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 Father {
@ -78,12 +78,12 @@ object BehaviorTestkitSpec {
}
//TODO WordSpec
class BehaviorTestkitSpec extends FlatSpec with Matchers {
class BehaviorTestkitSpec extends WordSpec with Matchers {
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())
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))
}
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())
ctx.run(SpawnChildrenWithProps(2, props))
val effects = ctx.retrieveAllEffects()
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())
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))
}
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())
ctx.run(SpawnAnonymousWithProps(2, props))
val effects = ctx.retrieveAllEffects()
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())
ctx.run(SpawnAdapter)
@ -123,7 +127,7 @@ class BehaviorTestkitSpec extends FlatSpec with Matchers {
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())
ctx.run(SpawnAdapterWithName("adapter"))
@ -131,3 +135,4 @@ class BehaviorTestkitSpec extends FlatSpec with Matchers {
effects shouldBe Seq(SpawnedAdapter)
}
}
}