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/05/28 19:17:22 UTC

svn commit: r1860297 - in /jmeter/trunk: src/core/org/apache/jmeter/report/core/Converters.java test/src/org/apache/jmeter/report/core/ConvertersSpec.groovy xdocs/changes.xml

Author: fschumacher
Date: Tue May 28 19:17:22 2019
New Revision: 1860297

URL: http://svn.apache.org/viewvc?rev=1860297&view=rev
Log:
StringConverters used for report generation should ignore white space around numbers.

Bugzilla Id: 63471

Added:
    jmeter/trunk/test/src/org/apache/jmeter/report/core/ConvertersSpec.groovy   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/report/core/Converters.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/report/core/Converters.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/core/Converters.java?rev=1860297&r1=1860296&r2=1860297&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/report/core/Converters.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/report/core/Converters.java Tue May 28 19:17:22 2019
@@ -82,7 +82,7 @@ public final class Converters {
             @Override
             public Integer convert(String value) throws ConvertException {
                 try {
-                    return Integer.valueOf(value);
+                    return Integer.valueOf(value.trim());
                 } catch (NumberFormatException ex) {
                     throw new ConvertException(value, Integer.class.getName(),
                             ex);
@@ -97,7 +97,7 @@ public final class Converters {
             @Override
             public Long convert(String value) throws ConvertException {
                 try {
-                    return Long.valueOf(value);
+                    return Long.valueOf(value.trim());
                 } catch (NumberFormatException ex) {
                     throw new ConvertException(value, Long.class.getName(), ex);
                 }

Added: jmeter/trunk/test/src/org/apache/jmeter/report/core/ConvertersSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/report/core/ConvertersSpec.groovy?rev=1860297&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/report/core/ConvertersSpec.groovy (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/report/core/ConvertersSpec.groovy Tue May 28 19:17:22 2019
@@ -0,0 +1,60 @@
+/*
+ * 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.core
+
+import spock.lang.Specification
+import spock.lang.Unroll
+
+@Unroll
+class ConvertersSpec extends Specification {
+
+    def "Convert number-like (#input) to instance of (#conversionDestClass)"() {
+        given:
+           def converter = Converters.getConverter(conversionDestClass)
+        when:
+            def result = converter.convert(input)
+        then:
+            result.class == expectedResult.class
+            result == expectedResult || Math.abs(expectedResult - result) < precision
+        where:
+        input       | conversionDestClass | expectedResult          | precision
+        " 42"       | Integer.class       | Integer.valueOf(42)     | 0
+        "-5"        | int.class           | Integer.valueOf(-5)     | 0
+        "5000000"   | Long.class          | Long.valueOf(5_000_000) | 0
+        "500 "      | long.class          | Long.valueOf(500)       | 0
+        "3.14"      | Double.class        | Double.valueOf(3.14)    | 0.0001
+        " 100 "     | double.class        | Double.valueOf(100)     | 0.0001
+        "+5"        | Float.class         | Float.valueOf(5)        | 0.0001
+        " 1.2E16 "  | float.class         | Float.valueOf(1.2E16)   | 0.0001
+    }
+
+    def "Convert (#input) to instance of (#conversionDestClass)"() {
+        given:
+        def converter = Converters.getConverter(conversionDestClass)
+     when:
+         def result = converter.convert(input)
+     then:
+         result == expectedResult
+     where:
+     input       | conversionDestClass | expectedResult
+     "FALSE"     | Boolean.class       | Boolean.FALSE
+     "true"      | boolean.class       | Boolean.TRUE
+     "a"         | Character.class     | 'a'
+     "ä"         | char.class          | 'ä'
+    }
+}
\ No newline at end of file

Propchange: jmeter/trunk/test/src/org/apache/jmeter/report/core/ConvertersSpec.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1860297&r1=1860296&r2=1860297&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Tue May 28 19:17:22 2019
@@ -172,6 +172,7 @@ to view the last major behaviors with th
 
 <h3>Report / Dashboard</h3>
 <ul>
+  <li><bug>63471</bug><code>StringConverter</code>s used for report generation should ignore white space around numbers.</li>
 </ul>
 
 <h3>Documentation</h3>