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

Scala TestSpec类代码示例

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

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



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

示例1: Foo

//设置package包名称以及导入依赖的类
package com.github.dnvriend.pickle.deserialization

import com.github.dnvriend.TestSpec
import org.typelevel.scalatest.DisjunctionMatchers

import upickle.default._

import scala.util.Try

final case class Foo(foo: Int)
final case class Bar(bar: String)
final case class Baz(baz: Option[String])
final case class Qux(qux: Option[Long])

class DeserializerTest extends TestSpec with DisjunctionMatchers {
  def fromJson(str: String): Option[Any] = {
    (
      Try(read[Foo](str)) orElse
      Try(read[Bar](str)) orElse
      Try(read[Baz](str)) orElse
      Try(read[Qux](str))
    ).toOption
  }

  val logOfMessages: String = List(
    write(Foo(1)), write(Bar("bar")), write(Baz(Option("baz"))), write(Qux(Option(1))), write(Foo(2)), write(Baz(None))
  ).mkString("\n")

  it should "read log of messages" in {
    logOfMessages.split("\n").toList.flatMap(fromJson) shouldBe List(Foo(1), Bar("bar"), Baz(Some("baz")), Qux(Some(1)), Foo(2), Baz(None))
  }
} 
开发者ID:dnvriend,项目名称:upickle-test,代码行数:33,代码来源:UPickleDeserializerTest.scala


示例2: Foo

//设置package包名称以及导入依赖的类
package com.github.dnvriend.play.deserialization

import com.github.dnvriend.TestSpec
import org.typelevel.scalatest.DisjunctionMatchers
import play.api.libs.json._

import scala.util.Try

object Foo {
  implicit val format = Json.format[Foo]
}
final case class Foo(foo: Int)

object Bar {
  implicit val format = Json.format[Bar]
}
final case class Bar(bar: String)

object Baz {
  implicit val format = Json.format[Baz]
}
final case class Baz(baz: Option[String])

object Qux {
  implicit val format = Json.format[Qux]
}
final case class Qux(qux: Option[Long])

class PlayDeserializerTest extends TestSpec with DisjunctionMatchers {
  def toJson[A: Format](a: A) = Json.toJson(a).toString

  def fromJson(json: JsValue): Option[Any] = {
    (
      Try(json.as[Foo]) orElse
      Try(json.as[Bar]) orElse
      Try(json.as[Baz]) orElse
      Try(json.as[Qux])
    ).map { e => println(s"$json => $e"); e }.toOption
  }

  val logOfMessages: String =
    List(
      toJson(Foo(1)),
      toJson(Bar("bar")),
      toJson(Baz(Option("baz"))),
      toJson(Qux(Option(1))),
      toJson(Foo(2)),
      toJson(Baz(None))
    ).mkString("\n")

  ignore should "read log of messages" in {
    // good to know that matching on a function with orElse can give false positives
    logOfMessages
      .split("\n")
      .toList
      .map(Json.parse)
      .flatMap(fromJson) shouldBe List(Foo(1), Bar("bar"), Baz(Some("baz")), Qux(Some(1)), Foo(2), Baz(None))
  }
} 
开发者ID:dnvriend,项目名称:upickle-test,代码行数:60,代码来源:PlayDeserializerTest.scala


示例3: ProducerConsumerTest

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

import akka.kafka.scaladsl.{Consumer, Producer}
import akka.kafka.scaladsl.Producer.Message
import akka.stream.scaladsl.Source
import com.github.dnvriend.TestSpec
import org.apache.kafka.clients.producer.ProducerRecord

class ProducerConsumerTest extends TestSpec {

  it should "produce and consume messages" in {
    Source(1 to 10000)
      .map(_.toString)
      .map(elem => Message(new ProducerRecord[Array[Byte], String]("topic1", elem), elem))
      .via(Producer.flow(producerSettings))
      .map { result =>
        val record = result.message.record
        println(s"${record.topic}/${record.partition} ${result.offset}: ${record.value} (${result.message.passThrough})")
        result
      }
      .runForeach(_ => ()).toTry should be a 'success

    Consumer.plainSource(consumerSettings.withClientId("client1"))
      .take(1000)
      .runForeach(println).toTry should be a 'success
  }

} 
开发者ID:dnvriend,项目名称:reactive-kafka-test,代码行数:29,代码来源:ProducerConsumerTest.scala


示例4: ConnectionTest

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

import com.github.dnvriend.TestSpec
import doobie.imports._
import scalaz._, Scalaz._
import scalaz.concurrent.Task

class ConnectionTest extends TestSpec {
  it should "0" in {
    val actions: ConnectionIO[Int] = 42.point[ConnectionIO]
    val task = actions.transact(xa)
    task.run shouldBe 42
  }

  it should "1" in {
    val actions: ConnectionIO[Int] = sql"select 42".query[Int].unique
    val task2 = actions.transact(xa)
    task2.run shouldBe 42
  }

  it should "2" in {
    val actions: ConnectionIO[(Int, Double)] =
      for {
        a ? sql"select 42".query[Int].unique
        b ? sql"select random()".query[Double].unique
      } yield (a, b)

    actions.transact(xa).run should matchPattern {
      case (x: Int, y: Double) ?
    }
  }

  it should "3" in {
    val actions: ConnectionIO[(Int, Double)] = {
      val a = sql"select 42".query[Int].unique
      val b = sql"select random()".query[Double].unique
      (a |@| b).tupled
    }
    actions.transact(xa).run should matchPattern {
      case (x: Int, y: Double) ?
    }
  }

  it should "4" in {
    val actions: ConnectionIO[(Int, Double)] = {
      val a = sql"select 42".query[Int].unique
      val b = sql"select random()".query[Double].unique
      (a |@| b).tupled
    }
    actions.replicateM(2).transact(xa).run should matchPattern {
      case (a: Int, b: Double) :: (c: Int, d: Double) :: Nil ?
    }
  }
} 
开发者ID:dnvriend,项目名称:doobie-test,代码行数:55,代码来源:ConnectionTest.scala


示例5: UserRepositoryTest

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

import com.github.dnvriend.{ TestSpec, UserTableRow }

class UserRepositoryTest extends TestSpec {
  it should "user repo should be empty" in {
    userRepository.allUsers.futureValue shouldBe empty
  }

  it should "initialize with users" in {
    userRepository.init.toTry should be a 'success
    userRepository.allUsers.futureValue should not be empty
  }

  it should "find by id" in {
    userRepository.init.toTry should be a 'success
    val users = userRepository.allUsers.futureValue
    users should not be empty
    val userId = userRepository.allUsers.futureValue.head.id.value
    userRepository.findById(userId).futureValue.value shouldBe UserTableRow(Option(5), "Bill", "Gates")
  }
} 
开发者ID:dnvriend,项目名称:scalikejdbc-test,代码行数:23,代码来源:UserRepositoryTest.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala DatabaseConfig类代码示例发布时间:2022-05-23
下一篇:
Scala ApplicationContext类代码示例发布时间: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