本文整理汇总了Scala中org.scalatest._类的典型用法代码示例。如果您正苦于以下问题:Scala _类的具体用法?Scala _怎么用?Scala _使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了_类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: EchoBotSpec
//设置package包名称以及导入依赖的类
package bot.application
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.testkit.ScalatestRouteTest
import bot.line.client.{MessageReplier, SignatureVerifier}
import bot.line.json.EventsJsonSupport
import bot.line.model.event._
import org.scalamock.scalatest.MockFactory
import org.scalatest.{Matchers, _}
import scala.concurrent.Future
class EchoBotSpec
extends FlatSpec
with Matchers
with ScalatestRouteTest
with EventsJsonSupport
with MockFactory {
def createBot(
sv: SignatureVerifier = mock[SignatureVerifier],
mr: MessageReplier = mock[MessageReplier]
): EchoLineBot = new EchoLineBot(
channelSecret = "channelSecret",
signatureVerifier = sv,
messageReplier = mr
)
it should "reply text message as reveived" in {
val signatureVerifier = stub[SignatureVerifier]
(signatureVerifier.isValid _).when(*, *, *) returns true
val messageReplier = stub[MessageReplier]
(messageReplier.replyMessage _).when(*, *).returns(Future.successful(Unit))
val bot = createBot(
signatureVerifier,
messageReplier
)
val event = MessageEvent(
replyToken = "replyToken",
timestamp = 0,
source = UserSource(id = "1"),
message = TextMessage(id = "2", text = "test message")
)
val body = Events(List(event))
val header = RawHeader("X-Line-Signature", "signature")
Post("/line/callback", body).withHeaders(header) ~> bot.routes ~> check {
status shouldBe StatusCodes.OK
responseAs[String] shouldBe "OK"
}
(signatureVerifier.isValid _).verify("channelSecret", *, "signature").once
(messageReplier.replyMessage _).verify("replyToken", "test message").once
}
}
示例2: BaseLineBotSpec
//设置package包名称以及导入依赖的类
package bot.application
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.testkit.ScalatestRouteTest
import bot.line.client.SignatureVerifier
import bot.line.json.EventsJsonSupport
import bot.line.model.event._
import org.scalamock.scalatest.MockFactory
import org.scalatest.{Matchers, _}
class BaseLineBotSpec
extends FlatSpec
with Matchers
with ScalatestRouteTest
with EventsJsonSupport
with MockFactory {
def createBot(
sv: SignatureVerifier = mock[SignatureVerifier],
rv:List[Event] => Unit
): BaseLineBot[Unit] = new BaseLineBot[Unit] {
override val channelSecret: String = "channelSecret"
override val signatureVerifier: SignatureVerifier = sv
override def receive(events: List[Event]): Unit = rv(events)
}
it should "Verify signature" in {
val signatureVerifier = stub[SignatureVerifier]
(signatureVerifier.isValid _).when(*, *, *) returns true
val receive = stubFunction[List[Event], Unit]
receive.when(*).returns(Unit)
val bot = createBot(
signatureVerifier,
receive
)
val event = MessageEvent(
replyToken = "replyToken",
timestamp = 0,
source = UserSource(id = "1"),
message = TextMessage(id = "2", text = "test message")
)
val body = Events(List(event))
val header = RawHeader("X-Line-Signature", "signature")
Post("/line/callback", body).withHeaders(header) ~> bot.routes ~> check {
status shouldBe StatusCodes.OK
responseAs[String] shouldBe "OK"
}
(signatureVerifier.isValid _).verify("channelSecret", *, "signature").once
receive.verify(body.events).once
}
}
示例3: CalcModelSpec
//设置package包名称以及导入依赖的类
import com.ccm.me.playground.bindingscala.calc._
import org.scalatest.{FlatSpec, _}
import org.scalatest.prop._
import scala.collection.immutable._
import scala.util.Success
class CalcModelSpec extends FlatSpec with TableDrivenPropertyChecks with Matchers {
val examples =
Table(
("tokens", "result"),
("", Success(0d)),
("0 0", Success(0d)),
("5", Success(5d)),
("21", Success(21d)),
("2 + 3", Success(3d)),
("2 + 3 =", Success(5d)),
("20 + 30 =", Success(50d)),
("2 - 3 =", Success(-1d)),
("2 * 3 =", Success(6d)),
("2 / 3 =", Success(2d / 3d)),
("2 + 3 *", Success(3d)),
("2 + 3 * 6", Success(6d)),
("2 * 3 +", Success(6d)),
("2 + 3 * 1", Success(1d)),
("2 + 3 * 1 -", Success(5d)),
("2 + 3 * 1 - 5 =", Success(0d)),
("2 + 3 * 1 - 5 * 12 =", Success(-55d)),
("12 + +", Success(24d)),
("12 + + =", Success(48d)),
("0012 + 0021 =", Success(33d))
)
it should "produce correct calculation" in {
forAll(examples) { (tokens, result) =>
val calc = parseTokens(tokens).foldLeft(CalcModel())((calc, token) => calc(token))
calc.result should equal(result)
}
}
private def parseTokens(s: String): Seq[Token] = {
s.filter(!_.isSpaceChar).map {
case n if n.isDigit => Digit(n.asDigit)
case '.' => Dot()
case '+' => Plus()
case '-' => Minus()
case '*' => Multiply()
case '/' => Divide()
case 'c' => Clear()
case '=' => Result()
case [email protected]_ => fail(s"Unexpected char: $c")
}
}
}
示例4: AkkademyDbSpec
//设置package包名称以及导入依赖的类
import akka.actor.{ActorSystem, Props}
import akka.testkit.TestActorRef
import akka.util.Timeout
import com.example.{AkkademyDb, ScalaPongActor, SetRequest}
import org.scalatest.{FunSpecLike, _}
import scala.concurrent.duration._
class AkkademyDbSpec extends FunSpecLike with Matchers {
implicit val system = ActorSystem()
implicit val timeout = Timeout(5 seconds)
describe("akkademyDb") {
describe("given SetRequest") {
it("should place key/value into your map") {
val actorRef = TestActorRef(new AkkademyDb)
actorRef ! SetRequest("key", "value")
val akkademyDb = actorRef.underlyingActor
akkademyDb.map.get("key") should equal(Some("value"))
}
}
}
}
class ScalaPongActorSpec extends FunSpecLike with Matchers {
implicit val system = ActorSystem()
implicit val timeout = Timeout(5 seconds)
describe("scalaPongActor") {
describe("given Ping") {
it("should return message Pong") {
val actorRef = system.actorOf(Props[ScalaPongActor], "PongFoo")
actorRef ! "ping"
true
}
}
}
}
示例5: UserServiceSpec
//设置package包名称以及导入依赖的类
package service.users
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.scalatest.{Matchers, _}
class UserServiceSpec extends WordSpecLike with Matchers with ScalatestRouteTest with SprayJsonSupport {
import spray.json.DefaultJsonProtocol._
"The UserService" should {
val repository = new UserRepositoryImpl()
"return a list of users" in {
Get("/users") ~> new UserService(repository).userRoutes ~> check {
status shouldEqual StatusCodes.OK
responseAs[List[User]].length shouldBe 2
}
}
}
}
示例6: ToguruClientSpec
//设置package包名称以及导入依赖的类
package toguru.api
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{FeatureSpec, _}
import toguru.api.Activations.Provider
class ToguruClientSpec extends FeatureSpec with MustMatchers with MockitoSugar {
val mockClientInfo = ClientInfo()
val mockClientProvider: ClientInfo.Provider[String] = _ => mockClientInfo
def activationProvider(activations: Activations = DefaultActivations, health: Boolean): Activations.Provider =
new Provider {
def healthy() = health
def apply() = activations
}
def toguruClient(clientProvider: ClientInfo.Provider[String] = mockClientProvider, activations: Activations.Provider) =
new ToguruClient(clientProvider, activations)
feature("health check") {
scenario("activations provider is healthy") {
val client = toguruClient(activations = activationProvider(health = true))
client.healthy() mustBe true
}
scenario("activations provider is unhealthy") {
val client = toguruClient(activations = activationProvider(health = false))
client.healthy() mustBe false
}
}
feature("client info provider") {
scenario("client info requested") {
val myActivations = mock[Activations]
val myInfo: ClientInfo = ClientInfo().withAttribute("user", "me")
val client = toguruClient(
clientProvider = _ => myInfo,
activations = activationProvider(health = true, activations = myActivations))
val toggling = client.apply("client")
toggling.activations mustBe myActivations
toggling.client mustBe myInfo
}
}
}
示例7: ConditionSpec
//设置package包名称以及导入依赖的类
package toguru.api
import org.scalatest.{FeatureSpec, _}
class ConditionSpec extends FeatureSpec with MustMatchers {
feature("Off Condition") {
scenario("can be created by API") {
Condition.Off mustBe a[Condition]
}
}
feature("On Condition") {
scenario("can be created") {
Condition.On mustBe a[Condition]
}
}
feature("Rollout Range Condition") {
scenario("can be created") {
Condition.UuidRange(1 to 20) mustBe a[Condition]
}
}
feature("Attribute Condition") {
scenario("can be created") {
Condition.Attribute("myAttribute", "one", "two", "three") mustBe a[Condition]
}
}
feature("Combined Condition") {
scenario("can be created") {
import Condition._
Condition(
UuidRange(1 to 20),
Attribute("myAttribute", "one", "two", "three")) mustBe a[Condition]
}
scenario("when created from one condition yields the given condition") {
Condition(Condition.Off) mustBe Condition.Off
}
scenario("when created from empty conditions yields Condition 'On'") {
Condition() mustBe Condition.On
}
}
}