Skip to content

Commit

Permalink
Fixes #57 - reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Weber committed Apr 14, 2016
1 parent b6d10b9 commit 5cfc1e8
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mesosphere.chaos.examples.trains

import mesosphere.chaos.examples.trains.modules.{StationModule, ModernShuntingModule, TraditionalShuntingModule, LoadingModule}

object TrainStation extends App {
val traditionalModules = new TraditionalShuntingModule
with LoadingModule
Expand All @@ -9,6 +11,8 @@ object TrainStation extends App {
with LoadingModule
with StationModule

println("### Traditional station:")
println(traditionalModules.trainStation.prepareAndDispatchNextTrain())
println("\n### Modern station:")
println(modernModules.trainStation.prepareAndDispatchNextTrain())
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mesosphere.chaos.examples.trains
package mesosphere.chaos.examples.trains.modules

import com.softwaremill.macwire._
import mesosphere.chaos.examples.trains.impl.loading.{CraneController, TrainLoader}
import mesosphere.chaos.examples.trains.impl.shunting.PointSwitcher
import mesosphere.chaos.examples.trains.modules.impl.loading.{CraneController, TrainLoader}
import mesosphere.chaos.examples.trains.modules.impl.shunting.PointSwitcher

@Module
trait LoadingModule {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package mesosphere.chaos.examples.trains
package mesosphere.chaos.examples.trains.modules

import com.softwaremill.macwire._
import mesosphere.chaos.examples.trains.impl.shunting._
import mesosphere.chaos.examples.trains.modules.impl.shunting._

@Module
trait ShuntingModule {
lazy val pointSwitcher = wire[PointSwitcher]

// dependency of the module
def trainShunter: TrainShunter
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mesosphere.chaos.examples.trains
package mesosphere.chaos.examples.trains.modules

import com.softwaremill.macwire._
import mesosphere.chaos.examples.trains.impl.station.{TrainDispatch, TrainStation}
import mesosphere.chaos.examples.trains.modules.impl.station.{TrainDispatch, TrainStation}

@Module
trait StationModule extends ShuntingModule with LoadingModule {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mesosphere.chaos.examples.trains
package mesosphere.chaos.examples.trains.modules

import com.softwaremill.macwire._
import mesosphere.chaos.examples.trains.impl.stats.{LoadingStats, ShuntingStats}
import mesosphere.chaos.examples.trains.modules.impl.stats.{LoadingStats, ShuntingStats}

class StatsModule(shuntingModule: ShuntingModule, loadingModule: LoadingModule) {
lazy val loadingStats = wire[LoadingStats]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mesosphere.chaos.examples.trains.modules.impl.loading

class CraneController() {
def controll() = println("crane moved")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mesosphere.chaos.examples.trains.modules.impl.loading

import mesosphere.chaos.examples.trains.modules.impl.shunting.PointSwitcher

class TrainLoader(craneController: CraneController,
pointSwitcher: PointSwitcher) {
def load() = {
println("loaded")
pointSwitcher.switch()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package mesosphere.chaos.examples.trains.modules.impl.shunting

class PointSwitcher() {
def switch() = println("switched")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package mesosphere.chaos.examples.trains.modules.impl.shunting

class TrainCarCoupler() { def couple() = println("coupled") }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mesosphere.chaos.examples.trains.modules.impl.shunting

trait TrainShunter { def shunt() = println("shunted") }
class TraditionalTrainShunter(pointSwitcher: PointSwitcher,
trainCarCoupler: TrainCarCoupler) extends TrainShunter {
override def shunt() = {
println("# Traditional shunter:")
pointSwitcher.switch()
trainCarCoupler.couple()
super.shunt()
}
}
class TeleportingTrainShunter() extends TrainShunter {
override def shunt() = {
println("# Modern shunter:")
println("teleported")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package mesosphere.chaos.examples.trains.modules.impl.station

class TrainDispatch() { def dispatch() = "dispatched" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mesosphere.chaos.examples.trains.modules.impl.station

import mesosphere.chaos.examples.trains.modules.impl.loading.TrainLoader
import mesosphere.chaos.examples.trains.modules.impl.shunting.TrainShunter

class TrainStation(trainShunter: TrainShunter,
trainLoader: TrainLoader,
trainDispatch: TrainDispatch) {

def prepareAndDispatchNextTrain() = {
println("## Shunter:")
trainShunter.shunt()
println("## Loader:")
trainLoader.load()
println("## Dispatcher:")
trainDispatch.dispatch()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mesosphere.chaos.examples.trains.modules.impl.stats

import mesosphere.chaos.examples.trains.modules.impl.loading.TrainLoader
import mesosphere.chaos.examples.trains.modules.impl.shunting.TrainShunter

class LoadingStats(trainLoader: TrainLoader)
class ShuntingStats(trainShunter: TrainShunter)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mesosphere.chaos.examples.trains.modules

import mesosphere.chaos.examples.trains.modules.impl.shunting.PointSwitcher
import org.scalamock.scalatest.MockFactory
import org.scalatest.FlatSpec

class ShuntingModuleTest extends FlatSpec with MockFactory {
it should "work" in {
// given
val mockPointSwitcher = mock[PointSwitcher]

// when
val moduleToTest = new ShuntingModule2 {
// the mock implementation will be used to wire the graph
override lazy val pointSwitcher = mockPointSwitcher
}

moduleToTest.trainShunter.shunt()

// then

// verify(mockPointSwitcher).switch()
}
}
7 changes: 5 additions & 2 deletions project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ object Dependencies {
// The macros subproject contains only code which is used at compile-time, hence the provided scope.
macWireMacros % "provided",
// The util subproject contains tagging, Wired and the @Module annotation; if you don't use these features, you don't need to include this dependency.
// macWireUtil % "compile",
macWireUtil % "compile",
macWireProxy % "compile",

// test
Expand All @@ -142,7 +142,8 @@ object Dependencies {
macWireProxy % "compile",

// test
Test.mockito % "test"
Test.mockito % "test",
Test.scalaMock % "test"
)
}

Expand All @@ -168,6 +169,7 @@ object Dependency {
val JUnit = "4.12"
val Mockito = "1.10.19"
val Akka = "2.3.9"
val ScalaMock = "3.2.2"
}

val guava = "com.google.guava" % "guava" % V.Guava
Expand Down Expand Up @@ -208,6 +210,7 @@ object Dependency {
object Test {
val junit = "junit" % "junit" % V.JUnit
val mockito = "org.mockito" % "mockito-all" % V.Mockito
val scalaMock = "org.scalamock" %% "scalamock-scalatest-support" % V.ScalaMock
}
}

Expand Down

0 comments on commit 5cfc1e8

Please sign in to comment.