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 2016/12/27 17:05:39 UTC

svn commit: r1776175 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java

Author: fschumacher
Date: Tue Dec 27 17:05:39 2016
New Revision: 1776175

URL: http://svn.apache.org/viewvc?rev=1776175&view=rev
Log:
Check for null is overkill, when it is followed by instanceof. Add test cases for checked anomalies.

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java
    jmeter/trunk/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java?rev=1776175&r1=1776174&r2=1776175&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/modifier/AnchorModifier.java Tue Dec 27 17:05:39 2016
@@ -67,7 +67,7 @@ public class AnchorModifier extends Abst
         SampleResult res = context.getPreviousResult();
         HTTPSamplerBase sampler = null;
         HTTPSampleResult result = null;
-        if (res == null || !(sam instanceof HTTPSamplerBase) || !(res instanceof HTTPSampleResult)) {
+        if (!(sam instanceof HTTPSamplerBase) || !(res instanceof HTTPSampleResult)) {
             log.info("Can't apply HTML Link Parser when the previous" + " sampler run is not an HTTP Request.");
             return;
         } else {

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java?rev=1776175&r1=1776174&r2=1776175&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java Tue Dec 27 17:05:39 2016
@@ -33,6 +33,7 @@ import org.apache.jmeter.protocol.http.s
 import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
 import org.apache.jmeter.protocol.http.util.HTTPConstants;
+import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.save.SaveService;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
@@ -104,6 +105,27 @@ public class TestAnchorModifier extends
         }
 
         @Test
+        public void testNullSampler() {
+            jmctx.setCurrentSampler(null);
+            jmctx.setPreviousResult(new HTTPSampleResult());
+            parser.process(); // should do nothing
+        }
+
+        @Test
+        public void testNullResult() throws Exception {
+            jmctx.setCurrentSampler(makeContext("http://www.apache.org/subdir/previous.html"));
+            jmctx.setPreviousResult(null);
+            parser.process(); // should do nothing
+        }
+
+        @Test
+        public void testWrongResultClass() throws Exception {
+            jmctx.setCurrentSampler(makeContext("http://www.apache.org/subdir/previous.html"));
+            jmctx.setPreviousResult(new SampleResult());
+            parser.process(); // should do nothing
+        }
+
+        @Test
         public void testSimpleParse() throws Exception {
             HTTPSamplerBase config = makeUrlConfig(".*/index\\.html");
             HTTPSamplerBase context = makeContext("http://www.apache.org/subdir/previous.html");