tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [2/2] git commit: Modify MessageFormatter to provide the format string as toString()
Date Fri, 02 Nov 2012 23:45:15 GMT
Modify MessageFormatter to provide the format string as toString()


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/5c10418f
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/5c10418f
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/5c10418f

Branch: refs/heads/5.4-js-rewrite
Commit: 5c10418ffedd6fb179a0f12d4b242c66378b95cf
Parents: 1778660
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Fri Nov 2 16:41:35 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Fri Nov 2 16:41:35 2012 -0700

----------------------------------------------------------------------
 .../ioc/internal/util/MessageFormatterImpl.java    |   10 ++++
 .../ioc/specs/MessageFormatterImplSpec.groovy      |   37 +++++++++-----
 2 files changed, 34 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5c10418f/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImpl.java
b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImpl.java
index 5c2da80..42757ee 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/MessageFormatterImpl.java
@@ -49,4 +49,14 @@ public class MessageFormatterImpl implements MessageFormatter
         return String.format(locale, format, args);
     }
 
+    /**
+     * Returns the underlying format string for this formatter.
+     *
+     * @since 5.4
+     */
+    public String toString()
+    {
+        return format;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/5c10418f/tapestry-ioc/src/test/groovy/ioc/specs/MessageFormatterImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/MessageFormatterImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/MessageFormatterImplSpec.groovy
index 5e5c0f1..e040954 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/MessageFormatterImplSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/MessageFormatterImplSpec.groovy
@@ -6,23 +6,34 @@ import spock.lang.Unroll
 
 class MessageFormatterImplSpec extends Specification {
 
-  @Unroll
-  def "standard formatting: #desc"() {
+    @Unroll
+    def "standard formatting: #desc"() {
 
-    def mf = new MessageFormatterImpl(format, null)
+        def mf = new MessageFormatterImpl(format, null)
 
-    expect:
+        expect:
 
-    mf.format(* args) == expected
+        mf.format(* args) == expected
 
-    where:
+        where:
 
-    format                    | args                                            | expected
                                        | desc
+        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"
+    }
+
+    def "toString() of a MessageFormatter is the format"() {
+
+        when:
+        def mf = new MessageFormatterImpl("this is the %s", null)
+
+        then:
+
+        mf.toString() == "this is the %s"
+    }
 
-    "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"
-  }
 }


Mime
View raw message