You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2019/09/29 10:17:12 UTC

[jmeter] 02/02: Extract common code blocks into private methods

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 c9fb919cc48be23847183360e070925a0bcc7c35
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Sun Sep 29 12:14:22 2019 +0200

    Extract common code blocks into private methods
---
 .../apache/jmeter/util/BeanShellTestElement.java   | 60 ++++++----------------
 1 file changed, 16 insertions(+), 44 deletions(-)

diff --git a/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java b/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java
index 76c97f9..93da10b 100644
--- a/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java
+++ b/src/core/src/main/java/org/apache/jmeter/util/BeanShellTestElement.java
@@ -177,67 +177,40 @@ public abstract class BeanShellTestElement extends AbstractTestElement
 
     @Override
     public void threadStarted() {
-        if (bshInterpreter == null || !hasInitFile) {
-            return;
-        }
-        try {
-            bshInterpreter.evalNoLog("threadStarted()"); // $NON-NLS-1$
-        } catch (JMeterException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("{} : {}", getClass().getName(), e.getLocalizedMessage()); // $NON-NLS-1$
-            }
-        }
+        tryEvalNoLog("threadStarted()"); // $NON-NLS-1$
     }
 
     @Override
     public void threadFinished() {
-        if (bshInterpreter == null || !hasInitFile) {
-            return;
-        }
-        try {
-            bshInterpreter.evalNoLog("threadFinished()"); // $NON-NLS-1$
-        } catch (JMeterException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("{} : {}", getClass().getName(), e.getLocalizedMessage()); // $NON-NLS-1$
-            }
-        }
+        tryEvalNoLog("threadFinished()"); // $NON-NLS-1$
     }
 
     @Override
     public void testEnded() {
-        if (bshInterpreter == null || !hasInitFile) {
-            return;
-        }
-        try {
-            bshInterpreter.evalNoLog("testEnded()"); // $NON-NLS-1$
-        } catch (JMeterException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("{} : {}", getClass().getName(), e.getLocalizedMessage()); // $NON-NLS-1$
-            }
-        }
+        tryEvalNoLog("testEnded()"); // $NON-NLS-1$
     }
 
     @Override
     public void testEnded(String host) {
-        if (bshInterpreter == null || !hasInitFile) {
-            return;
-        }
-        try {
-            bshInterpreter.eval("testEnded(\"" + host + "\")");
-        } catch (JMeterException e) {
-            if (log.isDebugEnabled()) {
-                log.debug("{} : {}", getClass().getName(), e.getLocalizedMessage()); // $NON-NLS-1$
-            }
-        }
+        tryEval("testEnded(\"" + host + "\")"); // $NON-NLS-1$
     }
 
     @Override
     public void testStarted() {
+        tryEvalNoLog("testStarted()");// $NON-NLS-1$
+    }
+
+    @Override
+    public void testStarted(String host) {
+        tryEval("testStarted(\"" + host + "\")"); // $NON-NLS-1$
+    }
+
+    private void tryEval(String code) {
         if (bshInterpreter == null || !hasInitFile) {
             return;
         }
         try {
-            bshInterpreter.evalNoLog("testStarted()"); // $NON-NLS-1$
+            bshInterpreter.eval(code);
         } catch (JMeterException e) {
             if (log.isDebugEnabled()) {
                 log.debug("{} : {}", getClass().getName(), e.getLocalizedMessage()); // $NON-NLS-1$
@@ -245,13 +218,12 @@ public abstract class BeanShellTestElement extends AbstractTestElement
         }
     }
 
-    @Override
-    public void testStarted(String host) {
+    private void tryEvalNoLog(String code) {
         if (bshInterpreter == null || !hasInitFile) {
             return;
         }
         try {
-            bshInterpreter.eval("testStarted(\"" + host + "\")");
+            bshInterpreter.evalNoLog(code);
         } catch (JMeterException e) {
             if (log.isDebugEnabled()) {
                 log.debug("{} : {}", getClass().getName(), e.getLocalizedMessage()); // $NON-NLS-1$