You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2011/05/17 20:10:23 UTC

svn commit: r1104445 - in /myfaces/core/branches/2.0.x/api/src: main/java/javax/faces/application/FacesMessage.java test/java/javax/faces/application/FacesMessageTest.java

Author: jakobk
Date: Tue May 17 18:10:22 2011
New Revision: 1104445

URL: http://svn.apache.org/viewvc?rev=1104445&view=rev
Log:
MYFACES-3140 FacesMessage.VALUES is not ordered properly (merge changes in 2.0.x branch)

Modified:
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/application/FacesMessage.java
    myfaces/core/branches/2.0.x/api/src/test/java/javax/faces/application/FacesMessageTest.java

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/application/FacesMessage.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/application/FacesMessage.java?rev=1104445&r1=1104444&r2=1104445&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/application/FacesMessage.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/application/FacesMessage.java Tue May 17 18:10:22 2011
@@ -94,8 +94,11 @@ public class FacesMessage implements Ser
         map.put(SEVERITY_WARN.toString(), SEVERITY_WARN);
         map.put(SEVERITY_ERROR.toString(), SEVERITY_ERROR);
         map.put(SEVERITY_FATAL.toString(), SEVERITY_FATAL);
-        VALUES = Collections.unmodifiableList(new ArrayList<FacesMessage.Severity>(map.values()));
         VALUES_MAP = Collections.unmodifiableMap(map);
+
+        List<FacesMessage.Severity> severityList = new ArrayList<FacesMessage.Severity>(map.values());
+        Collections.sort(severityList); // the JSF spec requires it to be sorted
+        VALUES = Collections.unmodifiableList(severityList);
     }
 
     private FacesMessage.Severity _severity;

Modified: myfaces/core/branches/2.0.x/api/src/test/java/javax/faces/application/FacesMessageTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/test/java/javax/faces/application/FacesMessageTest.java?rev=1104445&r1=1104444&r2=1104445&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/test/java/javax/faces/application/FacesMessageTest.java (original)
+++ myfaces/core/branches/2.0.x/api/src/test/java/javax/faces/application/FacesMessageTest.java Tue May 17 18:10:22 2011
@@ -21,6 +21,9 @@ package javax.faces.application;
 
 import junit.framework.TestCase;
 
+import javax.faces.application.FacesMessage.Severity;
+import java.util.Map;
+
 public class FacesMessageTest extends TestCase
 {
 
@@ -183,4 +186,26 @@ public class FacesMessageTest extends Te
         assertEquals(0, FacesMessage.SEVERITY_ERROR.compareTo(FacesMessage.SEVERITY_ERROR));
         assertEquals(0, FacesMessage.SEVERITY_FATAL.compareTo(FacesMessage.SEVERITY_FATAL));
     }
+
+    public void testSeverityValues()
+    {
+        // JSF spec requires this list to be sorted by ordinal
+        for (int i = 0, sz = FacesMessage.VALUES.size(); i < sz; i++)
+        {
+            FacesMessage.Severity severity = (Severity) FacesMessage.VALUES.get(i);
+            assertEquals(i + 1, severity.getOrdinal());
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testSeverityValuesMap()
+    {
+        Map<String, FacesMessage.Severity> severityMap = (Map<String, FacesMessage.Severity>) FacesMessage.VALUES_MAP;
+
+        for (Map.Entry<String, FacesMessage.Severity> e : severityMap.entrySet())
+        {
+            assertEquals(e.getKey(), e.getValue().toString());
+        }
+    }
+
 }