← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16539: Refactored test which failed at random due to relying on collection ordering.

 

------------------------------------------------------------
revno: 16539
committer: Halvdan Hoem Grelland <halvdanhg@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-08-27 13:57:02 +0200
message:
  Refactored test which failed at random due to relying on collection ordering.
modified:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/organisationunit/OrganisationUnitServiceTest.java	2014-08-27 11:57:02 +0000
@@ -589,30 +589,37 @@
         throws Exception
     {
         OrganisationUnitGroup group1 = new OrganisationUnitGroup( "organisationUnitGroupName1" );
-        int gid1 = organisationUnitGroupService.addOrganisationUnitGroup( group1 );
-
         OrganisationUnitGroup group2 = new OrganisationUnitGroup( "organisationUnitGroupName2" );
-        int gid2 = organisationUnitGroupService.addOrganisationUnitGroup( group2 );
-
         OrganisationUnitGroup group3 = new OrganisationUnitGroup( "organisationUnitGroupName3" );
-        int gid3 = organisationUnitGroupService.addOrganisationUnitGroup( group3 );
-
         OrganisationUnitGroup group4 = new OrganisationUnitGroup( "organisationUnitGroupName4" );
-        int gid4 = organisationUnitGroupService.addOrganisationUnitGroup( group4 );
-
-        Iterator<OrganisationUnitGroup> iterator = organisationUnitGroupService.getAllOrganisationUnitGroups().iterator();
-
-        OrganisationUnitGroup organisationUnitGroup1 = iterator.next();
-        assertTrue( organisationUnitGroup1.getId() == gid1 );
-
-        OrganisationUnitGroup organisationUnitGroup2 = iterator.next();
-        assertTrue( organisationUnitGroup2.getId() == gid2 );
-
-        OrganisationUnitGroup organisationUnitGroup3 = iterator.next();
-        assertTrue( organisationUnitGroup3.getId() == gid3 );
-
-        OrganisationUnitGroup organisationUnitGroup4 = iterator.next();
-        assertTrue( organisationUnitGroup4.getId() == gid4 );
+
+        Collection<OrganisationUnitGroup> groups = new ArrayList<>();
+        groups.add( group1 );
+        groups.add( group2 );
+        groups.add( group3 );
+        groups.add( group4 );
+
+        ArrayList<Integer> groupIds = new ArrayList<>();
+
+        for ( OrganisationUnitGroup group : groups )
+        {
+            groupIds.add( organisationUnitGroupService.addOrganisationUnitGroup( group ) );
+        }
+
+        Collection<OrganisationUnitGroup> fetchedGroups = organisationUnitGroupService.getAllOrganisationUnitGroups();
+
+        ArrayList<Integer> fetchedGroupIds = new ArrayList<>();
+
+        for ( OrganisationUnitGroup group : fetchedGroups )
+        {
+            fetchedGroupIds.add( group.getId() );
+        }
+
+        assertTrue( fetchedGroups.size() == 4 );
+        assertTrue( fetchedGroups.containsAll( groups ));
+
+        assertTrue( fetchedGroupIds.size() == 4 );
+        assertTrue( fetchedGroupIds.containsAll( groupIds ) );
     }
 
     @Test