• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala WordSpecLike类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: SellerTest

//设置package包名称以及导入依赖的类
package auction_system

import akka.actor.{Props, ActorSystem}
import akka.testkit.{TestProbe, TestFSMRef, ImplicitSender, TestKit}
import auction_system.auction.Auction
import auction_system.auction.Auction.{AuctionEnded, Setup}
import auction_system.auction_search.{MyAuctions, AuctionSearch}
import auction_system.notifier.Notifier
import auction_system.seller.Seller.Initialize
import auction_system.seller.{Active, Uninitialized, Seller}
import org.scalatest.{BeforeAndAfterAll, MustMatchers, WordSpecLike}


class SellerTest (_system: ActorSystem) extends TestKit(_system) with ImplicitSender
                                                                 with WordSpecLike
                                                                 with MustMatchers
                                                                 with BeforeAndAfterAll {

  def this() = this(ActorSystem("AuctionSearchTest"))

  override def afterAll: Unit = {
    system.terminate()
  }

  "A Seller actor" must {
    val seller = TestFSMRef(new Seller)
    "start in Uninitialized state" in {
      assert(seller.stateName == Uninitialized)
    }

    val auctionSearcher = TestFSMRef(new AuctionSearch, "auction_search")
    val notifier = TestFSMRef(new Notifier, "notifier")
    "create and register an auction and switch to Active state" in {
      seller ! Initialize(List("a1"), notifier)
      assert(seller.stateName == Active)
      assert(auctionSearcher.stateData.asInstanceOf[MyAuctions].auctions.head.path.name == "a1")
    }
  }

  "An Auction actor" must {
    val seller = TestProbe()
    val notifier = TestFSMRef(new Notifier, "notifier")
    val auction = seller.childActorOf(Props[Auction])
    seller.send(auction, Setup(seller.ref, notifier))
    "report the end of an auction afret tieout" in {
      seller.expectMsg(AuctionEnded(auction))
    }
  }

} 
开发者ID:pkociepka,项目名称:reactive_scala,代码行数:51,代码来源:SellerTest.scala


示例17: KafkaUtilsSpec

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

import org.scalatest.{ Finders, Matchers, Suite, WordSpecLike }

import kafka.cluster.Broker

class KafkaUtilsSpec extends Suite with WordSpecLike with Matchers {
  import Settings._

  "KafkaUtils.parseBrokerList" should {
    "return an empty list for blank string" in {
      KafkaUtils.parseBrokerList(" ") shouldBe Nil
      KafkaUtils.parseBrokerList(" , ") shouldBe Nil
    }
    "parse hosts with ports" in {
      KafkaUtils.parseBrokerList("host1:111, host2:222,host3:333") shouldBe
        Broker(0, "host1", 111) :: Broker(1, "host2", 222) :: Broker(2, "host3", 333) :: Nil
    }
    "parse hosts without ports" in {
      KafkaUtils.parseBrokerList("host1,host2, host3") shouldBe
        Broker(0, "host1", DEFAULT_PORT) :: Broker(1, "host2", DEFAULT_PORT) :: Broker(2, "host3", DEFAULT_PORT) :: Nil
    }
    "parse mixed hosts with/without ports" in {
      KafkaUtils.parseBrokerList("host1:111,host2, host3:333") shouldBe
        Broker(0, "host1", 111) :: Broker(1, "host2", DEFAULT_PORT) :: Broker(2, "host3", 333) :: Nil
    }
    "fail on bad port format" in {
      a[NumberFormatException] should be thrownBy KafkaUtils.parseBrokerList("host:port")
    }
  }

} 
开发者ID:IOT-DSA,项目名称:dslink-scala-kafka,代码行数:33,代码来源:KafkaUtilsSpec.scala


示例18: SyncMasterActorSpec

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

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.example.Orders.{Address, Order, OrderPage}
import com.example.SyncTriggerActor.SyncTrigger
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

class SyncMasterActorSpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {
  def this() = this(ActorSystem("MySpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "A SyncMasterActor" must {
    "sends a page after receiving it" in {

      val endProbe = TestProbe()
      val mockOrderClient = new MockOrderClient()

      val syncMaster = system.actorOf(SyncMasterActor.props(endProbe.ref, mockOrderClient))
      syncMaster ! new SyncTrigger()
      endProbe.expectMsg(OrderPage(1, List(Order("5704208B-1DED-0DB1-312D-0A0C05E643DB",Address("Pilatuspool 2",Some("Hamburg"), "DE")))))
    }
  }
} 
开发者ID:mduesterhoeft,项目名称:hack16-order-geo-statistics-akka-scala,代码行数:29,代码来源:SyncMasterActorSpec.scala


示例19: DependencyParserSpec

//设置package包名称以及导入依赖的类
package net.ssanj.dabble

import org.scalatest.{AppendedClues, Matchers, WordSpecLike}
import scalaz._

final class DependencyParserSpec extends Matchers with WordSpecLike with AppendedClues {

  "The dependency parser" should {
    "return dependencies" when {
      "dependencies are separated with a + and have a dangling +" in {
        val input1 = Seq("org.scalaz", "%", "scalaz-core_2.11", "%", "7.1.4", "+")
        val input2 = Seq("com.chuusai", "%%", "shapeless", "%", "2.3.0", "+")
        val input3 = Seq("net.databinder.dispatch", "%", "dispatch-core_2.11", "%", "0.11.2", "+")
        val input  = Seq(input1, input2, input3).flatten

        val \/-(dependencies) = DependencyParser.parseDependencies(input)

        dependencies should have size (3)
        dependencies(0) should be (ScalaVersionSupplied("org.scalaz", "scalaz-core_2.11", "7.1.4"))
        dependencies(1) should be (ScalaVersionDerived("com.chuusai", "shapeless", "2.3.0"))
        dependencies(2) should be (ScalaVersionSupplied("net.databinder.dispatch", "dispatch-core_2.11", "0.11.2"))
      }
    }

    "not return a dependency" when {
      "it is malformed" in {
        val input1 = Seq("org.scalaz") //missing 4 parts
        val input2 = Seq("org.scalaz", "%", "scalaz-core_2.11") //missing 3 parts
        val input3 = Seq("org.scalaz", "scalaz-core_2.11", "%", "7.1.4") //missing 1 part at between org and name
        val input4 = Seq("org.scalaz", "%", "scalaz-core_2.11", "7.1.4") //missing 1 part at between name and version
        val input5 = Seq("org.scalaz", "%", "scalaz-core_2.11", "%%", "7.1.4") //invalid %% part between name and version
        val input6 = Seq("+") //separator with nothing to separate
        val input7 = Seq("org.scalaz", "%", "scalaz-core_2.11", "%", "7.1.4", "+", "+") //double dangling +
        val input  = Seq(input1, input2, input3, input4, input5, input6, input7)

        input.foreach { i =>
          DependencyParser.parseDependencies(i).isLeft should be (true) withClue(s"Expected parser error for: $i")
        }
      }
    }
  }
} 
开发者ID:ssanj,项目名称:dabble,代码行数:43,代码来源:DependencyParserSpec.scala


示例20: PingPongActorSpec

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

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
 
class PingPongActorSpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  assert(1 == 1)
 
  def this() = this(ActorSystem("MySpec"))
 
  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }
 
  "A Ping actor" must {
    "send back a ping on a pong" in {
      val pingActor = system.actorOf(PingActor.props)
      pingActor ! PongActor.PongMessage("pong")
      expectMsg(PingActor.PingMessage("ping"))
    }
  }

  "A Pong actor" must {
    "send back a pong on a ping" in {
      val pongActor = system.actorOf(PongActor.props)
      pongActor ! PingActor.PingMessage("ping")
      expectMsg(PongActor.PongMessage("pong"))
    }
  }

} 
开发者ID:astray1988,项目名称:AkkaExplore,代码行数:35,代码来源:PingPongActorSpec.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala WSClient类代码示例发布时间:2022-05-23
下一篇:
Scala immutable类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap