1

如何调用下面的方法 def 只传递interactionId、transactionId、awResponseFile、testMethodName 和expectedNumberOfConsumers

方法定义

void verifyPersistence(String interactionId, String transactionId, 
                       File rawResponseFile, String testMethodName, 
                       int expectedNumberOfDatasourceProductResponseRaws=1, 
                       String dsProductName=datasourceSpec['creditreport.name'], 
                       int expectedNumberOfDatasourceProductResponses=1, 
                       int expectedNumberOfConsumers=1, 
                       int expectedNumberOfAddresses=1 )

方法调用

verifyPersistence interactionId.persistedVersion(), transactionId, 
                  results, testName.methodName, expectedNumberOfConsumers:8

例外

groovy.lang.MissingMethodException: No signature of method: verifyPersistence() is applicable for argument types: (java.util.LinkedHashMap, java.lang.String, java.lang.String, java.io.File, java.lang.String) values: [[expectedNumberOfConsumers:8], 3130001030065, 10003000000890059, C:\results, multiple consumers contracts]
Possible solutions: 

verifyPersistence(java.lang.String, java.lang.String, java.io.File, java.lang.String), 
verifyPersistence(java.lang.String, java.lang.String, java.io.File, java.lang.String, int), 
verifyPersistence(java.lang.String, java.lang.String, java.io.File, java.lang.String, int, java.lang.String), 
verifyPersistence(java.lang.String, java.lang.String, java.io.File, java.lang.String, int, java.lang.String, int), verifyPersistence(java.lang.String, java.lang.String, java.io.File, java.lang.String, int, java.lang.String, int, int)
    at HitmultipleconsumersPersistSpec.groovy:151)
4

1 回答 1

4

当您包含地图条目 ( key:value) 时,它们会被自动收集,放入哈希图中并作为第一个参数传递。Groovy 目前还没有命名参数。对于这种特定情况,我认为您最好使用该方法的地图:

def verifyPersistence(Map map) {
  String interactionId = map.interactionId
  String transactionId = map.transactionId
  File rawResponseFile = map.rawResponseFile
  String testMethodName = map.testMethodName
  int expectedNumberOfDatasourceProductResponseRaws = map.expectedNumberOfDatasourceProductResponseRaws ?: 1
  String dsProductName = map.dsProductName ?: datasourceSpec['creditreport.name']
  int expectedNumberOfDatasourceProductResponses = map.expectedNumberOfDatasourceProductResponses ?: 1
  int expectedNumberOfConsumers = map.expectedNumberOfConsumers ?: 1
  int expectedNumberOfAddresses = map.expectedNumberOfAddresses ?: 1
}


verifyPersistence(
  interactionId : interactionId.persistedVersion(), 
  transactionId : transactionId, 
  rawResponseFile : results, 
  expectedNumberOfDatasourceProductResponseRaws : 14, 
  expectedNumberOfConsumers:8
)

您显然不需要将每个参数分配给变量,您可以简单地使用map.field语法。如果您希望对其进行类型检查,那么我认为您最好使用对象来封装参数。

于 2013-03-07T22:28:41.400 回答