本文整理汇总了Scala中org.scalatest.FlatSpec类的典型用法代码示例。如果您正苦于以下问题:Scala FlatSpec类的具体用法?Scala FlatSpec怎么用?Scala FlatSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlatSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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")
}
}
示例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)
}
}
示例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
}
}
}
示例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"))
}
示例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) }
}
}
示例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")
}
}
示例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()
}
}
示例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
}
}
示例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")
}
}
示例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
}
}
示例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
}
}
示例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)
}
}
示例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))
}
}
示例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")
}
}
示例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))
)
}
}