我已经 mock 了Microsoft365Offer中的readCSV()方法。但是由于这个原因,我无法创建Microsoft365Offer类的对象。
GroovyMock(Microsoft365Offer, global: true)
Microsoft365Offer.readCSV(_,_) >> {
Microsoft365Offer microsoft365Offer = new Microsoft365Offer(
"name" : "any thing as product name",
"offerURI" : "4A-FAEA24541538",
"resellerPrice" : 1.6,
"fob" : 1.41,
"includedQuantities" : 0,
"minimumValue" : 0,
"taxesPISD" : 0,
"defaultTaxesISS" : 0)
println "=====coming in here========$microsoft365Offer"
return ["1":microsoft365Offer ]
}
输出=====这里出现========空
我该如何解决这个问题?提前致谢。
最佳答案
我找不到解决方案,但是找到了解决该问题的方法:
Microsoft365Offer microsoft365Offer = new Microsoft365Offer(
"name" : "any thing as product name",
"offerURI" : "4A-FAEA24541538",
"resellerPrice" : 1.6,
"fob" : 1.41,
"includedQuantities" : 0,
"minimumValue" : 0,
"taxesPISD" : 0,
"defaultTaxesISS" : 0)
GroovyMock(Microsoft365Offer, global: true)
Microsoft365Offer.readCSV(_,_) >> {
println "=====coming in here========$microsoft365Offer"
return ["1":microsoft365Offer]
}
关于grails - Grails Spock无法为模拟类创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38357155/