当前位置: 首页>>代码示例>>Scala>>正文


Scala WordSpecLike类代码示例

本文整理汇总了Scala中org.scalatest.WordSpecLike的典型用法代码示例。如果您正苦于以下问题:Scala WordSpecLike类的具体用法?Scala WordSpecLike怎么用?Scala WordSpecLike使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WordSpecLike类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: MySpec

//设置package包名称以及导入依赖的类
package docs.testkit

//#plain-spec
import akka.actor.ActorSystem
import akka.actor.Actor
import akka.actor.Props
import akka.testkit.{ TestActors, TestKit, ImplicitSender }
import org.scalatest.WordSpecLike
import org.scalatest.Matchers
import org.scalatest.BeforeAndAfterAll

//#implicit-sender
class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {
  //#implicit-sender

  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "An Echo actor" must {

    "send back messages unchanged" in {
      val echo = system.actorOf(TestActors.echoActorProps)
      echo ! "hello world"
      expectMsg("hello world")
    }

  }
}
//#plain-spec 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:34,代码来源:PlainWordSpec.scala

示例2: CamelMessageTest

//设置package包名称以及导入依赖的类
package akka.camel

import org.apache.camel.impl.{ DefaultExchange, DefaultMessage }
import akka.camel.TestSupport.SharedCamelSystem
import org.scalatest.Matchers
import org.scalatest.WordSpecLike

//TODO merge it with MessageScalaTest
class CamelMessageTest extends Matchers with WordSpecLike with SharedCamelSystem {

  "CamelMessage" must {

    "overwrite body and add header" in {
      val msg = sampleMessage
      CamelMessage.copyContent(CamelMessage("blah", Map("key" -> "baz")), msg)
      assert(msg.getBody === "blah")
      assert(msg.getHeader("foo") === "bar")
      assert(msg.getHeader("key") === "baz")
    }
  }

  private[camel] def sampleMessage = {
    val message = new DefaultMessage
    message.setBody("test")
    message.setHeader("foo", "bar")
    message.setExchange(new DefaultExchange(camel.context))
    message
  }
} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:30,代码来源:CamelMessageTest.scala

示例3: IPAddressSpec

//设置package包名称以及导入依赖的类
package edu.uw.at.iroberts.wirefugue.pcap

import org.scalatest.{Matchers, WordSpecLike}


class IPAddressSpec extends WordSpecLike with Matchers {
  val ipString: String = "192.168.42.196"
  val ipBytes: Seq[Byte] = Seq(0xc0, 0xa8, 0x2a, 0xc4).map(_.toByte)
  "an IPAddress" should {
    "be constructable from String and Seq[Byte]" in {
      IPAddress(ipString) shouldEqual IPAddress(ipBytes)
    }

    "produce a string representation" in {
      val a = IPAddress(ipBytes)

      a.toString shouldEqual ipString
    }

    "produce a byte sequence representation" in {
      val a = IPAddress(ipString)

      a.bytes shouldEqual ipBytes
    }

    "provide an equivalent java.net.Inet4Address" in {
      import java.net.{InetAddress, Inet4Address}

      val a = IPAddress(ipString)

      a.inet4Address shouldEqual InetAddress.getByAddress(ipBytes.toArray).asInstanceOf[Inet4Address]
    }

    "reject invalid sequences upon construction" in {
      assertThrows[IllegalArgumentException] {
        IPAddress(Seq[Byte](0x10, 0x20, 0x30, 0x40, 0x50))
      }
    }

    "reject invalid strings upon construction" in {
      assertThrows[IllegalArgumentException] {
        IPAddress("192.168.0.256")
      }
      assertThrows[IllegalArgumentException] {
        IPAddress("10.0.0.0.1")
      }
      assertThrows[IllegalArgumentException] {
        IPAddress("192.168.2")
      }
    }
  }

} 
开发者ID:robertson-tech,项目名称:wirefugue,代码行数:54,代码来源:IPAddressSpec.scala

示例4: ByteSeqOpsSpec

//设置package包名称以及导入依赖的类
package edu.uw.at.iroberts.wirefugue.pcap

import org.scalatest.{Matchers, WordSpecLike}


class ByteSeqOpsSpec extends WordSpecLike with Matchers {
  "toBytesBE" should {
    "serialize a 32-bit integer in big-endian format" in {
      import ByteSeqOps.toBytesBE
      val expected = Array(0xca.toByte, 0xfe.toByte, 0xba.toByte, 0xbe.toByte)
      toBytesBE(0xcafebabe.toInt) shouldEqual expected

    }
    "serialize a 16-bit integer in big-endian format" in {
      import ByteSeqOps.toBytesBE
      val expected = Array(0xbe.toByte, 0xef.toByte)
      toBytesBE(0xbeef.toShort) shouldEqual expected
    }
  }

} 
开发者ID:robertson-tech,项目名称:wirefugue,代码行数:22,代码来源:ByteSeqOpsSpec.scala

示例5: PlayerSpec

//设置package包名称以及导入依赖的类
package com.chriswk.gameranker.player

import akka.actor.ActorSystem
import com.chriswk.gameranker.player.impl.{CreatePlayer, Player, PlayerCreated, PlayerEntity}
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.typesafe.config.ConfigFactory
import org.scalactic.ConversionCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.Await
import scala.concurrent.duration._

class PlayerSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with ConversionCheckedTripleEquals {
  val config = ConfigFactory.load()
  val system = ActorSystem("PlayerSpec", config)

  override def afterAll(): Unit = {
    Await.ready(system.terminate, 10.seconds)
  }

  "Player entity" must {
    "handle CreatePlayer" in {
      val driver = new PersistentEntityTestDriver(system, new PlayerEntity, "player-1")
      val name = "Testing hero"
      val outcome = driver.run(CreatePlayer(name))
      outcome.events should ===(List(PlayerCreated(name)))
      outcome.state should ===(Some(Player("Testing hero")))
    }

    "be idempotent" in {
      val driver = new PersistentEntityTestDriver(system, new PlayerEntity, "player-1")
      val name = "Testing hero"
      val outcome = driver.run(CreatePlayer(name), CreatePlayer(name), CreatePlayer(name))
      outcome.events should ===(List(PlayerCreated(name)))
      outcome.state should ===(Some(Player("Testing hero")))
      val secondRun = driver.run(CreatePlayer("Frank"))
      secondRun.events should ===(List())
      secondRun.state should ===(Some(Player("Testing hero")))

    }
  }
} 
开发者ID:chriswk,项目名称:gameranker,代码行数:43,代码来源:PlayerSpec.scala

示例6: gen

//设置package包名称以及导入依赖的类
package org.dsa.iot.scala

import scala.collection.JavaConverters._

import org.dsa.iot.dslink.node.value.Value
import org.dsa.iot.dslink.util.json.{ JsonArray, JsonObject }
import org.scalacheck.{ Gen, Arbitrary }
import org.scalatest.{ BeforeAndAfterAll, Matchers, Suite, WordSpecLike }
import org.scalatest.prop.GeneratorDrivenPropertyChecks


trait AbstractSpec extends Suite
    with WordSpecLike
    with Matchers
    with BeforeAndAfterAll
    with GeneratorDrivenPropertyChecks {

  import Arbitrary._

  object gen {
    val ids = Gen.identifier.map(_.take(10))
    val scalars = Gen.oneOf(arbitrary[Number], arbitrary[Boolean], arbitrary[String], arbitrary[Array[Byte]])
    val scalarLists = Gen.resize(10, Gen.listOf(scalars))
    val scalarJavaLists = scalarLists.map(_.asJava)
    val scalarMaps = Gen.resize(10, Gen.mapOf(Gen.zip(ids, scalars)))
    val scalarJavaMaps = scalarMaps.map(_.asJava)
    val anyLists = Gen.resize(10, Gen.listOf(Gen.oneOf(scalars, scalarLists, scalarMaps)))
    val anyMaps = Gen.resize(10, Gen.mapOf(Gen.zip(ids, Gen.oneOf(scalars, scalarLists, scalarMaps))))
    val any = Gen.oneOf(scalars, anyLists, anyMaps)
  }

  object valueGen {
    val bools = arbitrary[Boolean] map (new Value(_))

    val ints = arbitrary[Int] map (new Value(_))
    val longs = arbitrary[Long] map (new Value(_))
    val shorts = arbitrary[Short] map (new Value(_))
    val bytes = arbitrary[Byte] map (new Value(_))
    val doubles = arbitrary[Double] map (new Value(_))
    val floats = arbitrary[Float] map (new Value(_))
    val numbers = Gen.oneOf(ints, longs, shorts, bytes, doubles, floats)

    val strings = arbitrary[String] map (new Value(_))

    val binary = arbitrary[Array[Byte]] map (new Value(_))

    val scalarArrays = gen.scalarLists map (x => new JsonArray(x.asJava))

    val scalarMaps = gen.scalarMaps map (x => new JsonObject(x.asInstanceOf[Map[String, Object]].asJava))

    val arrays = scalarArrays map (new Value(_))

    val maps = scalarMaps map (new Value(_))
  }
} 
开发者ID:IOT-DSA,项目名称:sdk-dslink-scala,代码行数:56,代码来源:AbstractSpec.scala

示例7: SettingsSpec

//设置package包名称以及导入依赖的类
package com.github.btesila.weather.monitor

import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalatest.{Matchers, WordSpecLike}

class SettingsSpec extends TestKit(ActorSystem()) with WordSpecLike with Matchers {
  "The `Settings` extension" should {
    "provide the appropriate Accuweather settings" in {
      val settings = Settings(system).Accuweather
      settings.ApiKey shouldBe "WTUr8dnrpCGYNnwDMDyv42qU9bxsAxjv"
      settings.LocationUri shouldBe "https://dataservice.accuweather.com/locations/v1/search"
      settings.CurrentConditionUri shouldBe "https://dataservice.accuweather.com/currentconditions/v1"
      settings.DailyForecastUri shouldBe "https://dataservice.accuweather.com/forecasts/v1/daily/1day"
      settings.ExtendedForecastUri shouldBe "https://dataservice.accuweather.com/forecasts/v1/daily/5day"
    }
    "provide the appropriate Http settings" in {
      val settings = Settings(system).WeatherMonitor.Acceptor
      settings.Host shouldBe "localhost"
      settings.Port shouldBe 8140
    }
  }
} 
开发者ID:Bii03,项目名称:weather-monitor,代码行数:24,代码来源:SettingsSpec.scala

示例8: SilentActor01Test

//设置package包名称以及导入依赖的类
package akka_in_action.tests

import akka.actor.ActorSystem
import akka.testkit.{TestKit}
import org.scalatest.{WordSpecLike, MustMatchers}

class SilentActor01Test extends TestKit(ActorSystem("testsystem"))
with WordSpecLike
with MustMatchers
with StopSystemAfterAll {

  "A Silent Actor" must {
    "change state when it receives a message, single threaded" in {
      fail("not implemented yet")
    }
    "change state when it receives a message, multi-threaded" in {
      fail("not implemeted yet")
    }
  }

} 
开发者ID:rockdragon,项目名称:fourthgala,代码行数:22,代码来源:SilentActor01Test.scala

示例9: BasketSpec

//设置package包名称以及导入依赖的类
import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import demo.api.basket.{Basket, Item}
import demo.impl.basket._
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._
import scala.concurrent.Await

class BasketSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with TypeCheckedTripleEquals {
  val system = ActorSystem("PostSpec", JsonSerializerRegistry.actorSystemSetupFor(BasketSerializerRegistry))

  override protected def afterAll() {
    Await.ready(system.terminate(), 20.seconds)
  }

  "Basket" must {
    "Add an item" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket1")
      val addItemOutcome = driver.run(AddItem(Item("Apple", 50)))
      addItemOutcome.events should ===(List(ItemAdded(Item("Apple", 50))))
      addItemOutcome.state.currentBasket.total should ===(50)
      addItemOutcome.state.currentBasket.items should ===(IndexedSeq(Item("Apple", 50)))
      addItemOutcome.replies should ===(List(Done))
      addItemOutcome.issues should ===(Nil)

      val getItemsOutcome = driver.run(GetBasket)
      getItemsOutcome.issues should ===(Nil)
      getItemsOutcome.replies should ===(List(Basket(Seq(Item("Apple", 50)), 50)))

      val getPriceOutcome = driver.run(GetTotal)
      getPriceOutcome.issues should ===(Nil)
      getPriceOutcome.replies should ===(List(50))
    }

    "Clear the basket" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket1")
      val addItemOutcome = driver.run(AddItem(Item("Apple", 50)))

      val clearOutcome = driver.run(ClearAll)
      clearOutcome.issues should ===(Nil)
      clearOutcome.replies should ===(List(Done))

      val getBasketOutcome = driver.run(GetBasket)
      getBasketOutcome.issues should ===(Nil)
      getBasketOutcome.replies should ===(List(Basket(Seq(), 0)))
    }

    "Place an order" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket2")
      driver.run(AddItem(Item("Apple", 50)))
      val outcome = driver.run(PlaceOrder)
      outcome.issues should ===(List())
      outcome.events should ===(List(OrderPlaced("Basket2", Basket(Seq(Item("Apple", 50)), 50))))
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:61,代码来源:BasketSpec.scala

示例10: OrderSpec

//设置package包名称以及导入依赖的类
import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.typesafe.config.ConfigFactory
import demo.impl.order._
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._
import scala.concurrent.Await

class OrderSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with TypeCheckedTripleEquals {
  val system = ActorSystem("PostSpec", JsonSerializerRegistry.actorSystemSetupFor(OrderSerializerRegistry))

  override protected def afterAll() {
    Await.ready(system.terminate(), 20.seconds)
  }

  "Order" must {
    "be created" in {
      val driver = new PersistentEntityTestDriver(system, new Order, "order1")
      val items = IndexedSeq("Apple", "Banana")
      val outcome = driver.run(CreateOrder(items))
      outcome.issues should ===(List())
      outcome.state should ===(OrderState(items))
      outcome.events should ===(List(OrderInitialized(items)))
      outcome.replies should ===(List(Done))

      val getOutcome = driver.run(GetOrder)

      getOutcome.issues should ===(List())
      getOutcome.state should ===(OrderState(items))
      getOutcome.replies should ===(List(OrderItems(items)))
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:38,代码来源:OrderSpec.scala

示例11: BasketSpec

//设置package包名称以及导入依赖的类
import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import demo.api.basket.{Basket, Item}
import demo.impl.basket._
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._
import scala.concurrent.Await

class BasketSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with TypeCheckedTripleEquals {
  val system = ActorSystem("PostSpec", JsonSerializerRegistry.actorSystemSetupFor(BasketSerializerRegistry))

  override protected def afterAll() {
    Await.ready(system.terminate(), 20.seconds)
  }

  "Basket" must {
    "Add an item" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket1")
      val addItemOutcome = driver.run(AddItem(Item("Apple", 50)))
      addItemOutcome.events should ===(List(ItemAdded(Item("Apple", 50))))
      addItemOutcome.state.currentBasket.total should ===(50)
      addItemOutcome.state.currentBasket.items should ===(IndexedSeq(Item("Apple", 50)))
      addItemOutcome.replies should ===(List(Done))
      addItemOutcome.issues should ===(Nil)

      val getItemsOutcome = driver.run(GetBasket)
      getItemsOutcome.issues should ===(Nil)
      getItemsOutcome.replies should ===(List(Basket(Seq(Item("Apple", 50)), 50)))

      val getPriceOutcome = driver.run(GetTotal)
      getPriceOutcome.issues should ===(Nil)
      getPriceOutcome.replies should ===(List(50))
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:40,代码来源:BasketSpec.scala

示例12: ActorSystemSpec

//设置package包名称以及导入依赖的类
package pt.tecnico.dsi.ldap.akka

import java.io.File

import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.LazyLogging
import org.apache.commons.io.FileUtils
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

abstract class ActorSystemSpec extends TestKit(ActorSystem("akka-ldap", ConfigFactory.load()))
  with Matchers
  with ImplicitSender
  with WordSpecLike
  with BeforeAndAfterAll
  with LazyLogging {

  val settings = new Settings()

  val ldapActor = system.actorOf(Props(new LdapActor(settings)), "ldap")

  private var seqCounter = 0L
  def nextSeq(): Long = {
    val ret = seqCounter
    seqCounter += 1
    ret
  }

  val storageLocations = List(
    "akka.persistence.journal.leveldb.dir",
    "akka.persistence.journal.leveldb-shared.store.dir",
    "akka.persistence.snapshot-store.local.dir"
  ).map(s ? new File(system.settings.config.getString(s)))

  override protected def beforeAll(): Unit = {
    super.beforeAll()
    storageLocations.foreach(FileUtils.deleteDirectory)
  }

  override protected def afterAll(): Unit = {
    super.afterAll()
    storageLocations.foreach(FileUtils.deleteDirectory)
    shutdown(verifySystemShutdown = true)
  }
} 
开发者ID:ist-dsi,项目名称:akka-ldap,代码行数:47,代码来源:ActorSystemSpec.scala

示例13: JsSortFnSpec

//设置package包名称以及导入依赖的类
package com.wellfactored.restless.play.json

import com.wellfactored.restless.query.QueryAST.Path
import org.scalatest.{Matchers, WordSpecLike}
import play.api.libs.json.Json

class JsSortFnSpec extends WordSpecLike with Matchers {

  val j1 = Json.parse("""{ "a" : 1 , "b" : 1 }""")
  val j2 = Json.parse("""{ "a" : 2 , "b" : 2 }""")
  val j3 = Json.parse("""{ "a" : 3 }""")

  import Selection.jsSortFn

  "jsSortFn" should {
    "sort numbers in ascending order" in {
      val f1 = jsSortFn(Path("a"), rev = false)
      f1(j1, j2) shouldBe true
      f1(j2, j1) shouldBe false
    }

    "sort missing field after those that have the field" in {
      val f = jsSortFn(Path("b"), rev = false)
      f(j1, j3) shouldBe true
      f(j3, j1) shouldBe false

      Seq(j3, j2, j1).sortWith(f) shouldBe Seq(j1, j2, j3)
    }

    "sort missing field after those that have the field even when reversed" in {
      val f = jsSortFn(Path("b"), rev = true)
      f(j1, j3) shouldBe true
      f(j3, j1) shouldBe false

      Seq(j3, j2, j1).sortWith(f) shouldBe Seq(j2, j1, j3)
    }
  }

} 
开发者ID:WellFactored,项目名称:restless,代码行数:40,代码来源:JsSortFnSpec.scala

示例14: GeneticAlgorithmFSMSpec

//设置package包名称以及导入依赖的类
package com.devdiscoveries.genalg

import akka.actor.{Props, ActorSystem}
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}


class GeneticAlgorithmFSMSpec extends TestKit(ActorSystem("GeneticAlgorithmSpec")) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  override def afterAll = {
    TestKit.shutdownActorSystem(system)
  }

  "The Genetic Algorithm" must {
    val gaActor = system.actorOf(Props(classOf[GeneticAlgorithmFSM]))
    "should start out in status Idle" in {
      gaActor ! Status
      expectMsg(CurrentStatus(Idle, 0, 0))
    }
    "should transition to Initialized with Initialize message" in {
      gaActor ! Initialize(1,1)
      gaActor ! Status
      expectMsg(CurrentStatus(Initialized, 0, 0))
    }
  }

} 
开发者ID:hugovalk,项目名称:genetic-programming,代码行数:29,代码来源:GeneticAlgorithmFSMSpec.scala

示例15: DateTimeFormatSpec

//设置package包名称以及导入依赖的类
package com.jatescher.layer.marshalling

import akka.http.scaladsl.model.DateTime
import com.jatescher.layer.marshalling.v1.DateTimeFormat._
import org.scalatest.{ Matchers, WordSpecLike }
import spray.json._

class DateTimeFormatSpec extends WordSpecLike with Matchers {
  val dateTimeString = "2014-09-09T04:44:47"
  val dateTime = DateTime.fromIsoDateTimeString(dateTimeString).get

  "#write" should {
    "marshall DateTime objects as ISO date time string" in {
      dateTime.toJson shouldBe dateTimeString.toJson
    }
  }

  "#read" should {
    "unmarshall messages that are ISO 8601 format without timezone" in {
      JsString(dateTimeString).convertTo[DateTime] shouldBe dateTime
    }

    "unmarshall messages that contain GMT timezone information" in {
      JsString(dateTimeString + "+00:00").convertTo[DateTime] shouldBe dateTime
    }

    "raise an exception if the time is not in GMT" in {
      intercept[DeserializationException] {
        JsString(dateTimeString + "+07:00").convertTo[DateTime]
      }
    }

    "raise an exception if the time is not ISO 8601" in {
      intercept[DeserializationException] {
        JsString("09/09/2014 04:44:47").convertTo[DateTime]
      }
    }

    "raise an exception if the time is not a string" in {
      intercept[DeserializationException] {
        JsNumber(1459359862).convertTo[DateTime]
      }
    }
  }

} 
开发者ID:jtescher,项目名称:layer-scala,代码行数:47,代码来源:DateTimeFormatSpec.scala


注:本文中的org.scalatest.WordSpecLike类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。