Skip to content

Commit

Permalink
Merge pull request #6 from kolotaev/1.1.0-preparation
Browse files Browse the repository at this point in the history
1.1.0 preparation
  • Loading branch information
kolotaev authored Jul 28, 2019
2 parents 98c8809 + f7c8f5c commit 9c26345
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: scala

dist: trusty

scala:
- 2.12.2

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log


## 1.1.0 - [2019-07-28]

Added:

- Construction of an Id object can be done with it's byte-array representation.


## 1.0.1

Added:
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sortable property of the ID.
In your `build.sbt` add
```scala
resolvers += Resolver.jcenterRepo
libraryDependencies += "com.github.kolotaev" %% "ride" % "1.0.1"
libraryDependencies += "com.github.kolotaev" %% "ride" % "1.1.0"
```

#### Generating IDs
Expand Down Expand Up @@ -77,6 +77,13 @@ println(s"$guid" == s"$guid2")

// Creating ID from malformed string throws IllegalArgumentException exception
val guid3 = Id("bad-string")


// Id can be reconstructed with byte-array representation (useful when you save it as bytes, for example in DB)
val guid4 = Id(Array[Byte](90, 61, 13, 107, 88, -105, 98, 106, -53, -1, -1, -3))

// Creating ID from incorrect byte-array throws IllegalArgumentException exception
val guid5 = Id(Array[Byte](90, 61, 13))
```

#### Obtaining embedded info
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ val repo = "ride"

name := "ride"
organization := s"com.github.$username"
version := "1.0.2-SNAPSHOT"
version := "1.1.0"

scalaVersion := "2.12.2"
javacOptions ++= Seq(
Expand Down
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 9c26345

Please sign in to comment.