2015-02-10 89 views
1

XmlMatchers非常強大,但我無法將它用作參數匹配器。我如何修改匹配器不能用於Seq [Node]?specs2與mockito xml匹配器

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] required:scala.xml.Node

如何將\(「ocl」)的XmlMatcher轉換爲單個節點,所以argThat可以匹配所需的Node參數?

回答

1

你需要 「適應」 的匹配取參數類型:

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