[go: nahoru, domu]

Skip to content

Commit

Permalink
Restructure some tests. Add wrong byte-array test
Browse files Browse the repository at this point in the history
  • Loading branch information
kolotaev committed Jul 28, 2019
1 parent 98c8809 commit 0566ddd
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/test/scala/com/github/kolotaev/ride/IdSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class IdSpec extends FlatSpec with Matchers {
s"$a".length should be (20)
}

"ID getBytes" should "return its bytes-array representation" in {
"ID getBytes" should "return its byte-array representation" in {
val a = Id("b8ugqqqoith6livvvvug")
a.getBytes should be (Array[Byte](90, 61, 13, 107, 88, -105, 98, 106, -53, -1, -1, -3))
}
Expand All @@ -76,16 +76,7 @@ class IdSpec extends FlatSpec with Matchers {
ids.toSet.size should equal (ids.length)
}

"IDs" should "not increment counter when constructed with string" in {
val a = Id()
new Id(a.toString)
new Id(a.toString)
val c = Id()
val diff = c.counter - a.counter
diff should equal (1)
}

"IDs" should "be constructed correctly value when constructed using a bytes-array representation" in {
"IDs" should "be constructed correctly when constructed using a byte-array representation" in {
val bytes = Array[Byte](90, 61, 13, 107, 88, -105, 98, 106, -53, -1, -1, -3)
val strId = "b8ugqqqoith6livvvvug"
val a = Id(bytes)
Expand All @@ -94,7 +85,7 @@ class IdSpec extends FlatSpec with Matchers {
a should be (Id(strId))
}

"IDs" should "not increment counter when constructed with byte array" in {
"IDs" should "not increment counter when constructed with byte-array" in {
val a = Id()
Id(a.getBytes)
Id(a.getBytes)
Expand All @@ -103,6 +94,29 @@ class IdSpec extends FlatSpec with Matchers {
diff should equal (1)
}

"ID" should "throw IllegalArgumentException if wrong byte-array is passed to constructor" in {
val data = List(
Array[Byte](),
Array[Byte](1, 2, 3),
Array.fill[Byte](11)(1),
Array.fill[Byte](13)(1)
)
for (i <- data) {
an [IllegalArgumentException] should be thrownBy {
Id(i)
}
}
}

"IDs" should "not increment counter when constructed with string" in {
val a = Id()
new Id(a.toString)
new Id(a.toString)
val c = Id()
val diff = c.counter - a.counter
diff should equal (1)
}

"ID" should "throw IllegalArgumentException if wrong base32 string is passed to constructor" in {
val data = List(
"",
Expand All @@ -112,13 +126,13 @@ class IdSpec extends FlatSpec with Matchers {
"b8sito2oithdkeou65xy"
)
for (i <- data) {
a [IllegalArgumentException] should be thrownBy {
an [IllegalArgumentException] should be thrownBy {
Id(i)
}
}
}

"IDs" should "support round-trip" in {
"IDs" should "support round-trip with string representation" in {
val a = Id()
val b = Id(Id(Id(a.toString).toString).toString)
s"$b" should equal (s"$a")
Expand Down

0 comments on commit 0566ddd

Please sign in to comment.