|
| 1 | +/* |
| 2 | + Copyright 2012 Twitter, Inc. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.twitter.chill |
| 18 | + |
| 19 | +import org.scalatest._ |
| 20 | + |
| 21 | +import com.twitter.bijection.Injection |
| 22 | +import scala.util.Try |
| 23 | + |
| 24 | +class NotSerializable { |
| 25 | + val x = "abcd" |
| 26 | + override def equals(other: Any): Boolean = |
| 27 | + other match { |
| 28 | + case i: NotSerializable => true |
| 29 | + case _ => false |
| 30 | + } |
| 31 | +} |
| 32 | +class ExternalizerCodecSpec extends WordSpec { |
| 33 | + import ExternalizerCodec._ |
| 34 | + import ExternalizerInjection._ |
| 35 | + |
| 36 | + def rt[T: ExternalizerInjection: ExternalizerCodec](t: T): Try[T] = { |
| 37 | + val connectedInj = Injection.connect[T, Externalizer[T], Array[Byte]] |
| 38 | + connectedInj.invert(connectedInj(t)) |
| 39 | + } |
| 40 | + |
| 41 | + "The codec on Externalizer" should { |
| 42 | + "round trip objects" in { |
| 43 | + val x = rt(() => Foo.Bar).get |
| 44 | + assert(x() == Foo.Bar) |
| 45 | + } |
| 46 | + "round not serializable classes" in { |
| 47 | + val baseSerializable = new NotSerializable |
| 48 | + val x = rt(baseSerializable).get |
| 49 | + assert(x == baseSerializable, "Should be value equal") |
| 50 | + assert(x ne baseSerializable, "Should not be reference equal, since through a serializer") |
| 51 | + } |
| 52 | + |
| 53 | + } |
| 54 | +} |
| 55 | + |
0 commit comments