tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r517739 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/translator/StringTranslator.java test/java/org/apache/tapestry/translator/StringTranslatorTest.java
Date Tue, 13 Mar 2007 15:47:07 GMT
Author: hlship
Date: Tue Mar 13 08:47:07 2007
New Revision: 517739

URL: http://svn.apache.org/viewvc?view=rev&rev=517739
Log:
TAPESTRY-1270: The StringTranslator should return null when an empty text field is submitted
with a form, not the empty string

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/translator/StringTranslatorTest.java
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/StringTranslator.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/StringTranslator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/StringTranslator.java?view=diff&rev=517739&r1=517738&r2=517739
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/StringTranslator.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/translator/StringTranslator.java
Tue Mar 13 08:47:07 2007
@@ -17,13 +17,14 @@
 import org.apache.tapestry.Translator;
 import org.apache.tapestry.ValidationException;
 import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
 
 public class StringTranslator implements Translator<String>
 {
-    /** Returns the client value (or the empty string, if the client value is null). */
+    /** Returns the client value (or null, if the client value is blank). */
     public String parseClient(String clientValue, Messages messages) throws ValidationException
     {
-        return clientValue == null ? "" : clientValue;
+        return InternalUtils.isBlank(clientValue) ? null : clientValue;
     }
 
     /** Returns the value, or the empty string if value is null. */

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/translator/StringTranslatorTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/translator/StringTranslatorTest.java?view=auto&rev=517739
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/translator/StringTranslatorTest.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/translator/StringTranslatorTest.java
Tue Mar 13 08:47:07 2007
@@ -0,0 +1,62 @@
+// Copyright 2007 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.tapestry.translator;
+
+import org.apache.tapestry.Translator;
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.Messages;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for the {@link StringTranslator} class.
+ */
+public class StringTranslatorTest extends InternalBaseTestCase
+{
+    @Test
+    public void from_client_normal() throws Exception
+    {
+        Messages messages = validationMessages();
+
+        Translator<String> translator = new StringTranslator();
+
+        assertEquals(translator.parseClient("abc", messages), "abc");
+    }
+
+    @Test
+    public void from_client_blank_to_null() throws Exception
+    {
+        Messages messages = validationMessages();
+
+        Translator<String> translator = new StringTranslator();
+
+        assertNull(translator.parseClient("", messages));
+    }
+
+    @Test
+    public void to_client_normal()
+    {
+        Translator<String> translator = new StringTranslator();
+
+        assertEquals(translator.toClient("abc"), "abc");
+    }
+
+    @Test
+    public void to_client_null_to_blank()
+    {
+        Translator<String> translator = new StringTranslator();
+
+        assertEquals(translator.toClient(null), "");
+    }
+}



Mime
View raw message