You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/06/02 23:21:40 UTC
[3/3] git commit: Convert TestNG to Spock
Convert TestNG to Spock
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/82a3af9d
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/82a3af9d
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/82a3af9d
Branch: refs/heads/master
Commit: 82a3af9d2295aaffeb4165cbeb842a846ea12eb8
Parents: 8215e9d
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Fri Jun 1 16:13:16 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Fri Jun 1 16:13:16 2012 -0700
----------------------------------------------------------------------
.../apache/tapestry5/util/TimeIntervalSpec.groovy | 72 +++++++++
.../tapestry5/ioc/util/TimeIntervalTest.java | 117 ---------------
2 files changed, 72 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/82a3af9d/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/TimeIntervalSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/TimeIntervalSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/TimeIntervalSpec.groovy
new file mode 100644
index 0000000..b6f8720
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/TimeIntervalSpec.groovy
@@ -0,0 +1,72 @@
+package org.apache.tapestry5.util
+
+import org.apache.tapestry5.ioc.util.TimeInterval
+import spock.lang.Specification
+import spock.lang.Unroll
+
+class TimeIntervalSpec extends Specification {
+
+ @Unroll
+ def "constructor usage '#input' parses to #milliseconds ms and '#units'"() {
+ when:
+
+ TimeInterval ti = new TimeInterval(input)
+
+ then:
+
+ ti.milliseconds() == milliseconds
+ ti.toString() == "TimeInterval[$units]"
+
+ ti.toDescription() == description
+
+ where:
+
+ input | milliseconds | units | description
+
+ "30 s" | 30000 | "30000 ms" | "30s"
+ "1h 30m" | 90 * 60 * 1000 | "5400000 ms" | "1h 30m"
+ "2d" | 2 * 24 * 60 * 60 * 1000 | "172800000 ms" | "2d"
+ "23ms" | 23 | "23 ms" | "23ms"
+ "62s" | 62 * 1000 | "62000 ms" | "1m 2s"
+ }
+
+ def "invalid units"() {
+
+ when:
+
+ TimeInterval.parseMilliseconds "30s 500mz"
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message == "Unknown time interval unit 'mz' (in '30s 500mz'). Defined units: d, h, m, ms, s, y."
+ }
+
+ def "unrecognized input"() {
+
+ when:
+
+ TimeInterval.parseMilliseconds "30s z 500ms"
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message.contains "Unexpected string 'z'"
+ }
+
+ def "unrecognized input at end"() {
+
+ when:
+
+ TimeInterval.parseMilliseconds "30s 500ms xyz"
+
+ then:
+
+ RuntimeException e = thrown()
+
+ e.message.contains "Unexpected string 'xyz'"
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/82a3af9d/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/TimeIntervalTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/TimeIntervalTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/TimeIntervalTest.java
deleted file mode 100644
index 8aaca63..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/TimeIntervalTest.java
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
-//
-// Licensed 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.tapestry5.ioc.util;
-
-import org.apache.tapestry5.ioc.test.TestBase;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-public class TimeIntervalTest extends TestBase
-{
- @Test
- public void use_constructor()
- {
- TimeInterval p = new TimeInterval("30 s");
-
- assertEquals(p.seconds(), 30);
- assertEquals(p.milliseconds(), 30 * 1000);
-
- assertEquals(p.toString(), "TimeInterval[30000 ms]");
- }
-
- @Test
- public void invalid_units()
- {
- try
- {
- TimeInterval.parseMilliseconds("30s 500mz");
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertEquals(ex.getMessage(),
- "Unknown time interval unit 'mz' (in '30s 500mz'). Defined units: d, h, m, ms, s, y.");
- }
- }
-
- @Test
- public void unrecognized_input()
- {
- try
- {
- TimeInterval.parseMilliseconds("30s z 500ms");
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertEquals(ex.getMessage(), "Unexpected string 'z' (in time interval '30s z 500ms').");
- }
- }
-
- @Test
- public void unrecognized_input_at_end()
- {
- try
- {
- TimeInterval.parseMilliseconds("30s 500ms xyz");
- unreachable();
- }
- catch (RuntimeException ex)
- {
- assertEquals(ex.getMessage(), "Unexpected string 'xyz' (in time interval '30s 500ms xyz').");
- }
- }
-
- @Test(dataProvider = "mix_of_units_data")
- public void mix_of_units(String input, long expected)
- {
- assertEquals(TimeInterval.parseMilliseconds(input), expected);
- }
-
- @DataProvider
- public Object[][] mix_of_units_data()
- {
- return new Object[][] { { "54321", 54321 },
-
- { "30s", 30 * 1000 },
-
- { "1h 30m", 90 * 60 * 1000 },
-
- { "2d", 2 * 24 * 60 * 60 * 1000 },
-
- { "2m", 2 * 60 * 1000 },
-
- { "23ms", 23 }
-
- };
- }
-
- @DataProvider
- public Object[][] to_description_data()
- {
- return new Object[][] { { 60 * 1000, "1m" },
- { 60 * 60 * 1000 + 35000 + 92, "1h 35s 92ms" },
- { 0, "" }};
- }
-
-
- @Test(dataProvider="to_description_data")
- public void to_description(long input, String expected)
- {
- assertEquals(new TimeInterval(input).toDescription(), expected);
- }
-
-
-}