divijvaidya commented on PR #15030:
URL: https://github.com/apache/kafka/pull/15030#issuecomment-1871243698

   Hey @sciclon2 , try something like this 
   ```
   @ClusterTest
       public void testAdminConfigCustomTimeouts() throws Exception {
           int defaultApiTimeoutMs = 240000;
           int requestTimeoutMs = 120000;
           Path adminConfigPath = tempAdminConfig(defaultApiTimeoutMs, 
requestTimeoutMs);
           try (final MockedStatic<Admin> mockedAdmin = 
Mockito.mockStatic(Admin.class)) {
               LeaderElectionCommand.main(
                   "--bootstrap-server", cluster.bootstrapServers(),
                   "--election-type", "unclean", "--all-topic-partitions",
                   "--admin.config", adminConfigPath.toString()
               );
   
               ArgumentCaptor<Properties> argumentCaptor = 
ArgumentCaptor.forClass(Properties.class);
               mockedAdmin.verify(() -> Admin.create(argumentCaptor.capture()));
   
               // verify that properties provided to admin client are the 
overridden properties
               final Properties actualProps = argumentCaptor.getValue();
               
assertEquals(actualProps.get(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG), 
requestTimeoutMs);
               
assertEquals(actualProps.get(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG), 
defaultApiTimeoutMs);
           }
       }
       ```
   
   We are using Mockito to mock a static method. You were getting a 
NullPointerException because you were trying to mock a static method with 
incorrect syntax. Note that we are also using ArgumentCapture to verify the 
arguments that are being passed while creation of admin client.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to