jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject [jmeter] branch master updated: Misc Sonar Fixes (#528)
Date Sun, 13 Oct 2019 12:35:58 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new efd30b7  Misc Sonar Fixes (#528)
efd30b7 is described below

commit efd30b7fc3a54f0e6e0e5ee5150775d7cb4140cd
Author: Graham Russell <graham@ham1.co.uk>
AuthorDate: Sun Oct 13 13:35:47 2019 +0100

    Misc Sonar Fixes (#528)
    
    * JSONPathAssertion: Merge nested if
    
    * SMIMEAssertion: add NOSONAR to getLogger class
    
    * XMLSchemaAssertion: Remove throws IllegalArgumentException
    
    * XMLSchemaAssertion: Formatting and removal of useless comments
    
    * AssertionGui: Replace String literal with constant
    
    * AssertionGui: Comment tidy and method simplification
    
    * SMIMEAssertion: Clarify comment
    
    * SMIMEAssertion: Remove invalid throws CertificateException
    
    * TimeShift: Use correct class for static access for systemDefault()
---
 .../jmeter/assertions/JSONPathAssertion.java       |  9 ++++----
 .../apache/jmeter/assertions/SMIMEAssertion.java   | 10 ++++-----
 .../jmeter/assertions/XMLSchemaAssertion.java      | 24 +++-------------------
 .../apache/jmeter/assertions/gui/AssertionGui.java | 21 ++++---------------
 .../org/apache/jmeter/functions/TimeShift.java     |  2 +-
 5 files changed, 16 insertions(+), 50 deletions(-)

diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
b/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
index 4d819aa..5b46caf 100644
--- a/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
+++ b/src/components/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
@@ -119,9 +119,8 @@ public class JSONPathAssertion extends AbstractTestElement implements
Serializab
                 return;
             }
         } else {
-            if (isExpectNull() && value == null) {
-                return;
-            } else if (isEquals(value)) {
+            if ((isExpectNull() && value == null)
+                    || isEquals(value)) {
                 return;
             }
         }
@@ -145,8 +144,8 @@ public class JSONPathAssertion extends AbstractTestElement implements
Serializab
         }
 
         for (Object subj : value.toArray()) {
-            if ((subj == null && isExpectNull()) ||
-                    isEquals(subj)) {
+            if ((subj == null && isExpectNull())
+                    || isEquals(subj)) {
                 return true;
             }
         }
diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/SMIMEAssertion.java
b/src/components/src/main/java/org/apache/jmeter/assertions/SMIMEAssertion.java
index 4c5ac1f..48d4677 100644
--- a/src/components/src/main/java/org/apache/jmeter/assertions/SMIMEAssertion.java
+++ b/src/components/src/main/java/org/apache/jmeter/assertions/SMIMEAssertion.java
@@ -26,7 +26,6 @@ import java.io.InputStream;
 import java.math.BigInteger;
 import java.security.GeneralSecurityException;
 import java.security.Security;
-import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
@@ -70,8 +69,9 @@ import org.slf4j.LoggerFactory;
  */
 class SMIMEAssertion {
 
-    // Use the name of the test element, otherwise cannot enable/disable debug from the GUI
-    private static final Logger log = LoggerFactory.getLogger(SMIMEAssertionTestElement.class);
+    // Use the name of the test element, SMIMEAssertionTestElement, instead of
+    // the expected SMIMEAssertion, otherwise cannot enable/disable debug in the GUI
+    private static final Logger log = LoggerFactory.getLogger(SMIMEAssertionTestElement.class);
// NOSONAR
 
     SMIMEAssertion() {
         super();
@@ -329,10 +329,8 @@ class SMIMEAssertion {
      *
      * @param cert the X509 certificate holder
      * @return a List of all email addresses found
-     * @throws CertificateException
      */
-    private static List<String> getEmailFromCert(X509CertificateHolder cert)
-            throws CertificateException {
+    private static List<String> getEmailFromCert(X509CertificateHolder cert) {
         List<String> res = new ArrayList<>();
 
         X500Name subject = cert.getSubject();
diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/XMLSchemaAssertion.java
b/src/components/src/main/java/org/apache/jmeter/assertions/XMLSchemaAssertion.java
index b0d7781..b65810f 100644
--- a/src/components/src/main/java/org/apache/jmeter/assertions/XMLSchemaAssertion.java
+++ b/src/components/src/main/java/org/apache/jmeter/assertions/XMLSchemaAssertion.java
@@ -45,22 +45,14 @@ public class XMLSchemaAssertion extends AbstractTestElement implements
Serializa
 
     private static final long serialVersionUID = 234L;
 
-    public static final String FILE_NAME_IS_REQUIRED = "FileName is required";
+    private static final Logger log = LoggerFactory.getLogger(XMLSchemaAssertion.class);
 
+    public static final String FILE_NAME_IS_REQUIRED = "FileName is required";
     public static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
-
     public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
-
     public static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
-
-    private static final Logger log = LoggerFactory.getLogger(XMLSchemaAssertion.class);
-
     public static final String XSD_FILENAME_KEY = "xmlschema_assertion_filename";
 
-    /**
-     * getResult
-     *
-     */
     @Override
     public AssertionResult getResult(SampleResult response) {
         AssertionResult result = new AssertionResult(getName());
@@ -81,7 +73,7 @@ public class XMLSchemaAssertion extends AbstractTestElement implements Serializa
         return result;
     }
 
-    public void setXsdFileName(String xmlSchemaFileName) throws IllegalArgumentException
{
+    public void setXsdFileName(String xmlSchemaFileName) {
         setProperty(XSD_FILENAME_KEY, xmlSchemaFileName);
     }
 
@@ -89,13 +81,6 @@ public class XMLSchemaAssertion extends AbstractTestElement implements
Serializa
         return getPropertyAsString(XSD_FILENAME_KEY);
     }
 
-    /**
-     * set Schema result
-     *
-     * @param result
-     * @param xmlStr
-     * @param xsdFileName
-     */
     private void setSchemaResult(AssertionResult result, String xmlStr, String xsdFileName)
{
         try {
             DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
@@ -153,9 +138,6 @@ public class XMLSchemaAssertion extends AbstractTestElement implements
Serializa
         return str.toString();
     }
 
-    /**
-     * SAXErrorHandler class
-     */
     private static class SAXErrorHandler implements ErrorHandler {
         private final AssertionResult result;
 
diff --git a/src/components/src/main/java/org/apache/jmeter/assertions/gui/AssertionGui.java
b/src/components/src/main/java/org/apache/jmeter/assertions/gui/AssertionGui.java
index 7262852..698829f 100644
--- a/src/components/src/main/java/org/apache/jmeter/assertions/gui/AssertionGui.java
+++ b/src/components/src/main/java/org/apache/jmeter/assertions/gui/AssertionGui.java
@@ -97,8 +97,7 @@ public class AssertionGui extends AbstractAssertionGui {
     private JCheckBox assumeSuccess;
 
     /**
-     * Radio button indicating to test if the field contains one of the
-     * patterns.
+     * Radio button indicating to test if the field contains one of the patterns.
      */
     private JRadioButton containsBox;
 
@@ -123,15 +122,11 @@ public class AssertionGui extends AbstractAssertionGui {
      */
     private JCheckBox notBox;
 
-    /**
-     * Add new OR checkbox.
-     */
     private JCheckBox orBox;
 
     /** A table of patterns to test against. */
     private JTable stringTable;
 
-    /** Button to delete a pattern. */
     private JButton deletePattern;
 
     /** Table model for the pattern table. */
@@ -139,9 +134,6 @@ public class AssertionGui extends AbstractAssertionGui {
 
     private JSyntaxTextArea alternativeFailureMessage;
 
-    /**
-     * Create a new AssertionGui panel.
-     */
     public AssertionGui() {
         init();
     }
@@ -461,7 +453,7 @@ public class AssertionGui extends AbstractAssertionGui {
 
         JPanel panel = new JPanel();
         panel.setLayout(new BorderLayout());
-        panel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("assertion_patterns_to_test")));
//$NON-NLS-1$
+        panel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString(COL_RESOURCE_NAME)));
 
         panel.add(GuiUtils.emptyBorder(new JScrollPane(stringTable)), BorderLayout.CENTER);
         panel.add(createButtonPanel(), BorderLayout.SOUTH);
@@ -502,7 +494,6 @@ public class AssertionGui extends AbstractAssertionGui {
 
     /**
      * An ActionListener for deleting a pattern.
-     *
      */
     private class ClearPatternsListener implements ActionListener {
         @Override
@@ -582,11 +573,7 @@ public class AssertionGui extends AbstractAssertionGui {
     }
 
     protected void checkButtonsStatus() {
-        // Disable DELETE if there are no rows in the table to delete.
-        if (tableModel.getRowCount() == 0) {
-            deletePattern.setEnabled(false);
-        } else {
-            deletePattern.setEnabled(true);
-        }
+        // Enable DELETE if there are rows in the table to delete.
+        deletePattern.setEnabled(tableModel.getRowCount() != 0);
     }
 }
diff --git a/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java b/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java
index a3d45a2..438be1a 100644
--- a/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java
+++ b/src/functions/src/main/java/org/apache/jmeter/functions/TimeShift.java
@@ -182,7 +182,7 @@ public class TimeShift extends AbstractFunction {
         if (formatter != null) {
             dateString = localDateTimeToShift.format(formatter);
         } else {
-            ZoneOffset offset = ZoneOffset.systemDefault().getRules().getOffset(localDateTimeToShift);
+            ZoneOffset offset = ZoneId.systemDefault().getRules().getOffset(localDateTimeToShift);
             dateString = String.valueOf(localDateTimeToShift.toInstant(offset).toEpochMilli());
         }
 


Mime
View raw message