From d99515e31e726b5a3b4aeb21854f51077d71c649 Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Tue, 11 Aug 2026 15:03:05 -0500 Subject: [PATCH] Avoid calling method when mocking a stub from another class --- .../textsecuregcm/controllers/AccountControllerV2Test.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java index 66d8d710f..a6d92996d 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2Test.java @@ -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()