2017-08-06 36 views
0

case类需要3个参数id,由内部名称应用。试图使结果lenght返回3.内部名称是一个新增加的字段/参数所以这就是为什么它返回0,而不是3试图在&scala中使用&操作

我想用

result.topics.find(_.topicId == "urn:emmet:1234567").get.appliedBy should be ("human") & 
    result.topics.find(_.topicId == "urn:emmet:2345678").get.internalName should be ("") 

它给我的语法错误,请提前

it should "dedup topics by id, keeping those applied by human if possible" in { 
val doc = Document.empty.copy(
    topics = Array(
    Topic("urn:emmet:1234567", appliedBy = "machine" , internalName = ""), 
    Topic("urn:emmet:2345678", appliedBy = "human", internalName = ""), 
    Topic("urn:emmet:1234567", appliedBy = "human", internalName = ""), 
    Topic("urn:emmet:2345678", appliedBy = "machine", internalName = ""), 
    Topic("urn:emmet:3456789", appliedBy = "machine", internalName = ""), 
    Topic("urn:emmet:3456789", appliedBy = "machine", internalName = "") 
) 
) 

val result = DocumentTransform.dedupSubRecords(doc) 

result.topics.length should be (3) 
result.topics.find(_.topicId == "urn:emmet:1234567").get.appliedBy should be ("human") 
result.topics.find(_.topicId == "urn:emmet:2345678").get.appliedBy should be ("human") 
result.topics.find(_.topicId == "urn:emmet:3456789").get.appliedBy should be ("machine") 

}

+0

你想用'&'来实现什么?你能提供一个最小的工作例子吗?它看起来像你正在使用scalatest,你能标记它,所以那些可以帮助你更有可能看到它吗? –

+0

这是正确的,它是单元测试。 &正是为了另一个附加条件与'应该是“人类”'....试图包括另一个应该是这次与internalName字段 – dedpo

回答

1

多个测试语句已经是“和”忠告感谢,因为如果它们中的任何一个失败,整个测试失败。

val e1234567 = result.topics.find(_.topicId == "urn:emmet:1234567").get 
e1234567.appliedBy shouldEqual "human" 
e1234567.internalName shouldEqual "" 
+0

使用'.get'是不安全的:'.find(..)。exists {x => x.appliedBy ==“human”&& x.internalName ==“”} shouldEqual true'(或者'必须使用Specs2使用类似') – cchantep