Avoid calling method when mocking a stub from another class

This commit is contained in:
Ravi Khadiwala authored and ravi-signal committed 2026-08-11 15:56:28 -05:00
1 parent edce40958b
commit d99515e31e
1 file changed
+5 -1
@@ -12,6 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -510,7 +511,10 @@ class AccountControllerV2Test {
@ParameterizedTest
@ArgumentsSource(AccountsTestHelper.AccountsDataReportArgumentProvider.class)
void testGetAccountDataReport(final Account account, final String expectedTextAfterHeader) throws Exception {
when(AuthHelper.ACCOUNTS_MANAGER.getByAccountIdentifier(account.getAccountIdentifier())).thenReturn(Optional.of(account));
// Use doReturn when mocking a stub from another class
doReturn(Optional.of(account))
.when(AuthHelper.ACCOUNTS_MANAGER)
.getByAccountIdentifier(account.getAccountIdentifier());
when(accountsManager.getByAccountIdentifier(account.getAccountIdentifier())).thenReturn(Optional.of(account));
final Response response = resources.getJerseyTest()