-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fef344
commit 7092a2a
Showing
19 changed files
with
824 additions
and
121 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
jvm/src/test/scala-2/com/paulbutcher/test/mock/ByNameParametersTest.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.paulbutcher.test.mock | ||
|
||
import com.paulbutcher.test.TestTrait | ||
import org.scalamock.function.FunctionAdapter1 | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalamock.scalatest.MockFactory | ||
import org.scalatest.freespec.AnyFreeSpec | ||
|
||
class ByNameParametersTest extends AnyFreeSpec with MockFactory with Matchers { | ||
|
||
autoVerify = false | ||
|
||
"cope with methods with by name parameters" in { | ||
withExpectations { | ||
val m = mock[TestTrait] | ||
(m.byNameParam _).expects(*).returning("it worked") | ||
assertResult("it worked") { m.byNameParam(42) } | ||
} | ||
} | ||
|
||
//! TODO - find a way to make this less ugly | ||
"match methods with by name parameters" in { | ||
withExpectations { | ||
val m = mock[TestTrait] | ||
val f: (=> Int) => Boolean = { x => x == 1 && x == 2 } | ||
((m.byNameParam _): (=> Int) => String).expects(new FunctionAdapter1(f)).returning("it works") | ||
var y = 0 | ||
assertResult("it works") { m.byNameParam { y += 1; y } } | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package mock | ||
|
||
import com.paulbutcher.test.TestTrait | ||
import org.scalamock.scalatest.MockFactory | ||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class ByNameParametersTest extends AnyFunSpec with MockFactory with Matchers { | ||
|
||
autoVerify = false | ||
|
||
it("cope with methods with by name parameters") { | ||
withExpectations { | ||
val m = mock[TestTrait] | ||
(m.byNameParam(_: Int)).expects(*).returning("it worked") | ||
assertResult("it worked") { | ||
m.byNameParam(42) | ||
} | ||
} | ||
} | ||
|
||
it("match methods with by name parameters") { | ||
withExpectations { | ||
val m = mock[TestTrait] | ||
(m.byNameParam(_: Int)).expects(where[Int](Set(1, 2))).returning("it works") | ||
var y = 0 | ||
assertResult("it works") { | ||
m.byNameParam { | ||
y += 1; y | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
File renamed without changes.
Oops, something went wrong.