mdedetrich commented on code in PR #12725:
URL: https://github.com/apache/kafka/pull/12725#discussion_r1003508600


##########
connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java:
##########
@@ -262,127 +254,96 @@ public void testFullExpandConnectors() {
         assertEquals(connectorInfo, expanded.get(CONNECTOR_NAME).get("info"));
         assertEquals(connector2, expanded.get(CONNECTOR2_NAME).get("status"));
         assertEquals(connector, expanded.get(CONNECTOR_NAME).get("status"));
-        PowerMock.verifyAll();
     }
 
     @Test
     public void testExpandConnectorsWithConnectorNotFound() {
-        
EasyMock.expect(herder.connectors()).andReturn(Arrays.asList(CONNECTOR2_NAME, 
CONNECTOR_NAME));
-        ConnectorStateInfo connector = EasyMock.mock(ConnectorStateInfo.class);
-        ConnectorStateInfo connector2 = 
EasyMock.mock(ConnectorStateInfo.class);
-        
EasyMock.expect(herder.connectorStatus(CONNECTOR2_NAME)).andReturn(connector2);
-        
EasyMock.expect(herder.connectorStatus(CONNECTOR_NAME)).andThrow(EasyMock.mock(NotFoundException.class));
+        when(herder.connectors()).thenReturn(Arrays.asList(CONNECTOR2_NAME, 
CONNECTOR_NAME));
+        ConnectorStateInfo connector = mock(ConnectorStateInfo.class);
+        ConnectorStateInfo connector2 = mock(ConnectorStateInfo.class);
+        when(herder.connectorStatus(CONNECTOR2_NAME)).thenReturn(connector2);
+        
doThrow(mock(NotFoundException.class)).when(herder).connectorStatus(CONNECTOR_NAME);
 
-        forward = EasyMock.mock(UriInfo.class);
+        forward = mock(UriInfo.class);
         MultivaluedMap<String, String> queryParams = new 
MultivaluedHashMap<>();
         queryParams.putSingle("expand", "status");
-        
EasyMock.expect(forward.getQueryParameters()).andReturn(queryParams).anyTimes();
-        EasyMock.replay(forward);
-
-        PowerMock.replayAll();
+        when(forward.getQueryParameters()).thenReturn(queryParams);
 
         Map<String, Map<String, Object>> expanded = (Map<String, Map<String, 
Object>>) connectorsResource.listConnectors(forward, NULL_HEADERS).getEntity();
         // Ordering isn't guaranteed, compare sets
         assertEquals(Collections.singleton(CONNECTOR2_NAME), 
expanded.keySet());
         assertEquals(connector2, expanded.get(CONNECTOR2_NAME).get("status"));
-        PowerMock.verifyAll();
     }
 
 
     @Test
     public void testCreateConnector() throws Throwable {
         CreateConnectorRequest body = new 
CreateConnectorRequest(CONNECTOR_NAME, 
Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
 
-        final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = 
Capture.newInstance();
-        herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), 
EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
+        final ArgumentCaptor<Callback<Herder.Created<ConnectorInfo>>> cb = 
ArgumentCaptor.forClass(Callback.class);
         expectAndCallbackResult(cb, new Herder.Created<>(true, new 
ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG,
-            CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
-
-        PowerMock.replayAll();
+            CONNECTOR_TASK_NAMES, ConnectorType.SOURCE))
+        ).when(herder).putConnectorConfig(eq(CONNECTOR_NAME), 
eq(body.config()), eq(false), cb.capture());
 
         connectorsResource.createConnector(FORWARD, NULL_HEADERS, body);
-
-        PowerMock.verifyAll();
     }
 
     @Test
     public void testCreateConnectorNotLeader() throws Throwable {
         CreateConnectorRequest body = new 
CreateConnectorRequest(CONNECTOR_NAME, 
Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
 
-        final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = 
Capture.newInstance();
-        herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), 
EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
-        expectAndCallbackNotLeaderException(cb);
-        // Should forward request
-        EasyMock.expect(RestClient.httpRequest(EasyMock.eq(LEADER_URL + 
"connectors?forward=false"), EasyMock.eq("POST"), EasyMock.isNull(), 
EasyMock.eq(body), EasyMock.anyObject(), 
EasyMock.anyObject(WorkerConfig.class)))
-                .andReturn(new RestClient.HttpResponse<>(201, new HashMap<>(), 
new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES,
-                    ConnectorType.SOURCE)));
+        final ArgumentCaptor<Callback<Herder.Created<ConnectorInfo>>> cb = 
ArgumentCaptor.forClass(Callback.class);
+        expectAndCallbackNotLeaderException(cb).when(herder)
+            .putConnectorConfig(eq(CONNECTOR_NAME), eq(body.config()), 
eq(false), cb.capture());
 
-        PowerMock.replayAll();
+        // Should forward request
+        restClientStatic.when(() ->
+            RestClient.httpRequest(eq(LEADER_URL + 
"connectors?forward=false"), eq("POST"), isNull(), eq(body), any(), 
any(WorkerConfig.class))
+        ).thenReturn(new RestClient.HttpResponse<>(201, new HashMap<>(), new 
ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, 
ConnectorType.SOURCE)));

Review Comment:
   So yes this is possible, I added a `verifyRestRequestWithCall` method in the 
`Verify mocked calls are actually called with verifyRestRequestWithCall` 
commit. Let me know if you are happy with the solution.



-- 
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