本文整理汇总了Scala中org.scalatest.FlatSpec类的典型用法代码示例。如果您正苦于以下问题:Scala FlatSpec类的具体用法?Scala FlatSpec怎么用?Scala FlatSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlatSpec类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: URIUtilsSpec
//设置package包名称以及导入依赖的类
package com.pygmalios.reactiveinflux.impl
import java.net.URI
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class URIUtilsSpec extends FlatSpec {
behavior of "appendPath"
it should "strip /" in {
assert(URIUtils.appendPath(new URI("http://x/"), "/a").toString == "http://x/a")
}
behavior of "queryToString"
it should "create empty query string" in {
assert(URIUtils.queryToString() == "")
}
it should "create query string with single item" in {
assert(URIUtils.queryToString("a" -> "b") == "?a=b")
}
it should "create query string with two items" in {
assert(URIUtils.queryToString("a" -> "b", "c" -> "d") == "?a=b&c=d")
}
}
开发者ID:pygmalios,项目名称:reactiveinflux,代码行数:31,代码来源:URIUtilsSpec.scala
示例2: HttpJsonTopicFetcherTest
//设置package包名称以及导入依赖的类
package com.groupon.dse.kafka.topic
import org.mockito.Mockito
import org.scalatest.{BeforeAndAfter, FlatSpec}
class HttpJsonTopicFetcherTest extends FlatSpec with BeforeAndAfter {
"The topic fetcher" should "return the correct list of topics " in {
val http = Mockito.spy(new HttpJsonTopicFetcher("http://test-url"))
val content = "{\"topics\":[{\"name\":\"topic1\",\"metadata\":{\"m1\":\"v1\",\"m2\":true}},{\"name\":\"topic2\",\"metadata\":{\"m3\":\"v3\"}}],\"extras\":\"test\"}"
Mockito.doReturn(Some(content)).when(http).getContentFromUrl
assert(http.fetchTopics == Seq(TopicAndMetadata("topic1", Map("m1" -> "v1", "m2" -> true.asInstanceOf[AnyRef])), TopicAndMetadata("topic2", Map("m3" -> "v3"))))
}
"The topic fetcher" should "return an empty list if the Json in incorrect " in {
val http = Mockito.spy(new HttpJsonTopicFetcher("http://test-url"))
val content = "{\"topics\":[{\"name\":\"topic1\",\"metadata\":{\"m1\":\"v1\",\"m2\":true}}{\"name\":\"topic2\",\"metadata\":{\"m3\":\"v3\"}}],\"extras\":\"test\"}"
Mockito.doReturn(Some(content)).when(http).getContentFromUrl
assert(http.fetchTopics == Seq())
}
"The topic fetcher " should "return the filtered list if the name field is missing for any topic" in {
val http = Mockito.spy(new HttpJsonTopicFetcher("http://test-url"))
val contents = "{\"topics\":[{\"name\":\"topic1\",\"metadata\":{\"m1\":\"v1\",\"m2\":\"v2\"}},{\"name1\":\"topic2\",\"enabled\":\"false\",\"metadata\":{\"m3\":\"v3\",\"m4\":\"v4\"}},{\"name\":\"topic3\",\"enabled\":\"true\",\"metadata\":{\"m3\":\"v3\",\"m4\":\"v4\"}}],\"extras\":\"test\"}"
Mockito.doReturn(Some(contents)).when(http).getContentFromUrl
assert(http.fetchTopics == Seq(TopicAndMetadata("topic1", Map("m1" -> "v1", "m2" -> "v2")), TopicAndMetadata("topic3", Map("m3" -> "v3", "m4" -> "v4"))))
}
"The topic fetcher" should "return an empty map if no metadata is provided" in {
val http = Mockito.spy(new HttpJsonTopicFetcher("http://test-url"))
val contents = "{\"topics\":[{\"name\":\"topic1\"},{\"name\":\"topic2\",\"metadata\":{\"m3\":\"v3\",\"m4\":{\"m5\":\"v5\"},\"bool\":true}}]}"
Mockito.doReturn(Some(contents)).when(http).getContentFromUrl
assert(http.fetchTopics == Seq(TopicAndMetadata("topic1", Map()), TopicAndMetadata("topic2", Map("m3" -> "v3", "m4" -> Map("m5" -> "v5").asInstanceOf[AnyRef], "bool" -> true.asInstanceOf[AnyRef]))))
}
"The topic fetcher" should "return an empty list of topics if there is any problem when fetching the Json" in {
val http = Mockito.spy(new HttpJsonTopicFetcher("http://test-url"))
Mockito.doReturn(None).when(http).getContentFromUrl
assert(http.fetchTopics == Seq.empty)
}
}
开发者ID:groupon,项目名称:baryon,代码行数:43,代码来源:HttpJsonTopicFetcherTest.scala
示例3: NoneToDefulatValueDataSetSpec
//设置package包名称以及导入依赖的类
package com.newegg.eims.DataPorter.Base
import com.newegg.eims.DataPorter.Base.Converts._
import org.scalatest.{FlatSpec, Matchers}
class NoneToDefulatValueDataSetSpec extends FlatSpec with Matchers {
val ValMap = Map(
"TINYINT" -> (new DataColumn[Int](0, "TINYINT", CByte, i => None), 0.toByte),
"int" -> (new DataColumn[Int](1, "int", CInt, i => None), 0),
"smallint" -> (new DataColumn[Int](2, "smallint", CShort, i => None), 0.toShort),
"bigint" -> (new DataColumn[Int](3, "bigint", CLong, i => None), 0L),
"boolean" -> (new DataColumn[Int](4, "boolean", CBool, i => None), false),
"float" -> (new DataColumn[Int](5, "float", CFloat, i => None), 0.toFloat),
"double" -> (new DataColumn[Int](6, "double", CDouble, i => None), 0D),
"decimal" -> (new DataColumn[Int](7, "decimal", CBigdecimal(38, 10), i => None), java.math.BigDecimal.ZERO),
"string" -> (new DataColumn[Int](8, "string", CString, i => None), ""),
"timestamp" -> (new DataColumn[Int](9, "timestamp", CTimestamp, i => None), java.sql.Timestamp.valueOf("1997-01-01 00:00:00")),
"test" -> (new DataColumn[Int](10, "test", CNoSupport, i => None), null)
)
val data: DataSet[IDataRow] = Array(1, 2).toIterable.transform(ValMap.values.map(_._1).toSeq: _*)
it should "read csv expect and has right schema" in {
for (i <- 1.to(2)) {
val dataSet = data.noneToDefulatValue()
val rowIterator = dataSet.iterator.asInstanceOf[DataRowIterator[IDataRow]]
val schema = rowIterator.getSchema
rowIterator.foreach(j => {
schema.getColumns.length shouldBe ValMap.size
j.isNull shouldBe false
ValMap.values.map(_._1).foreach(x => {
j.getVal(x.getName).getOrElse(None) shouldBe ValMap(x.getName)._2
})
})
rowIterator.next().isNull shouldBe true
}
}
}
开发者ID:CodeBabyBear,项目名称:DataPorter,代码行数:39,代码来源:NoneToDefulatValueDataSetSpec.scala
示例4: HttpExportSpec
//设置package包名称以及导入依赖的类
package com.github.norwae.ignifera
import akka.http.scaladsl.model.HttpEntity
import io.prometheus.client.exporter.common.TextFormat
import io.prometheus.client.{CollectorRegistry, Gauge}
import org.scalatest.matchers.{MatchResult, Matcher}
import org.scalatest.{FlatSpec, Matchers}
import scala.concurrent.duration._
class HttpExportSpec extends FlatSpec with Matchers {
"The http export object" should "include metrics provided by the collector" in {
val export = new HttpExport {
override val registry: CollectorRegistry = new CollectorRegistry()
}
val gauge = Gauge.build("testgauge", "Test").register(export.registry)
gauge.inc()
val reply = export.exportReply
val entity = reply.entity.asInstanceOf[HttpEntity.Strict]
val string = entity.data.utf8String
string should containSubstring("testgauge")
}
it should "have the correct content type" in {
val reply = new HttpExport {}.exportReply
reply.entity.contentType.value.toLowerCase shouldEqual TextFormat.CONTENT_TYPE_004.toLowerCase
}
it should "include the default metrics" in {
val reply = new HttpExport {}.exportReply
val entity = reply.entity.asInstanceOf[HttpEntity.Strict]
val string = entity.data.utf8String
string should containSubstring("process_cpu_seconds_total")
string should containSubstring("jvm_classes_loaded")
}
private def containSubstring(expected: String) =
Matcher[String](left => MatchResult(left.contains(expected), s"Contain $expected", s"not contain $expected"))
}
开发者ID:Norwae,项目名称:ignifera,代码行数:40,代码来源:HttpExportSpec.scala
示例5: ChunkifyAndBuildTest
//设置package包名称以及导入依赖的类
package io
import java.io.File
import communication.FileManifest
import index.FileIndex
import org.scalatest.{FlatSpec, Matchers}
class ChunkifyAndBuildTest extends FlatSpec with Matchers {
implicit val homeDirPath = "/home/mike/Programming/scala/"
"Chunkifier and FileBuilder" should "chunkify and rebuild file properly" in {
val originalFile = new File("src/test/resources/chunkifierTest")
val chunksList: List[Chunk] = Chunkifier(100, originalFile)
val fileManifest = FileManifest(new FileIndex(originalFile), 100)
val fileBuilder = new FileBuilder(fileManifest)
chunksList.foreach(chunk => fileBuilder.accept(chunk))
fileBuilder.build()
val newChunksList: List[Chunk] = Chunkifier(100, originalFile)
chunksList.indices.foreach { i => chunksList(i).content should equal(newChunksList(i).content) }
}
}
开发者ID:mprzewie,项目名称:cloudia-utils,代码行数:25,代码来源:ChunkifyAndBuildTest.scala
示例6: SalesforceCustomerRepoSpec
//设置package包名称以及导入依赖的类
package com.ovoenergy.comms.profiles.salesforce
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Paths}
import com.ovoenergy.comms.profiles.domain._
import okhttp3._
import org.scalatest.{EitherValues, FlatSpec, Matchers}
class SalesforceCustomerRepoSpec extends FlatSpec with Matchers with EitherValues {
behavior of "SalesforceCustomerRepo"
val request = new Request.Builder().url("http://google.com").get().build()
def buildResponse(code: Int, body: String): (String) => Either[SalesforceError, Response] =
(str: String) =>
Right(
new Response.Builder()
.protocol(Protocol.HTTP_1_1)
.code(code)
.request(request)
.body(ResponseBody.create(MediaType.parse("application/json"), body))
.build()
)
it should "Successfull deserialise a valid customer json body" in {
val json =
new String(Files.readAllBytes(Paths.get("src/test/resources/customer_profile.json")), StandardCharsets.UTF_8)
val makeAuthenticatedRequest = buildResponse(200, json)
val profile = SalesforceCustomerRepo.getCustomerProfile(makeAuthenticatedRequest)("customer123")
profile shouldBe Right(
Customer(
Name(Some("Mr"), "Gary", "Philpott", None),
EmailAddresses(Some("[email protected]"), None),
TelephoneNumbers(Some("+441285112233"), Some("+447834774651"), Some("+441285112233")),
Embedded(
List(
CommunicationPreference("SERVICE", List("Sms", "Email", "POST")),
CommunicationPreference("MARKETING", List.empty),
CommunicationPreference("THIRDPARTY", List.empty)
)
)
)
)
}
it should "display an appropriate message if invalid json is returned" in {
val makeAuthenticatedRequest = buildResponse(200, """{"some": "thing"}""")
val profile = SalesforceCustomerRepo.getCustomerProfile(makeAuthenticatedRequest)("customer123")
profile.left.value.message should startWith("Invalid JSON from salesforce api")
}
}
开发者ID:ovotech,项目名称:comms-profiles,代码行数:55,代码来源:SalesforceCustomerRepoSpec.scala
示例7: StuffTest
//设置package包名称以及导入依赖的类
import org.scalamock.scalatest.MockFactory
import org.scalatest.FlatSpec
class StuffTest extends FlatSpec with MockFactory {
"A stuff" should "write stuff to db" in {
val dbmock = mock[Database]
Stuff.setDatabase(dbmock)
(dbmock.write _).expects("A", "string").once()
(dbmock.close _).expects().once()
Stuff.writeAtoDB()
}
"A stuff" should "write B stuff to db" in {
val dbmock = mock[Database]
Stuff.setDatabase(dbmock)
(dbmock.write _).expects("B", "string").twice()
(dbmock.close _).expects().twice()
Stuff.writeBtoDB()
}
}
开发者ID:mrcarlosrendon,项目名称:scala-unit-testing,代码行数:22,代码来源:StuffTest.scala
示例8: BEncodeTest
//设置package包名称以及导入依赖的类
import java.time.Instant
import com.karasiq.bittorrent.format.{Torrent, TorrentFile, TorrentPiece}
import org.apache.commons.codec.binary.Hex
import org.apache.commons.io.IOUtils
import org.scalatest.{FlatSpec, Matchers}
class BEncodeTest extends FlatSpec with Matchers {
val testFile = IOUtils.toByteArray(getClass.getResource("ubuntu-15.10-desktop-amd64.iso.torrent"))
"BEncode parser" should "parse torrent file" in {
val torrent = Torrent(testFile)
Hex.encodeHexString(torrent.infoHash.toArray).toUpperCase shouldBe "3F19B149F53A50E14FC0B79926A391896EABAB6F"
torrent.announce shouldBe "http://torrent.ubuntu.com:6969/announce"
torrent.announceList shouldBe Vector(Vector("http://torrent.ubuntu.com:6969/announce"), Vector("http://ipv6.torrent.ubuntu.com:6969/announce"))
torrent.comment shouldBe Some("Ubuntu CD releases.ubuntu.com")
torrent.date shouldBe Some(Instant.parse("2015-10-22T09:48:19Z"))
torrent.data.pieceLength shouldBe 524288L
torrent.data.pieces.length shouldBe 44960
torrent.data.files.headOption shouldBe Some(TorrentFile("ubuntu-15.10-desktop-amd64.iso", 1178386432L))
}
"Torrent pieces" should "be constructed" in {
val torrent = Torrent(testFile)
val pieces = TorrentPiece.pieces(torrent.data)
pieces.length shouldBe (torrent.data.pieces.length / 20)
pieces.map(_.size).sum shouldBe torrent.size
pieces.head.sha1.length shouldBe 20
}
"Torrent piece blocks" should "be constructed" in {
val torrent = Torrent(testFile)
val pieces = TorrentPiece.pieces(torrent.data)
val blocks = TorrentPiece.blocks(pieces.head, 10000)
blocks.map(_.size).sum shouldBe pieces.head.size
}
}
开发者ID:Karasiq,项目名称:torrentstream,代码行数:38,代码来源:BEncodeTest.scala
示例9: AX25FrameSpec
//设置package包名称以及导入依赖的类
package com.softwaremill.modemconnector.ax25
import com.softwaremill.modemconnector.FrameUtils
import org.scalatest.{BeforeAndAfter, FlatSpec, Matchers}
class AX25FrameSpec extends FlatSpec with Matchers with BeforeAndAfter {
"A simple AX25Frame" should "contain decoded data" in {
val ax25frame: AX25Frame = FrameUtils.ax25frameFromFile("/andrej.bin")
new String(ax25frame.body) should equal("=4603.63N/01431.26E-Op. Andrej")
}
"A simple AX25Frame" should "contain sender callsign" in {
val ax25frame: AX25Frame = FrameUtils.ax25frameFromFile("/andrej.bin")
ax25frame.sender.callsign should equal("S57LN")
}
"A simple AX25Frame" should "contain destination callsign" in {
val ax25frame: AX25Frame = FrameUtils.ax25frameFromFile("/andrej.bin")
ax25frame.dest.callsign should equal("APRS")
}
"A simple AX25Frame" should "encode byte array" in {
val ax25frame = AX25Frame(FrameUtils.ax25frameFromFile("/andrej.bin").toBytes)
new String(ax25frame.body) should equal("=4603.63N/01431.26E-Op. Andrej")
ax25frame.dest.callsign should equal("APRS")
ax25frame.sender.callsign should equal("S57LN")
}
"An AX25Frame with digipiters" should "contain decoded data" in {
val ax25frame = FrameUtils.ax25frameFromFile("/complexFrame.bin")
new String(ax25frame.body) should equal("`'4< \\4>/]\"3k}145.500MHz qrv her=\r")
}
"An AX25Frame with digipiters" should "contain sender callsign" in {
val ax25frame = FrameUtils.ax25frameFromFile("/complexFrame.bin")
ax25frame.sender.toString should equal("OZ1IEP-9")
}
"An AX25Frame with digipiters" should "contain destination callsign" in {
val ax25frame = FrameUtils.ax25frameFromFile("/complexFrame.bin")
ax25frame.dest.toString should equal("U4TQ33")
}
"An AX25Frame with digipiters" should "contain digipiters" in {
val ax25frame = FrameUtils.ax25frameFromFile("/complexFrame.bin")
ax25frame.digipeaters.map(_.toString).toSeq should contain theSameElementsInOrderAs List("OZ6DIA-2", "OZ4DIA-2", "OZ4DIE-2")
}
"An AX25Frame with digipiters" should "encode byte array" in {
val ax25frame = AX25Frame(FrameUtils.ax25frameFromFile("/complexFrame.bin").toBytes)
ax25frame.digipeaters.map(_.toString).toSeq should contain theSameElementsInOrderAs List("OZ6DIA-2", "OZ4DIA-2", "OZ4DIE-2")
ax25frame.dest.toString should equal("U4TQ33")
ax25frame.sender.toString should equal("OZ1IEP-9")
new String(ax25frame.body) should equal("`'4< \\4>/]\"3k}145.500MHz qrv her=\r")
}
}
开发者ID:softwaremill,项目名称:modem-connector,代码行数:59,代码来源:AX25FrameSpec.scala
示例10: AGWPEConnectorSpec
//设置package包名称以及导入依赖的类
package com.softwaremill.modemconnector.agwpe
import java.net.ServerSocket
import org.scalatest.{BeforeAndAfterEach, FlatSpec, Matchers}
class AGWPEConnectorSpec extends FlatSpec with Matchers with BeforeAndAfterEach {
var server: ServerSocket = _
override def beforeEach(): Unit = {
server = new ServerSocket(AGWPESettings.port)
}
override def afterEach(): Unit = {
server.close()
}
"An AGWPEConnector" should "be created with configuration settings as default" in {
//when
val connector: AGWPEConnector = new AGWPEConnector()
//then
connector.host shouldEqual "127.0.0.1"
connector.port shouldEqual 8000
connector.timeout shouldEqual 3000
}
"An AGWPEConnector" should "be created with configuration settings as constructor arguments" in {
//given
val host: String = "127.0.0.1"
val port: Int = 8000
val timeout: Int = 1000
//when
val connector: AGWPEConnector = new AGWPEConnector(host, port, timeout)
//then
connector.host shouldEqual host
connector.port shouldEqual port
connector.timeout shouldEqual timeout
}
}
开发者ID:softwaremill,项目名称:modem-connector,代码行数:42,代码来源:AGWPEConnectorSpec.scala
示例11: HexSpec
//设置package包名称以及导入依赖的类
package com.esri
import org.scalatest.{FlatSpec, Matchers}
class HexSpec extends FlatSpec with Matchers {
it should "add" in {
val h1 = Hex(10, 20, 30)
val h2 = Hex(11, 22, 33)
h1 + h2 shouldBe Hex(21, 42, 63)
}
it should "sub" in {
val h1 = Hex(21, 42, 63)
val h2 = Hex(11, 22, 33)
h1 - h2 shouldBe Hex(10, 20, 30)
}
it should "calc length" in {
val h1 = Hex(10, -20, 33)
h1.length shouldBe (10 + 20 + 33) / 2
}
it should "range 0" in {
val h = Hex(10, 20)
(h range 0).head shouldBe Hex(10, 20)
}
it should "range 1" in {
val h = Hex(10, 20)
val range = h range 1
range should contain(h)
range should contain(h neighbor 0)
range should contain(h neighbor 1)
range should contain(h neighbor 2)
range should contain(h neighbor 3)
range should contain(h neighbor 4)
range should contain(h neighbor 5)
}
it should "range 2" in {
val h = Hex(10, 20)
val range = h range 2
range.length shouldBe 19
}
}
开发者ID:mraad,项目名称:grid-hex,代码行数:47,代码来源:HexSpec.scala
示例12: ExecutionContextBackboneCoordinatorSpec
//设置package包名称以及导入依赖的类
package ie.zalando.pipeline.backbone.concurrent
import scala.concurrent.ExecutionContext
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{ FlatSpec, Matchers }
import ie.zalando.pipeline.backbone.PhaseTrackingPhase.PhaseTrackingTopLevelInitPhase
import ie.zalando.pipeline.backbone.Phases.TopLevelInitializationPhase
import ie.zalando.pipeline.backbone.TestDatum
class ExecutionContextBackboneCoordinatorSpec extends FlatSpec with Matchers with ScalaFutures {
"An ExecutionContextBackboneCoordinator" should "push a datum through the pipeline" in new Fixture {
val ec = ExecutionContext.global
val coordinator = new ExecutionContextBackboneCoordinator(backbone, ec)
val f1 = coordinator.process(TestDatum(name = "Megatron"))
val f2 = coordinator.process(TestDatum(name = "Soundwave"))
val f3 = coordinator.process(TestDatum(name = "Shockwave"))
f1.futureValue.isRight shouldBe true
f1.futureValue.foreach(_.phrase shouldBe "Hello, Megatron, this was calculated on partition -1")
f1.futureValue.foreach(_.wordCount shouldBe 8)
f1.futureValue.foreach(_.isEven shouldBe Some(true))
f2.futureValue.isRight shouldBe true
f2.futureValue.foreach(_.phrase shouldBe "Hello, Soundwave, this was calculated on partition -1")
f2.futureValue.foreach(_.wordCount shouldBe 8)
f2.futureValue.foreach(_.isEven shouldBe Some(false))
f3.futureValue.isRight shouldBe true
f3.futureValue.foreach(_.phrase shouldBe "Hello, Shockwave, this was calculated on partition -1")
f3.futureValue.foreach(_.wordCount shouldBe 8)
f3.futureValue.foreach(_.isEven shouldBe Some(false))
}
"An ExecutionContextBackboneCoordinator" should "intialize and release the local phases properly" in new Fixture {
override def driverInitPhases: Seq[TopLevelInitializationPhase[TestDatum]] = super.driverInitPhases :+ PhaseTrackingTopLevelInitPhase()
val ec = ExecutionContext.global
val coordinator = new ExecutionContextBackboneCoordinator(backbone, ec)
val f1 = coordinator.process(TestDatum(name = "Megatron"))
val f2 = coordinator.process(TestDatum(name = "Soundwave"))
val f3 = coordinator.process(TestDatum(name = "Shockwave"))
f1.futureValue.isRight shouldBe true
f2.futureValue.isRight shouldBe true
f3.futureValue.isRight shouldBe true
f1.futureValue.foreach(_.phrase shouldBe "Hello, Megatron, this was calculated on partition -1")
f2.futureValue.foreach(_.phrase shouldBe "Hello, Soundwave, this was calculated on partition -1")
f3.futureValue.foreach(_.phrase shouldBe "Hello, Shockwave, this was calculated on partition -1")
f1.futureValue.foreach(_.localReleased.get.get shouldBe true)
f2.futureValue.foreach(_.localReleased.get.get shouldBe true)
f3.futureValue.foreach(_.localReleased.get.get shouldBe true)
}
}
开发者ID:retnuh,项目名称:pipeline-backbone,代码行数:58,代码来源:ExecutionContextBackboneCoordinatorSpec.scala
示例13: ParsersSpec
//设置package包名称以及导入依赖的类
package examples.parser
import org.scalatest.{FlatSpec, Matchers}
import shapeless.HNil
import scalaz.{Failure, NonEmptyList, Success}
class ParsersSpec extends FlatSpec with Matchers {
"Parser" should "succeeds" in {
Parser[Book]("Hamlet;Shakespeare;2012") should equal(Success(Book("Hamlet", "Shakespeare", 2012)))
}
"Parser" should "fails because of the absence of one field" in {
Parser[Book]("Hamlet;Shakespeare") should equal(Failure(NonEmptyList("Error parsing Int : For input string: \"\"")))
}
"Parser" should "fails because of wrong types" in {
Parser[Country]("England;12f;13.6a") should equal(Failure(NonEmptyList("Error parsing Int 12f: For input string: \"12f\"")))
}
"Case class" should "be converted into HList" in {
parse[Book](Book("Hamlet", "Shakespeare", 2012)) should(equal("Hamlet" :: "Shakespeare" :: 2012 :: HNil))
}
}
开发者ID:haghard,项目名称:shapeless-playbook,代码行数:26,代码来源:ParsersSpec.scala
示例14: DeBufferSpec
//设置package包名称以及导入依赖的类
package com.init6.connection
import akka.util.ByteString
import com.init6.coders.binary.DeBuffer
import org.scalatest.{Matchers, FlatSpec}
class DeBufferSpec extends FlatSpec with Matchers {
"debuffer" should "work" in {
val debuffer = DeBuffer(ByteString(0x1E, 0x00, 0x00, 0x00, 0x00, 0x20, 0x33, 0x34, 0x35, 0x00))
val dword1e = debuffer.dword()
val word0020 = debuffer.word()
val string345 = debuffer.string()
dword1e should be(0x1E)
word0020 should be(0x2000)
string345 should be("345")
}
}
开发者ID:fjaros,项目名称:init6,代码行数:22,代码来源:DeBufferSpec.scala
示例15: BSHA1Spec
//设置package包名称以及导入依赖的类
package com.init6.coders.binary.hash
import org.scalatest.{Matchers, FlatSpec}
class BSHA1Spec extends FlatSpec with Matchers {
"bsha1" should "work" in {
getStringFromHash(BSHA1("")) should be("67452301efcdab8998badcfe10325476c3d2e1f0")
getStringFromHash(BSHA1("The quick brown fox jumps over the lazy dog.")) should be("011a2027a5d5c5448356db5e207d391d8d970534")
getStringFromHash(BSHA1("The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.")) should be("d1cc8c9acaa7eac78ab86f915588114d4d273a3d")
getStringFromHash(BSHA1(0xDEADBEEF, 0xBADCAB, BSHA1("The quick brown fox jumps over the lazy dog."))) should be("5b4ad103d0c63e0fe6405585c7288e8c6145c1ee")
}
def getStringFromHash(hash: Array[Byte]) = {
hash
.grouped(4)
.foldLeft("")((result: String, nextGroup: Array[Byte]) =>
result + "%02x%02x%02x%02x".format(nextGroup(3), nextGroup(2), nextGroup(1), nextGroup(0))
)
}
}
开发者ID:fjaros,项目名称:init6,代码行数:24,代码来源:BSHA1Spec.scala
示例16: S3HeadersSpec
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.impl
import akka.http.scaladsl.model.headers.RawHeader
import akka.stream.alpakka.s3.acl.CannedAcl
import org.scalatest.{FlatSpec, Matchers}
class S3HeadersSpec extends FlatSpec with Matchers {
"ServerSideEncryption" should "create well formed headers for AES-256 encryption" in {
ServerSideEncryption.AES256.headers should contain(RawHeader("x-amz-server-side-encryption", "AES256"))
}
it should "create well formed headers for aws:kms encryption" in {
val kms =
ServerSideEncryption.KMS("arn:aws:kms:my-region:my-account-id:key/my-key-id", Some("base-64-encoded-context"))
kms.headers should contain(RawHeader("x-amz-server-side-encryption", "aws:kms"))
kms.headers should contain(
RawHeader("x-amz-server-side-encryption-aws-kms-key-id", "arn:aws:kms:my-region:my-account-id:key/my-key-id")
)
kms.headers should contain(RawHeader("x-amz-server-side-encryption-context", "base-64-encoded-context"))
}
"StorageClass" should "create well formed headers for 'infrequent access'" in {
StorageClass.InfrequentAccess.header shouldEqual RawHeader("x-amz-storage-class", "STANDARD_IA")
}
"S3Headers" should "aggregate headers to one sequence" in {
val s3Headers = S3Headers(
cannedAcl = CannedAcl.PublicRead,
metaHeaders = MetaHeaders(Map("custom-meta" -> "custom")),
encryption = ServerSideEncryption.AES256,
customHeaders = Seq(RawHeader("Cache-Control", "no-cache")),
storageClass = StorageClass.ReducedRedundancy
)
s3Headers.headers.size shouldEqual 5
}
}
开发者ID:akka,项目名称:alpakka,代码行数:38,代码来源:S3HeadersSpec.scala
示例17: UtilsSpec
//设置package包名称以及导入依赖的类
import java.util.Properties
import org.scalatest.{FlatSpec, Matchers}
import io.clickhouse.ext.Utils._
class UtilsSpec extends FlatSpec with Matchers{
"case 1" should "ok" in {
var f = false
case class Mock(){
def print(): Unit = {
println("mock print")
}
def close(): Unit ={
f = true
}
}
using(Mock()){ mock =>
mock.print()
}
assert(f.equals(true))
}
}
开发者ID:DmitryBe,项目名称:spark-clickhouse,代码行数:27,代码来源:UtilsSpec.scala
示例18: ScrapingKitReactorTest
//设置package包名称以及导入依赖的类
package ru.fediq.scrapingkit
import java.util.concurrent.TimeUnit
import akka.actor.ActorSystem
import akka.http.scaladsl.model.{HttpMethods, Uri}
import com.codahale.metrics.Slf4jReporter
import com.codahale.metrics.Slf4jReporter.LoggingLevel
import com.typesafe.config.ConfigFactory
import org.scalatest.FlatSpec
import org.slf4j.LoggerFactory
import ru.fediq.scrapingkit.backend.{InMemoryFifoLinksQueue, InMemoryLinksHistory, NoOpFeedExporter, NoOpPageCache}
import ru.fediq.scrapingkit.model.PageRef
import ru.fediq.scrapingkit.scraper.HtmlCrawlingScraper
import ru.fediq.scrapingkit.util.Metrics
class ScrapingKitReactorTest extends FlatSpec {
"Reactor" should "crawl something" in {
val scraperName = "crawl"
val scrapers = Map(scraperName -> new HtmlCrawlingScraper(scraperName))
val config = ConfigFactory.load()
implicit val system = ActorSystem("reactor-test", config)
val linksQueue = new InMemoryFifoLinksQueue()
val linksHistory = new InMemoryLinksHistory()
val pageCache = new NoOpPageCache()
val exporter = new NoOpFeedExporter()
val reactor = new ScrapingKitReactor(linksQueue, linksHistory, pageCache, exporter, scrapers)
linksQueue.enqueue(PageRef(Uri("http://quotes.toscrape.com/"), HttpMethods.GET, scraperName))
Slf4jReporter
.forRegistry(Metrics.metricRegistry)
.withLoggingLevel(LoggingLevel.INFO)
.outputTo(LoggerFactory.getLogger("METRICS"))
.convertDurationsTo(TimeUnit.MILLISECONDS)
.convertRatesTo(TimeUnit.SECONDS)
.build()
.start(10, TimeUnit.SECONDS)
Thread.sleep(10000)
reactor.close()
}
}
开发者ID:fediq,项目名称:scraping-kit,代码行数:48,代码来源:ScrapingKitReactorTest.scala
示例19: DateTimeSpec
//设置package包名称以及导入依赖的类
package apodemakeles.scaluty
import java.util._
import org.scalatest.{Matchers, FlatSpec}
class DateTimeSpec extends FlatSpec with Matchers
{
"DateTime.now" should "greater or equals a earlier Date's value" in {
val time1 = Calendar.getInstance.getTime
Thread.sleep(10)
val time2 = Calendar.getInstance.getTime
DateTime.now should be > (time1)
DateTime.now should be >= (time2)
}
"DateTime.apply" should "works well" in {
DateTime(2016, 9, 27) should be (new Date(2016 - 1900, 9, 27))
DateTime(2016, 9, 27, 9, 56) should be (new Date(2016 -1900, 9, 27, 9, 56))
DateTime(2016, 9, 27, 9, 56, 59) should be (new Date(2016 - 1900, 9, 27, 9, 56, 59))
}
}
开发者ID:apodemakeles,项目名称:scaluty,代码行数:25,代码来源:DateTimeSpec.scala
示例20: RomanNumeralsInverseTest
//设置package包名称以及导入依赖的类
package numerals
import org.scalatest.{FlatSpec, Matchers}
class RomanNumeralsInverseTest extends FlatSpec with Matchers{
"I" should "be 1" in {
val answer = RomanNumeralsInverse.convert("I")
answer shouldBe 1
}
"II" should "be 2" in {
val answer = RomanNumeralsInverse.convert("II")
answer shouldBe 2
}
}
开发者ID:ollyjshaw,项目名称:roman,代码行数:17,代码来源:CanaryTest.scala
注:本文中的org.scalatest.FlatSpec类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论