Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unit test cleanups

  • Loading branch information...
commit f095e8ac59bdc16242835404444f2da6807d1345 1 parent 4983aa3
@benmur authored
View
17 src/test/scala/net/benmur/riemann/client/EventSenderDSLTest.scala
@@ -1,14 +1,11 @@
package net.benmur.riemann.client
-
-import org.scalatest.{ BeforeAndAfterAll, FunSuite }
-import com.aphyr.riemann.Proto
-import akka.actor.ActorSystem
-import net.benmur.riemann.client.testingsupport.TestingTransportSupport
-import org.scalamock.scalatest.MockFactory
import org.scalamock.ProxyMockFactory
+import org.scalamock.scalatest.MockFactory
+import org.scalatest.FunSuite
+import net.benmur.riemann.client.testingsupport.TestingTransportSupport
class EventSenderDSLTest extends FunSuite
- with BeforeAndAfterAll
+ with testingsupport.ImplicitActorSystem
with MockFactory
with ProxyMockFactory {
@@ -17,12 +14,6 @@ class EventSenderDSLTest extends FunSuite
import TestingTransportSupport._
import EventSenderDSL._
- implicit val system = ActorSystem()
-
- override def afterAll {
- system.shutdown
- }
-
def makeDestination = {
val conn = new TestingTransportConnection
val dest = new DestinationOps.RiemannDestination[TestingTransport](EventPart(), conn)
View
13 src/test/scala/net/benmur/riemann/client/ReliableIOTest.scala
@@ -1,11 +1,11 @@
package net.benmur.riemann.client
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, DataOutputStream }
-import java.net.{ InetSocketAddress, SocketAddress }
+import java.net.SocketAddress
import org.scalamock.ProxyMockFactory
import org.scalamock.scalatest.MockFactory
-import org.scalatest.{ BeforeAndAfterAll, FunSuite }
+import org.scalatest.FunSuite
import org.scalatest.matchers.ShouldMatchers
import com.aphyr.riemann.Proto
@@ -16,7 +16,7 @@ import akka.testkit.CallingThreadDispatcher
import akka.util.duration.intToDurationInt
class ReliableIOTest extends FunSuite
- with BeforeAndAfterAll
+ with testingsupport.ImplicitActorSystem
with MockFactory
with ProxyMockFactory
with ShouldMatchers {
@@ -24,13 +24,6 @@ class ReliableIOTest extends FunSuite
import ReliableIO._
import testingsupport.TestingTransportSupport._
- implicit val system = ActorSystem()
- val address = new InetSocketAddress(0)
-
- override def afterAll {
- system.shutdown
- }
-
test("sending a protobuf Msg with Event") {
val in = Array.ofDim[Byte](256)
val ios = new ByteArrayInputStream(in)
View
20 src/test/scala/net/benmur/riemann/client/RiemannClientWithDestinationAPITest.scala
@@ -1,27 +1,19 @@
package net.benmur.riemann.client
-import java.net.InetSocketAddress
-import org.scalatest.{ BeforeAndAfterAll, FunSuite }
-import org.scalatest.matchers.ShouldMatchers
-import RiemannClient.{ host, riemannConnectAs, service, state }
-import akka.actor.ActorSystem
import org.scalamock.ProxyMockFactory
import org.scalamock.scalatest.MockFactory
+import org.scalatest.FunSuite
+import org.scalatest.matchers.ShouldMatchers
+
+import RiemannClient.riemannConnectAs
class RiemannClientWithDestinationAPITest extends FunSuite
- with BeforeAndAfterAll
+ with testingsupport.ImplicitActorSystem
with ShouldMatchers
with MockFactory
with ProxyMockFactory {
import testingsupport.TestingTransportSupport._
- implicit val system = ActorSystem()
- val address = new InetSocketAddress(0)
-
- override def afterAll {
- system.shutdown
- }
-
test("entry point to create a connection (pristine state)") {
val dest = riemannConnectAs[TestingTransport] to address
val conn = dest.connection.asInstanceOf[TestingTransportConnection]
@@ -75,6 +67,6 @@ class RiemannClientWithDestinationAPITest extends FunSuite
val ev = EventPart(host = Some("h"), service = Some("s"), state = Some("ok"))
sender expects 'sendOff withArguments (dest.connection, Write(ev)) once
- dest send state("ok")
+ dest send EventPart(state = Some("ok"))
}
}
View
14 src/test/scala/net/benmur/riemann/client/UnreliableIOTest.scala
@@ -1,20 +1,19 @@
package net.benmur.riemann.client
-import java.net.{ InetSocketAddress, SocketAddress }
+import java.net.SocketAddress
-import scala.annotation.implicitNotFound
import scala.collection.mutable.WrappedArray
import org.scalamock.ProxyMockFactory
import org.scalamock.scalatest.MockFactory
-import org.scalatest.{ BeforeAndAfterAll, FunSuite }
+import org.scalatest.FunSuite
import org.scalatest.matchers.ShouldMatchers
import akka.actor.ActorSystem
import akka.testkit.CallingThreadDispatcher
class UnreliableIOTest extends FunSuite
- with BeforeAndAfterAll
+ with testingsupport.ImplicitActorSystem
with MockFactory
with ProxyMockFactory
with ShouldMatchers {
@@ -22,13 +21,6 @@ class UnreliableIOTest extends FunSuite
import UnreliableIO._
import testingsupport.TestingTransportSupport._
- implicit val system = ActorSystem()
- val address = new InetSocketAddress(0)
-
- override def afterAll {
- system.shutdown
- }
-
test("send a protobuf Msg") {
val socket = mock[UnconnectedSocketWrapper]
socket expects 'send withArguments (WrappedArray.make(protoMsgEvent.toByteArray)) once
View
16 src/test/scala/net/benmur/riemann/client/testingsupport/ImplicitActorSystem.scala
@@ -0,0 +1,16 @@
+package net.benmur.riemann.client.testingsupport
+
+import org.scalatest.BeforeAndAfterAll
+import akka.actor.ActorSystem
+import org.scalatest.Suite
+
+trait ImplicitActorSystem extends BeforeAndAfterAll {
+ self: Suite =>
+
+ implicit val system = ActorSystem()
+
+ override def afterAll {
+ super.afterAll
+ system.shutdown
+ }
+}
View
1  src/test/scala/net/benmur/riemann/client/testingsupport/TestingTransportSupport.scala
@@ -12,6 +12,7 @@ trait TestingTransportSupport {
import RiemannClient._
implicit val timeout = Timeout(10 seconds)
+ val address = new InetSocketAddress(0)
class TestingTransportConnection(val where: SocketAddress = new InetSocketAddress(0)) extends Connection[TestingTransport]
Please sign in to comment.
Something went wrong with that request. Please try again.