jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1854237 - in /jmeter/trunk: test/src/org/apache/jmeter/assertions/ test/src/org/apache/jmeter/control/ test/src/org/apache/jmeter/engine/util/ test/src/org/apache/jmeter/extractor/ test/src/org/apache/jmeter/functions/ test/src/org/apache/...
Date Sat, 23 Feb 2019 23:47:26 GMT
Author: pmouawad
Date: Sat Feb 23 23:47:26 2019
New Revision: 1854237

URL: http://svn.apache.org/viewvc?rev=1854237&view=rev
Log:
 Improve Unit tests readability and use of Spock #446 
 
 Contributed by Graham Russell
 This closes #446

Added:
    jmeter/trunk/test/src/org/apache/jmeter/report/processor/FieldSampleComparatorSpec.groovy
Removed:
    jmeter/trunk/test/src/org/apache/jmeter/report/processor/FieldSampleComparatorTest.java
Modified:
    jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/control/ThroughputControllerSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/extractor/JoddExtractorSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/gui/util/MenuFactorySpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/junit/spock/JMeterSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/report/processor/ListResultDataSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsBySamplerConsumerSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsSummaryDataSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/services/FileServerSpec.groovy
    jmeter/trunk/test/src/org/apache/jmeter/timers/UniformRandomTimerSpec.groovy
    jmeter/trunk/test/src/org/apache/jorphan/util/ConverterSpec.groovy
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/assertions/MD5HexAssertionSpec.groovy Sat Feb
23 23:47:26 2019
@@ -18,14 +18,14 @@
 package org.apache.jmeter.assertions
 
 import org.apache.commons.lang3.StringUtils
-import org.apache.jmeter.junit.spock.JMeterSpec
 import org.apache.jmeter.samplers.SampleResult
+import spock.lang.Specification
 import spock.lang.Unroll
 
 import java.nio.charset.StandardCharsets
 
 @Unroll
-class MD5HexAssertionSpec extends JMeterSpec {
+class MD5HexAssertionSpec extends Specification {
 
     def sut = new MD5HexAssertion()
 

Modified: jmeter/trunk/test/src/org/apache/jmeter/control/ThroughputControllerSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/control/ThroughputControllerSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/control/ThroughputControllerSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/control/ThroughputControllerSpec.groovy Sat Feb
23 23:47:26 2019
@@ -90,25 +90,25 @@ class ThroughputControllerSpec extends S
      */
     def "0 maxThroughput does not run any sampler inside the TC and does not cause StackOverFlowError"()
{
         given:
-        sut.setStyle(ThroughputController.BYNUMBER)
-        sut.setMaxThroughput(0)
+            sut.setStyle(ThroughputController.BYNUMBER)
+            sut.setMaxThroughput(0)
 
-        LoopController innerLoop = new LoopController()
-        innerLoop.setLoops(10000)
-        innerLoop.addTestElement(sut)
-        innerLoop.addIterationListener(sut)
-        innerLoop.initialize()
-        innerLoop.setRunningVersion(true)
-        sut.testStarted()
-        sut.setRunningVersion(true)
+            LoopController innerLoop = new LoopController()
+            innerLoop.setLoops(10000)
+            innerLoop.addTestElement(sut)
+            innerLoop.addIterationListener(sut)
+            innerLoop.initialize()
+            innerLoop.setRunningVersion(true)
+            sut.testStarted()
+            sut.setRunningVersion(true)
 
         when:
-            innerLoop.next() == null;
+            innerLoop.next() == null
             innerLoop.next() == null
         then:
             sut.testEnded()
     }
-    
+
     /**
      * <pre>
      *   - innerLoop
@@ -119,20 +119,20 @@ class ThroughputControllerSpec extends S
      */
     def "0.0 percentThroughput does not run any sampler inside the TC and does not cause
StackOverFlowError"() {
         given:
-        sut.setStyle(ThroughputController.BYPERCENT)
-        sut.setPercentThroughput("0.0")
+            sut.setStyle(ThroughputController.BYPERCENT)
+            sut.setPercentThroughput("0.0")
 
-        LoopController innerLoop = new LoopController()
-        innerLoop.setLoops(10000)
-        innerLoop.addTestElement(sut)
-        innerLoop.addIterationListener(sut)
-        innerLoop.initialize()
-        innerLoop.setRunningVersion(true)
-        sut.testStarted()
-        sut.setRunningVersion(true)
+            LoopController innerLoop = new LoopController()
+            innerLoop.setLoops(10000)
+            innerLoop.addTestElement(sut)
+            innerLoop.addIterationListener(sut)
+            innerLoop.initialize()
+            innerLoop.setRunningVersion(true)
+            sut.testStarted()
+            sut.setRunningVersion(true)
 
         when:
-            innerLoop.next() == null;
+            innerLoop.next() == null
             innerLoop.next() == null
         then:
             sut.testEnded()
@@ -222,7 +222,7 @@ class ThroughputControllerSpec extends S
      * </pre>
      *
      * @param innerLoops number of times to loop the {@link ThroughputController}
-     * @return the {@link LoopController}
+     * @return the{@link LoopController}
      */
     def createLoopController(int innerLoops) {
         LoopController innerLoop = new LoopController()

Modified: jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/engine/util/PackageSpec.groovy Sat Feb 23 23:47:26
2019
@@ -17,19 +17,19 @@
 
 package org.apache.jmeter.engine.util
 
-import org.apache.jmeter.junit.spock.JMeterSpec
 import org.apache.jmeter.samplers.SampleResult
 import org.apache.jmeter.testelement.property.JMeterProperty
 import org.apache.jmeter.testelement.property.StringProperty
 import org.apache.jmeter.threads.JMeterContextService
 import org.apache.jmeter.threads.JMeterVariables
+import spock.lang.Specification
 import spock.lang.Unroll
 
 /**
  * To run this test stand-alone, ensure that ApacheJMeter_functions.jar is on the classpath,
  * as it is needed to resolve the functions.
  */
-class PackageSpec extends JMeterSpec {
+class PackageSpec extends Specification {
 
     def transformer
     def jmctx

Modified: jmeter/trunk/test/src/org/apache/jmeter/extractor/JoddExtractorSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/extractor/JoddExtractorSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/extractor/JoddExtractorSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/extractor/JoddExtractorSpec.groovy Sat Feb 23
23:47:26 2019
@@ -14,24 +14,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.jmeter.extractor
 
-package org.apache.jmeter.extractor;
-
-import java.awt.event.ActionEvent
-
-import org.apache.jmeter.junit.spock.JMeterSpec
-
-import spock.lang.IgnoreIf
+import spock.lang.Specification
 import spock.lang.Unroll
 
 @Unroll
-class JoddExtractorSpec extends JMeterSpec {
+class JoddExtractorSpec extends Specification {
 
     def "extract #expression and #attribute"() {
-        when:
-          def extractor = new JoddExtractor()
-          def resultList = []
-          def input = """
+        given:
+            def resultList = []
+            def input = """
 <html>
   <head><title>Test</title></head>
   <body>
@@ -41,14 +35,16 @@ class JoddExtractorSpec extends JMeterSp
   </body>
 </html>
 """
+        when:
+            def foundCount = new JoddExtractor().extract(expression, attribute, matchNumber,
input, resultList, found, cacheKey)
         then:
-          expected == extractor.extract(expression, attribute, matchNumber, input, resultList,
found, cacheKey)
-          expectedList == resultList
+            foundCount == expected
+            resultList == expectedList
         where:
-          expression        | attribute | matchNumber | expectedList                  | found
| expected | cacheKey
-          "p"               | ""        | 1           | ["Some text"]                 | -1
   | 0        | "key"
-          "h1[class=title]" | "class"   | 1           | ["title"]                     | -1
   | 0        | "key"
-          "h1"              | ""        | 0           | ["TestTitle", "AnotherTitle"] | -1
   | 1        | "key"
-          "notthere"        | ""        | 0           | []                            | -1
   | -1       | "key"
+            expression        | attribute | matchNumber | expectedList                  |
found | expected | cacheKey
+            "p"               | ""        | 1           | ["Some text"]                 |
-1    | 0        | "key"
+            "h1[class=title]" | "class"   | 1           | ["title"]                     |
-1    | 0        | "key"
+            "h1"              | ""        | 0           | ["TestTitle", "AnotherTitle"] |
-1    | 1        | "key"
+            "notthere"        | ""        | 0           | []                            |
-1    | -1       | "key"
     }
 }

Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy Sat Feb 23 23:47:26
2019
@@ -30,14 +30,14 @@ class ChangeCaseSpec extends Specificati
 
     def "convert '#input' using mode #mode to '#output'"() {
         given:
-            def changeCase = new ChangeCase();
-            def jMCtx = JMeterContextService.getContext();
-            def result = new SampleResult();
-            result.setResponseData("dummy data", null);
-            jMCtx.setVariables(new JMeterVariables());
-            jMCtx.setPreviousResult(result);
+            def changeCase = new ChangeCase()
+            def jMCtx = JMeterContextService.getContext()
+            def result = new SampleResult()
+            result.setResponseData("dummy data", null)
+            jMCtx.setVariables(new JMeterVariables())
+            jMCtx.setPreviousResult(result)
         when:
-            changeCase.setParameters([new CompoundVariable(input), new CompoundVariable(mode)]);
+            changeCase.setParameters([new CompoundVariable(input), new CompoundVariable(mode)])
         then:
             output == changeCase.execute(result, null)
         where:
@@ -67,4 +67,3 @@ class ChangeCaseSpec extends Specificati
     }
 
 }
-

Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy Sat Feb
23 23:47:26 2019
@@ -15,41 +15,37 @@
  * limitations under the License.
  */
 
-package org.apache.jmeter.functions.gui;
-
-import java.awt.event.ActionEvent
+package org.apache.jmeter.functions.gui
 
 import org.apache.jmeter.config.Argument
 import org.apache.jmeter.config.Arguments
-import org.apache.jmeter.junit.spock.JMeterSpec
-import org.apache.jorphan.gui.GuiUtils
-
 import spock.lang.IgnoreIf
+import spock.lang.Specification
 import spock.lang.Unroll
 
 @Unroll
-class FunctionHelperSpec extends JMeterSpec {
+class FunctionHelperSpec extends Specification {
 
-    @IgnoreIf({ Boolean.valueOf(System.properties['java.awt.headless']) })
+    @IgnoreIf({ System.properties['java.awt.headless'] as boolean })
     def "construct correct call string for parameters #parameters"() {
         setup:
-          def functionHelper = new FunctionHelper()
+            def functionHelper = new FunctionHelper()
         when:
-          def args = new Arguments()
-          args.setArguments(parameters.collect { new Argument("dummy${it}", it)})
+            def args = new Arguments()
+            args.setArguments(parameters.collect { new Argument("dummy${it}", it) })
         then:
-          functionHelper.buildFunctionCallString(functionName, args).toString() == combined
+            functionHelper.buildFunctionCallString(functionName, args).toString() == combined
         where:
-          functionName | parameters    | combined
-          "fname"      | []            | "\${fname}"
-          "fname"      | ["a"]         | "\${fname(a)}"
-          "fname"      | ["a,b"]       | "\${fname(a\\,b)}"
-          "fname"      | ["a,b,c"]     | "\${fname(a\\,b\\,c)}"
-          "fname"      | ["a", "b"]    | "\${fname(a,b)}"
-          "fname"      | ["a,b", "c"]  | "\${fname(a\\,b,c)}"
-          "fname"      | ["\\\${f(a,b)}"]                  | "\${fname(\\\${f(a\\,b)})}"
-          "fname"      | ["\${f(a,b)},c,\${g(d,e)}","h"]   | "\${fname(\${f(a,b)}\\,c\\,\${g(d,e)},h)}"
-          "fname"      | ["a,\${f(b,\${g(c,d)},e)},f","h"] | "\${fname(a\\,\${f(b,\${g(c,d)},e)}\\,f,h)}"
+            functionName | parameters                         | combined
+            "fname"      | []                                 | "\${fname}"
+            "fname"      | ["a"]                              | "\${fname(a)}"
+            "fname"      | ["a,b"]                            | "\${fname(a\\,b)}"
+            "fname"      | ["a,b,c"]                          | "\${fname(a\\,b\\,c)}"
+            "fname"      | ["a", "b"]                         | "\${fname(a,b)}"
+            "fname"      | ["a,b", "c"]                       | "\${fname(a\\,b,c)}"
+            "fname"      | ["\\\${f(a,b)}"]                   | "\${fname(\\\${f(a\\,b)})}"
+            "fname"      | ["\${f(a,b)},c,\${g(d,e)}", "h"]   | "\${fname(\${f(a,b)}\\,c\\,\${g(d,e)},h)}"
+            "fname"      | ["a,\${f(b,\${g(c,d)},e)},f", "h"] | "\${fname(a\\,\${f(b,\${g(c,d)},e)}\\,f,h)}"
     }
 }
 

Modified: jmeter/trunk/test/src/org/apache/jmeter/gui/util/MenuFactorySpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/gui/util/MenuFactorySpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/gui/util/MenuFactorySpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/gui/util/MenuFactorySpec.groovy Sat Feb 23 23:47:26
2019
@@ -14,8 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
- package org.apache.jmeter.gui.util
+package org.apache.jmeter.gui.util
 
 import org.apache.jmeter.junit.spock.JMeterSpec
 
@@ -24,12 +23,12 @@ class MenuFactorySpec extends JMeterSpec
     def "ensure each menu has something in it"() {
         expect:
             MenuFactory.menuMap.size() == 12
-            MenuFactory.menuMap.every {!it.value.isEmpty()}
+            MenuFactory.menuMap.every { !it.value.isEmpty() }
     }
 
     def "default add menu has expected item count"() {
         expect:
-            MenuFactory.createDefaultAddMenu().itemCount == 6 + 3 // items + seperators
+            MenuFactory.createDefaultAddMenu().itemCount == 6 + 3 // items + separators
     }
 }
 

Modified: jmeter/trunk/test/src/org/apache/jmeter/junit/spock/JMeterSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/junit/spock/JMeterSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/junit/spock/JMeterSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/junit/spock/JMeterSpec.groovy Sat Feb 23 23:47:26
2019
@@ -23,7 +23,11 @@ import spock.lang.Specification
 import java.nio.charset.Charset
 
 /**
- * Common setup for Spock test cases
+ * Common setup for Spock test cases.
+ * <p>
+ * Please only use this class if you <em>need</em> the things set up here.
+ * <p>
+ * Otherwise, extend {@link Specification}
  */
 abstract class JMeterSpec extends Specification {
 

Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/jdbc/sampler/JDBCSamplerSpec.groovy Sat
Feb 23 23:47:26 2019
@@ -18,9 +18,9 @@
 package org.apache.jmeter.protocol.jdbc.sampler
 
 import org.apache.jmeter.config.ConfigTestElement
-import org.apache.jmeter.junit.spock.JMeterSpec
 import org.apache.jmeter.samplers.SampleResult
 import org.apache.jmeter.testelement.property.JMeterProperty
+import spock.lang.Specification
 import spock.lang.Unroll
 
 import java.sql.Connection
@@ -30,7 +30,7 @@ import java.sql.SQLException
 import java.sql.Statement
 
 @Unroll
-class JDBCSamplerSpec extends JMeterSpec {
+class JDBCSamplerSpec extends Specification {
 
     def sut = new JDBCSampler()
 

Added: jmeter/trunk/test/src/org/apache/jmeter/report/processor/FieldSampleComparatorSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/processor/FieldSampleComparatorSpec.groovy?rev=1854237&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/processor/FieldSampleComparatorSpec.groovy
(added)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/processor/FieldSampleComparatorSpec.groovy
Sat Feb 23 23:47:26 2019
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.jmeter.report.processor
+
+import org.apache.jmeter.report.core.Sample
+import org.apache.jmeter.report.core.SampleMetadata
+import spock.lang.Specification
+
+class FieldSampleComparatorSpec extends Specification {
+
+    def sampleMetadata = new SampleMetadata(',' as char, "test")
+    def comparator = new FieldSampleComparator("test")
+
+    def testCompare() {
+        given:
+            def s1 = new Sample(0, sampleMetadata, "1")
+            def s2 = new Sample(1, sampleMetadata, "2")
+            comparator.initialize(sampleMetadata)
+        expect:
+            comparator.compare(s1, s2) < 0
+            comparator.compare(s2, s1) > 0
+            comparator.compare(s1, s1) == 0
+            comparator.compare(s2, s2) == 0
+    }
+
+}

Modified: jmeter/trunk/test/src/org/apache/jmeter/report/processor/ListResultDataSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/processor/ListResultDataSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/processor/ListResultDataSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/processor/ListResultDataSpec.groovy Sat
Feb 23 23:47:26 2019
@@ -25,9 +25,12 @@ class ListResultDataSpec extends Specifi
 
     def sut = new ListResultData()
 
+    def "a new ListResultData is empty"() {
+        expect:
+            new ListResultData().size() == 0
+    }
+
     def "addResult adds #object to list and returns true"() {
-        given:
-            assert sut.getSize() == 0
         when:
             def result = sut.addResult(object)
         then:

Modified: jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsBySamplerConsumerSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsBySamplerConsumerSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsBySamplerConsumerSpec.groovy
(original)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsBySamplerConsumerSpec.groovy
Sat Feb 23 23:47:26 2019
@@ -17,11 +17,12 @@
 
 package org.apache.jmeter.report.processor
 
-import org.apache.jmeter.junit.spock.JMeterSpec
+
 import org.apache.jmeter.report.core.Sample
 import org.apache.jmeter.report.utils.MetricUtils
+import spock.lang.Specification
 
-class Top5ErrorsBySamplerConsumerSpec extends JMeterSpec {
+class Top5ErrorsBySamplerConsumerSpec extends Specification {
 
     def sut = new Top5ErrorsBySamplerConsumer()
 
@@ -71,7 +72,6 @@ class Top5ErrorsBySamplerConsumerSpec ex
         expect:
             sut.createResultTitles().size ==
                     3 + 2 * sut.MAX_NUMBER_OF_ERRORS_IN_TOP
-
     }
 
 }

Modified: jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsSummaryDataSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsSummaryDataSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsSummaryDataSpec.groovy
(original)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/processor/Top5ErrorsSummaryDataSpec.groovy
Sat Feb 23 23:47:26 2019
@@ -23,6 +23,21 @@ class Top5ErrorsSummaryDataSpec extends
 
     def sut = new Top5ErrorsSummaryData()
 
+    def "error and total count start at 0"() {
+        expect:
+            sut.getErrors() == 0
+            sut.getTotal() == 0
+    }
+
+    def "error and total count increment by one each time"() {
+        when:
+            sut.incErrors()
+            sut.incTotal()
+        then:
+            sut.getErrors() == 1
+            sut.getTotal() == 1
+    }
+
     def "when no errors are registered an array with null values is returned"() {
         expect:
             sut.getTop5ErrorsMetrics() == new Object[5][2]
@@ -37,26 +52,9 @@ class Top5ErrorsSummaryDataSpec extends
 
     def "error messages are sorted by size, descending"() {
         given:
-            ["A", "A", "A", "B", "B", "C"].each {
-                sut.registerError(it)
-            }
+            ["A", "A", "A", "B", "B", "C"].each { sut.registerError(it) }
         expect:
             sut.getTop5ErrorsMetrics() == [["A", 3], ["B", 2], ["C", 1], [null, null], [null,
null]]
     }
 
-    def "error and total count start at 0"() {
-        expect:
-            sut.getErrors() == 0
-            sut.getTotal() == 0
-    }
-
-    def "error and total count increment by one each time"() {
-        when:
-            sut.incErrors()
-            sut.incTotal()
-        then:
-            sut.getErrors() == 1
-            sut.getTotal() == 1
-    }
-
 }

Modified: jmeter/trunk/test/src/org/apache/jmeter/services/FileServerSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/services/FileServerSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/services/FileServerSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/services/FileServerSpec.groovy Sat Feb 23 23:47:26
2019
@@ -65,10 +65,9 @@ class FileServerSpec extends JMeterSpec
     }
 
     def "file is not opened until read from"() {
-        when:
+        given:
             sut.reserveFile(testFile) // Does not open file
-        then:
-            !sut.filesOpen()
+            assert !sut.filesOpen()
         when:
             def line = sut.readLine(testFile)
         then:

Modified: jmeter/trunk/test/src/org/apache/jmeter/timers/UniformRandomTimerSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/timers/UniformRandomTimerSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/timers/UniformRandomTimerSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/timers/UniformRandomTimerSpec.groovy Sat Feb 23
23:47:26 2019
@@ -35,6 +35,15 @@ class UniformRandomTimerSpec extends Spe
 
     def "default range is 0"() {
         given:
+            sut.iterationStart(null)
+        when:
+            def actualRange = sut.range
+        then:
+            actualRange == 0L
+    }
+
+    def "delay can be set via a String"() {
+        given:
             sut.setDelay("1")
             sut.iterationStart(null)
         when:

Modified: jmeter/trunk/test/src/org/apache/jorphan/util/ConverterSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/util/ConverterSpec.groovy?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/util/ConverterSpec.groovy (original)
+++ jmeter/trunk/test/src/org/apache/jorphan/util/ConverterSpec.groovy Sat Feb 23 23:47:26
2019
@@ -15,107 +15,93 @@
  * limitations under the License.
  */
 
-package org.apache.jorphan.util;
+package org.apache.jorphan.util
 
-import java.awt.event.ActionEvent
 
-import org.apache.jmeter.junit.spock.JMeterSpec
-
-import spock.lang.IgnoreIf
+import spock.lang.Specification
 import spock.lang.Unroll
 
 @Unroll
-class ConverterSpec extends JMeterSpec {
+class ConverterSpec extends Specification {
 
-    def "convert #value to #type should give [#expected] when value or type is null"() {
-        when:
-          def converted = Converter.convert(value, type)
-        then:
-          converted == expected
-        where:
-          value | type              | expected
-          null       | null         | ""
-          "anything" | null         | ""
-          23         | null         | ""
-          null       | String.class | ""
-          null       | Number.class | ""
+    def 'convert #value to #type should give "" when value or type is null'() {
+        expect:
+            Converter.convert(value, type) == ""
+        where:
+            value      | type
+            null       | null
+            "anything" | null
+            23         | null
+            null       | String.class
+            null       | Number.class
     }
 
     def "convert #value to #type should downcast gracefully and give [#expected]"() {
-        when:
-          def converted = Converter.convert(value, type)
-        then:
-          converted == expected
-        where:
-          value      | type         | expected
-          "anything" | String.class | "anything"
-          "anything" | Object.class | "anything"
-          23         | Number.class | 23
+        expect:
+            Converter.convert(value, type) == expected
+        where:
+            value      | type         | expected
+            "anything" | Object.class | "anything"
+            23         | Number.class | 23
     }
 
     def "convert #value to string should give [#expected]"() {
-        when:
-          def converted = Converter.convert(value, String.class)
-        then:
-          converted == expected
-        where:
-          value               | expected
-          "anything"          | "anything"
-          23                  | "23"
-    }
-
-    def "convert #value to #type should give number [#expected]"() {
-        when:
-          def converted = Converter.convert(value, type)
-        then:
-          Math.abs(converted - expected) < expected * 0.000001
-        where:
-          value      | type         | expected
-          23f        | float.class  | 23f
-          42f        | Float.class  | 42f
-          "42"       | Float.class  | 42f
-          23f        | double.class | 23d
-          42f        | Double.class | 42d
-          "42"       | Double.class | 42d
-          23l        | int.class    | 23
-          42         | Integer.class| 42
-          "42"       | Integer.class| 42
-          23l        | long.class   | 23
-          42         | Long.class   | 42
-          "42"       | Long.class   | 42
-    }
-
-    def "Convert #value to diverse class types (#type)"() {
-        when:
-          def converted = Converter.convert(value, type)
-        then:
-          converted == expected
-        where:
-          value              | type        | expected
-          "java.lang.String" | Class.class | String.class
-          "not.a.valid.class"| Class.class | "not.a.valid.class"
+        expect:
+            Converter.convert(value, String.class) == expected
+        where:
+            value      | expected
+            "anything" | "anything"
+            23         | "23"
+            42L        | "42"
+            64f        | "64.0"
+    }
+
+    def "convert #value to number #type should give number [#expected]"() {
+        expect:
+            Converter.convert(value, type) == expected
+        where:
+            value | type          | expected
+            23f   | float.class   | 23f
+            42f   | Float.class   | 42f
+            "42"  | Float.class   | 42f
+            23f   | double.class  | 23d
+            42f   | Double.class  | 42d
+            "42"  | Double.class  | 42d
+            23L   | int.class     | 23
+            42    | Integer.class | 42
+            "42"  | Integer.class | 42
+            23L   | long.class    | 23L
+            42    | Long.class    | 42L
+            "42"  | Long.class    | 42L
+    }
+
+    def "Convert #value to Class gives #expected"() {
+        expect:
+            Converter.convert(value, Class.class) == expected
+        where:
+            value               | expected
+            "java.lang.String"  | String.class
+            "not.a.valid.class" | "not.a.valid.class"
     }
 
     def "Convert #value to #type"() {
-        when:
-          def converted = Converter.convert(value, type)
-        then:
-          converted == expected
-        where:
-          value                | type            | expected
-          ""                   | Boolean.class   | false
-          "true"               | Boolean.class   | true
-          true                 | Boolean.class   | true
-          false                | Boolean.class   | false
-          ""                   | boolean.class   | false
-          "true"               | boolean.class   | true
-          true                 | boolean.class   | true
-          false                | boolean.class   | false
-          "filename"           | File.class      | new File("filename")
-          new File("filename") | File.class      | new File("filename")
-          "c"                  | Character.class | 'c'
-          "c"                  | char.class      | 'c'
-          "char"               | char.class      | 'c'
-          65                   | char.class      | 'A'
+        expect:
+            Converter.convert(value, type) == expected
+        where:
+            value                | type            | expected
+            ""                   | Boolean.class   | false
+            "true"               | Boolean.class   | true
+            true                 | Boolean.class   | true
+            false                | Boolean.class   | false
+            ""                   | boolean.class   | false
+            "true"               | boolean.class   | true
+            true                 | boolean.class   | true
+            false                | boolean.class   | false
+            "filename"           | File.class      | new File("filename")
+            new File("filename") | File.class      | new File("filename")
+            "c"                  | Character.class | 'c'
+            "c"                  | char.class      | 'c'
+            "char"               | char.class      | 'c'
+            65                   | char.class      | 'A'
     }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1854237&r1=1854236&r2=1854237&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Feb 23 23:47:26 2019
@@ -108,7 +108,8 @@ Summary
 
 <h3>General</h3>
 <ul>
-    <li><pr>444</pr> Update to latest Spock v1.2 (was 1.0). Contributed
by Graham Russell (graham at ham1.co.uk)</li>
+    <li><pr>444</pr>Update to latest Spock v1.2 (was 1.0). Contributed
by Graham Russell (graham at ham1.co.uk)</li>
+    <li><pr>446</pr>Improve Unit tests readability and use of Spock. Contributed
by Graham Russell (graham at ham1.co.uk)</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>



Mime
View raw message