rfellows commented on code in PR #11244:
URL: https://github.com/apache/nifi/pull/11244#discussion_r3243341997
##########
nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/ConnectorFlowEndpointMergerTest.java:
##########
Review Comment:
This uses 8 separate `@Test` methods, each with a single assertion. The
established convention in this exact test folder
(`AccessPolicyEndpointMergerTest`, `ClearBulletinsEndpointMergerTest`,
`ClearBulletinsForGroupEndpointMergerTest`) and the project rule
`.cursor/rules/testing-standards.mdc` ("create the prerequisite objects, invoke
the method we care about with appropriate arguments, make assertions, and then
invoke again with a different set of arguments, make assertions") both point
toward a single consolidated `testCanHandle()` method with multiple assertions.
Suggested rewrite:
```java
@Test
public void testCanHandle() {
final ConnectorFlowEndpointMerger merger = new
ConnectorFlowEndpointMerger();
final String connectorId = "12345678-1234-1234-1234-123456789012";
final String processGroupId = "abcdef01-2345-6789-abcd-ef0123456789";
final String connectorFlowUri = "/nifi-api/connectors/" + connectorId +
"/flow/process-groups/" + processGroupId;
assertTrue(merger.canHandle(URI.create(connectorFlowUri), "GET"));
assertTrue(merger.canHandle(URI.create(connectorFlowUri +
"?uiOnly=true"), "GET"));
assertFalse(merger.canHandle(URI.create(connectorFlowUri), "POST"));
assertFalse(merger.canHandle(URI.create("/nifi-api/connectors/" +
connectorId + "/flow"), "GET"));
assertFalse(merger.canHandle(URI.create(connectorFlowUri +
"/controller-services"), "GET"));
assertFalse(merger.canHandle(URI.create("/nifi-api/flow/process-groups/"
+ processGroupId), "GET"));
assertFalse(merger.canHandle(URI.create("/nifi-api/connectors/not-a-uuid/flow/process-groups/"
+ processGroupId), "GET"));
assertFalse(merger.canHandle(URI.create("/nifi-api/connectors/" +
connectorId + "/flow/process-groups/not-a-uuid"), "GET"));
}
```
##########
nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/ConnectorFlowEndpointMergerTest.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.cluster.coordination.http.endpoints;
+
+import org.junit.jupiter.api.Test;
+
+import java.net.URI;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ConnectorFlowEndpointMergerTest {
+
+ private static final String CONNECTOR_ID =
"12345678-1234-1234-1234-123456789012";
+ private static final String PROCESS_GROUP_ID =
"abcdef01-2345-6789-abcd-ef0123456789";
+
+ private final ConnectorFlowEndpointMerger merger = new
ConnectorFlowEndpointMerger();
+
+ @Test
+ public void testCanHandleConnectorProcessGroupFlowUri() {
+ final URI uri = URI.create("/nifi-api/connectors/" + CONNECTOR_ID +
"/flow/process-groups/" + PROCESS_GROUP_ID);
+ assertTrue(merger.canHandle(uri, "GET"));
+ }
+
+ @Test
+ public void testCanHandleIgnoresQueryParameters() {
+ final URI uri = URI.create("/nifi-api/connectors/" + CONNECTOR_ID +
"/flow/process-groups/" + PROCESS_GROUP_ID + "?uiOnly=true");
+ assertTrue(merger.canHandle(uri, "GET"));
+ }
+
+ @Test
+ public void testCannotHandleNonGetMethods() {
+ final URI uri = URI.create("/nifi-api/connectors/" + CONNECTOR_ID +
"/flow/process-groups/" + PROCESS_GROUP_ID);
+ assertFalse(merger.canHandle(uri, "POST"));
+ assertFalse(merger.canHandle(uri, "PUT"));
+ assertFalse(merger.canHandle(uri, "DELETE"));
Review Comment:
`testCannotHandleNonGetMethods` exercises the same
`!"GET".equalsIgnoreCase(method)` branch three times (`POST`/`PUT`/`DELETE`).
Project guidance is to avoid "multiple tests whose differences are conditions
that do not truly affect the behavior of the code." One non-GET method is
enough. (Falls out naturally if the consolidation above is applied.)
--
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]