use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldNotFailIfProvider2HasNoAssociatedPerson.
@Test
public void compareProvidersByPersonName_shouldNotFailIfProvider2HasNoAssociatedPerson() {
Person person1 = new Person();
person1.addName(new PersonName("givenName", "middleName", "familyName"));
Provider provider1 = new Provider();
provider1.setPerson(person1);
Provider provider2 = new Provider();
int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
Assert.assertTrue("Expected a negative value but it was: " + actualValue, actualValue < 0);
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class ProviderByPersonNameComparatorTest method compareProvidersByPersonsName_shouldReturnNegativeIfPersonNameForProvider1ComesBeforeThatOfProvider2.
/**
* @see PersonByNameComparator#comparePersonsByName(org.openmrs.Person, org.openmrs.Person)
*/
@Test
public void compareProvidersByPersonsName_shouldReturnNegativeIfPersonNameForProvider1ComesBeforeThatOfProvider2() {
Person person1 = new Person();
person1.addName(new PersonName("givenName", "middleName", "familyName"));
Provider provider1 = new Provider();
provider1.setPerson(person1);
Person person2 = new Person();
person2.addName(new PersonName("givenName", "middleNamf", "familyName"));
Provider provider2 = new Provider();
provider2.setPerson(person2);
int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
Assert.assertTrue("Expected a negative value but it was: " + actualValue, actualValue < 0);
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class ProviderByPersonNameComparatorTest method compareProvidersByPersonName_shouldReturnZeroIfTheGivenNameMiddleNameAndFamilyNameMatch.
/**
* @see PersonByNameComparator#comparePersonsByName(Person,Person)
*/
@Test
public void compareProvidersByPersonName_shouldReturnZeroIfTheGivenNameMiddleNameAndFamilyNameMatch() {
Person person1 = new Person();
person1.addName(new PersonName("givenName", "middleName", "familyName"));
Provider provider1 = new Provider();
provider1.setPerson(person1);
Person person2 = new Person();
person2.addName(new PersonName("givenName", "middleName", "familyName"));
Provider provider2 = new Provider();
provider2.setPerson(person2);
int actualValue = new ProviderByPersonNameComparator().compare(provider1, provider2);
Assert.assertTrue("Expected zero but it was: " + actualValue, actualValue == 0);
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class UserByNameComparatorTest method compare_shouldSortUsersByPersonNames.
/**
* This tests sorting with the {@link UserByNameComparator} given a set of users with
* personNames
*
* @see UserByNameComparator#compare(User,User)
*/
@Test
public void compare_shouldSortUsersByPersonNames() {
Person person1 = new Person();
person1.addName(new PersonName("givenName", "middleName", "familyName"));
User user1 = new User(person1);
Person person2 = new Person();
person2.addName(new PersonName("givenName", "middleNamf", "familyName"));
User user2 = new User(person2);
Person person3 = new Person();
person3.addName(new PersonName("givenName", "middleNamg", "familyName"));
User user3 = new User(person3);
Person person4 = new Person();
person4.addName(new PersonName("givenName", "middleNamh", "familyName"));
User user4 = new User(person4);
List<User> listToSort = new ArrayList<>();
// add the users randomly
listToSort.add(user3);
listToSort.add(user1);
listToSort.add(user4);
listToSort.add(user2);
// sort the list with userByNameComparator
listToSort.sort(new UserByNameComparator());
// make sure that the users are sorted in the expected order
Iterator<User> it = listToSort.iterator();
Assert.assertTrue("Expected user1 to be the first in the sorted user list but wasn't", user1.equals(it.next()));
Assert.assertTrue("Expected user2 to be the second in the sorted user list but wasn't", user2.equals(it.next()));
Assert.assertTrue("Expected user3 to be the third in the sorted user list but wasn't", user3.equals(it.next()));
Assert.assertTrue("Expected user4 to be the fourth in the sorted user list but wasn't", user4.equals(it.next()));
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PersonServiceTest method parsePersonName_shouldNotFailWhenEndingWithAComma.
/**
* @see PersonService#parsePersonName(String)
*/
@Test
public void parsePersonName_shouldNotFailWhenEndingWithAComma() throws Exception {
PersonName pname = Context.getPersonService().parsePersonName("John,");
assertEquals("John", pname.getGivenName());
}
Aggregations