Skip to content

Instantly share code, notes, and snippets.

@chrisphelps
Last active August 29, 2015 14:04
Show Gist options
  • Save chrisphelps/edb18992ff82c4d248e5 to your computer and use it in GitHub Desktop.
Save chrisphelps/edb18992ff82c4d248e5 to your computer and use it in GitHub Desktop.
Implicit arguments for mocking
class Foo (name: String) {
def apply() = "Foo " + name + "results"
}
class Bar(name: String) {
def apply()(implicit f: Foo) = "Bar" + name + "results: " + f()
}
class Baz {
implicit val myfoo = new Foo("production")
val mybar = new Bar("production")
def apply() = mybar()
}
class Quux {
implicit val testfoo = new Foo("test")
val mybar = new Bar("production")
def apply() = mybar()
}
val mybaz = new Baz
val myquux = new Quux
mybaz()
myquux()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment