如何为这些类调用XYZ.doSomething方法:
XYZ.scala
object XYZ { private def doSomething(i : Int)(implicit s: String): String { s + i.toString } }
XYZTest.scala
class XYZTest extends FunSpec with PrivateMethodTester { describe("SomeTest") { it("Can't find a private method named: doSomething :( ") { implicit lazy val someStr: String = "sahil" val doSomething = PrivateMethod[String]('doSomething) val myStr = XYZ invokePrivate doSomething(1) assert(myStr == "sahil1") } } describe("SomeTest") { it("This doesn't even compile :( ") { val doSomething = PrivateMethod[String]('doSomething) val myStr = XYZ invokePrivate doSomething(1)("sahil") assert(myStr == "sahil1") } } }
vvg.. 5
正确答案是:
object XYZ { private def doSomething(i : Int)(implicit s: String): String = { s + i.toString } } class XYZTest extends FunSpec with PrivateMethodTester { describe("SomeTest") { it("Can't find a private method named: doSomething :( ") { implicit lazy val someStr: String = "sahil" val doSomething = PrivateMethod[String]('doSomething) val myStr = XYZ invokePrivate doSomething(1, someStr) assert(myStr == "sahil1") } } }
关于invokePrivate
method的简要视图表明它不支持implicits
,但看起来像将currying
参数列表视为一般参数序列
def invokePrivate[T](invocation : PrivateMethodTester.this.Invocation[T])
args
顺序在哪里:
final class Invocation[T](val methodName : scala.Symbol, val args : scala.Any*)
正确答案是:
object XYZ { private def doSomething(i : Int)(implicit s: String): String = { s + i.toString } } class XYZTest extends FunSpec with PrivateMethodTester { describe("SomeTest") { it("Can't find a private method named: doSomething :( ") { implicit lazy val someStr: String = "sahil" val doSomething = PrivateMethod[String]('doSomething) val myStr = XYZ invokePrivate doSomething(1, someStr) assert(myStr == "sahil1") } } }
关于invokePrivate
method的简要视图表明它不支持implicits
,但看起来像将currying
参数列表视为一般参数序列
def invokePrivate[T](invocation : PrivateMethodTester.this.Invocation[T])
args
顺序在哪里:
final class Invocation[T](val methodName : scala.Symbol, val args : scala.Any*)