Browse files

Merge branch 'tmp'

  • Loading branch information...
2 parents fbfa89d + 1846e5b commit b3f6c0bb449002cf5632c73b18fc60a4acae8b84 Jenkins (CI) committed Jan 10, 2014
Showing with 1,938 additions and 1,453 deletions.
  1. +10 −0 CHANGES
  2. +0 −6 demos/scrooge-maven-demo/pom.xml
  3. +1 −0 demos/scrooge-maven-demo/src/main/thrift/user.thrift
  4. +8 −4 demos/scrooge-maven-demo/src/test/scala/com/twitter/example/DemoSpec.scala
  5. +1 −1 pom.xml
  6. +2 −7 project/Build.scala
  7. +3 −3 scrooge-benchmark/pom.xml
  8. +1 −1 scrooge-core/pom.xml
  9. +71 −0 scrooge-core/src/main/scala/com/twitter/scrooge/TReusableMemoryTransport.scala
  10. +8 −8 scrooge-generator/pom.xml
  11. +13 −3 scrooge-generator/src/main/resources/scalagen/finagleClient.scala
  12. +24 −16 scrooge-generator/src/main/resources/scalagen/finagleClientFunction.scala
  13. +49 −21 scrooge-generator/src/main/resources/scalagen/finagleService.scala
  14. +1 −0 scrooge-generator/src/main/resources/scalagen/service.scala
  15. +9 −2 scrooge-generator/src/main/resources/scalagen/struct.scala
  16. +0 −1 scrooge-generator/src/main/scala/com/twitter/scrooge/java_generator/ServiceController.scala
  17. +1 −1 scrooge-generator/src/main/scala/com/twitter/scrooge/java_generator/test/Main.scala
  18. +11 −12 scrooge-generator/src/test/scala/com/twitter/scrooge/ASTSpec.scala
  19. +3 −4 scrooge-generator/src/test/scala/com/twitter/scrooge/MainSpec.scala
  20. +33 −0 scrooge-generator/src/test/scala/com/twitter/scrooge/TReusableMemoryTransportSpec.scala
  21. +28 −28 scrooge-generator/src/test/scala/com/twitter/scrooge/ThriftStructMetaDataSpec.scala
  22. +3 −3 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/GeneratorFactorySpec.scala
  23. +13 −13 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ImmutableStructSpec.scala
  24. +437 −337 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/JavaGeneratorSpec.scala
  25. +6 −6 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/NamespaceSpec.scala
  26. +15 −15 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/NamingConvention.scala
  27. +14 −10 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/NonFinagleSpec.scala
  28. +574 −468 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ScalaGeneratorSpec.scala
  29. +221 −191 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ServiceGeneratorSpec.scala
  30. +9 −9 scrooge-generator/src/test/scala/com/twitter/scrooge/frontend/ImporterSpec.scala
  31. +104 −94 scrooge-generator/src/test/scala/com/twitter/scrooge/frontend/ThriftParserSpec.scala
  32. +70 −45 scrooge-generator/src/test/scala/com/twitter/scrooge/frontend/TypeResolverSpec.scala
  33. +6 −6 scrooge-generator/src/test/scala/com/twitter/scrooge/integration/JavaIntegrationSpec.scala
  34. +23 −21 scrooge-generator/src/test/scala/com/twitter/scrooge/integration/ScalaIntegrationSpec.scala
  35. +15 −16 scrooge-generator/src/test/scala/com/twitter/scrooge/java_generator/ApacheJavaGeneratorSpec.scala
  36. +14 −14 scrooge-generator/src/test/scala/com/twitter/scrooge/mustache/DictionarySpec.scala
  37. +22 −22 scrooge-generator/src/test/scala/com/twitter/scrooge/mustache/HandlebarSpec.scala
  38. +27 −23 scrooge-generator/src/test/scala/com/twitter/scrooge/mustache/ParserSpec.scala
  39. +66 −34 scrooge-generator/src/test/scala/com/twitter/scrooge/testutil/EvalHelper.scala
  40. +14 −0 scrooge-generator/src/test/scala/com/twitter/scrooge/testutil/Spec.scala
  41. +3 −3 scrooge-maven-plugin/pom.xml
  42. +1 −1 scrooge-ostrich/pom.xml
  43. +2 −2 scrooge-runtime/pom.xml
  44. +2 −2 scrooge-serializer/pom.xml
View
10 CHANGES
@@ -6,6 +6,16 @@ as it is included in Scoorge's user's guide.
3.x
-----
+3.12.0
+~~~~~
+
+- scrooge: use a TReusableMemoryTransport in finagle services
+- Bump guava to 15.0
+- scrooge-generator: trim some allocations from generated scala code
+- scrooge: use scalatest, remove specs
+- added scala namespace to demo
+- Rm all imports of `scala.Some`
+
3.11.2
~~~~~
View
6 demos/scrooge-maven-demo/pom.xml
@@ -73,12 +73,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.scala-tools.testing</groupId>
- <artifactId>specs_2.9.1</artifactId>
- <version>1.6.9</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>2.4.0</version>
View
1 demos/scrooge-maven-demo/src/main/thrift/user.thrift
@@ -1,4 +1,5 @@
namespace java com.twitter.demo
+#@namespace scala com.twitter.demo.thriftscala
struct User {
1: i64 id
View
12 demos/scrooge-maven-demo/src/test/scala/com/twitter/example/DemoSpec.scala
@@ -1,17 +1,21 @@
package com.twitter.example
-import org.specs.SpecificationWithJUnit
+import org.junit.runner.RunWith
+import org.scalatest.WordSpec
+import org.scalatest.junit.JUnitRunner
+import org.scalatest.matchers.MustMatchers
import com.twitter.mydemo.renamed.User
-class DemoSpec extends SpecificationWithJUnit {
+@RunWith(classOf[JUnitRunner])
+class DemoSpec extends WordSpec with MustMatchers {
def printUser(user: User) {println("User %s, id %d".format(user.name, user.id))}
"generated finagle service" should {
"server and client" in {
val server = DemoServer.buildServer()
val client = DemoClient.buildClient(server.localAddress)
- client.createUser("Tyrion")().name mustEqual("Tyrion")
- client.createUser("Jon")().name mustEqual("Jon")
+ client.createUser("Tyrion")().name must be("Tyrion")
+ client.createUser("Jon")().name must be("Jon")
}
}
}
View
2 pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
<packaging>pom</packaging>
- <version>3.11.3-SNAPSHOT</version>
+ <version>3.12.1-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>artifactory-release</id>
View
9 project/Build.scala
@@ -4,7 +4,7 @@ import com.typesafe.sbt.SbtSite.site
import com.typesafe.sbt.site.SphinxSupport.Sphinx
object Scrooge extends Build {
- val libVersion = "3.11.2"
+ val libVersion = "3.12.0"
val utilVersion = "6.10.0"
val finagleVersion = "6.10.0"
@@ -79,12 +79,7 @@ object Scrooge extends Build {
otherResolvers += m2Repo,
libraryDependencies ++= Seq(
- "org.scalatest" %% "scalatest" %"1.9.1" % "test",
- "org.scala-tools.testing" %% "specs" % "1.6.9" % "test" cross CrossVersion.binaryMapped {
- case "2.9.2" => "2.9.1"
- case "2.10.0" => "2.10"
- case x => x
- },
+ "org.scalatest" %% "scalatest" % "1.9.1" % "test",
"junit" % "junit" % "4.8.1" % "test"
),
resolvers += "twitter-repo" at "http://maven.twttr.com",
View
6 scrooge-benchmark/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-benchmark</artifactId>
<packaging>jar</packaging>
- <version>3.11.3-SNAPSHOT</version>
+ <version>3.12.1-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -19,7 +19,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.11.3-SNAPSHOT</version>
+ <version>3.12.1-SNAPSHOT</version>
</dependency>
<!-- library dependencies -->
<dependency>
@@ -30,7 +30,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-generator</artifactId>
- <version>3.11.3-SNAPSHOT</version>
+ <version>3.12.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
View
2 scrooge-core/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-core</artifactId>
<packaging>jar</packaging>
- <version>3.11.3-SNAPSHOT</version>
+ <version>3.12.1-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
View
71 scrooge-core/src/main/scala/com/twitter/scrooge/TReusableMemoryTransport.scala
@@ -0,0 +1,71 @@
+package com.twitter.scrooge
+
+import org.apache.thrift.transport.TTransport
+import org.apache.thrift.TByteArrayOutputStream
+
+object TReusableMemoryTransport {
+
+ def apply(initialSize: Int = 512): TReusableMemoryTransport = {
+ new TReusableMemoryTransport(new TByteArrayOutputStream(initialSize))
+ }
+
+}
+
+/**
+ * A version of TMemoryTransport that allows for reuse in order to minimize
+ * object allocations.
+ */
+class TReusableMemoryTransport(
+ baos: TByteArrayOutputStream)
+ extends TTransport
+{
+
+ private[this] var readPos = 0
+
+ /**
+ * Resets both reads and writes.
+ */
+ def reset() {
+ baos.reset()
+ readPos = 0
+ }
+
+ def numWrittenBytes: Int = baos.len()
+
+ // Here for drop-in api compatibility with TMemoryBuffer
+ def length(): Int = numWrittenBytes
+
+ // Here for drop-in api compatibility with TMemoryBuffer
+ def getArray(): Array[Byte] = baos.get()
+
+ /**
+ * Total bytes currently allowed in the struct.
+ *
+ * Note: more writes beyond this length will cause the struct to grow.
+ */
+ def currentCapacity: Int = baos.get().length
+
+ override def isOpen: Boolean = true
+
+ override def close() { }
+
+ override def open() { }
+
+ override def write(from: Array[Byte], off: Int, len: Int) {
+ baos.write(from, off, len)
+ }
+
+ override def read(into: Array[Byte], off: Int, len: Int): Int = {
+ val bytesToRead = if (len > baos.len() - readPos) {
+ baos.len() - readPos
+ } else {
+ len
+ }
+ if (bytesToRead > 0) {
+ System.arraycopy(baos.get(), readPos, into, off, bytesToRead)
+ readPos += bytesToRead
+ }
+ bytesToRead
+ }
+
+}
View
16 scrooge-generator/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-generator</artifactId>
<packaging>jar</packaging>
- <version>3.11.3-SNAPSHOT</version>
+ <version>3.12.1-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -20,7 +20,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.11.3-SNAPSHOT</version>
+ <version>3.12.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<!-- library dependencies -->
@@ -57,12 +57,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.scala-tools.testing</groupId>
- <artifactId>specs_2.9.1</artifactId>
- <version>1.6.9</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
@@ -81,6 +75,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.scalatest</groupId>
+ <artifactId>scalatest_2.9.2</artifactId>
+ <version>1.8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.1_3</version>
View
16 scrooge-generator/src/main/resources/scalagen/finagleClient.scala
@@ -1,11 +1,10 @@
package {{package}}
-import com.twitter.finagle.SourcedException
+import com.twitter.finagle.{SourcedException, Service => FinagleService}
import com.twitter.finagle.stats.{NullStatsReceiver, StatsReceiver}
import com.twitter.finagle.thrift.ThriftClientRequest
-import com.twitter.finagle.{Service => FinagleService}
import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec}
-import com.twitter.util.Future
+import com.twitter.util.{Future, Return, Throw}
import java.nio.ByteBuffer
import java.util.Arrays
import org.apache.thrift.protocol._
@@ -63,6 +62,17 @@ class {{ServiceName}}$FinagleClient(
)
}
+ protected def setServiceName(ex: Exception): Exception =
+ if (this.serviceName == "") ex
+ else {
+ ex match {
+ case se: SourcedException =>
+ se.serviceName = this.serviceName
+ se
+ case _ => ex
+ }
+ }
+
// ----- end boilerplate.
{{/hasParent}}
View
40 scrooge-generator/src/main/resources/scalagen/finagleClientFunction.scala
@@ -4,33 +4,41 @@ private[this] object {{__stats_name}} {
val FailuresCounter = scopedStats.scope("{{clientFuncNameForWire}}").counter("failures")
val FailuresScope = scopedStats.scope("{{clientFuncNameForWire}}").scope("failures")
}
-
{{#headerInfo}}{{>header}}{{/headerInfo}} = {
{{__stats_name}}.RequestsCounter.incr()
this.service(encodeRequest("{{clientFuncNameForWire}}", {{ArgsStruct}}({{argNames}}))) flatMap { response =>
val result = decodeResponse(response, {{ResultStruct}})
- val exception =
+ val exception: Future[Nothing] =
{{#hasThrows}}
- ({{#throws}}result.{{throwName}}{{/throws| orElse }}).map(Future.exception)
+ if (false)
+ null // can never happen, but needed to open a block
+{{#throws}}
+ else if (result.{{throwName}}.isDefined)
+ Future.exception(setServiceName(result.{{throwName}}.get))
+{{/throws}}
+ else
+ null
{{/hasThrows}}
{{^hasThrows}}
- None
+ null
{{/hasThrows}}
+
{{#isVoid}}
- exception.getOrElse(Future.Done)
+ if (exception != null) exception else Future.Done
{{/isVoid}}
{{^isVoid}}
- exception.orElse(result.success.map(Future.value)).getOrElse(Future.exception(missingResult("{{clientFuncNameForWire}}")))
+ if (result.success.isDefined)
+ Future.value(result.success.get)
+ else if (exception != null)
+ exception
+ else
+ Future.exception(missingResult("{{clientFuncNameForWire}}"))
{{/isVoid}}
- } rescue {
- case ex: SourcedException => {
- if (this.serviceName != "") { ex.serviceName = this.serviceName }
- Future.exception(ex)
- }
- } onSuccess { _ =>
- {{__stats_name}}.SuccessCounter.incr()
- } onFailure { ex =>
- {{__stats_name}}.FailuresCounter.incr()
- {{__stats_name}}.FailuresScope.counter(ex.getClass.getName).incr()
+ } respond {
+ case Return(_) =>
+ {{__stats_name}}.SuccessCounter.incr()
+ case Throw(ex) =>
+ {{__stats_name}}.FailuresCounter.incr()
+ {{__stats_name}}.FailuresScope.counter(ex.getClass.getName).incr()
}
}
View
70 scrooge-generator/src/main/resources/scalagen/finagleService.scala
@@ -1,13 +1,13 @@
package {{package}}
import com.twitter.finagle.{Service => FinagleService}
-import com.twitter.scrooge.ThriftStruct
+import com.twitter.scrooge.{ThriftStruct, TReusableMemoryTransport}
import com.twitter.util.Future
import java.nio.ByteBuffer
import java.util.Arrays
import org.apache.thrift.protocol._
import org.apache.thrift.TApplicationException
-import org.apache.thrift.transport.{TMemoryBuffer, TMemoryInputTransport}
+import org.apache.thrift.transport.TMemoryInputTransport
import scala.collection.mutable.{
ArrayBuffer => mutable$ArrayBuffer, HashMap => mutable$HashMap}
import scala.collection.{Map, Set}
@@ -21,6 +21,22 @@ class {{ServiceName}}$FinagleService(
import {{ServiceName}}._
{{^hasParent}}
+ private[this] val tlReusableBuffer = new ThreadLocal[TReusableMemoryTransport] {
+ override def initialValue() = TReusableMemoryTransport(512)
+ }
+
+ private[this] def reusableBuffer: TReusableMemoryTransport = {
+ val buf = tlReusableBuffer.get()
+ buf.reset()
+ buf
+ }
+
+ private[this] def resetBuffer(trans: TReusableMemoryTransport, maxCapacity: Int = 4096) {
+ if (trans.currentCapacity > maxCapacity) {
+ tlReusableBuffer.remove()
+ }
+ }
+
protected val functionMap = new mutable$HashMap[String, (TProtocol, Int) => Future[Array[Byte]]]()
protected def addFunction(name: String, f: (TProtocol, Int) => Future[Array[Byte]]) {
@@ -30,29 +46,37 @@ class {{ServiceName}}$FinagleService(
protected def exception(name: String, seqid: Int, code: Int, message: String): Future[Array[Byte]] = {
try {
val x = new TApplicationException(code, message)
- val memoryBuffer = new TMemoryBuffer(512)
- val oprot = protocolFactory.getProtocol(memoryBuffer)
-
- oprot.writeMessageBegin(new TMessage(name, TMessageType.EXCEPTION, seqid))
- x.write(oprot)
- oprot.writeMessageEnd()
- oprot.getTransport().flush()
- Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()))
+ val memoryBuffer = reusableBuffer
+ try {
+ val oprot = protocolFactory.getProtocol(memoryBuffer)
+
+ oprot.writeMessageBegin(new TMessage(name, TMessageType.EXCEPTION, seqid))
+ x.write(oprot)
+ oprot.writeMessageEnd()
+ oprot.getTransport().flush()
+ Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()))
+ } finally {
+ resetBuffer(memoryBuffer)
+ }
} catch {
case e: Exception => Future.exception(e)
}
}
protected def reply(name: String, seqid: Int, result: ThriftStruct): Future[Array[Byte]] = {
try {
- val memoryBuffer = new TMemoryBuffer(512)
- val oprot = protocolFactory.getProtocol(memoryBuffer)
+ val memoryBuffer = reusableBuffer
+ try {
+ val oprot = protocolFactory.getProtocol(memoryBuffer)
- oprot.writeMessageBegin(new TMessage(name, TMessageType.REPLY, seqid))
- result.write(oprot)
- oprot.writeMessageEnd()
+ oprot.writeMessageBegin(new TMessage(name, TMessageType.REPLY, seqid))
+ result.write(oprot)
+ oprot.writeMessageEnd()
- Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()))
+ Future.value(Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()))
+ } finally {
+ resetBuffer(memoryBuffer)
+ }
} catch {
case e: Exception => Future.exception(e)
}
@@ -64,11 +88,15 @@ class {{ServiceName}}$FinagleService(
try {
val msg = iprot.readMessageBegin()
- functionMap.get(msg.name) map { _.apply(iprot, msg.seqid) } getOrElse {
- TProtocolUtil.skip(iprot, TType.STRUCT)
- exception(msg.name, msg.seqid, TApplicationException.UNKNOWN_METHOD,
- "Invalid method name: '" + msg.name + "'")
- }
+ val func = functionMap.get(msg.name)
+ func match {
+ case Some(fn) =>
+ fn(iprot, msg.seqid)
+ case _ =>
+ TProtocolUtil.skip(iprot, TType.STRUCT)
+ exception(msg.name, msg.seqid, TApplicationException.UNKNOWN_METHOD,
+ "Invalid method name: '" + msg.name + "'")
+ }
} catch {
case e: Exception => Future.exception(e)
}
View
1 scrooge-generator/src/main/resources/scalagen/service.scala
@@ -10,6 +10,7 @@ import org.apache.thrift.TApplicationException
import org.apache.thrift.transport.TMemoryBuffer
import scala.collection.immutable.{Map => immutable$Map}
import scala.collection.mutable.{
+ Builder,
ArrayBuffer => mutable$ArrayBuffer, Buffer => mutable$Buffer,
HashMap => mutable$HashMap, HashSet => mutable$HashSet}
import scala.collection.{Map, Set}
View
11 scrooge-generator/src/main/resources/scalagen/struct.scala
@@ -8,6 +8,7 @@ import org.apache.thrift.transport.{TMemoryBuffer, TTransport}
import java.nio.ByteBuffer
import java.util.Arrays
import scala.collection.immutable.{Map => immutable$Map}
+import scala.collection.mutable.Builder
import scala.collection.mutable.{
ArrayBuffer => mutable$ArrayBuffer, Buffer => mutable$Buffer,
HashMap => mutable$HashMap, HashSet => mutable$HashSet}
@@ -16,6 +17,7 @@ import scala.collection.{Map, Set}
{{/public}}
{{docstring}}
object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
+ private val NoPassthroughFields = immutable$Map.empty[Short, TFieldBlob]
val Struct = new TStruct("{{StructNameForWire}}")
{{#fields}}
val {{fieldConst}} = new TField("{{fieldNameForWire}}", TType.{{constType}}, {{id}})
@@ -54,7 +56,7 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
{{/required}}
{{/optional}}
{{/fields}}
- var _passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
+ var _passthroughFields: Builder[(Short, TFieldBlob), immutable$Map[Short, TFieldBlob]] = null
var _done = false
_iprot.readStructBegin()
@@ -70,6 +72,8 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
{{>readField}}
{{/fields}}
case _ =>
+ if (_passthroughFields == null)
+ _passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
_passthroughFields += (_field.id -> TFieldBlob.read(_field, _iprot))
_readField = true
}
@@ -90,7 +94,10 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
{{#fields}}
{{fieldName}},
{{/fields}}
- _passthroughFields.result()
+ if (_passthroughFields == null)
+ NoPassthroughFields
+ else
+ _passthroughFields.result()
)
}
View
1 scrooge-generator/src/main/scala/com/twitter/scrooge/java_generator/ServiceController.scala
@@ -2,7 +2,6 @@ package com.twitter.scrooge.java_generator
import com.twitter.scrooge.ast._
import com.twitter.scrooge.ast.Service
-import scala.Some
class ServiceController(service: Service, generator: ApacheJavaGenerator, ns: Option[Identifier])
extends TypeController(service, generator, ns) {
View
2 scrooge-generator/src/main/scala/com/twitter/scrooge/java_generator/test/Main.scala
@@ -48,7 +48,7 @@ object Main {
val oldGenMap = new mutable.HashMap[String, File]
if (newGenMap.size != oldGenMap.size) {
println("Wrong number of files generated")
- exit(1)
+ sys.exit(1)
}
FileUtils.getFiles(new File(compiler.destFolder), "**/*.java", "") foreach { s =>
val file = s.asInstanceOf[File]
View
23 scrooge-generator/src/test/scala/com/twitter/scrooge/ASTSpec.scala
@@ -1,18 +1,18 @@
package com.twitter.scrooge.ast
-import org.specs.SpecificationWithJUnit
+import com.twitter.scrooge.testutil.Spec
-class ASTSpec extends SpecificationWithJUnit {
+class ASTSpec extends Spec {
"Namespace" should {
"generate correct namespace from java" in {
val doc = Document(Seq(Namespace("java", Identifier("com.twitter.oatmeal"))), Nil)
- doc.namespace("java").isDefined must beTrue
- doc.namespace("java").get.fullName mustEqual ("com.twitter.oatmeal")
+ doc.namespace("java").isDefined must be(true)
+ doc.namespace("java").get.fullName must be("com.twitter.oatmeal")
}
"reject undefined namespace" in {
val doc = Document(Seq(Namespace("warble", Identifier("com.twitter.oatmeal"))), Nil)
- doc.namespace("garble") mustEqual None
+ doc.namespace("garble") must be(None)
}
"map namespaces" in {
@@ -21,8 +21,8 @@ class ASTSpec extends SpecificationWithJUnit {
val rbOatmealNs = Namespace("rb", Identifier("Oatmeal"))
val doc = Document(Seq(javaOatmealNs, rbOatmealNs), Nil)
val namespaceMap = Map(javaOatmealNs.id.fullName -> javaGranolaNs.id.fullName)
- doc.mapNamespaces(namespaceMap) mustEqual
- Document(Seq(javaGranolaNs, rbOatmealNs), Nil)
+ doc.mapNamespaces(namespaceMap) must be(
+ Document(Seq(javaGranolaNs, rbOatmealNs), Nil))
}
"map namespaces recursively" in {
@@ -31,10 +31,9 @@ class ASTSpec extends SpecificationWithJUnit {
val doc1 = Document(Seq(javaOatmealNs), Nil)
val doc2 = Document(Seq(javaOatmealNs, Include("other", doc1)), Nil)
val namespaceMap = Map(javaOatmealNs.id.fullName -> javaGranolaNs.id.fullName)
- doc2.mapNamespaces(namespaceMap) must beLike {
+ doc2.mapNamespaces(namespaceMap) match {
case Document(Seq(javaGranolaNs, Include(_, included)), Nil) =>
- included mustEqual Document(Seq(javaGranolaNs), Nil)
- true
+ included must be(Document(Seq(javaGranolaNs), Nil))
}
}
}
@@ -68,15 +67,15 @@ class ASTSpec extends SpecificationWithJUnit {
simpleCases foreach {
case (input, (expected, _)) =>
val sid = SimpleID(input)
- sid.toCamelCase.name mustEqual expected
+ sid.toCamelCase.name must be(expected)
}
}
"title case conversion" in {
simpleCases foreach {
case (input, (_, expected)) =>
val sid = SimpleID(input)
- sid.toTitleCase.name mustEqual expected
+ sid.toTitleCase.name must be(expected)
}
}
}
View
7 scrooge-generator/src/test/scala/com/twitter/scrooge/MainSpec.scala
@@ -2,10 +2,9 @@ package com.twitter.scrooge
import java.io.{FileWriter, File}
import scala.io.Source
-import org.specs.SpecificationWithJUnit
-import com.twitter.scrooge.testutil.TempDirectory
+import com.twitter.scrooge.testutil.{Spec, TempDirectory}
-class MainSpec extends SpecificationWithJUnit {
+class MainSpec extends Spec {
"Scrooge Main" should {
"gen file mapping with absolute paths" in {
val inDir = TempDirectory.create(None)
@@ -51,6 +50,6 @@ struct Point {
input.getPath + " -> " + buildPath(outDir.getPath, "MyTest", "Constants.scala") + "\n" +
input.getPath + " -> " + buildPath(outDir.getPath, "MyTest", "Direction.scala") + "\n" +
input.getPath + " -> " + buildPath(outDir.getPath, "MyTest", "Point.scala")+ "\n"
- manifestString mustEqual expected
+ manifestString must be(expected)
}
}
View
33 scrooge-generator/src/test/scala/com/twitter/scrooge/TReusableMemoryTransportSpec.scala
@@ -0,0 +1,33 @@
+package com.twitter.scrooge
+
+import com.twitter.scrooge.testutil.Spec
+
+class TReusableMemoryTransportSpec extends Spec {
+
+ "is reusable" in {
+ val cap = 10
+ val trans = TReusableMemoryTransport(cap)
+ trans.currentCapacity must be(cap)
+ var bytesRead = trans.read(new Array[Byte](1), 0, 999)
+ bytesRead must be(0)
+
+ val stringInBytes = "abcde".getBytes("UTF-8")
+ trans.write(stringInBytes)
+ trans.numWrittenBytes must be(5)
+
+ val read = new Array[Byte](100)
+ bytesRead = trans.read(read, 0, 999)
+ bytesRead must be(5)
+ read.take(bytesRead).mkString must be(stringInBytes.mkString)
+
+ trans.reset()
+
+ trans.numWrittenBytes must be(0)
+ bytesRead = trans.read(new Array[Byte](1), 0, 999)
+ bytesRead must be(0)
+
+ trans.write(stringInBytes)
+ trans.numWrittenBytes must be(5)
+ }
+
+}
View
56 scrooge-generator/src/test/scala/com/twitter/scrooge/ThriftStructMetaDataSpec.scala
@@ -1,48 +1,48 @@
package com.twitter.scrooge
+import com.twitter.scrooge.testutil.Spec
import org.apache.thrift.protocol.TType
-import org.specs.SpecificationWithJUnit
import scala.collection.{Map, Set}
import thrift.test._
// This is a cross project test and I feel bad for putting it here
// but scrooge-generator already has all the infrastructure to do
// generation and testing and anyway requires scrooge-runtime for
// tests.
-class ThriftStructMetaDataSpec extends SpecificationWithJUnit {
+class ThriftStructMetaDataSpec extends Spec {
"Provide useful metadata" in {
val s = XtructColl(Map(1 -> 2L), Seq("test"), Set(10.toByte), 123)
val metaData = XtructColl.metaData
assert(metaData.codecClass == XtructColl.getClass) // mustEqual doesn't work here
- metaData.structClassName mustEqual "thrift.test.XtructColl"
- metaData.structName mustEqual "XtructColl"
- metaData.structClass mustEqual classOf[XtructColl]
+ metaData.structClassName must be("thrift.test.XtructColl")
+ metaData.structName must be("XtructColl")
+ metaData.structClass must be(classOf[XtructColl])
val Seq(f1, f2, f3, f4) = metaData.fields.sortBy(_.id)
- f1.name mustEqual "a_map"
- f1.id mustEqual 1
- f1.`type` mustEqual TType.MAP
- f1.manifest mustEqual Some(implicitly[Manifest[Map[Int, Long]]])
- f1.getValue[Map[Int, Long]](s) mustEqual Map(1 -> 2L)
-
- f2.name mustEqual "a_list"
- f2.id mustEqual 2
- f2.`type` mustEqual TType.LIST
- f2.manifest mustEqual Some(implicitly[Manifest[Seq[String]]])
- f2.getValue[Seq[String]](s) mustEqual Seq("test")
-
- f3.name mustEqual "a_set"
- f3.id mustEqual 3
- f3.`type` mustEqual TType.SET
- f3.manifest mustEqual Some(implicitly[Manifest[Set[Byte]]])
- f3.getValue[Set[Byte]](s) mustEqual Set(10.toByte)
-
- f4.name mustEqual "non_col"
- f4.id mustEqual 4
- f4.`type` mustEqual TType.I32
- f4.manifest mustEqual Some(implicitly[Manifest[Int]])
- f4.getValue[Int](s) mustEqual 123
+ f1.name must be("a_map")
+ f1.id must be(1)
+ f1.`type` must be(TType.MAP)
+ f1.manifest must be(Some(implicitly[Manifest[Map[Int, Long]]]))
+ f1.getValue[Map[Int, Long]](s) must be(Map(1 -> 2L))
+
+ f2.name must be("a_list")
+ f2.id must be(2)
+ f2.`type` must be(TType.LIST)
+ f2.manifest must be(Some(implicitly[Manifest[Seq[String]]]))
+ f2.getValue[Seq[String]](s) must be(Seq("test"))
+
+ f3.name must be("a_set")
+ f3.id must be(3)
+ f3.`type` must be(TType.SET)
+ f3.manifest must be(Some(implicitly[Manifest[Set[Byte]]]))
+ f3.getValue[Set[Byte]](s) must be(Set(10.toByte))
+
+ f4.name must be("non_col")
+ f4.id must be(4)
+ f4.`type` must be(TType.I32)
+ f4.manifest must be(Some(implicitly[Manifest[Int]]))
+ f4.getValue[Int](s) must be(123)
}
}
View
6 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/GeneratorFactorySpec.scala
@@ -1,7 +1,7 @@
package com.twitter.scrooge.backend
-import org.specs.SpecificationWithJUnit
import com.twitter.scrooge.frontend.ResolvedDocument
+import com.twitter.scrooge.testutil.Spec
class TestGeneratorFactory extends GeneratorFactory {
val lang = "test"
@@ -13,11 +13,11 @@ class TestGeneratorFactory extends GeneratorFactory {
): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, generationDate, experimentFlags)
}
-class GeneratorFactorySpec extends SpecificationWithJUnit {
+class GeneratorFactorySpec extends Spec {
"GeneratorFactory" should {
"be loadable" in {
val generator = Generator("test", Map.empty[String, ResolvedDocument], "", "", Seq.empty[String])
- generator must haveClass[ScalaGenerator]
+ generator.isInstanceOf[ScalaGenerator] must be(true)
}
}
}
View
26 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ImmutableStructSpec.scala
@@ -1,18 +1,18 @@
package com.twitter.scrooge.backend
-import org.specs.SpecificationWithJUnit
+import com.twitter.scrooge.testutil.Spec
import org.apache.thrift.protocol.TBinaryProtocol
import org.apache.thrift.transport.TMemoryBuffer
-class ImmutableStructSpec extends SpecificationWithJUnit {
+class ImmutableStructSpec extends Spec {
"Scala objects" should {
import thrift.test._
"encode and decode" in {
val protocol = new TBinaryProtocol(new TMemoryBuffer(10000))
val originalBonk = Bonk("This is Bonk message", 13)
Bonk.encode(originalBonk, protocol)
- Bonk.decode(protocol) mustEqual(originalBonk)
+ Bonk.decode(protocol) must be(originalBonk)
}
"deep copy" in {
@@ -49,10 +49,10 @@ class ImmutableStructSpec extends SpecificationWithJUnit {
structThing = xtructSwapped
)
)
- copied.x1 mustEqual(nested.x1)
- copied.x2.structThing must_!=(nested.x2.structThing) //swapped
- copied.x2 must_!=(nested.x2)
- copied.x3 mustEqual(nested.x3)
+ copied.x1 must be(nested.x1)
+ copied.x2.structThing must not be(nested.x2.structThing) //swapped
+ copied.x2 must not be(nested.x2)
+ copied.x3 must be(nested.x3)
}
}
@@ -62,7 +62,7 @@ class ImmutableStructSpec extends SpecificationWithJUnit {
val protocol = new TBinaryProtocol(new TMemoryBuffer(10000))
val originalBonk = new Bonk("This is Bonk message", 13)
Bonk.encode(originalBonk, protocol)
- Bonk.decode(protocol) mustEqual(originalBonk)
+ Bonk.decode(protocol) must be(originalBonk)
}
"deep copy" in {
@@ -96,13 +96,13 @@ class ImmutableStructSpec extends SpecificationWithJUnit {
.x2(xtruct2.copy().structThing(xtructSwapped).build())
.build()
- copied.getX1 mustEqual(nested.getX1)
- copied.getX2.getStructThing must_!=(nested.getX2.getStructThing) //swapped
- copied.getX2 must_!=(nested.getX2)
- copied.getX3 mustEqual(nested.getX3)
+ copied.getX1 must be(nested.getX1)
+ copied.getX2.getStructThing must not be(nested.getX2.getStructThing) //swapped
+ copied.getX2 must not be(nested.getX2)
+ copied.getX3 must be(nested.getX3)
val copiedPartial = nested.copy().unsetX2().build()
- copiedPartial.isSetX2 must beFalse
+ copiedPartial.isSetX2 must be(false)
}
}
}
View
774 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/JavaGeneratorSpec.scala
@@ -1,41 +1,39 @@
package com.twitter.scrooge
package backend
+import com.twitter.scrooge.testutil.{EvalHelper, JMockSpec}
import java.io.{ObjectInputStream, ByteArrayInputStream, ObjectOutputStream, ByteArrayOutputStream}
import java.nio.ByteBuffer
import org.apache.thrift.protocol._
import org.apache.thrift.transport.TMemoryBuffer
-import org.specs.mock.{ClassMocker, JMocker}
-import org.specs.SpecificationWithJUnit
-import com.twitter.scrooge.testutil.EvalHelper
+import org.jmock.Expectations
+import org.jmock.Expectations.{any, returnValue}
import thrift.java_test._
-class JavaGeneratorSpec extends SpecificationWithJUnit with EvalHelper with JMocker with ClassMocker {
- val protocol = mock[TProtocol]
-
+class JavaGeneratorSpec extends JMockSpec with EvalHelper {
def stringToBytes(string: String) = ByteBuffer.wrap(string.getBytes)
"JavaGenerator" should {
- "generate an enum" in {
- "correct constants" in {
- NumberID.ONE.getValue() mustEqual 1
- NumberID.TWO.getValue() mustEqual 2
- NumberID.THREE.getValue() mustEqual 3
- NumberID.FIVE.getValue() mustEqual 5
- NumberID.SIX.getValue() mustEqual 6
- NumberID.EIGHT.getValue() mustEqual 8
+ "generate an enum" should {
+ "correct constants" in { _ =>
+ NumberID.ONE.getValue() must be(1)
+ NumberID.TWO.getValue() must be(2)
+ NumberID.THREE.getValue() must be(3)
+ NumberID.FIVE.getValue() must be(5)
+ NumberID.SIX.getValue() must be(6)
+ NumberID.EIGHT.getValue() must be(8)
}
- "findByValue" in {
- NumberID.findByValue(1) mustEqual NumberID.ONE
- NumberID.findByValue(2) mustEqual NumberID.TWO
- NumberID.findByValue(3) mustEqual NumberID.THREE
- NumberID.findByValue(5) mustEqual NumberID.FIVE
- NumberID.findByValue(6) mustEqual NumberID.SIX
- NumberID.findByValue(8) mustEqual NumberID.EIGHT
+ "findByValue" in { _ =>
+ NumberID.findByValue(1) must be(NumberID.ONE)
+ NumberID.findByValue(2) must be(NumberID.TWO)
+ NumberID.findByValue(3) must be(NumberID.THREE)
+ NumberID.findByValue(5) must be(NumberID.FIVE)
+ NumberID.findByValue(6) must be(NumberID.SIX)
+ NumberID.findByValue(8) must be(NumberID.EIGHT)
}
- "java-serializable" in {
+ "java-serializable" in { _ =>
val bos = new ByteArrayOutputStream()
val out = new ObjectOutputStream(bos)
out.writeObject(NumberID.ONE)
@@ -45,519 +43,621 @@ class JavaGeneratorSpec extends SpecificationWithJUnit with EvalHelper with JMoc
val in = new ObjectInputStream(new ByteArrayInputStream(bytes))
var obj = in.readObject()
- obj.isInstanceOf[NumberID] must beTrue
- obj.asInstanceOf[NumberID].getValue mustEqual NumberID.ONE.getValue
- obj.asInstanceOf[NumberID].name mustEqual NumberID.ONE.name
+ obj.isInstanceOf[NumberID] must be(true)
+ obj.asInstanceOf[NumberID].getValue must be(NumberID.ONE.getValue)
+ obj.asInstanceOf[NumberID].name must be(NumberID.ONE.name)
obj = in.readObject()
- obj.isInstanceOf[NumberID] must beTrue
- obj.asInstanceOf[NumberID].getValue mustEqual NumberID.TWO.getValue
- obj.asInstanceOf[NumberID].name mustEqual NumberID.TWO.name
+ obj.isInstanceOf[NumberID] must be(true)
+ obj.asInstanceOf[NumberID].getValue must be(NumberID.TWO.getValue)
+ obj.asInstanceOf[NumberID].name must be(NumberID.TWO.name)
}
}
- "generate constants" in {
- Constants.myWfhDay mustEqual WeekDay.THU
- Constants.myDaysOut mustEqual Utilities.makeList(WeekDay.THU, WeekDay.SAT, WeekDay.SUN)
- Constants.name mustEqual "Columbo"
- Constants.someInt mustEqual 1
- Constants.someDouble mustEqual 3.0
- Constants.someList mustEqual Utilities.makeList("piggy")
- Constants.emptyList mustEqual Utilities.makeList()
- Constants.someMap mustEqual Utilities.makeMap(Utilities.makeTuple("foo", "bar"))
- Constants.someSimpleSet mustEqual Utilities.makeSet("foo", "bar")
- Constants.someSet mustEqual Utilities.makeSet(
+ "generate constants" in { _ =>
+ Constants.myWfhDay must be(WeekDay.THU)
+ Constants.myDaysOut must be(Utilities.makeList(WeekDay.THU, WeekDay.SAT, WeekDay.SUN))
+ Constants.name must be("Columbo")
+ Constants.someInt must be(1)
+ Constants.someDouble must be(3.0)
+ Constants.someList must be(Utilities.makeList("piggy"))
+ Constants.emptyList must be(Utilities.makeList())
+ Constants.someMap must be(Utilities.makeMap(Utilities.makeTuple("foo", "bar")))
+ Constants.someSimpleSet must be(Utilities.makeSet("foo", "bar"))
+ Constants.someSet must be(Utilities.makeSet(
Utilities.makeList("piggy"),
Utilities.makeList("kitty")
- )
+ ))
}
- "basic structs" in {
- "ints" in {
- "read" in {
- expect {
- startRead(protocol, new TField("baby", TType.I16, 1))
- one(protocol).readI16() willReturn (16: Short)
- nextRead(protocol, new TField("mama", TType.I32, 2))
- one(protocol).readI32() willReturn 32
- nextRead(protocol, new TField("papa", TType.I64, 3))
- one(protocol).readI64() willReturn 64L
- endRead(protocol)
+ "basic structs" should {
+ "ints" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("baby", TType.I16, 1))
+ one(protocol).readI16(); will(returnValue(16: Short))
+ nextRead(e, protocol, new TField("mama", TType.I32, 2))
+ one(protocol).readI32(); will(returnValue(32))
+ nextRead(e, protocol, new TField("papa", TType.I64, 3))
+ one(protocol).readI64(); will(returnValue(64L))
+ endRead(e, protocol)
}
- Ints.decode(protocol) mustEqual new Ints(16, 32, 64L)
+ whenExecuting {
+ Ints.decode(protocol) must be(new Ints(16, 32, 64L))
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("baby", TType.I16, 1))
- one(protocol).writeI16(16)
- nextWrite(protocol, new TField("mama", TType.I32, 2))
- one(protocol).writeI32(32)
- nextWrite(protocol, new TField("papa", TType.I64, 3))
- one(protocol).writeI64(64)
- endWrite(protocol)
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("baby", TType.I16, 1))
+ one(protocol).writeI16(`with`(Expectations.equal(16: Short)))
+ nextWrite(e, protocol, new TField("mama", TType.I32, 2))
+ one(protocol).writeI32(`with`(Expectations.equal(32)))
+ nextWrite(e, protocol, new TField("papa", TType.I64, 3))
+ one(protocol).writeI64(`with`(Expectations.equal(64L)))
+ endWrite(e, protocol)
}
- new Ints(16, 32, 64L).write(protocol) mustEqual ()
+ whenExecuting {
+ new Ints(16, 32, 64L).write(protocol) must be(())
+ }
}
}
- "bytes" in {
- "read" in {
- expect {
- startRead(protocol, new TField("x", TType.BYTE, 1))
- one(protocol).readByte() willReturn 3.toByte
- nextRead(protocol, new TField("y", TType.STRING, 2))
- one(protocol).readBinary() willReturn stringToBytes("hello")
- endRead(protocol)
+ "bytes" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("x", TType.BYTE, 1))
+ one(protocol).readByte(); will(returnValue(3.toByte))
+ nextRead(e, protocol, new TField("y", TType.STRING, 2))
+ one(protocol).readBinary(); will(returnValue(stringToBytes("hello")))
+ endRead(e, protocol)
}
- val bytes = Bytes.decode(protocol)
- bytes.getX mustEqual 3.toByte
- new String(bytes.getY.array) mustEqual "hello"
+ whenExecuting {
+ val bytes = Bytes.decode(protocol)
+ bytes.getX must be(3.toByte)
+ new String(bytes.getY.array) must be("hello")
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("x", TType.BYTE, 1))
- one(protocol).writeByte(16.toByte)
- nextWrite(protocol, new TField("y", TType.STRING, 2))
- one(protocol).writeBinary(stringToBytes("goodbye"))
- endWrite(protocol)
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("x", TType.BYTE, 1))
+ one(protocol).writeByte(`with`(Expectations.equal(16.toByte)))
+ nextWrite(e, protocol, new TField("y", TType.STRING, 2))
+ one(protocol).writeBinary(`with`(Expectations.equal(stringToBytes("goodbye"))))
+ endWrite(e, protocol)
}
- new Bytes(16.toByte, stringToBytes("goodbye")).write(protocol) mustEqual ()
+ whenExecuting {
+ new Bytes(16.toByte, stringToBytes("goodbye")).write(protocol) must be(())
+ }
}
}
- "bool, double, string" in {
- "read" in {
- expect {
- startRead(protocol, new TField("alive", TType.BOOL, 1))
- one(protocol).readBool() willReturn true
- nextRead(protocol, new TField("pi", TType.DOUBLE, 2))
- one(protocol).readDouble() willReturn 3.14
- nextRead(protocol, new TField("name", TType.STRING, 3))
- one(protocol).readString() willReturn "bender"
- endRead(protocol)
+ "bool, double, string" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("alive", TType.BOOL, 1))
+ one(protocol).readBool(); will(returnValue(true))
+ nextRead(e, protocol, new TField("pi", TType.DOUBLE, 2))
+ one(protocol).readDouble(); will(returnValue(3.14))
+ nextRead(e, protocol, new TField("name", TType.STRING, 3))
+ one(protocol).readString(); will(returnValue("bender"))
+ endRead(e, protocol)
}
- Misc.decode(protocol) mustEqual new Misc(true, 3.14, "bender")
+ whenExecuting {
+ Misc.decode(protocol) must be(new Misc(true, 3.14, "bender"))
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("alive", TType.BOOL, 1))
- one(protocol).writeBool(false)
- nextWrite(protocol, new TField("pi", TType.DOUBLE, 2))
- one(protocol).writeDouble(6.28)
- nextWrite(protocol, new TField("name", TType.STRING, 3))
- one(protocol).writeString("fry")
- endWrite(protocol)
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("alive", TType.BOOL, 1))
+ one(protocol).writeBool(`with`(Expectations.equal(false)))
+ nextWrite(e, protocol, new TField("pi", TType.DOUBLE, 2))
+ one(protocol).writeDouble(`with`(Expectations.equal(6.28)))
+ nextWrite(e, protocol, new TField("name", TType.STRING, 3))
+ one(protocol).writeString(`with`(Expectations.equal("fry")))
+ endWrite(e, protocol)
}
- new Misc(false, 6.28, "fry").write(protocol) mustEqual ()
+ whenExecuting {
+ new Misc(false, 6.28, "fry").write(protocol) must be(())
+ }
}
}
- "lists, sets, and maps" in {
+ "lists, sets, and maps" should {
val exemplar = new Compound.Builder()
.intlist(Utilities.makeList(10, 20))
.intset(Utilities.makeSet(44, 55))
.namemap(Utilities.makeMap(Utilities.makeTuple("wendy", 500)))
.nested(Utilities.makeList(Utilities.makeSet(9)))
.build()
- "read" in {
- expect {
- startRead(protocol, new TField("intlist", TType.LIST, 1))
- one(protocol).readListBegin() willReturn new TList(TType.I32, 2)
- one(protocol).readI32() willReturn 10
- one(protocol).readI32() willReturn 20
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("intlist", TType.LIST, 1))
+ one(protocol).readListBegin(); will(returnValue(new TList(TType.I32, 2)))
+ one(protocol).readI32(); will(returnValue(10))
+ one(protocol).readI32(); will(returnValue(20))
one(protocol).readListEnd()
- nextRead(protocol, new TField("intset", TType.SET, 2))
- one(protocol).readSetBegin() willReturn new TSet(TType.I32, 2)
- one(protocol).readI32() willReturn 44
- one(protocol).readI32() willReturn 55
+ nextRead(e, protocol, new TField("intset", TType.SET, 2))
+ one(protocol).readSetBegin(); will(returnValue(new TSet(TType.I32, 2)))
+ one(protocol).readI32(); will(returnValue(44))
+ one(protocol).readI32(); will(returnValue(55))
one(protocol).readSetEnd()
- nextRead(protocol, new TField("namemap", TType.MAP, 3))
- one(protocol).readMapBegin() willReturn new TMap(TType.STRING, TType.I32, 1)
- one(protocol).readString() willReturn "wendy"
- one(protocol).readI32() willReturn 500
+ nextRead(e, protocol, new TField("namemap", TType.MAP, 3))
+ one(protocol).readMapBegin(); will(returnValue(new TMap(TType.STRING, TType.I32, 1)))
+ one(protocol).readString(); will(returnValue("wendy"))
+ one(protocol).readI32(); will(returnValue(500))
one(protocol).readMapEnd()
- nextRead(protocol, new TField("nested", TType.LIST, 4))
- one(protocol).readListBegin() willReturn new TList(TType.SET, 1)
- one(protocol).readSetBegin() willReturn new TSet(TType.I32, 1)
- one(protocol).readI32() willReturn 9
+ nextRead(e, protocol, new TField("nested", TType.LIST, 4))
+ one(protocol).readListBegin(); will(returnValue(new TList(TType.SET, 1)))
+ one(protocol).readSetBegin(); will(returnValue(new TSet(TType.I32, 1)))
+ one(protocol).readI32(); will(returnValue(9))
one(protocol).readSetEnd()
one(protocol).readListEnd()
- endRead(protocol)
+ endRead(e, protocol)
}
- Compound.decode(protocol) mustEqual exemplar
+ whenExecuting {
+ Compound.decode(protocol) must be(exemplar)
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("intlist", TType.LIST, 1))
- one(protocol).writeListBegin(equal(new TList(TType.I32, 2)))
- one(protocol).writeI32(10)
- one(protocol).writeI32(20)
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("intlist", TType.LIST, 1))
+ one(protocol).writeListBegin(`with`(listEqual(new TList(TType.I32, 2))))
+ one(protocol).writeI32(`with`(Expectations.equal(10)))
+ one(protocol).writeI32(`with`(Expectations.equal(20)))
one(protocol).writeListEnd()
- nextWrite(protocol, new TField("intset", TType.SET, 2))
- one(protocol).writeSetBegin(equal(new TSet(TType.I32, 2)))
- one(protocol).writeI32(44)
- one(protocol).writeI32(55)
+ nextWrite(e, protocol, new TField("intset", TType.SET, 2))
+ one(protocol).writeSetBegin(`with`(setEqual(new TSet(TType.I32, 2))))
+ one(protocol).writeI32(`with`(Expectations.equal(44)))
+ one(protocol).writeI32(`with`(Expectations.equal(55)))
one(protocol).writeSetEnd()
- nextWrite(protocol, new TField("namemap", TType.MAP, 3))
- one(protocol).writeMapBegin(equal(new TMap(TType.STRING, TType.I32, 1)))
- one(protocol).writeString("wendy")
- one(protocol).writeI32(500)
+ nextWrite(e, protocol, new TField("namemap", TType.MAP, 3))
+ one(protocol).writeMapBegin(`with`(mapEqual(new TMap(TType.STRING, TType.I32, 1))))
+ one(protocol).writeString(`with`(Expectations.equal("wendy")))
+ one(protocol).writeI32(`with`(Expectations.equal(500)))
one(protocol).writeMapEnd()
- nextWrite(protocol, new TField("nested", TType.LIST, 4))
- one(protocol).writeListBegin(equal(new TList(TType.SET, 1)))
- one(protocol).writeSetBegin(equal(new TSet(TType.I32, 1)))
+ nextWrite(e, protocol, new TField("nested", TType.LIST, 4))
+ one(protocol).writeListBegin(`with`(listEqual(new TList(TType.SET, 1))))
+ one(protocol).writeSetBegin(`with`(setEqual(new TSet(TType.I32, 1))))
one(protocol).writeI32(9)
one(protocol).writeSetEnd()
one(protocol).writeListEnd()
- endWrite(protocol)
+ endWrite(e, protocol)
}
- exemplar.write(protocol) mustEqual ()
+ whenExecuting {
+ exemplar.write(protocol) must be(())
+ }
}
}
}
- "complicated structs" in {
- "with required fields" in {
- "read" in {
- expect {
- startRead(protocol, new TField("string", TType.STRING, 1))
- one(protocol).readString() willReturn "yo"
- endRead(protocol)
+ "complicated structs" should {
+ "with required fields" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("string", TType.STRING, 1))
+ one(protocol).readString(); will(returnValue("yo"))
+ endRead(e, protocol)
}
- RequiredString.decode(protocol) mustEqual new RequiredString("yo")
+ whenExecuting {
+ RequiredString.decode(protocol) must be(new RequiredString("yo"))
+ }
}
- "missing required value throws exception during deserialization" in {
- doBefore {
- expect {
- emptyRead(protocol)
+ "missing required value throws exception during deserialization" should {
+ "with no default value" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ emptyRead(e, protocol)
}
- }
- "with no default value" in {
- RequiredString.decode(protocol) must throwA[TProtocolException]
+ whenExecuting {
+ intercept[TProtocolException] {
+ RequiredString.decode(protocol)
+ }
+ }
}
- "with default value" in {
- RequiredStringWithDefault.decode(protocol) must throwA[TProtocolException]
+ "with default value" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ emptyRead(e, protocol)
+ }
+
+ whenExecuting {
+ intercept[TProtocolException] {
+ RequiredStringWithDefault.decode(protocol)
+ }
+ }
}
}
- "null required value throws exception during serialization" in {
- "with no default value" in {
- new RequiredString(null).write(protocol) must throwA[TProtocolException]
+ "null required value throws exception during serialization" should {
+ "with no default value" in { e => import e._
+ val protocol = mock[TProtocol]
+
+ intercept[TProtocolException] {
+ new RequiredString(null).write(protocol)
+ }
}
- "with default value" in {
- new RequiredStringWithDefault(null).write(protocol) must throwA[TProtocolException]
+ "with default value" in { e => import e._
+ val protocol = mock[TProtocol]
+
+ intercept[TProtocolException] {
+ new RequiredStringWithDefault(null).write(protocol)
+ }
}
}
}
- "with optional fields" in {
- "read" in {
- expect {
- startRead(protocol, new TField("name", TType.STRING, 1))
- one(protocol).readString() willReturn "Commie"
- nextRead(protocol, new TField("age", TType.I32, 2))
- one(protocol).readI32() willReturn 14
- endRead(protocol)
+ "with optional fields" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).readString(); will(returnValue("Commie"))
+ nextRead(e, protocol, new TField("age", TType.I32, 2))
+ one(protocol).readI32(); will(returnValue(14))
+ endRead(e, protocol)
}
- OptionalInt.decode(protocol) mustEqual new OptionalInt("Commie", new Option.Some(14))
+ whenExecuting {
+ OptionalInt.decode(protocol) must be(new OptionalInt("Commie", new Option.Some(14)))
+ }
}
- "read with missing field" in {
- expect {
- startRead(protocol, new TField("name", TType.STRING, 1))
- one(protocol).readString() willReturn "Commie"
- endRead(protocol)
+ "read with missing field" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).readString(); will(returnValue( "Commie"))
+ endRead(e, protocol)
}
- OptionalInt.decode(protocol) mustEqual new OptionalInt("Commie", Option.none())
+ whenExecuting {
+ OptionalInt.decode(protocol) must be(new OptionalInt("Commie", Option.none()))
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("name", TType.STRING, 1))
- one(protocol).writeString("Commie")
- nextWrite(protocol, new TField("age", TType.I32, 2))
- one(protocol).writeI32(14)
- endWrite(protocol)
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).writeString(`with`(Expectations.equal("Commie")))
+ nextWrite(e, protocol, new TField("age", TType.I32, 2))
+ one(protocol).writeI32(`with`(Expectations.equal(14)))
+ endWrite(e, protocol)
}
- new OptionalInt("Commie", new Option.Some(14)).write(protocol) mustEqual ()
+ whenExecuting {
+ new OptionalInt("Commie", new Option.Some(14)).write(protocol) must be(())
+ }
}
- "write with missing field" in {
- expect {
- startWrite(protocol, new TField("name", TType.STRING, 1))
- one(protocol).writeString("Commie")
- endWrite(protocol)
+ "write with missing field" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).writeString(`with`(Expectations.equal("Commie")))
+ endWrite(e, protocol)
}
- new OptionalInt("Commie", Option.none()).write(protocol) mustEqual ()
+ whenExecuting {
+ new OptionalInt("Commie", Option.none()).write(protocol) must be(())
+ }
}
}
- "with default values" in {
- "read with value missing, using default" in {
- expect {
+ "with default values" should {
+ "read with value missing, using default" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
one(protocol).readStructBegin()
- one(protocol).readFieldBegin() willReturn new TField("stop", TType.STOP, 10)
+ one(protocol).readFieldBegin(); will(returnValue(new TField("stop", TType.STOP, 10)))
one(protocol).readStructEnd()
}
- DefaultValues.decode(protocol) mustEqual new DefaultValues("leela")
+ whenExecuting {
+ DefaultValues.decode(protocol) must be(new DefaultValues("leela"))
+ }
}
- "read with value present" in {
- expect {
+ "read with value present" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
one(protocol).readStructBegin()
- nextRead(protocol, new TField("name", TType.STRING, 1))
- one(protocol).readString() willReturn "delilah"
- one(protocol).readFieldBegin() willReturn new TField("stop", TType.STOP, 10)
+ nextRead(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).readString(); will(returnValue( "delilah"))
+ one(protocol).readFieldBegin(); will(returnValue(new TField("stop", TType.STOP, 10)))
one(protocol).readStructEnd()
}
- DefaultValues.decode(protocol) mustEqual new DefaultValues("delilah")
+ whenExecuting {
+ DefaultValues.decode(protocol) must be(new DefaultValues("delilah"))
+ }
}
}
- "nested" in {
- "read" in {
- expect {
- startRead(protocol, new TField("name", TType.STRING, 1))
- one(protocol).readString() willReturn "United States of America"
- nextRead(protocol, new TField("provinces", TType.LIST, 2))
- one(protocol).readListBegin() willReturn new TList(TType.STRING, 2)
- one(protocol).readString() willReturn "connecticut"
- one(protocol).readString() willReturn "california"
+ "nested" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).readString(); will(returnValue("United States of America"))
+ nextRead(e, protocol, new TField("provinces", TType.LIST, 2))
+ one(protocol).readListBegin(); will(returnValue(new TList(TType.STRING, 2)))
+ one(protocol).readString(); will(returnValue("connecticut"))
+ one(protocol).readString(); will(returnValue("california"))
one(protocol).readListEnd()
- nextRead(protocol, new TField("emperor", TType.STRUCT, 5))
+ nextRead(e, protocol, new TField("emperor", TType.STRUCT, 5))
/** Start of Emperor struct **/
- startRead(protocol, new TField("name", TType.STRING, 1))
- one(protocol).readString() willReturn "Bush"
- nextRead(protocol, new TField("age", TType.I32, 2))
- one(protocol).readI32() willReturn 42
- endRead(protocol)
+ startRead(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).readString(); will(returnValue( "Bush"))
+ nextRead(e, protocol, new TField("age", TType.I32, 2))
+ one(protocol).readI32(); will(returnValue(42))
+ endRead(e, protocol)
/** End of Emperor struct **/
- endRead(protocol)
+ endRead(e, protocol)
}
- Empire.decode(protocol) mustEqual new Empire(
- "United States of America",
- Utilities.makeList("connecticut", "california"),
- new Emperor("Bush", 42))
+ whenExecuting {
+ Empire.decode(protocol) must be(new Empire(
+ "United States of America",
+ Utilities.makeList("connecticut", "california"),
+ new Emperor("Bush", 42)))
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("name", TType.STRING, 1))
- one(protocol).writeString("Canada")
- nextWrite(protocol, new TField("provinces", TType.LIST, 2))
- one(protocol).writeListBegin(equal(new TList(TType.STRING, 2)))
- one(protocol).writeString("Manitoba")
- one(protocol).writeString("Alberta")
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).writeString(`with`(Expectations.equal("Canada")))
+ nextWrite(e, protocol, new TField("provinces", TType.LIST, 2))
+ one(protocol).writeListBegin(`with`(listEqual(new TList(TType.STRING, 2))))
+ one(protocol).writeString(`with`(Expectations.equal("Manitoba")))
+ one(protocol).writeString(`with`(Expectations.equal("Alberta")))
one(protocol).writeListEnd()
- nextWrite(protocol, new TField("emperor", TType.STRUCT, 5))
+ nextWrite(e, protocol, new TField("emperor", TType.STRUCT, 5))
// emperor
- startWrite(protocol, new TField("name", TType.STRING, 1))
- one(protocol).writeString("Larry")
- nextWrite(protocol, new TField("age", TType.I32, 2))
+ startWrite(e, protocol, new TField("name", TType.STRING, 1))
+ one(protocol).writeString(`with`(Expectations.equal("Larry")))
+ nextWrite(e, protocol, new TField("age", TType.I32, 2))
one(protocol).writeI32(13)
- endWrite(protocol)
+ endWrite(e, protocol)
- endWrite(protocol)
+ endWrite(e, protocol)
}
- new Empire(
- "Canada",
- Utilities.makeList("Manitoba", "Alberta"),
- new Emperor("Larry", 13)
- ).write(protocol) mustEqual ()
+ whenExecuting {
+ new Empire(
+ "Canada",
+ Utilities.makeList("Manitoba", "Alberta"),
+ new Emperor("Larry", 13)
+ ).write(protocol) must be(())
+ }
}
}
- "exception" in {
- new Xception(1, "boom") must haveSuperClass[Exception]
- new Xception(2, "kathunk").getMessage mustEqual "kathunk"
+ "exception" in { _ =>
+ (new Xception(1, "boom")).isInstanceOf[Exception] must be(true)
+ new Xception(2, "kathunk").getMessage must be("kathunk")
}
- "exception getMessage" in {
- new StringMsgException(1, "jeah").getMessage mustEqual "jeah"
- new NonStringMessageException(5).getMessage mustEqual "5"
+ "exception getMessage" in { _ =>
+ new StringMsgException(1, "jeah").getMessage must be("jeah")
+ new NonStringMessageException(5).getMessage must be("5")
}
- "with more than 22 fields" in {
- "apply" in {
- new Biggie.Builder().build().getNum25() mustEqual 25
+ "with more than 22 fields" should {
+ "apply" in { _ =>
+ new Biggie.Builder().build().getNum25() must be(25)
}
- "two default object must be equal" in {
- new Biggie.Builder().build() mustEqual new Biggie.Builder().build()
+ "two default object must be equal" in { _ =>
+ new Biggie.Builder().build() must be(new Biggie.Builder().build())
}
- "copy and equals" in {
- new Biggie.Builder().build().copy().num10(-5).build() mustEqual new Biggie.Builder().num10(-5).build()
+ "copy and equals" in { _ =>
+ new Biggie.Builder().build().copy().num10(-5).build() must be(new Biggie.Builder().num10(-5).build())
}
- "hashCode is the same for two similar objects" in {
- new Biggie.Builder().build().hashCode mustEqual new Biggie.Builder().build().hashCode
- new Biggie.Builder().num10(-5).build().hashCode mustEqual new Biggie.Builder().num10(-5).build().hashCode
+ "hashCode is the same for two similar objects" in { _ =>
+ new Biggie.Builder().build().hashCode must be(new Biggie.Builder().build().hashCode)
+ new Biggie.Builder().num10(-5).build().hashCode must be(new Biggie.Builder().num10(-5).build().hashCode)
}
- "hashCode is different for two different objects" in {
- new Biggie.Builder().num10(-5).build().hashCode mustNot beEqual(new Biggie.Builder().build().hashCode)
+ "hashCode is different for two different objects" in { _ =>
+ new Biggie.Builder().num10(-5).build().hashCode must not be(new Biggie.Builder().build().hashCode)
}
- "toString" in {
- new Biggie.Builder().build().toString mustEqual ("Biggie(" + 1.to(25).map(_.toString).mkString(",") + ")")
+ "toString" in { _ =>
+ new Biggie.Builder().build().toString must be(("Biggie(" + 1.to(25).map(_.toString).mkString(",") + ")"))
}
}
}
- "unions" in {
- "zero fields" in {
- "read" in {
- expect {
- emptyRead(protocol)
+ "unions" should {
+ "zero fields" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ emptyRead(e, protocol)
}
- Bird.decode(protocol) must throwA[TProtocolException]
+ whenExecuting {
+ intercept[TProtocolException] {
+ Bird.decode(protocol)
+ }
+ }
}
- "instantiate" in {
- Bird.newRaptor(null) must throwA[NullPointerException]
+ "instantiate" in { _ =>
+ intercept[NullPointerException] {
+ Bird.newRaptor(null)
+ }
}
}
- "one field" in {
- "read" in {
- expect {
- startRead(protocol, new TField("hummingbird", TType.STRING, 2))
- one(protocol).readString() willReturn "Ruby-Throated"
- endRead(protocol)
+ "one field" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("hummingbird", TType.STRING, 2))
+ one(protocol).readString(); will(returnValue("Ruby-Throated"))
+ endRead(e, protocol)
}
- Bird.decode(protocol) mustEqual Bird.newHummingbird("Ruby-Throated")
+ whenExecuting {
+ Bird.decode(protocol) must be(Bird.newHummingbird("Ruby-Throated"))
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("owlet_nightjar", TType.STRING, 3))
- one(protocol).writeString("foo")
- endWrite(protocol)
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("owlet_nightjar", TType.STRING, 3))
+ one(protocol).writeString(`with`(Expectations.equal("foo")))
+ endWrite(e, protocol)
}
- Bird.newOwletNightjar("foo").write(protocol)
+ whenExecuting {
+ Bird.newOwletNightjar("foo").write(protocol)
+ }
}
}
- "more than one field" in {
- "read" in {
- expect {
- startRead(protocol, new TField("hummingbird", TType.STRING, 2))
- one(protocol).readString() willReturn "Anna's Hummingbird"
- nextRead(protocol, new TField("owlet_nightjar", TType.STRING, 3))
- one(protocol).readBinary() willReturn ByteBuffer.allocate(1)
- endRead(protocol)
+ "more than one field" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("hummingbird", TType.STRING, 2))
+ one(protocol).readString(); will(returnValue("Anna's Hummingbird"))
+ nextRead(e, protocol, new TField("owlet_nightjar", TType.STRING, 3))
+ one(protocol).readBinary(); will(returnValue(ByteBuffer.allocate(1)))
+ endRead(e, protocol)
}
- Bird.decode(protocol) must throwA[TProtocolException]
+ whenExecuting {
+ intercept[TProtocolException] {
+ Bird.decode(protocol)
+ }
+ }
}
// no write test because it's not possible
}
- "nested struct" in {
- "read" in {
- expect {
- startRead(protocol, new TField("raptor", TType.STRUCT, 1))
- startRead(protocol, new TField("isOwl", TType.BOOL, 1))
- one(protocol).readBool() willReturn false
- nextRead(protocol, new TField("species", TType.STRING, 2))
- one(protocol).readString() willReturn "peregrine"
- endRead(protocol)
- endRead(protocol)
+ "nested struct" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("raptor", TType.STRUCT, 1))
+ startRead(e, protocol, new TField("isOwl", TType.BOOL, 1))
+ one(protocol).readBool(); will(returnValue(false))
+ nextRead(e, protocol, new TField("species", TType.STRING, 2))
+ one(protocol).readString(); will(returnValue("peregrine"))
+ endRead(e, protocol)
+ endRead(e, protocol)
}
- Bird.decode(protocol) mustEqual Bird.newRaptor(new Raptor(false, "peregrine"))
+ whenExecuting {
+ Bird.decode(protocol) must be(Bird.newRaptor(new Raptor(false, "peregrine")))
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("raptor", TType.STRUCT, 1))
- startWrite(protocol, new TField("isOwl", TType.BOOL, 1))
- one(protocol).writeBool(true)
- nextWrite(protocol, new TField("species", TType.STRING, 2))
- one(protocol).writeString("Tyto alba")
- endWrite(protocol)
- endWrite(protocol)
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("raptor", TType.STRUCT, 1))
+ startWrite(e, protocol, new TField("isOwl", TType.BOOL, 1))
+ one(protocol).writeBool(`with`(Expectations.equal(true)))
+ nextWrite(e, protocol, new TField("species", TType.STRING, 2))
+ one(protocol).writeString(`with`(Expectations.equal("Tyto alba")))
+ endWrite(e, protocol)
+ endWrite(e, protocol)
}
- Bird.newRaptor(new Raptor(true, "Tyto alba")).write(protocol)
+ whenExecuting {
+ Bird.newRaptor(new Raptor(true, "Tyto alba")).write(protocol)
+ }
}
}
- "collection" in {
- "read" in {
- expect {
- startRead(protocol, new TField("flock", TType.LIST, 4))
- one(protocol).readListBegin() willReturn new TList(TType.STRING, 3)
- one(protocol).readString() willReturn "starling"
- one(protocol).readString() willReturn "kestrel"
- one(protocol).readString() willReturn "warbler"
+ "collection" should {
+ "read" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startRead(e, protocol, new TField("flock", TType.LIST, 4))
+ one(protocol).readListBegin(); will(returnValue(new TList(TType.STRING, 3)))
+ one(protocol).readString(); will(returnValue("starling"))
+ one(protocol).readString(); will(returnValue("kestrel"))
+ one(protocol).readString(); will(returnValue("warbler"))
one(protocol).readListEnd()
- endRead(protocol)
+ endRead(e, protocol)
}
- Bird.decode(protocol) mustEqual Bird.newFlock(Utilities.makeList("starling", "kestrel", "warbler"))
+ whenExecuting {
+ Bird.decode(protocol) must be(Bird.newFlock(Utilities.makeList("starling", "kestrel", "warbler")))
+ }
}
- "write" in {
- expect {
- startWrite(protocol, new TField("flock", TType.LIST, 4))
- one(protocol).writeListBegin(equal(new TList(TType.STRING, 3)))
- one(protocol).writeString("starling")
- one(protocol).writeString("kestrel")
- one(protocol).writeString("warbler")
+ "write" in { cycle => import cycle._
+ val protocol = mock[TProtocol]
+ expecting { e => import e._
+ startWrite(e, protocol, new TField("flock", TType.LIST, 4))
+ one(protocol).writeListBegin(`with`(listEqual(new TList(TType.STRING, 3))))
+ one(protocol).writeString(`with`(Expectations.equal("starling")))
+ one(protocol).writeString(`with`(Expectations.equal("kestrel")))
+ one(protocol).writeString(`with`(Expectations.equal("warbler")))
one(protocol).writeListEnd()
- endWrite(protocol)
+ endWrite(e, protocol)
}
- Bird.newFlock(Utilities.makeList("starling", "kestrel", "warbler")).write(protocol)
+ whenExecuting {
+ Bird.newFlock(Utilities.makeList("starling", "kestrel", "warbler")).write(protocol)
+ }
}
}
- "primitive field type" in {
+ "primitive field type" in { _ =>
import thrift.java_def._default_._
val protocol = new TBinaryProtocol(new TMemoryBuffer(10000))
var original: NaughtyUnion = NaughtyUnion.newValue(1)
NaughtyUnion.encode(original, protocol)
- NaughtyUnion.decode(protocol) mustEqual(original)
+ NaughtyUnion.decode(protocol) must be(original)
original = NaughtyUnion.newFlag(true)
NaughtyUnion.encode(original, protocol)
- NaughtyUnion.decode(protocol) mustEqual(original)
+ NaughtyUnion.decode(protocol) must be(original)
original = NaughtyUnion.newText("false")
NaughtyUnion.encode(original, protocol)
- NaughtyUnion.decode(protocol) mustEqual(original)
+ NaughtyUnion.decode(protocol) must be(original)
}
}
}
View
12 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/NamespaceSpec.scala
@@ -1,8 +1,8 @@
package com.twitter.scrooge.backend
-import org.specs.SpecificationWithJUnit
+import com.twitter.scrooge.testutil.Spec
-class NamespaceSpec extends SpecificationWithJUnit {
+class NamespaceSpec extends Spec {
"Scala Generator" should {
import foo._
import bar._
@@ -13,8 +13,8 @@ class NamespaceSpec extends SpecificationWithJUnit {
def makeReservation(whichDay: Weekday, howMany: Int) =
Some(if (whichDay == Weekday.Monday) 0 else howMany)
}
- service.makeReservation(Weekday.Monday, 2) mustEqual Some(0)
- service.makeReservation(Weekday.Tuesday, 2) mustEqual Some(2)
+ service.makeReservation(Weekday.Monday, 2) must be(Some(0))
+ service.makeReservation(Weekday.Tuesday, 2) must be(Some(2))
}
}
@@ -28,8 +28,8 @@ class NamespaceSpec extends SpecificationWithJUnit {
def makeReservation(whichDay: Weekday, howMany: Int) =
if (whichDay == Weekday.MONDAY) 0 else howMany
}
- service.makeReservation(Weekday.MONDAY, 2) mustEqual 0
- service.makeReservation(Weekday.TUESDAY, 2) mustEqual 2
+ service.makeReservation(Weekday.MONDAY, 2) must be(0)
+ service.makeReservation(Weekday.TUESDAY, 2) must be(2)
}
}
}
View
30 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/NamingConvention.scala
@@ -1,37 +1,37 @@
package com.twitter.scrooge.backend
-import org.specs.SpecificationWithJUnit
+import com.twitter.scrooge.testutil.Spec
-class NamingConventionSpec extends SpecificationWithJUnit {
+class NamingConventionSpec extends Spec {
"Scala Generator" should {
"follow naming conventions" in {
import thrift.`def`.default._
- Constants.`val` mustEqual 10
- Constants.`try` mustEqual 123
+ Constants.`val` must be(10)
+ Constants.`try` must be(123)
val naughty = Naughty("car", 100)
- naughty.`type` mustEqual "car"
- naughty.`abstract` mustEqual 100
+ naughty.`type` must be("car")
+ naughty.`abstract` must be(100)
- Super.Trait.getValue mustEqual 20
- Super.get(99) must beSome(Super.Native)
- Super.valueOf("trait") must beSome(Super.Trait)
+ Super.Trait.getValue must be(20)
+ Super.get(99) must be(Some(Super.Native))
+ Super.valueOf("trait") must be(Some(Super.Trait))
}
}
"Java Generator" should {
"follow naming convention" in {
import thrift.java_def._default_._ // package name "default" got rewritten in Java
- Constants.`val` mustEqual 10
- Constants._try_ mustEqual 123
+ Constants.`val` must be(10)
+ Constants._try_ must be(123)
val naughty = new Naughty("car", 100)
- naughty.getType() mustEqual "car"
- naughty.getAbstract() mustEqual 100
+ naughty.getType() must be("car")
+ naughty.getAbstract() must be(100)