Spock: method not recognized as an invocation












1














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









share|improve this question



























    1














    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









    share|improve this question

























      1












      1








      1







      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









      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 0:29









      Matt Takao

      153




      153
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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, [:])
          }





          share|improve this answer























          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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, [:])
          }





          share|improve this answer























          • 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
















          1














          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, [:])
          }





          share|improve this answer























          • 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














          1












          1








          1






          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, [:])
          }





          share|improve this answer














          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, [:])
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Lugert, Oklahoma