title: Mockito returning empty optional
body: <p>I am seeing a weird issue with my method returning an empty <code>Optional</code> in spite of mocking with <code>mockito</code>. What could be going wrong?</p>
  <p>My test:</p>
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(InfoController.class)
  @ActiveProfiles(&quot;test&quot;)
  public class InfoControllerTest 
  {
      @Autowired
      private MockMvc mockMvc;
  
      @MockBean
      private Service service;
  
      @Autowired
      private ObjectMapper objectMapper;
  
   @Test
   public void testDeleteValueSet() throws JsonProcessingException, Exception
   {
       DeleteValueSetContainer c1 = new DeleteValueSetContainer();
       c1.setValueSetIds(Collections.singletonList(1L));
      
       Mockito.when(service.deleteValueSet(Mockito.anyList(), 
                Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(Optional.of(new Info()));
       mockMvc.perform(delete(&quot;/deleteValueSet&quot;).
               accept(MediaType.APPLICATION_JSON)
               .content(objectMapper.writeValueAsString(c1))
             .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent());
   }
  }
  </code></pre>
  <p>Method under test:</p>
  <pre><code>@DeleteMapping(&quot;/deleteValueSet&quot;)
  public ResponseEntity&lt;Long&gt; deleteValueSet(@RequestBody(required=true) DeleteValueSetContainer 
          deleteValueSetContainer)
  {
      Optional&lt;Info&gt; optional = service.deleteValueSet(valueSetIds, 
              null, null);
      if(optional.isPresent())
      {
          Info valueInformation = optional.get();
          
          Long parentValueId = valueInformation.getParentValueId();
          if(parentValueId != null &amp;&amp; parentValueId != 0L)
          {
              return ResponseEntity.created(ServletUriComponentsBuilder.
                      fromCurrentRequest().build().toUri())
                      .body((Long)valueInformation.getParentValueId());
          }
          return ResponseEntity.noContent().build();
      }
      
      return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
  }
  </code></pre>
  <p>I end up getting 500 error instead of 200 because the mock doesn't work as expected.</p>
  <p>Method being mocked:</p>
  <pre><code>public Optional&lt;Info&gt; deleteValueSet(List&lt;Long&gt; ids, Boolean char, 
          Boolean digit)
  { 
     // Logic to populate Info
     Info i = new Info();  
     return Optional.of(information);
  }
  </code></pre>
  <p><code>Info</code> is a public static inner class in the service.</p>
  <pre><code>public static class Info
  {
      private Long parentValueId;
      private Long id;
      private Map&lt;Long, Long&gt; idInfos;
   }
  </code></pre>