Created
February 4, 2013 16:35
-
-
Save dylemma/4707840 to your computer and use it in GitHub Desktop.
Using ScalaMock to test a Java class with overloaded methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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