You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by me...@apache.org on 2023/12/11 12:27:44 UTC
(myfaces) branch 2.3.x updated: Backport MYFACES-4646 (#657)
This is an automated email from the ASF dual-hosted git repository.
melloware pushed a commit to branch 2.3.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/2.3.x by this push:
new 26873d965 Backport MYFACES-4646 (#657)
26873d965 is described below
commit 26873d965ef47770aafed1c126ef5ef9d8ab170c
Author: Markus Jung <54...@users.noreply.github.com>
AuthorDate: Mon Dec 11 13:27:38 2023 +0100
Backport MYFACES-4646 (#657)
only add FacesMessage detail to ValidatorException message if detail is not empty
---
.../javax/faces/validator/ValidatorException.java | 4 +-
.../faces/validator/ValidatorExceptionTest.java | 114 +++++++++++++++++++++
2 files changed, 116 insertions(+), 2 deletions(-)
diff --git a/api/src/main/java/javax/faces/validator/ValidatorException.java b/api/src/main/java/javax/faces/validator/ValidatorException.java
index 0e14966f7..d280b8199 100755
--- a/api/src/main/java/javax/faces/validator/ValidatorException.java
+++ b/api/src/main/java/javax/faces/validator/ValidatorException.java
@@ -75,7 +75,7 @@ public class ValidatorException
if (summary != null)
{
- if (detail != null)
+ if (detail != null && !detail.isEmpty())
{
return summary + ": " + detail;
}
@@ -106,7 +106,7 @@ public class ValidatorException
{
sb.append(separator);
sb.append(summary);
- if (detail != null)
+ if (detail != null && !detail.isEmpty())
{
sb.append(": ");
sb.append(detail);
diff --git a/api/src/test/java/javax/faces/validator/ValidatorExceptionTest.java b/api/src/test/java/javax/faces/validator/ValidatorExceptionTest.java
new file mode 100644
index 000000000..3ef74ec43
--- /dev/null
+++ b/api/src/test/java/javax/faces/validator/ValidatorExceptionTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 javax.faces.validator;
+
+import org.junit.Test;
+
+import javax.faces.application.FacesMessage;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class ValidatorExceptionTest
+{
+ @Test
+ public void singleFacesMessageNullSummary()
+ {
+ FacesMessage message = new FacesMessage(null, null);
+
+ ValidatorException exception = new ValidatorException(message);
+ assertEquals("", exception.getMessage());
+ }
+
+ @Test
+ public void singleFacesMessageWithDetail()
+ {
+ FacesMessage message = new FacesMessage("summary", "detail");
+
+ ValidatorException exception = new ValidatorException(message);
+ assertEquals("summary: detail", exception.getMessage());
+ }
+
+ @Test
+ public void singleFacesMessageEmptyDetail()
+ {
+ FacesMessage message = new FacesMessage("summary", "");
+
+ ValidatorException exception = new ValidatorException(message);
+ assertEquals("summary", exception.getMessage());
+
+ }
+
+ @Test
+ public void singleFacesMaessageNullDetail()
+ {
+ FacesMessage message = new FacesMessage("summary", null);
+
+ ValidatorException exception = new ValidatorException(message);
+ assertEquals("summary: summary", exception.getMessage());
+ }
+
+ @Test
+ public void multipleFacesMessagesSummaryNull()
+ {
+ List<FacesMessage> messages = new ArrayList<>();
+ messages.add(new FacesMessage(null, null));
+ messages.add(new FacesMessage("summary2", "detail2"));
+
+ ValidatorException exception = new ValidatorException(messages);
+ assertEquals("summary2: detail2", exception.getMessage());
+ }
+
+
+ @Test
+ public void multipleFacesMessagesWithDetail()
+ {
+ List<FacesMessage> messages = new ArrayList<>();
+ messages.add(new FacesMessage("summary1", "detail1"));
+ messages.add(new FacesMessage("summary2", "detail2"));
+
+ ValidatorException exception = new ValidatorException(messages);
+ assertEquals("summary1: detail1, summary2: detail2", exception.getMessage());
+ }
+
+ @Test
+ public void multipleFacesMessagesEmptyDetail()
+ {
+ List<FacesMessage> messages = new ArrayList<>();
+ messages.add(new FacesMessage("summary1", ""));
+ messages.add(new FacesMessage("summary2", "detail2"));
+
+ ValidatorException exception = new ValidatorException(messages);
+ assertEquals("summary1, summary2: detail2", exception.getMessage());
+
+ }
+
+ @Test
+ public void multipleFacesMessagesNullDetail()
+ {
+ List<FacesMessage> messages = new ArrayList<>();
+ messages.add(new FacesMessage("summary1", null));
+ messages.add(new FacesMessage("summary2", "detail2"));
+
+ ValidatorException exception = new ValidatorException(messages);
+ assertEquals("summary1: summary1, summary2: detail2", exception.getMessage());
+ }
+}