This is a subset of the test that I can make work:
import org.specs2.SpecificationWithJUnit
import org.specs2.mock.Mockito
class PartialFunctionCommandStream[A, S](pf: PartialFunction[S, A]) {
def next(s: S): (A, PartialFunctionCommandStream[A, S]) = {
if (pf.isDefinedAt(s)) (pf.apply(s), this)
else throw new NoSuchElementException("CommandStream not defined at " + s)
}
def hasNext(s: S): Boolean = pf.isDefinedAt(s)
}
class PFTest extends SpecificationWithJUnit with Mockito {
def is =
"Must have next " ! e2 ^
"Must mock a PF " ! e1 ^
end
def e1 = {
val pf = mock[PartialFunction[Int,Int]]
val pfcs = new PartialFunctionCommandStream(pf)
pf.isDefinedAt(1) returns true
pf.apply(1) returns 10
(pfcs.next(1) must_== 10) and (there was one(pf).isDefinedAt(1) then one(pf).apply(1))
}
def e2 = {
val pf = mock[PartialFunction[Int,Int]]
val pfcs = new PartialFunctionCommandStream(pf)
pf.isDefinedAt(1) returns true
pf.apply(1) returns 10
(pfcs.hasNext(1) must beTrue) and (there was one(pf).isDefinedAt(1))
}
}
e2 works fine. e1 does not.
On Mon, Jul 4, 2011 at 10:09 PM, etorreborre
<etorr...@gmail.com> wrote:
Hi Thomas,
Could you please post some code?
No I actually have not evolved that approach much more, tests changed a bit :(
Thomas