You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2023/01/04 18:07:31 UTC

[GitHub] [nifi] exceptionfactory opened a new pull request, #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

exceptionfactory opened a new pull request, #6823:
URL: https://github.com/apache/nifi/pull/6823

   # Summary
   
   [NIFI-00000](https://issues.apache.org/jira/browse/NIFI-00000)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [ ] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [ ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [ ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [ ] Pull Request based on current revision of the `main` branch
   - [ ] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `mvn clean install -P contrib-check`
     - [ ] JDK 8
     - [ ] JDK 11
     - [ ] JDK 17
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] exceptionfactory commented on pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
exceptionfactory commented on PR #6823:
URL: https://github.com/apache/nifi/pull/6823#issuecomment-1373918612

   Thanks for the detailed and helpful feedback @dan-s1! I pushed changes to include using the `TempDir` annotation, and also adjusted the `TestConnectionStatusAnalytics` class to remove the unnecessary casting in multiple places.


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] dan-s1 commented on a diff in pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
dan-s1 commented on code in PR #6823:
URL: https://github.com/apache/nifi/pull/6823#discussion_r1063478024


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java:
##########
@@ -383,48 +360,48 @@ public void testGetNextIntervalPercentageUseBytes() {
         ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
         Long percentage = connectionStatusAnalytics.getNextIntervalPercentageUseBytes(connection, flowFileEvent);
         assertNotNull(percentage);
-        assert (percentage == 10);
+        assertEquals(10, percentage);
     }
 
     @Test
     public void testGetScores() {
         Date now = new Date();
-        Long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
-        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0,tomorrowMillis.doubleValue());
-        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.9,50.0,tomorrowMillis.doubleValue());
+        long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
+        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0, (double) tomorrowMillis);
+        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.9,50.0, (double) tomorrowMillis);

Review Comment:
   Instead of assigning `tomorrowMillis` as a long you could assign it as as a Long and then call doubleValue() on it on lines 370 and 371 instead of casting.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] mattyb149 closed pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
mattyb149 closed pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5
URL: https://github.com/apache/nifi/pull/6823


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] mattyb149 commented on pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
mattyb149 commented on PR #6823:
URL: https://github.com/apache/nifi/pull/6823#issuecomment-1376050217

   Reviewing as well, thanks @dan-s1 for the thorough review!


-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] dan-s1 commented on a diff in pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
dan-s1 commented on code in PR #6823:
URL: https://github.com/apache/nifi/pull/6823#discussion_r1062980880


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/AbstractNativeLibHandlingClassLoaderTest.java:
##########
@@ -61,13 +64,12 @@ public class AbstractNativeLibHandlingClassLoaderTest {
     private boolean isOsMaxOsx;
     private boolean isOsLinux;
 
-    @Before
+    @BeforeEach
     public void setUp() throws Exception {
-        initMocks(this);
         tempDirectory = Files.createTempDirectory(this.getClass().getSimpleName());

Review Comment:
   Shouldn't Junit 5 `@TempDir` be used for this i.e. annotate the variable tempDirectory with it on line 56?



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] dan-s1 commented on a diff in pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
dan-s1 commented on code in PR #6823:
URL: https://github.com/apache/nifi/pull/6823#discussion_r1062979166


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java:
##########
@@ -151,7 +148,7 @@ public void testInvalidModelNaNScore() {
         ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
         Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
         assertNotNull(countTime);
-        assert (countTime == -1);
+        assertEquals(-1, countTime);

Review Comment:
   In all other instances you cast countTime with (long). If you need a cast then it should be done here also. If you do not need a cast then the cases should not need it either.



##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/AbstractNativeLibHandlingClassLoaderTest.java:
##########
@@ -61,13 +64,12 @@ public class AbstractNativeLibHandlingClassLoaderTest {
     private boolean isOsMaxOsx;
     private boolean isOsLinux;
 
-    @Before
+    @BeforeEach
     public void setUp() throws Exception {
-        initMocks(this);
         tempDirectory = Files.createTempDirectory(this.getClass().getSimpleName());

Review Comment:
   Shouldn't Junit 5 `@TempDir` be used for this?



##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java:
##########
@@ -36,19 +37,15 @@ public class XmlValidator {
      */
     public static void assertXmlValid(String xml) {
         final String html = xml.replace(DOCTYPE, EMPTY);
-        try {
-            final DocumentProvider provider = new StandardDocumentProvider();
-            provider.parse(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)));
-        } catch (final ProcessingException e) {
-            Assert.fail(e.getMessage());
-        }
+        final DocumentProvider provider = new StandardDocumentProvider();
+        provider.parse(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)));

Review Comment:
   Wouldn't assertDoesNotThrow be more appropriate:
   
   ```
   final DocumentProvider provider = new StandardDocumentProvider();
   assertDoesNotThrow(() -> provider.parse(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8))));
   ```



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] dan-s1 commented on a diff in pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
dan-s1 commented on code in PR #6823:
URL: https://github.com/apache/nifi/pull/6823#discussion_r1063479870


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java:
##########
@@ -383,48 +360,48 @@ public void testGetNextIntervalPercentageUseBytes() {
         ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
         Long percentage = connectionStatusAnalytics.getNextIntervalPercentageUseBytes(connection, flowFileEvent);
         assertNotNull(percentage);
-        assert (percentage == 10);
+        assertEquals(10, percentage);
     }
 
     @Test
     public void testGetScores() {
         Date now = new Date();
-        Long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
-        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0,tomorrowMillis.doubleValue());
-        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.9,50.0,tomorrowMillis.doubleValue());
+        long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
+        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0, (double) tomorrowMillis);
+        Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.9,50.0, (double) tomorrowMillis);
         countModelMap.putAll(bytesModelMap);
         ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(countModelMap);
         connectionStatusAnalytics.loadPredictions(repositoryStatusReport);
         Map<String,Long> scores = connectionStatusAnalytics.getPredictions();
         assertNotNull(scores);
         assertFalse(scores.isEmpty());
-        assertTrue(scores.get("nextIntervalPercentageUseCount").equals(50L));
-        assertTrue(scores.get("nextIntervalBytes").equals(10000000L));
+        assertEquals(50L, (long) scores.get("nextIntervalPercentageUseCount"));
+        assertEquals(10000000L, (long) scores.get("nextIntervalBytes"));

Review Comment:
   Casts are not necessary as it is coming from a Map whose values are  of type Long.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] dan-s1 commented on a diff in pull request #6823: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5

Posted by GitBox <gi...@apache.org>.
dan-s1 commented on code in PR #6823:
URL: https://github.com/apache/nifi/pull/6823#discussion_r1062979166


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java:
##########
@@ -151,7 +148,7 @@ public void testInvalidModelNaNScore() {
         ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
         Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
         assertNotNull(countTime);
-        assert (countTime == -1);
+        assertEquals(-1, countTime);

Review Comment:
   In all other instances you cast countTime with (long). If you need a cast then it should be done here also. If you do not need a cast then the other cases should not need it either.



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org