Skip to content

Commit

Permalink
Concept.getName(Locale) and Concept.getName(Locale, false) are broken…
Browse files Browse the repository at this point in the history
… - TRUNK-3981

Renamed ConceptGeNameMethodTest to ConceptIT, also cleaned up the code in Concept.getName(Locale, Boolean) - TRUNK-3981

applying auto format changes

Renamed ConceptIt to ConceptComponentTest
  • Loading branch information
akolodziejski authored and wluyima committed Aug 23, 2013
1 parent ad213ee commit 7b9daa8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 16 deletions.
43 changes: 27 additions & 16 deletions api/src/main/java/org/openmrs/Concept.java
Expand Up @@ -655,23 +655,34 @@ public ConceptName getName(Locale locale, boolean exact) {

if (log.isDebugEnabled())
log.debug("Getting conceptName for locale: " + locale);
if (exact && locale != null) {
ConceptName preferredName = getPreferredName(locale);
if (preferredName != null)
return preferredName;

ConceptName fullySpecifiedName = getFullySpecifiedName(locale);
if (fullySpecifiedName != null)
return fullySpecifiedName;
else if (getSynonyms(locale).size() > 0)
return getSynonyms(locale).iterator().next();

return null;

} else {
//just get any name
return getName();

ConceptName exactName = getNameInLocale(locale);

if (exactName != null || exact) {
return exactName;
}

//just get any name
return getName();
}

/**
* Gets the best name in the specified locale.
* @param locale
* @return null if name in given locale doesn't exist
*/
private ConceptName getNameInLocale(Locale locale) {
ConceptName preferredName = getPreferredName(locale);
if (preferredName != null)
return preferredName;

ConceptName fullySpecifiedName = getFullySpecifiedName(locale);
if (fullySpecifiedName != null)
return fullySpecifiedName;
else if (getSynonyms(locale).size() > 0)
return getSynonyms(locale).iterator().next();

return null;
}

/**
Expand Down
43 changes: 43 additions & 0 deletions api/src/test/java/org/openmrs/ConceptComponentTest.java
@@ -0,0 +1,43 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs;

import org.junit.Test;
import org.openmrs.test.BaseContextSensitiveTest;

import java.util.Locale;

import static org.junit.Assert.assertEquals;

/**
* Contains integration tests of the Concept class.
*/
public class ConceptComponentTest extends BaseContextSensitiveTest {

/**
* @verifies return a name in the matching locale if exact is set to false
* @see Concept#getName(java.util.Locale, boolean)
*/
@Test
public void getName_shouldReturnANameInTheMatchingLocaleIfExactIsSetToFalse() throws Exception {
Concept concept = new Concept();
ConceptName frenchConceptName = new ConceptName("frenchName", Locale.FRENCH);
ConceptName englishConceptName = new ConceptName("enqlishName", Locale.ENGLISH);

concept.addName(englishConceptName);
concept.addName(frenchConceptName);

assertEquals(frenchConceptName, concept.getName(Locale.FRENCH));
}
}

0 comments on commit 7b9daa8

Please sign in to comment.