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/fb18dd48 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/fb18dd48 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/fb18dd48 Branch: refs/heads/master Commit: fb18dd4841d95b0341a08f9f9e98c7268bf2634d Parents: f5a8042 Author: Howard M. Lewis Ship <[email protected]> Authored: Mon Jun 18 16:25:06 2012 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Mon Jun 18 16:25:06 2012 -0700 ---------------------------------------------------------------------- .../ioc/util/MessageFormatterImplSpec.groovy | 28 ++++++++ .../internal/util/MessageFormatterImplTest.java | 50 --------------- 2 files changed, 28 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fb18dd48/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/MessageFormatterImplSpec.groovy ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/MessageFormatterImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/MessageFormatterImplSpec.groovy new file mode 100644 index 0000000..c8e8a46 --- /dev/null +++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/util/MessageFormatterImplSpec.groovy @@ -0,0 +1,28 @@ +package org.apache.tapestry5.ioc.util + +import org.apache.tapestry5.ioc.internal.util.MessageFormatterImpl +import spock.lang.Specification +import spock.lang.Unroll + +class MessageFormatterImplSpec extends Specification { + + @Unroll + def "standard formatting: #desc"() { + + def mf = new MessageFormatterImpl(format, null) + + expect: + + mf.format(* args) == expected + + where: + + format | args | expected | desc + + "Tapestry is %s." | ["cool"] | "Tapestry is cool." | "simple substition" + "Tapestry release #%d." | [5] | "Tapestry release #5." | "numeric conversion" + "%s is %s at version %d." | ["Tapestry", "cool", 5] | "Tapestry is cool at version 5." | "multiple conversions" + "%s failed: %s" | ["Something", new RuntimeException("bad wolf")] | "Something failed: bad wolf" | "expansion of exception message" + "%s failed: %s" | ["Another", new NullPointerException()] | "Another failed: java.lang.NullPointerException" | "expansion of exception without message is exception class name" + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fb18dd48/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImplTest.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImplTest.java deleted file mode 100644 index 81bc3fe..0000000 --- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImplTest.java +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2006 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.internal.util; - -import org.testng.Assert; -import org.testng.annotations.Test; - -public class MessageFormatterImplTest extends Assert -{ - private String run(String format, Object... args) - { - return new MessageFormatterImpl(format, null).format(args); - } - - @Test - public void standard_args() - { - assertEquals(run("Tapestry is %s.", "cool"), "Tapestry is cool."); - assertEquals(run("Tapestry release #%d.", 5), "Tapestry release #5."); - assertEquals(run("%s is %s at version %d.", "Tapestry", "cool", 5), "Tapestry is cool at version 5."); - } - - @Test - public void throwable_argument() - { - Throwable t = new RuntimeException("Just didn't feel right."); - - assertEquals(run("%s failed: %s", "Something", t), "Something failed: Just didn't feel right."); - } - - @Test - public void throwable_argument_with_null_message() - { - Throwable t = new NullPointerException(); - - assertEquals(run("%s failed: %s", "Something", t), "Something failed: java.lang.NullPointerException"); - } -}
