Spock: method not recognized as an invocation
up vote
1
down vote
favorite
Trying to figure out why Spock doesn't seem to recognize a method call (of a Mocked object) as an invocation. Looked at the docs (http://spockframework.org/spock/docs/1.1-rc-3/all_in_one.html#_mocking) and couldn't figure it out.
Here's a dumbed down version of the code:
class VmExportTaskSplitter implements TaskSplitter<Export> {
@Inject
AssetServiceClient assetServiceClient
@Override
int splitAndSend(Export export) {
Map batch = [:]
Map tags = [:]
if (true) {
println('test')
batch = assetServiceClient.getAssetIdBatch(export.containerUuid,
export.userUuid, (String) batch.scrollId, tags)
print('batch: ')
println(batch)
}
return 1
}
}
And now the test:
class VmExportTaskSplitterSpecification extends Specification{
def "tags should be parsed correctly"(){
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClientImpl)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
Map map1 = [assetIds:["1","2","3","4","5"],scrollId:null]
client.getAssetIdBatch(_ as String,_ as String, null, _ as Map) >> map1
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map)
}
}
Here's the annoying part: both lines on either side of the assetServiceClient.getAssetIdBatch
call are printed. But Spock is claiming there are no invocations whatsoever...
Using logging directory: './logs'
Using log file prefix: ''
test
batch: [assetIds:[1, 2, 3, 4, 5], scrollId:null]
Too few invocations for:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
Unmatched invocations (ordered by similarity):
None
groovy spock
add a comment |
up vote
1
down vote
favorite
Trying to figure out why Spock doesn't seem to recognize a method call (of a Mocked object) as an invocation. Looked at the docs (http://spockframework.org/spock/docs/1.1-rc-3/all_in_one.html#_mocking) and couldn't figure it out.
Here's a dumbed down version of the code:
class VmExportTaskSplitter implements TaskSplitter<Export> {
@Inject
AssetServiceClient assetServiceClient
@Override
int splitAndSend(Export export) {
Map batch = [:]
Map tags = [:]
if (true) {
println('test')
batch = assetServiceClient.getAssetIdBatch(export.containerUuid,
export.userUuid, (String) batch.scrollId, tags)
print('batch: ')
println(batch)
}
return 1
}
}
And now the test:
class VmExportTaskSplitterSpecification extends Specification{
def "tags should be parsed correctly"(){
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClientImpl)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
Map map1 = [assetIds:["1","2","3","4","5"],scrollId:null]
client.getAssetIdBatch(_ as String,_ as String, null, _ as Map) >> map1
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map)
}
}
Here's the annoying part: both lines on either side of the assetServiceClient.getAssetIdBatch
call are printed. But Spock is claiming there are no invocations whatsoever...
Using logging directory: './logs'
Using log file prefix: ''
test
batch: [assetIds:[1, 2, 3, 4, 5], scrollId:null]
Too few invocations for:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
Unmatched invocations (ordered by similarity):
None
groovy spock
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Trying to figure out why Spock doesn't seem to recognize a method call (of a Mocked object) as an invocation. Looked at the docs (http://spockframework.org/spock/docs/1.1-rc-3/all_in_one.html#_mocking) and couldn't figure it out.
Here's a dumbed down version of the code:
class VmExportTaskSplitter implements TaskSplitter<Export> {
@Inject
AssetServiceClient assetServiceClient
@Override
int splitAndSend(Export export) {
Map batch = [:]
Map tags = [:]
if (true) {
println('test')
batch = assetServiceClient.getAssetIdBatch(export.containerUuid,
export.userUuid, (String) batch.scrollId, tags)
print('batch: ')
println(batch)
}
return 1
}
}
And now the test:
class VmExportTaskSplitterSpecification extends Specification{
def "tags should be parsed correctly"(){
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClientImpl)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
Map map1 = [assetIds:["1","2","3","4","5"],scrollId:null]
client.getAssetIdBatch(_ as String,_ as String, null, _ as Map) >> map1
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map)
}
}
Here's the annoying part: both lines on either side of the assetServiceClient.getAssetIdBatch
call are printed. But Spock is claiming there are no invocations whatsoever...
Using logging directory: './logs'
Using log file prefix: ''
test
batch: [assetIds:[1, 2, 3, 4, 5], scrollId:null]
Too few invocations for:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
Unmatched invocations (ordered by similarity):
None
groovy spock
Trying to figure out why Spock doesn't seem to recognize a method call (of a Mocked object) as an invocation. Looked at the docs (http://spockframework.org/spock/docs/1.1-rc-3/all_in_one.html#_mocking) and couldn't figure it out.
Here's a dumbed down version of the code:
class VmExportTaskSplitter implements TaskSplitter<Export> {
@Inject
AssetServiceClient assetServiceClient
@Override
int splitAndSend(Export export) {
Map batch = [:]
Map tags = [:]
if (true) {
println('test')
batch = assetServiceClient.getAssetIdBatch(export.containerUuid,
export.userUuid, (String) batch.scrollId, tags)
print('batch: ')
println(batch)
}
return 1
}
}
And now the test:
class VmExportTaskSplitterSpecification extends Specification{
def "tags should be parsed correctly"(){
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClientImpl)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
Map map1 = [assetIds:["1","2","3","4","5"],scrollId:null]
client.getAssetIdBatch(_ as String,_ as String, null, _ as Map) >> map1
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map)
}
}
Here's the annoying part: both lines on either side of the assetServiceClient.getAssetIdBatch
call are printed. But Spock is claiming there are no invocations whatsoever...
Using logging directory: './logs'
Using log file prefix: ''
test
batch: [assetIds:[1, 2, 3, 4, 5], scrollId:null]
Too few invocations for:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
Unmatched invocations (ordered by similarity):
None
groovy spock
groovy spock
asked Nov 12 at 0:29
Matt Takao
153
153
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Change this line:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
... on:
1 * client.getAssetIdBatch(_ as String, _ as String, _, _ as Map)
In VmExportTaskSplitter
you pass empty Map
into getAssetIdBatch
method so batch.scrollId
will be null
and it will not match the _ as String
.
Your specification can be also simplified, but it depends on what do you need to test. Guessing from the then
part you test only if the getAssetIdBatch
method was called then it is enough to write it like this:
def "tags should be parsed correctly"() {
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClient)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch('000', '000', null, [:])
}
thanks very much! that answers what I was trying to ask here. Unfortunately, the real code isn't totally fixed with this, if you don't mind could you take a look at this? stackoverflow.com/questions/53267791/…
– Matt Takao
Nov 12 at 18:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Change this line:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
... on:
1 * client.getAssetIdBatch(_ as String, _ as String, _, _ as Map)
In VmExportTaskSplitter
you pass empty Map
into getAssetIdBatch
method so batch.scrollId
will be null
and it will not match the _ as String
.
Your specification can be also simplified, but it depends on what do you need to test. Guessing from the then
part you test only if the getAssetIdBatch
method was called then it is enough to write it like this:
def "tags should be parsed correctly"() {
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClient)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch('000', '000', null, [:])
}
thanks very much! that answers what I was trying to ask here. Unfortunately, the real code isn't totally fixed with this, if you don't mind could you take a look at this? stackoverflow.com/questions/53267791/…
– Matt Takao
Nov 12 at 18:10
add a comment |
up vote
1
down vote
accepted
Change this line:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
... on:
1 * client.getAssetIdBatch(_ as String, _ as String, _, _ as Map)
In VmExportTaskSplitter
you pass empty Map
into getAssetIdBatch
method so batch.scrollId
will be null
and it will not match the _ as String
.
Your specification can be also simplified, but it depends on what do you need to test. Guessing from the then
part you test only if the getAssetIdBatch
method was called then it is enough to write it like this:
def "tags should be parsed correctly"() {
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClient)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch('000', '000', null, [:])
}
thanks very much! that answers what I was trying to ask here. Unfortunately, the real code isn't totally fixed with this, if you don't mind could you take a look at this? stackoverflow.com/questions/53267791/…
– Matt Takao
Nov 12 at 18:10
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Change this line:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
... on:
1 * client.getAssetIdBatch(_ as String, _ as String, _, _ as Map)
In VmExportTaskSplitter
you pass empty Map
into getAssetIdBatch
method so batch.scrollId
will be null
and it will not match the _ as String
.
Your specification can be also simplified, but it depends on what do you need to test. Guessing from the then
part you test only if the getAssetIdBatch
method was called then it is enough to write it like this:
def "tags should be parsed correctly"() {
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClient)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch('000', '000', null, [:])
}
Change this line:
1 * client.getAssetIdBatch(_ as String, _ as String, _ as String, _ as Map) (0 invocations)
... on:
1 * client.getAssetIdBatch(_ as String, _ as String, _, _ as Map)
In VmExportTaskSplitter
you pass empty Map
into getAssetIdBatch
method so batch.scrollId
will be null
and it will not match the _ as String
.
Your specification can be also simplified, but it depends on what do you need to test. Guessing from the then
part you test only if the getAssetIdBatch
method was called then it is enough to write it like this:
def "tags should be parsed correctly"() {
setup:
Export export = new Export(containerUuid: "000", userUuid: "000", chunkSize: 10)
AssetServiceClient client = Mock(AssetServiceClient)
VmExportTaskSplitter splitter = new VmExportTaskSplitter()
splitter.assetServiceClient = client
when:
splitter.splitAndSend(export)
then:
1 * client.getAssetIdBatch('000', '000', null, [:])
}
edited Nov 12 at 6:31
answered Nov 12 at 6:11
cgrim
1,1281418
1,1281418
thanks very much! that answers what I was trying to ask here. Unfortunately, the real code isn't totally fixed with this, if you don't mind could you take a look at this? stackoverflow.com/questions/53267791/…
– Matt Takao
Nov 12 at 18:10
add a comment |
thanks very much! that answers what I was trying to ask here. Unfortunately, the real code isn't totally fixed with this, if you don't mind could you take a look at this? stackoverflow.com/questions/53267791/…
– Matt Takao
Nov 12 at 18:10
thanks very much! that answers what I was trying to ask here. Unfortunately, the real code isn't totally fixed with this, if you don't mind could you take a look at this? stackoverflow.com/questions/53267791/…
– Matt Takao
Nov 12 at 18:10
thanks very much! that answers what I was trying to ask here. Unfortunately, the real code isn't totally fixed with this, if you don't mind could you take a look at this? stackoverflow.com/questions/53267791/…
– Matt Takao
Nov 12 at 18:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254616%2fspock-method-not-recognized-as-an-invocation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown