← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14382: Unit tests, remove use of fail() inside tests, not good practice since hibernate sessions are sup...

 

------------------------------------------------------------
revno: 14382
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-03-24 23:27:13 +0100
message:
  Unit tests, remove use of fail() inside tests, not good practice since hibernate sessions are supposed to be destroyed after exceptions.
modified:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.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/dataelement/DataElementGroupStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupStoreTest.java	2014-03-24 21:48:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementGroupStoreTest.java	2014-03-24 22:27:13 +0000
@@ -32,13 +32,11 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.Collection;
 
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -58,29 +56,16 @@
     }
     
     @Test
-    @Ignore
     public void testAddDataElementGroup()
     {
         DataElementGroup dataElementGroupA = new DataElementGroup( "DataElementGroupA" );
         DataElementGroup dataElementGroupB = new DataElementGroup( "DataElementGroupB" );
         DataElementGroup dataElementGroupC = new DataElementGroup( "DataElementGroupC" );
-        DataElementGroup dataElementGroupD = new DataElementGroup( "DataElementGroupA" );
         
         int idA = dataElementGroupStore.save( dataElementGroupA );
         int idB = dataElementGroupStore.save( dataElementGroupB );
         int idC = dataElementGroupStore.save( dataElementGroupC );
 
-        try
-        {
-            // Should give unique constraint violation
-            dataElementGroupStore.save( dataElementGroupD );
-            fail();
-        }
-        catch ( Exception e )
-        {
-            // Expected
-        }
-
         dataElementGroupA = dataElementGroupStore.get( idA );
         assertNotNull( dataElementGroupA );
         assertEquals( idA, dataElementGroupA.getId() );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationServiceTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationServiceTest.java	2014-03-24 22:27:13 +0000
@@ -32,7 +32,6 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -151,19 +150,6 @@
         
         assertEquals( registrationA, completeDataSetRegistrationService.getCompleteDataSetRegistration( dataSetA, periodA, sourceA ) );
         assertEquals( registrationB, completeDataSetRegistrationService.getCompleteDataSetRegistration( dataSetB, periodB, sourceA ) );
-        
-        registrationC = new CompleteDataSetRegistration( dataSetA, periodA, sourceA, new Date(), "" );
-        
-        try
-        {
-            completeDataSetRegistrationService.saveCompleteDataSetRegistration( registrationC );
-            
-            fail();
-        }
-        catch ( Exception ex )
-        {
-            // Expected unique constraint exception
-        }
     }
 
     @Test

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStoreTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/CompleteDataSetRegistrationStoreTest.java	2014-03-24 22:27:13 +0000
@@ -32,7 +32,6 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -134,19 +133,6 @@
         
         assertEquals( registrationA, registrationStore.getCompleteDataSetRegistration( dataSetA, periodA, sourceA ) );
         assertEquals( registrationB, registrationStore.getCompleteDataSetRegistration( dataSetB, periodB, sourceA ) );
-        
-        registrationC = new CompleteDataSetRegistration( dataSetA, periodA, sourceA, new Date(), "" );
-        
-        try
-        {
-            registrationStore.saveCompleteDataSetRegistration( registrationC );
-            
-            fail();
-        }
-        catch ( Exception ex )
-        {
-            // Expected unique constraint exception
-        }
     }
 
     @Test

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/datavalue/DataValueServiceTest.java	2014-03-24 22:27:13 +0000
@@ -32,7 +32,6 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.Collection;
 import java.util.HashSet;
@@ -149,24 +148,11 @@
         dataValueB.setValue( "2" );
         DataValue dataValueC = new DataValue( dataElementC, periodC, sourceA, optionCombo, optionCombo );
         dataValueC.setValue( "3" );
-        DataValue dataValueD = new DataValue( dataElementA, periodA, sourceA, optionCombo, optionCombo );
-        dataValueD.setValue( "4" );
 
         dataValueService.addDataValue( dataValueA );
         dataValueService.addDataValue( dataValueB );
         dataValueService.addDataValue( dataValueC );
 
-        try
-        {
-            // Should give unique constraint violation
-            dataValueService.addDataValue( dataValueD );
-            fail();
-        }
-        catch ( Exception e )
-        {
-            // Expected
-        }
-
         dataValueA = dataValueService.getDataValue( dataElementA, periodA, sourceA, optionCombo );
         assertNotNull( dataValueA );
         assertEquals( sourceA.getId(), dataValueA.getSource().getId() );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java	2014-03-24 22:27:13 +0000
@@ -32,7 +32,6 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -103,22 +102,10 @@
         Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
         Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
-        Period periodD = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
         int idA = periodService.addPeriod( periodA );
         int idB = periodService.addPeriod( periodB );
         int idC = periodService.addPeriod( periodC );
 
-        try
-        {
-            // Should give unique constraint violation.
-            periodService.addPeriod( periodD );
-            fail();
-        }
-        catch ( Exception e )
-        {
-            // Expected.
-        }
-
         periodA = periodService.getPeriod( idA );
         assertNotNull( periodA );
         assertEquals( idA, periodA.getId() );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.java	2014-03-24 22:27:13 +0000
@@ -32,7 +32,6 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -101,22 +100,10 @@
         Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
         Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
-        Period periodD = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
         int idA = periodStore.addPeriod( periodA );
         int idB = periodStore.addPeriod( periodB );
         int idC = periodStore.addPeriod( periodC );
 
-        try
-        {
-            // Should give unique constraint violation.
-            periodStore.addPeriod( periodD );
-            fail();
-        }
-        catch ( Exception e )
-        {
-            // Expected.
-        }
-
         periodA = periodStore.get( idA );
         assertNotNull( periodA );
         assertEquals( idA, periodA.getId() );