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


Scala MustMatchers类代码示例

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


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

示例1: IssuesSpec

//设置package包名称以及导入依赖的类
package io.scalaland.chimney

import org.scalatest.{MustMatchers, WordSpec}
import shapeless.HNil

class IssuesSpec extends WordSpec with MustMatchers {

  import dsl._

  "IssuesSpec" should {

    "fix issue #19" in {
      case class NewEntity(name: String)
      case class Entity(id: Long, name: String, isDeleted: Boolean)

      NewEntity("name")
        .into[Entity]
        .withFieldConst('id, 0L)
        .withFieldConst('isDeleted, false)
        .transform mustBe
        Entity(0, "name", isDeleted = false)
    }

    "fix issue #21" in {
      import shapeless.tag
      import shapeless.tag._
      sealed trait Test

      case class EntityWithTag1(id: Long, name: String @@ Test)
      case class EntityWithTag2(name: String @@ Test)

      // This test doesn't work on 2.12+ due to:
      // https://github.com/milessabin/shapeless/pull/726
      // EntityWithTag1(0L, tag[Test]("name")).transformInto[EntityWithTag2] mustBe EntityWithTag2(tag[Test]("name"))
    }
  }

} 
开发者ID:scalalandio,项目名称:chimney,代码行数:39,代码来源:IssuesSpec.scala

示例2: ActionsTest

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

import org.scalatest.{ MustMatchers, WordSpec }

class ActionsTest extends WordSpec with MustMatchers {

  "RequestReport" must {
    val a = Actions.RequestReport

    "provide toParameterValue" in {
      a.toParameterValue mustEqual "RequestReport"
    }
  }

  "GetReportRequestList" must {
    val a = Actions.GetReportRequestList

    "provide toParameterValue" in {
      a.toParameterValue mustEqual "GetReportRequestList"
    }
  }

  "GetReportList" must {
    val a = Actions.GetReportList

    "provide toParameterValue" in {
      a.toParameterValue mustEqual "GetReportList"
    }
  }
} 
开发者ID:wegtam,项目名称:amws-scala,代码行数:31,代码来源:ActionsTest.scala

示例3: RegionsTest

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

import java.net.URI

import com.wegtam.amws.common.MarketPlaces._
import com.wegtam.amws.common.Regions._
import org.scalatest.prop.PropertyChecks
import org.scalatest.{ MustMatchers, WordSpec }

import scala.collection.immutable.Seq

class RegionsTest extends WordSpec with MustMatchers with PropertyChecks {
  private final val expectedEndpoints = Table(
    ("Region", "Endpoint"),
    (NorthAmerica, new URI("https://mws.amazonservices.com")),
    (Brazil, new URI("https://mws.amazonservices.com")),
    (Europe, new URI("https://mws-eu.amazonservices.com")),
    (India, new URI("https://mws.amazonservices.in")),
    (China, new URI("https://mws.amazonservices.com.cn")),
    (Japan, new URI("https://mws.amazonservices.jp"))
  )
  private final val expectedMarketplaces = Table(
    ("Region", "Marketplaces"),
    (NorthAmerica, Seq(CA, MX, US)),
    (Brazil, Seq(BR)),
    (Europe, Seq(DE, ES, FR, IT, UK)),
    (India, Seq(IN)),
    (China, Seq(CN)),
    (Japan, Seq(JP))
  )

  "endpoint" must {
    "return the correct region endpoint" in {
      forAll(expectedEndpoints) { (r: Region, u: URI) =>
        r.endPoint mustEqual u
      }
    }
  }

  "marketPlaces" must {
    "return the correct marketplaces for the region" in {
      forAll(expectedMarketplaces) { (r: Region, mps: Seq[MarketPlace]) =>
        r.marketPlaces mustEqual mps
      }
    }
  }

} 
开发者ID:wegtam,项目名称:amws-scala,代码行数:49,代码来源:RegionsTest.scala

示例4: AbstractSpec

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

import actors.Receptionist
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, MustMatchers}

class AbstractSpec extends TestKit(ActorSystem("test-system"))
  with FlatSpecLike
  with ImplicitSender
  with BeforeAndAfterAll
  with MustMatchers {

  val receptionist = system.actorOf(Receptionist.props(), "receptionist")


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

} 
开发者ID:Sengab-platform,项目名称:backend,代码行数:22,代码来源:AbstractSpec.scala

示例5: ExistentialPrerequisitesSpec

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

import org.scalatest.{ FreeSpec, MustMatchers }

class ExistentialPrerequisitesSpec extends FreeSpec with MustMatchers {

  "must work a as a type erasure" in {

    trait Existential {
      type Inner
      val value: Inner
    }

    case class ExOne(value: Int) extends Existential {
      override type Inner = Int
    }

    val ex1: Existential = ExOne(1)
    println(ex1.getClass)

    final case class TypeErasor[A](value: A) extends Existential { type Inner = A }

    val intErased: Existential = TypeErasor(1)
    println(intErased)
    val v1: intErased.Inner = intErased.value
    val stringErased        = TypeErasor("abc")
    println(stringErased)
    val v2: stringErased.Inner = stringErased.value
    val caseErased             = TypeErasor(ExOne(4))
    println(caseErased)
    val v3: caseErased.Inner = caseErased.value

    // we lost the information about the type of the .value of each Existential instance.
    //  but we can still add restrictions to it

  }

} 
开发者ID:ksilin,项目名称:catfood,代码行数:39,代码来源:ExistentialPrerequisitesSpec.scala

示例6: EitherErrorSpec

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

import com.example.catfood.errors.ApplicationDomain._
import org.scalatest.{ FreeSpec, MustMatchers }

class EitherErrorSpec extends FreeSpec with MustMatchers {

  def arm: Either[SystemOffline, Nuke]      = Right(Nuke())
  def aim: Either[RotationNeedsOil, Target] = Right(Target())
  def launch(target: Target, nuke: Nuke): Either[MissedByMeters, Impacted] =
    Left(MissedByMeters(5))

  def attack(): Either[NukeException, Impacted] =
    for {
      nuke     <- arm
      target   <- aim
      impacted <- launch(target, nuke)
    } yield impacted

  "must attack" in {
    attack() mustBe Left(MissedByMeters(5))
  }

} 
开发者ID:ksilin,项目名称:catfood,代码行数:25,代码来源:EitherErrorSpec.scala

示例7: TextDSLSpec

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

import org.scalatest.{FlatSpec, MustMatchers}

class TextDSLSpec extends FlatSpec with MustMatchers with TextDSL {

  "aligncolumns" must "align columns" in {

    val doc: Document =
      """|---x--
         |---x--x----x--
         |-x--
         |-xxxxx""".stripMargin.document

    val expected: Document =
      """|---x--
         |---x--x----x--
         |-  x--
         |-  x  x    x  xx""".stripMargin.document

    toText(alignColumns("x")(doc)) mustEqual toText(expected)
  }

  "document" must "convert a string to a Document" in {
    val text =
      """hi
        |bye""".stripMargin

    document(text) mustEqual Vector("hi", "bye")
  }

  it must "support different line feed characters" in {
    document("HiXBye")(new LineFeed("X")) mustEqual Vector("Hi", "Bye")
  }
} 
开发者ID:channingwalton,项目名称:textdsl,代码行数:36,代码来源:TextDSLSpec.scala

示例8: ObsoletePersistenceSpec

//设置package包名称以及导入依赖的类
package io.scalac.frees.modules

import cats.Id
import freestyle._
import freestyle.implicits._
import io.scalac.frees.login.handlers.id.{Level, RecordingLogger}
import io.scalac.frees.login.obsolete.{AlreadyExists, Database, InMemoryDatabase, Persistence}
import io.scalac.frees.login.types._
import org.scalatest.{MustMatchers, WordSpec}


class ObsoletePersistenceSpec extends WordSpec with MustMatchers {

  val Email1 = "email1"
  val Password1 = "abc"
  val Password2 = "def"
  val User1Credentials = Credentials(Email1, Password1)

  "Persistence" when {
    "inserting user" should {
      "log line before trying to insert to DB" in new Context {
        persistence.insertUser(Email1, Password1).interpret[Id]
        logHandler.getRecords.filter(e => e.lvl == Level.INFO && e.msg.matches(s"Inserting.*$Email1.*")) must have size 1
      }
      "log line in case of success" in new Context {
        persistence.insertUser(Email1, Password1).interpret[Id]
        logHandler.getRecords.filter(e => e.lvl == Level.INFO && e.msg.contains("inserted")) must have size 1
      }

      "fail when same email address is used again" in new Context {
        val result = persistence.insertUser(Email1, Password1).flatMap { _ =>
          persistence.insertUser(Email1, Password2)
        }.interpret[Id]
        result mustBe AlreadyExists
      }

      "log line in case of failure" in new Context {
        persistence.insertUser(Email1, Password1).flatMap { _ =>
          persistence.insertUser(Email1, Password1)
        }.interpret[Id]
        logHandler.getRecords.filter(e => e.lvl == Level.WARN && e.msg.matches(s".*$Email1.*already exists.*")) must have size 1
      }
      
      "be able to get user back by email" in new Context {
        val u = (for {
          result <- persistence.insertUser(Email1, Password1)
          u <- persistence.database.getUserByEmail(Email1)
        } yield u).interpret[Id]
        u.isDefined mustEqual true
      }
    }
  }

  trait Context {
    implicit lazy val logHandler = new RecordingLogger
    implicit lazy val dbHandler: Database.Handler[Id] = new InMemoryDatabase
    implicit lazy val persistence = implicitly[Persistence[Persistence.Op]]
  }

} 
开发者ID:LGLO,项目名称:freestyle-login,代码行数:61,代码来源:ObsoletePersistenceSpec.scala

示例9: LircParserSpec

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

import javax.inject.Provider

import io.TestableProcessLogger
import org.scalatest.{FlatSpec, MustMatchers}
import org.scalamock.scalatest.MockFactory

import scala.sys.process._


class LircParserSpec extends FlatSpec with MustMatchers with MockFactory {

  "The irsend command" should "find devices" in {

    val process = mock[ProcessCreation]
    val builder = mock[ProcessBuilder]
    val provider = mock[Provider[TestableProcessLogger]]
    val logger = mock[TestableProcessLogger]

    (process.apply(_:String,_:Seq[String])).expects("irsend", Seq("list", "", "")).returns(builder)
    (logger.processLogger _).expects().returns(null)
    (logger.lines _).expects().returns(List("irsend: sony", "irsend: jvc"))
    (provider.get _).expects().returns(logger)
    (builder.lineStream_! (_: ProcessLogger)).expects(*)

    val lircParser = new DefaultLircParser(process, provider)
    lircParser.listDevices must be(Seq("sony", "jvc"))
  }

  it should "find buttons for a device" in {

    val process = mock[ProcessCreation]
    val builder = mock[ProcessBuilder]
    val provider = mock[Provider[TestableProcessLogger]]
    val logger = mock[TestableProcessLogger]

    (process.apply(_:String,_:Seq[String])).expects("irsend", Seq("list", "sony", "")).returns(builder)
    (logger.processLogger _).expects().returns(null)
    (logger.lines _).expects().returns(List("irsend: 0000000000000481 KEY_VOLUMEUP", "irsend: 0000000000000c81 KEY_VOLUMEDOWN"))
    (provider.get _).expects().returns(logger)
    (builder.lineStream_! (_:ProcessLogger)).expects(*)

    val lircParser = new DefaultLircParser(process, provider)
    lircParser.listButtons("sony") must be(Seq("KEY_VOLUMEUP", "KEY_VOLUMEDOWN"))
  }

  it should "press buttons for a device" in {

    val process = mock[ProcessCreation]
    val builder = mock[ProcessBuilder]
    val provider = mock[Provider[TestableProcessLogger]]
    val logger = mock[TestableProcessLogger]

    (process.apply(_:String,_:Seq[String])).expects("irsend", Seq("SEND_ONCE", "sony", "KEY_VOLUMEUP")).returns(builder)
    (builder.! _).expects().returns(0)

    val lircParser = new DefaultLircParser(process, null)
    lircParser.pressButton("sony", "KEY_VOLUMEUP") must be(true)
  }
} 
开发者ID:jimnybob,项目名称:smartii-ir,代码行数:62,代码来源:LircParserSpec.scala

示例10: RuleGeneratorTest

//设置package包名称以及导入依赖的类
package de.zalando.play.generator.routes

import de.zalando.apifirst.Application.StrictModel
import de.zalando.apifirst.naming.Path
import org.scalatest.{ FunSpec, MustMatchers }
import play.routes.compiler.{ DynamicPart, StaticPart }


class RuleGeneratorTest extends FunSpec with MustMatchers {

  implicit val model = StrictModel(Nil, Map.empty, Map.empty, Map.empty, "/base/", None, Map.empty, Map.empty)

  val routes = Map(
    "/" -> Nil, "/a/b/c/d" -> List(StaticPart("a/b/c/d")), "/a/b/c/d/" -> List(StaticPart("a/b/c/d/")), "/a/{b}/c/{d}" -> List(StaticPart("a/"), DynamicPart("b", """[^/]+""", true), StaticPart("/c/"), DynamicPart("d", """[^/]+""", true)), "/{a}/{b}/{c}/{d}/" -> List(DynamicPart("a", """[^/]+""", true), StaticPart("/"), DynamicPart("b", """[^/]+""", true), StaticPart("/"), DynamicPart("c", """[^/]+""", true), StaticPart("/"), DynamicPart("d", """[^/]+""", true), StaticPart("/")), "/{a}/b/{c}/d/" -> List(DynamicPart("a", """[^/]+""", true), StaticPart("/b/"), DynamicPart("c", """[^/]+""", true), StaticPart("/d/"))
  )

  describe("RuleGeneratorTest") {
    routes.foreach {
      case (path, expected) =>
        it(s"should parse $path as expected") {
          val result = RuleGenerator.convertPath(Path(path)).parts
          result must contain theSameElementsInOrderAs expected
        }
    }
  }
} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:27,代码来源:RuleGeneratorTest.scala

示例11: ScalaNameTest

//设置package包名称以及导入依赖的类
package de.zalando.apifirst

import de.zalando.apifirst.ScalaName._
import de.zalando.apifirst.naming.dsl._
import org.scalatest.{ FunSpec, MustMatchers }

class ScalaNameTest extends FunSpec with MustMatchers {

  it("must correctly capitalize names") {
    ("one" / "two" / "three").names mustBe (("one", "Two", "three"))
    ("ONE" / "TWO" / "THREE").names mustBe (("one", "TWO", "tHREE"))
    ("OnE" / "TwO" / "ThReE").names mustBe (("one", "TwO", "thReE"))
  }

  it("must correctly recognize short names") {
    ("one" / "two").names mustBe (("one", "Two", "two"))
  }

  it("must correctly escape scala names") {
    ("catch" / "if" / "match").names mustBe (("`catch`", "If", "`match`"))
  }

  it("must be able to produce import statemets") {
    ("java.util" / "date").qualifiedName("", "") mustBe (("java.util", "Date"))
  }

  it("must correctly concat names") {
    ("definitions" / "Example" / "nestedArrays" / "Opt" / "Arr:").names mustBe (("definitions", "Example", "arr_esc"))
  }

} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:32,代码来源:ScalaNameTest.scala

示例12: SecurityDefinitionDeserializerTest

//设置package包名称以及导入依赖的类
package de.zalando.swagger

import java.io.File

import de.zalando.swagger.strictModel._
import org.scalatest.{ MustMatchers, FunSpec }


class SecurityDefinitionDeserializerTest extends FunSpec with MustMatchers with ExpectedResults {

  val file = new File(resourcesPath + "examples/security.api.yaml")

  describe("SecurityDefinitionDeserializer") {
    it(s"should parse security definitions in the ${file.getName}") {
      val (uri, model) = StrictYamlParser.parse(file)
      val result = model.securityDefinitions
      result.size mustBe 6
      result("petstoreImplicit") mustBe a[Oauth2ImplicitSecurity]
      result("githubAccessCode") mustBe a[Oauth2AccessCodeSecurity]
      result("petstorePassword") mustBe a[Oauth2PasswordSecurity]
      result("justBasicStuff") mustBe a[BasicAuthenticationSecurity]
      result("petstoreApplication") mustBe a[Oauth2ApplicationSecurity]
      result("internalApiKey") mustBe a[ApiKeySecurity]
    }
  }
} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:27,代码来源:SecurityDefinitionDeserializerTest.scala

示例13: SecurityConstraintsIntegrationTest

//设置package包名称以及导入依赖的类
package de.zalando.swagger

import java.io.File

import org.scalatest.{ FunSpec, MustMatchers }


class SecurityConstraintsIntegrationTest extends FunSpec with MustMatchers with ExpectedResults {

  override val expectationsFolder = super.expectationsFolder + "security_constraints/"

  val fixtures = new File("swagger-parser/src/test/resources/examples").listFiles

  describe("Swagger ApiCall Converter with security constraints") {
    fixtures.filter(_.getName.endsWith(".yaml")).foreach { file =>
      testSecurityConverter(file)
    }
  }

  def testSecurityConverter(file: File): Unit = {
    it(s"should convert security constraints in ${file.getName}") {
      val (base, model) = StrictYamlParser.parse(file)
      val ast = ModelConverter.fromModel(base, model, Option(file))
      val fullResult = ast.calls.filter(_.security.nonEmpty).flatMap(_.security).distinct.mkString("\n")
      val expected = asInFile(file, "types")
      if (expected.isEmpty && fullResult.trim.nonEmpty)
        dump(fullResult, file, "types")
      clean(fullResult) mustBe clean(expected)
    }
  }

} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:33,代码来源:SecurityConstraintsIntegrationTest.scala

示例14: SecurityConverterIntegrationTest

//设置package包名称以及导入依赖的类
package de.zalando.swagger

import java.io.File

import de.zalando.swagger.strictModel.SwaggerModel
import org.scalatest.{ FunSpec, MustMatchers }


class SecurityConverterIntegrationTest extends FunSpec with MustMatchers with ExpectedResults {

  override val expectationsFolder = super.expectationsFolder + "security_definitions/"

  val fixtures = new File(resourcesPath + "examples").listFiles

  describe("Swagger Security Converter") {
    fixtures.filter(_.getName.endsWith(".yaml")).foreach { file =>
      testSecurityConverter(file)
    }
  }

  def testSecurityConverter(file: File): Unit = {
    it(s"should convert security definitions from ${file.getName}") {
      val (base, model) = StrictYamlParser.parse(file)
      model mustBe a[SwaggerModel]
      val securityDefs = SecurityConverter.convertDefinitions(model.securityDefinitions)
      val fullResult = securityDefs.mkString("\n")
      val expected = asInFile(file, "types")
      if (expected.isEmpty)
        dump(fullResult, file, "types")
      clean(fullResult) mustBe clean(expected)
    }
  }
} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:34,代码来源:SecurityConverterIntegrationTest.scala

示例15: TypeConverterTest

//设置package包名称以及导入依赖的类
package de.zalando.swagger

import java.io.File

import de.zalando.swagger.strictModel.SwaggerModel
import org.scalatest.{ FunSpec, MustMatchers }

class TypeConverterTest extends FunSpec with MustMatchers with ExpectedResults {

  override val expectationsFolder = super.expectationsFolder + "types/"

  val modelFixtures = new File(resourcesPath + "model").listFiles

  val exampleFixtures = new File(resourcesPath + "examples").listFiles

  describe("Strict Swagger Parser model") {
    modelFixtures.filter(_.getName.endsWith(".yaml")).foreach { file =>
      testTypeConverter(file)
    }
  }

  describe("Strict Swagger Parser examples") {
    exampleFixtures.filter(_.getName.endsWith(".yaml")).foreach { file =>
      testTypeConverter(file)
    }
  }

  def testTypeConverter(file: File): Unit = {
    it(s"should parse the yaml swagger file ${file.getName} as specification") {
      val (base, model) = StrictYamlParser.parse(file)
      model mustBe a[SwaggerModel]
      val typeDefs = ModelConverter.fromModel(base, model, Some(file)).typeDefs
      val typeMap = typeDefs map { case (k, v) => k -> ("\n\t" + de.zalando.apifirst.util.ShortString.toShortString("\t\t")(v)) }
      val typesStr = typeMap.toSeq.sortBy(_._1.parts.size).map(p => p._1 + " ->" + p._2).mkString("\n")
      val expected = asInFile(file, "types")
      if (expected.isEmpty) dump(typesStr, file, "types")
      clean(typesStr) mustBe clean(expected)
    }
  }

} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:42,代码来源:TypeConverterTest.scala


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