jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] 05/07: Silence ErrorProne in test class
Date Sun, 21 Feb 2021 10:01:20 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git

commit 335958967f655e8849532851a3f8d870f674db08
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Sun Feb 21 10:45:27 2021 +0100

    Silence ErrorProne in test class
    
    Use ArrayDeque instead of LinkedList, even if it doesn't matter here (performance wise).
    Use assertThrows instead of fail together with a try-catch block, as it should make
    the intent clearer.
---
 .../org/apache/jmeter/junit/JMeterTestCase.java    | 32 +++++++---------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCase.java b/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCase.java
index 8696d22..1296969 100644
--- a/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCase.java
+++ b/src/core/src/test/java/org/apache/jmeter/junit/JMeterTestCase.java
@@ -17,12 +17,12 @@
 
 package org.apache.jmeter.junit;
 
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.File;
 import java.nio.charset.Charset;
+import java.util.ArrayDeque;
 import java.util.Collection;
-import java.util.LinkedList;
 import java.util.Locale;
 import java.util.MissingResourceException;
 
@@ -113,14 +113,10 @@ public abstract class JMeterTestCase {
 
     protected void checkInvalidParameterCounts(AbstractFunction func, int minimum)
             throws Exception {
-        Collection<CompoundVariable> parms = new LinkedList<>();
+        Collection<CompoundVariable> parms = new ArrayDeque<>();
         for (int c = 0; c < minimum; c++) {
-            try {
-                func.setParameters(parms);
-                fail("Should have generated InvalidVariableException for " + parms.size()
-                        + " parameters");
-            } catch (InvalidVariableException ignored) {
-            }
+            assertThrows(InvalidVariableException.class, () -> func.setParameters(parms),
+                    "parms.size() = " + parms.size() + " is too small");
             parms.add(new CompoundVariable());
         }
         func.setParameters(parms);
@@ -128,14 +124,10 @@ public abstract class JMeterTestCase {
 
     protected void checkInvalidParameterCounts(AbstractFunction func, int min,
             int max) throws Exception {
-        Collection<CompoundVariable> parms = new LinkedList<>();
+        Collection<CompoundVariable> parms = new ArrayDeque<>();
         for (int count = 0; count < min; count++) {
-            try {
-                func.setParameters(parms);
-                fail("Should have generated InvalidVariableException for " + parms.size()
-                        + " parameters");
-            } catch (InvalidVariableException ignored) {
-            }
+            assertThrows(InvalidVariableException.class, () -> func.setParameters(parms),
+                    "parms.size() = " + parms.size() + " is too small");
             parms.add(new CompoundVariable());
         }
         for (int count = min; count <= max; count++) {
@@ -143,12 +135,8 @@ public abstract class JMeterTestCase {
             parms.add(new CompoundVariable());
         }
         parms.add(new CompoundVariable());
-        try {
-            func.setParameters(parms);
-            fail("Should have generated InvalidVariableException for " + parms.size()
-                    + " parameters");
-        } catch (InvalidVariableException ignored) {
-        }
+        assertThrows(InvalidVariableException.class, () -> func.setParameters(parms),
+                "parms.size() = " + parms.size() + " is too big");
     }
 
     public static void assertPrimitiveEquals(boolean expected, boolean actual) {


Mime
View raw message