jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Make method less complex by extracting private methods
Date Sat, 26 Sep 2020 11:54:10 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


The following commit(s) were added to refs/heads/master by this push:
     new 34ace7b  Make method less complex by extracting private methods
34ace7b is described below

commit 34ace7b007e341ec5953652cdeb481eeded508fb
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Sat Sep 26 11:23:27 2020 +0200

    Make method less complex by extracting private methods
---
 .../java/org/apache/jmeter/config/CSVDataSet.java  | 70 ++++++++++++----------
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java b/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java
index 4887938..dab3190 100644
--- a/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java
+++ b/src/components/src/main/java/org/apache/jmeter/config/CSVDataSet.java
@@ -168,37 +168,7 @@ public class CSVDataSet extends ConfigTestElement
             delim=",";
         }
         if (vars == null) {
-            String fileName = getFilename().trim();
-            String mode = getShareMode();
-            int modeInt = CSVDataSetBeanInfo.getShareModeAsInt(mode);
-            switch(modeInt){
-                case CSVDataSetBeanInfo.SHARE_ALL:
-                    alias = fileName;
-                    break;
-                case CSVDataSetBeanInfo.SHARE_GROUP:
-                    alias = fileName+"@"+System.identityHashCode(context.getThreadGroup());
-                    break;
-                case CSVDataSetBeanInfo.SHARE_THREAD:
-                    alias = fileName+"@"+System.identityHashCode(context.getThread());
-                    break;
-                default:
-                    alias = fileName+"@"+mode; // user-specified key
-                    break;
-            }
-            final String names = getVariableNames();
-            if (StringUtils.isEmpty(names)) {
-                String header = server.reserveFile(fileName, getFileEncoding(), alias, true);
-                try {
-                    vars = CSVSaveService.csvSplitString(header, delim.charAt(0));
-                    firstLineIsNames = true;
-                } catch (IOException e) {
-                    throw new IllegalArgumentException("Could not split CSV header line from
file:" + fileName,e);
-                }
-            } else {
-                server.reserveFile(fileName, getFileEncoding(), alias, ignoreFirstLine);
-                vars = JOrphanUtils.split(names, ","); // $NON-NLS-1$
-            }
-            trimVarNames(vars);
+            initVars(server, context, delim);
         }
 
         // TODO: fetch this once as per vars above?
@@ -230,6 +200,44 @@ public class CSVDataSet extends ConfigTestElement
         }
     }
 
+    private void initVars(FileServer server, final JMeterContext context, String delim) {
+        String fileName = getFilename().trim();
+        setAlias(context, fileName);
+        final String names = getVariableNames();
+        if (StringUtils.isEmpty(names)) {
+            String header = server.reserveFile(fileName, getFileEncoding(), alias, true);
+            try {
+                vars = CSVSaveService.csvSplitString(header, delim.charAt(0));
+                firstLineIsNames = true;
+            } catch (IOException e) {
+                throw new IllegalArgumentException("Could not split CSV header line from
file:" + fileName,e);
+            }
+        } else {
+            server.reserveFile(fileName, getFileEncoding(), alias, ignoreFirstLine);
+            vars = JOrphanUtils.split(names, ","); // $NON-NLS-1$
+        }
+        trimVarNames(vars);
+    }
+
+    private void setAlias(final JMeterContext context, String fileName) {
+        String mode = getShareMode();
+        int modeInt = CSVDataSetBeanInfo.getShareModeAsInt(mode);
+        switch(modeInt){
+            case CSVDataSetBeanInfo.SHARE_ALL:
+                alias = fileName;
+                break;
+            case CSVDataSetBeanInfo.SHARE_GROUP:
+                alias = fileName+"@"+System.identityHashCode(context.getThreadGroup());
+                break;
+            case CSVDataSetBeanInfo.SHARE_THREAD:
+                alias = fileName+"@"+System.identityHashCode(context.getThread());
+                break;
+            default:
+                alias = fileName+"@"+mode; // user-specified key
+                break;
+        }
+    }
+
     /**
      * trim content of array varNames
      * @param varsNames


Mime
View raw message