带有 mockito 的 specs2 xml 匹配器

specs2 xml matcher with mockito

XmlMatchers 非常强大,但我无法将其用作参数匹配器。我如何修改匹配器使其不适用于 Seq[Node]?

  trait Connector {
      def send(envelope: Node):Elem    
  }

使用 mockito 和 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")) )
      }

    }

编译错误:类型不匹配;发现:Seq[scala.xml.Node] 要求:scala.xml.Node

我如何将 \("ocl") 的 XmlMatcher 转换为单个节点,以便 argThat 可以匹配所需的节点参数?

您需要"adapt"匹配器来获取参数类型:

there was one(connector).send(argThat(\("ocl") ^^ ((_:Node).toSeq)))