XmlMatchers非常强大,但我无法将其用作参数匹配器。如何修改匹配器不适用于Seq [Node]?
trait Connector {
def send(envelope: Node):Elem
}
使用simito和xmlMatchers traits编写带有scalatest的测试:
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")) )
}
}
编译错误:类型不匹配; found:需要seq [scala.xml.Node]:scala.xml.Node
如何将XmlMatcher for \(“ocl”)转换为单个节点,以便argThat可以匹配所需的Node参数?
答案 0 :(得分:1)
你需要&#34;适应&#34;匹配器采用参数类型:
there was one(connector).send(argThat(\\("ocl") ^^ ((_:Node).toSeq)))