0

I have a Cucumber test class where I also want to do some mocking in. I want to mock a service call that's happening in one of my actual classes. I set up in my Cucumber config class as such:

public class TestConfig {

     @Autowired @MockBean private RestService restService;

}

And in the Cucumber test class:

public class TestClass {

     private RestService restService;

     public TestClass(@Autowired(required = false) RestService restService) {
         this.restService = restService;
     }
}

So when the mocking occurs, I want to capture the arguments being passed into the mock method call within restService, as such:

when(restService.someCall(anyLong())).thenAnswer( (Answer) invocation -> {
     Object[] args = invocation.getArguments();
}

Yet, the arguments that are being picked up (args) for these mock calls are always "0L", which I suspect is some kind of default parameter passed in as arguments for Mockito interceptors, since I try to pick it up by calling getArguments on invocation as well as using ArgumentCapture, both of which return the argument as "0L".

archingfork
  • 145
  • 1
  • 7
  • @BoristheSpider ??? My question was blindly marked as a duplicate, and the link provided did not sufficiently answer my question. I had the option to delete and re-post the question. – archingfork Jun 13 '21 at 05:42
  • How about you read all the way to the bottom of this question, where I shared an update of how I had already tried that. – archingfork Jun 13 '21 at 05:47
  • @Martjin Pieters You get that once a question is closed for being a duplicate, you can't just edit it and re-open it for submissions? Literally the only feedback was "Your post has been associated with a similar question. If this question doesn’t resolve your question, ask a new one." So, I really don't understand what you want me to do here lol – archingfork Jun 13 '21 at 06:05
  • @archingfork I've tried to reproduce your problem in earnest so that I could perhaps edit the question to clarify the confusion. Yet it seems that your problem is not reproducible. You may want to start from scratch - as in delete what you had, create a minimal project, reproduce the problem and clearly show what the problem is, using the right terminology. https://gist.github.com/mpkorstanje/06d6e9d0aed9d6f17854e82897ac7a53 – M.P. Korstanje Jun 13 '21 at 08:52
  • Additionally the code in your question creates the impression that you are trying to do some advanced stubbing. Yet the text of your question suggests that you are trying to capture the arguments for which your code is indeed the wrong approach. So you may also have an XY problem. https://xyproblem.info/ – M.P. Korstanje Jun 13 '21 at 09:01
  • @archingfork: of course you can edit it. Substantial edits put your post into the reopen queue. I can get that that may be frustrating, but just circumventing the process can lead to other automated processes then adding more blocks on your account. – Martijn Pieters Jun 13 '21 at 11:47

0 Answers0