title: how test returned object from a mocked dependency that accepts two arguments inside the mocked object?
body: <p>I couldn't find any post related to my problem. I'm using Mockito and I want to test the behavior inside a controller. I think the core of the problem is that I'm not using Mockito correctly when I send in two arguments to the mocked interface. It works fine if I only send in one argument. I don't think the fact that I'm also using Spring mock mvc has anything to do with this.</p>
  
  <p>I have an interface <code>MyService</code>:</p>
  
  <pre><code>public MyObject doSomeDoggyStuff(long id, SomeOtherObject soo);
  </code></pre>
  
  <p>The purpose of the interface is to do things and return MyObject if it was successful. If it can't find the object then just return null.</p>
  
  <p>I have a controller <code>MyController</code>:</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/dogs")
  public MyController
  &lt;snip&gt;
  
   @RequestMapping(method = RequestMethod.POST, value = "/{id}/toys/{toy}")
    ResponseEntity&lt;MyObject&gt; doDoggyStuff(@PathVariable Long id, @RequestBody Toy toy) {
      MyObject result = this.myService.doSomeDoggyStuff(id, toy);
      if(result == null) {
         return new ResponseEntity("errorinfo", HttpStatus.NOT_FOUND);
       }
      else {
        return new ResponseEntity&lt;MyObject&gt;(result,HttpStatus.CREATED)'
       }
    }
  </code></pre>
  
  <p>My test class looks like this:</p>
  
  <pre><code>Public MyControllerTest &lt;snip&gt;
  
    @Mock
    private MyService myServiceMock;
  
    @InjectMocks
    private MyController myController;
  </code></pre>
  
  <p>The relevant logic of test method looks this.</p>
  
  <pre><code>MyObject myObj = new MyObject();
  Toy toy = new Toy();
  
  when(myServiceMock.doSomeDoggyStuff(1, toy)).thenReturn(myObj);
  mockMvc
      .perform(
          post("/dogs/{id}/toys/{toys}", 1, toy).contentType(
              TestUtil.APPLICATION_JSON_UTF8).content(
              TestUtil.convertObjectToJsonBytes(toy))).andExpect(status().isCreated())
      .andReturn();
  </code></pre>
  
  <p>The problem I'm having is that I expect in this scenario that when it tests MyController that on the line: <code>MyObject result = this.myService.doSomeDoggyStuff(id, toy);</code></p>
  
  <p>result should be the myObj I set up in the thenReturn but it's always set to null. I have other methods in my service that just accepts one argument and it works fine. I can't grasp what I need to do differently when I send in two arguments using Mockito.</p>