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/08/22 11:03:22 UTC

[jmeter] branch master updated: Add a few more tests for date conversion

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 1cab3b8  Add a few more tests for date conversion
1cab3b8 is described below

commit 1cab3b82da5cbf095404fc1f4e76bbb7aae6237e
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Thu Aug 22 13:03:08 2019 +0200

    Add a few more tests for date conversion
---
 .../org/apache/jorphan/util/ConverterSpec.groovy   | 32 +++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/jorphan/src/test/groovy/org/apache/jorphan/util/ConverterSpec.groovy b/src/jorphan/src/test/groovy/org/apache/jorphan/util/ConverterSpec.groovy
index 20f60a5..fa61e33 100644
--- a/src/jorphan/src/test/groovy/org/apache/jorphan/util/ConverterSpec.groovy
+++ b/src/jorphan/src/test/groovy/org/apache/jorphan/util/ConverterSpec.groovy
@@ -18,6 +18,8 @@
 package org.apache.jorphan.util
 
 
+import java.text.DateFormat
+
 import spock.lang.Specification
 import spock.lang.Unroll
 
@@ -84,7 +86,7 @@ class ConverterSpec extends Specification {
             "not.a.valid.class" | "not.a.valid.class"
     }
 
-    def "Convert #value to #type"() {
+    def "Convert '#value' to #type"() {
         expect:
             Converter.convert(value, type) == expected
         where:
@@ -104,4 +106,32 @@ class ConverterSpec extends Specification {
             "char"               | char.class      | 'c'
             65                   | char.class      | 'A'
     }
+
+    def "Convert to date from '#value'"() {
+        expect:
+            Math.abs(Converter.convert(value, Date.class).getTime() - expected.getTime()) < 1000
+        where:
+            value                  | expected
+            ""                     | new Date()
+            new Date(30000)   | new Date(30000)
+            toLocalDateFormat("08/20/2019", DateFormat.SHORT) | new Date(1566252000L * 1000)
+    }
+
+    def "Convert to Calendar from '#value'"() {
+        expect:
+            Math.abs(
+                Converter.convert(value, Calendar.class).getTime().getTime() - expected.getTime()) < 1000
+        where:
+            value                  | expected
+            ""                     | new Date()
+            new Date(30000)   | new Date(30000)
+            toLocalDateFormat("08/20/2019", DateFormat.SHORT) | new Date(1566252000L * 1000)
+    }
+
+    def toLocalDateFormat(String dateString, int format) {
+        def date = DateFormat
+                .getDateInstance(DateFormat.SHORT, Locale.forLanguageTag("en_US"))
+                .parse(dateString)
+        return DateFormat.getDateInstance(format).format(date)
+    }
 }