Grails
  1. Grails
  2. GRAILS-6902

Mocked domain doesn't sort correctly on enum variable

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Not A Bug
    • Affects Version/s: 1.3.4
    • Fix Version/s: None
    • Component/s: Testing
    • Labels:
      None
    • Testcase included:
      yes

      Description

      If a domain object includes a variable with an enum type, sorting on that variable does not return the values in the correct alphabetical sort order when the domain is mocked during a unit test. It appears that instead of returning these alphabetically the enum values are sorted based on the order in which the enum constants are listed in the class file.

      An example grails app is attached that demonstrates this problem. The included unit test fails because the sorted test domain returns C (the first defined constant in the class file) instead of A when a list(sort, asc) is called on the mocked domain. To verify the expected behavior the included Test controller sorts bootstrapped data in ascending and descending order and the gsp prints the results. The values are printed A-Z and Z-A.

        Activity

        Hide
        John Scheeser added a comment -

        The sorting described is consistent with the natural sort of java enums. In hindsight I question if this is a problem at all.

        Show
        John Scheeser added a comment - The sorting described is consistent with the natural sort of java enums. In hindsight I question if this is a problem at all.
        Hide
        Bobby Warner added a comment -

        Right, the natural order implemented by Enum.compareTo is the order in which the constants are declared. So, closing this as not a bug. Thanks, Bobby

        http://docs.oracle.com/javase/6/docs/api/java/lang/Enum.html#compareTo(E)

        Show
        Bobby Warner added a comment - Right, the natural order implemented by Enum.compareTo is the order in which the constants are declared. So, closing this as not a bug. Thanks, Bobby http://docs.oracle.com/javase/6/docs/api/java/lang/Enum.html#compareTo(E )

          People

          • Assignee:
            Bobby Warner
            Reporter:
            John Scheeser
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development