XmlMatcher非常强大,但我不能将其用作参数匹配器。如何将匹配器修改为不适用于Seq[Node]?
trait Connector {
def send(envelope: Node):Elem
}
用scalatest编写一个测试,使用mockito和xmlMatchers特性:
import org.scalatest.junit.AssertionsForJUnit
import org.junit.Test
import org.specs2.mock.Mockito
import scala.xml.Node
import org.specs2.matcher.ThrownExpectations
import org.specs2.matcher.XmlMatchers
class MyClientTest extends AssertionsForJUnit with Mockito with ThrownExpectations with XmlMatchers {
@Test def oclQuery_oclExpression_queryRequestWithOclElement {
//arrange
val connector=mock[Connector]
val testee=MyClient.create(connector)
//act
testee.oclQuery("oclexpr", <Response/> )
//assert
there was one(connector).send( argThat(\("ocl")) )
}
}
编译错误:类型不匹配;已找到:需要Seq[scala.xml.Node]:scala.xml。Node
如何将\("ocl")的XmlMatcher转换为单个节点,以便argThat能够匹配所需的node参数?
您需要"调整"匹配器以采用参数类型:
there was one(connector).send(argThat(\("ocl") ^^ ((_:Node).toSeq)))