Skip to content

Instantly share code, notes, and snippets.

@dylemma
Created February 4, 2013 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylemma/4707840 to your computer and use it in GitHub Desktop.
Save dylemma/4707840 to your computer and use it in GitHub Desktop.
Using ScalaMock to test a Java class with overloaded methods
> test:compile
[info] Compiling 2 Scala sources to <the path>\target\scala-2.10\test-classes...
[info] <the path>\src\test\scala\FooTest.scala:10: Unable to resolve overloaded method bar
[info] (m.bar(_: String)).expects(*).once
[info] ^
[error] <the path>\src\test\scala\FooTest.scala:10: value expects is not a member of String => Unit
[error] (m.bar(_: String)).expects(*).once
[error] ^
[error] one error found
[error] (Common/test:compile) Compilation failed
[error] Total time: 1 s, completed Feb 4, 2013 11:33:10 AM
public class Foo
{
public void bar(String a){
System.out.println("Foo.bar(a)");
}
public void bar(String a, String b){
System.out.println("Foo.bar(a, b)");
}
}
import org.scalatest.FunSpec
import org.scalatest.matchers.ShouldMatchers
import org.scalamock.scalatest.MockFactory
class FooTest extends FunSpec with ShouldMatchers with MockFactory {
describe("Foo") {
it("should bar") {
val m = mock[Foo]
(m.bar(_: String)).expects(*).once
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment