涉及隐式方法的模拟,EasyMock

时间:2019-01-21 07:31:07

标签: scala easymock

我有以下方法:

def someMethod(steamId: String): Boolean = {    
    db.execute("SELECT * FROM table where colum1 = ? AND column2 = ? AND colum3 = ?", List("params1", "param2", "param3"))((statement: PreparedStatement) => statement.execute())
}

在我的单元测试中,我想模拟db.execute调用,但是不能为上帝的爱弄清楚如何进行。

我在单元测试中具有以下设置:

EasyMock.expect(mockedDb.execute[Boolean](_:String,_:List[Any])(_:PreparedStatement => Boolean)).andReturn(???).times(1)
EasyMock.replay(mockedDb)

及其???我需要帮助的部分。期望返回类型为:

Error:(69, 116) type mismatch;
found   : Boolean(true)
required: (String, List[Any], java.sql.PreparedStatement => Boolean) => Boolean
    EasyMock.expect(mockedDb.execute[Boolean](_:String,_:List[Any])(_:PreparedStatement => Boolean)).andReturn(true).times(1)

我通过将execute调用包装在它自己的包装对象中,然后模拟了THAT对象来解决了这个问题,但是我觉得必须有一些聪明的方法来解决这个问题。

0 个答案:

没有答案