title: Mockito failing inside internal call for mocked method
body: <p>I'm trying to mock the return value for a method using the when call from mockito. However, I'm new to this and I may perhaps be misunderstanding how mockito works, since the call is failing inside the method mocked when that calls another method. I thought regardless of how that method is implemented, I should be getting the return value I'm asking for? Or do I need to mock also the internals for that method? I feel that shouldn't be it.</p>
  <pre><code>public boolean verifyState(HttpServletRequest request, String s) {
  
      String stateToken = getCookieByName(request, STATE_TOKEN);
      String authToken = getCookieByName(request, AUTHN);
  
      boolean isValidState = true;
  
      if (isValidState) {
          
          try {
              log.info(getEdUserId(stateToken, authToken));
  
              return true;
          } catch (Exception e) {
              ExceptionLogger.logDetailedError(&quot;CookieSessionUtils.verifyState&quot;, e);
              return false;
          }
      } else {
          return false;
      }
  }
  
  public String getEdUserId(String stateToken, String authToken) throws Exception {
      String edUserId;
      Map&lt;String, Object&gt; jwtClaims;
      jwtClaims = StateUtils.checkJWT(stateToken, this.stateSharedSecret); // Failing here not generating a proper jwt token
      log.info(&quot;State Claims: &quot; + jwtClaims);
      edUserId = sifAuthorizationService.getEdUserIdFromAuthJWT(authToken);
      return edUserId;
  }
  </code></pre>
  <p>My test:</p>
  <pre><code>@ActiveProfiles(resolver = MyActiveProfileResolver.class)
  @WebMvcTest(value = CookieSessionUtils.class, includeFilters = {
          @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {ApiOriginFilter.class, ValidationFilter.class})})
  class CookieSessionUtilsTest {
  
  @Autowired
  private CookieSessionUtils cookieSessionUtils; // Service class
  
  @Mock
  private CookieSessionUtils cookieSessionUtilsMocked; // Both the method under test and the one mocked are under the same class, so trying these two annotations together.
  
  @Mock
  private HttpServletRequest request;
  
  @BeforeEach
  public void setUp() {
      MockitoAnnotations.initMocks(this);
  }
  
  @Test
  public void testVerifyState1() throws Exception {
  
      //...Some mocks for getCookieName
  
      UUID uuid = UUID.randomUUID();
      when(cookieSessionUtils.getEdUserId(anyString(), anyString()).thenReturn(eq(String.valueOf(uuid))); // When this line runs it fails on verifyState method
  
      assertTrue(cookieSessionUtils.verifyState(request, &quot;&quot;));
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Zc8IX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zc8IX.png" alt="enter image description here" /></a></p>
  <p><strong>UPDATE</strong></p>
  <p>Attempt using anyString() instead of eq().</p>
  <p><a href="https://i.stack.imgur.com/LXm8R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LXm8R.png" alt="enter image description here" /></a></p>
  <p>Thank you.</p>