Reputation: 21
I'm trying to mock the Sql instance in Groovy the following way, I'm using the spock framework for testing. However the test fails, please see below:
class SQLStatsStorageManagerTest extends Specification {
def mockSql
def setup() {
mockSql = GroovyMock(Sql, global: true)
}
void "SQLStatsStorageManager instantiation succeed"() {
def c
when: "SQLStatsStorageManager is instantiated"
c = new SQLStatsStorageManager("test", [hostname: "localhost", port: 666, database: "db", login: "root", password: "pass"])
then: "there is no error and name is set"
1 * mockSql.newInstance('jdbc:mysql://localhost:666/db', 'root', 'pass', 'com.mysql.jdbc.Driver')
assert c.getName() == "test"
}
}
The test fails with the following error:
Too few invocations for:
1 * mockSql.newInstance('jdbc:mysql://localhost:666/db', 'root', 'pass', 'com.mysql.jdbc.Driver') (0 invocations)
Unmatched invocations (ordered by similarity):
1 * mockSql.newInstance(jdbc:mysql://localhost:666/db, 'root', 'pass', 'com.mysql.jdbc.Driver')
Any idea ?
Thanks.
Upvotes: 2
Views: 1156
Reputation: 84844
Pay attention to the fact that the only argument that does not match is db link.
You try to verify it as an instance of String
:
'jdbc:mysql://localhost:666/db'
but in unmatched invocation it is:
jdbc:mysql://localhost:666/db
so here's the question, what it actually is? Verify the types and you'll have the problem solved.
Upvotes: 0