Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
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.
-
Hide
- tester.zip
- 01/Nov/10 3:39 PM
- 296 kB
- John Scheeser
-
- tester/.classpath 0.7 kB
- tester/.project 0.5 kB
- tester/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- tester/application.properties 0.2 kB
- tester/grails-app/conf/BootStrap.groovy 0.2 kB
- __MACOSX/tester/.../conf/._BootStrap.groovy 0.2 kB
- tester/grails-app/.../BuildConfig.groovy 1 kB
- tester/grails-app/conf/Config.groovy 3 kB
- tester/grails-app/conf/DataSource.groovy 0.8 kB
- tester/grails-app/.../resources.groovy 0.0 kB
- tester/grails-app/.../UrlMappings.groovy 0.2 kB
- tester/grails-app/.../TestController.groovy 0.2 kB
- __MACOSX/tester/.../._TestController.groovy 0.2 kB
- tester/grails-app/.../tester/Test.groovy 0.0 kB
- __MACOSX/tester/.../tester/._Test.groovy 0.2 kB
- tester/grails-app/.../tester/TestEnum.groovy 0.0 kB
- __MACOSX/tester/.../tester/._TestEnum.groovy 0.2 kB
- tester/grails-app/.../messages.properties 3 kB
- tester/grails-app/.../messages_da.properties 3 kB
- tester/grails-app/.../messages_de.properties 4 kB
- tester/grails-app/.../messages_es.properties 3 kB
- tester/grails-app/.../messages_fr.properties 2 kB
- tester/grails-app/.../messages_it.properties 2 kB
- tester/grails-app/.../messages_ja.properties 2 kB
- tester/grails-app/.../messages_nl.properties 3 kB
- tester/.../messages_pt_BR.properties 3 kB
- tester/.../messages_pt_PT.properties 3 kB
- tester/grails-app/.../messages_ru.properties 4 kB
- tester/grails-app/.../messages_th.properties 5 kB
- tester/.../messages_zh_CN.properties 2 kB
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
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)
The sorting described is consistent with the natural sort of java enums. In hindsight I question if this is a problem at all.