← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2690: Don't add unwanted spaces to fullName, added a little test

 

------------------------------------------------------------
revno: 2690
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-01-21 09:38:36 +0530
message:
  Don't add unwanted spaces to fullName, added a little test
added:
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/patient/
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/patient/PatientTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.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-api/src/main/java/org/hisp/dhis/patient/Patient.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2011-01-11 01:56:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2011-01-21 04:08:36 +0000
@@ -452,7 +452,28 @@
 
     public String getFullName()
     {
-        return firstName + " " + middleName + " " + lastName;
+        boolean space = false;
+        String name = "";
+
+        if ( firstName != null && firstName.length() != 0 )
+        {
+            name = firstName;
+            space = true;
+        }
+        if ( middleName != null && middleName.length() != 0 )
+        {
+            if ( space )
+                name += " ";
+            name += middleName;
+            space = true;
+        }
+        if ( lastName != null && lastName.length() != 0 )
+        {
+            if ( space )
+                name += " ";
+            name += lastName;
+        }
+        return name;
     }
 
     public String getBloodGroup()

=== added directory 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/patient'
=== added file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/patient/PatientTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/patient/PatientTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/patient/PatientTest.java	2011-01-21 04:08:36 +0000
@@ -0,0 +1,35 @@
+package org.hisp.dhis.patient;
+
+import static junit.framework.Assert.*;
+
+import org.junit.Test;
+
+public class PatientTest
+{
+
+    
+    @Test
+    public void testFullname() {
+
+        Patient patient = new Patient();
+        
+        assertEquals( "", patient.getFullName() );
+        
+        patient.setFirstName( "firstName" );
+        assertEquals( "firstName", patient.getFullName() );
+        
+        patient.setLastName( "lastName" );
+        assertEquals( "firstName lastName", patient.getFullName() );
+
+        patient.setMiddleName( "middleName" );
+        assertEquals( "firstName middleName lastName", patient.getFullName() );
+
+        patient.setFirstName( "" );
+        assertEquals( "middleName lastName", patient.getFullName() );
+
+        patient.setFirstName( "firstName middleName lastName" );
+        patient.setMiddleName( null );
+        patient.setLastName( null );
+        assertEquals( "firstName middleName lastName", patient.getFullName() );
+    }
+}