Skip to content

Commit 46e6fc1

Browse files
author
Joe Nievelt
committed
Merge branch 'release/0.8.0'
2 parents d8f7f60 + cf205bd commit 46e6fc1

File tree

31 files changed

+411
-152
lines changed

31 files changed

+411
-152
lines changed

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Bijection #
22

3+
### 0.8.0
4+
* add twitter util Buf <-> Array[Byte] bijection https://github.com/twitter/bijection/pull/208
5+
* upgrade testing libraries https://github.com/twitter/bijection/pull/207
6+
* Add implicit conversion for GZippedBase64String to String https://github.com/twitter/bijection/pull/203
7+
* Make property tests work again https://github.com/twitter/bijection/pull/198
8+
* Add a module for finagle-mysql bijections. https://github.com/twitter/bijection/pull/197
9+
* Build bijection-scrooge for scala 2.11 https://github.com/twitter/bijection/pull/196
10+
311
### 0.7.2
412
* FIX: gzip Bijection resource leak. https://github.com/twitter/bijection/pull/193
513
* Use new Travis CI infrastructure https://github.com/twitter/bijection/pull/191

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ string2Long2Bytes2B64: com.twitter.bijection.Bijection[String,com.twitter.biject
8686
scala> 243L.as[Base64String]
8787
res0: com.twitter.bijection.Base64String = Base64String(MjQz)
8888

89-
scala> long2String2Bytes2B64.invert(res5)
89+
scala> long2String2Bytes2B64.invert(res0)
9090
res1: Try[Long] = Success(243)
9191
```
9292

@@ -134,7 +134,7 @@ Discussion occurs primarily on the [Bijection mailing list](https://groups.googl
134134

135135
## Maven
136136

137-
Bijection modules are available on maven central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.7.2`.
137+
Bijection modules are available on maven central. The current groupid and version for all modules is, respectively, `"com.twitter"` and `0.8.0`.
138138

139139
Current published artifacts are
140140

bijection-avro/src/test/scala/com/twitter/bijection/avro/GenericAvroCodecLaws.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ limitations under the License.
1313
*/
1414
package com.twitter.bijection.avro
1515

16-
import com.twitter.bijection.{ BaseProperties, Injection }
17-
18-
import org.scalatest.PropSpec
19-
import org.scalatest.prop.PropertyChecks
20-
21-
import org.apache.avro.generic.{ GenericRecord, GenericData }
16+
import com.twitter.bijection.{ BaseProperties, CheckProperties, Injection }
2217
import org.apache.avro.Schema
18+
import org.apache.avro.generic.{ GenericData, GenericRecord }
2319

2420
/**
2521
* @author Muhammad Ashraf
2622
* @since 7/5/13
2723
*/
28-
class GenericAvroCodecLaws extends PropSpec with PropertyChecks with BaseProperties {
24+
class GenericAvroCodecLaws extends CheckProperties with BaseProperties {
2925
val testSchema = new Schema.Parser().parse("""{
3026
"type":"record",
3127
"name":"FiscalRecord",

bijection-avro/src/test/scala/com/twitter/bijection/avro/GenericAvroCodecsSpecification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.apache.avro.generic.{ GenericData, GenericRecord }
2424
* @author Muhammad Ashraf
2525
* @since 7/6/13
2626
*/
27-
object GenericAvroCodecsSpecification extends WordSpec with Matchers with BaseProperties {
27+
class GenericAvroCodecsSpecification extends WordSpec with Matchers with BaseProperties {
2828
val testSchema = new Schema.Parser().parse("""{
2929
"type":"record",
3030
"name":"FiscalRecord",

bijection-avro/src/test/scala/com/twitter/bijection/avro/SpecificAvroCodecLaws.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.twitter.bijection.avro
22

3-
import org.scalatest.{ PropSpec, MustMatchers }
4-
import org.scalatest.prop.PropertyChecks
5-
import com.twitter.bijection.{ Injection, BaseProperties }
6-
import org.apache.avro.Schema
73
import avro.FiscalRecord
4+
import com.twitter.bijection.{ BaseProperties, CheckProperties, Injection }
5+
import org.apache.avro.Schema
86

97
/**
108
* @author Muhammad Ashraf
119
* @since 10/5/13
1210
*/
13-
class SpecificAvroCodecLaws extends PropSpec with PropertyChecks with MustMatchers with BaseProperties {
11+
class SpecificAvroCodecLaws extends CheckProperties with BaseProperties {
1412
val testSchema = new Schema.Parser().parse("""{
1513
"type":"record",
1614
"name":"FiscalRecord",

bijection-avro/src/test/scala/com/twitter/bijection/avro/SpecificAvroCodecsSpecification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import avro.FiscalRecord
99
* @author Muhammad Ashraf
1010
* @since 10/5/13
1111
*/
12-
object SpecificAvroCodecsSpecification extends WordSpec with Matchers with BaseProperties {
12+
class SpecificAvroCodecsSpecification extends WordSpec with Matchers with BaseProperties {
1313
val testSchema = new Schema.Parser().parse("""{
1414
"type":"record",
1515
"name":"FiscalRecord",

bijection-core/src/main/scala/com/twitter/bijection/BinaryBijections.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,21 @@ case class GZippedBytes(bytes: Array[Byte]) extends AnyVal {
3030

3131
case class GZippedBase64String(str: String) extends AnyVal
3232

33+
object GZippedBase64String {
34+
implicit val unwrap: Injection[GZippedBase64String, String] =
35+
new AbstractInjection[GZippedBase64String, String] {
36+
override def apply(gzbs: GZippedBase64String) = gzbs.str
37+
override def invert(str: String) = attemptWhen(str)(Base64.isBase64)(GZippedBase64String(_))
38+
}
39+
}
40+
3341
case class Base64String(str: String) extends AnyVal
3442

3543
object Base64String {
3644
implicit val unwrap: Injection[Base64String, String] =
3745
new AbstractInjection[Base64String, String] {
3846
override def apply(bs: Base64String) = bs.str
39-
override def invert(str: String) = attemptWhen(str)(Base64.isBase64(_))(Base64String(_))
47+
override def invert(str: String) = attemptWhen(str)(Base64.isBase64)(Base64String(_))
4048
}
4149
}
4250

bijection-core/src/test/scala/com/twitter/bijection/BinaryBijectionLaws.scala

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ limitations under the License.
1717
package com.twitter.bijection
1818

1919
import java.nio.ByteBuffer
20-
import org.scalatest.{ PropSpec, MustMatchers }
21-
import org.scalatest.prop.PropertyChecks
2220

23-
import org.scalacheck.Prop._
21+
import com.twitter.bijection.codec.Base64
22+
import org.scalacheck.Arbitrary
23+
import org.scalatest.MustMatchers
2424

25-
class BinaryBijectionLaws extends PropSpec with PropertyChecks with MustMatchers
25+
class BinaryBijectionLaws extends CheckProperties with MustMatchers
2626
with BaseProperties {
27-
implicit val arbBB = arbitraryViaFn[Array[Byte], ByteBuffer] { ByteBuffer.wrap(_) }
27+
implicit val arbBB = arbitraryViaFn[Array[Byte], ByteBuffer] { ByteBuffer.wrap }
2828

2929
// TODO: These are all bijections,
3030
property("Array[Byte] <=> ByteBuffer") {
@@ -40,10 +40,24 @@ class BinaryBijectionLaws extends PropSpec with PropertyChecks with MustMatchers
4040
isInjective[Array[Byte], Base64String]
4141
}
4242

43+
property("Base64String -> String") {
44+
implicit val arbB64: Arbitrary[Base64String] = arbitraryViaFn { s: String =>
45+
Base64String(Base64.encodeBase64String(s.getBytes("UTF-8")))
46+
}
47+
isInjection[Base64String, String]
48+
}
49+
4350
property("rts Array[Byte] -> GZippedBase64String") {
4451
isInjective[Array[Byte], GZippedBase64String]
4552
}
4653

54+
property("GZippedBase64String -> String") {
55+
implicit val arbGzB64: Arbitrary[GZippedBase64String] = arbitraryViaFn { s: String =>
56+
GZippedBase64String(Base64.encodeBase64String(s.getBytes("UTF-8")))
57+
}
58+
isInjection[GZippedBase64String, String]
59+
}
60+
4761
implicit val optSer = JavaSerializationInjection[Option[Int]]
4862

4963
property("java serialize Option[Int]") {

bijection-core/src/test/scala/com/twitter/bijection/BufferableLaws.scala

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,9 @@ limitations under the License.
1616

1717
package com.twitter.bijection
1818

19-
import java.lang.{
20-
Short => JShort,
21-
Integer => JInt,
22-
Long => JLong,
23-
Float => JFloat,
24-
Double => JDouble,
25-
Byte => JByte
26-
}
27-
19+
import java.lang.{ Byte => JByte, Double => JDouble, Float => JFloat, Integer => JInt, Long => JLong, Short => JShort }
2820
import java.nio.ByteBuffer
2921

30-
import org.scalatest.{ PropSpec, MustMatchers }
31-
import org.scalatest.prop.PropertyChecks
32-
3322
import org.scalacheck.Arbitrary
3423
import org.scalacheck.Prop.forAll
3524

@@ -51,23 +40,24 @@ trait BaseBufferable {
5140
}
5241
}
5342

54-
class BufferableLaws extends PropSpec with PropertyChecks with MustMatchers with BaseBufferable {
43+
class BufferableLaws extends CheckProperties with BaseBufferable {
44+
5545
property("Reallocate works properly") {
5646
forAll { (bytes: Array[Byte]) =>
5747
val bb = ByteBuffer.wrap(bytes)
5848
bb.position(bytes.size)
5949
val newBb = Bufferable.reallocate(bb)
60-
assert(Bufferable.getBytes(bb).toList == Bufferable.getBytes(newBb).toList)
61-
assert(newBb.capacity > bb.capacity)
62-
assert(newBb.position == bb.position)
50+
Bufferable.getBytes(bb).toList == Bufferable.getBytes(newBb).toList &&
51+
newBb.capacity > bb.capacity &&
52+
newBb.position == bb.position
6353
}
6454
}
6555

6656
property("getBytes works") {
6757
forAll { (bytes: Array[Byte]) =>
6858
val bb = ByteBuffer.wrap(bytes)
6959
bb.position(bytes.size)
70-
assert(Bufferable.getBytes(bb).toList == bytes.toList)
60+
Bufferable.getBytes(bb).toList == bytes.toList
7161
}
7262
}
7363

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.twitter.bijection
2+
3+
import org.scalatest.PropSpec
4+
import org.scalatest.prop.Checkers
5+
6+
/**
7+
* @author Mansur Ashraf.
8+
*/
9+
trait CheckProperties extends PropSpec with Checkers {
10+
11+
def property(testName: scala.Predef.String, testTags: org.scalatest.Tag*)(testFun: org.scalacheck.Prop): scala.Unit =
12+
super.property(testName, testTags: _*) { check { testFun } }
13+
}

0 commit comments

Comments
 (0)