Skip to content

Commit 7b9daa8

Browse files
akolodziejskiwluyima
authored andcommittedAug 23, 2013
Concept.getName(Locale) and Concept.getName(Locale, false) are broken - 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
1 parent ad213ee commit 7b9daa8

File tree

2 files changed

+70
-16
lines changed

2 files changed

+70
-16
lines changed
 

‎api/src/main/java/org/openmrs/Concept.java

+27-16
Original file line numberDiff line numberDiff line change
@@ -655,23 +655,34 @@ public ConceptName getName(Locale locale, boolean exact) {
655655

656656
if (log.isDebugEnabled())
657657
log.debug("Getting conceptName for locale: " + locale);
658-
if (exact && locale != null) {
659-
ConceptName preferredName = getPreferredName(locale);
660-
if (preferredName != null)
661-
return preferredName;
662-
663-
ConceptName fullySpecifiedName = getFullySpecifiedName(locale);
664-
if (fullySpecifiedName != null)
665-
return fullySpecifiedName;
666-
else if (getSynonyms(locale).size() > 0)
667-
return getSynonyms(locale).iterator().next();
668-
669-
return null;
670-
671-
} else {
672-
//just get any name
673-
return getName();
658+
659+
ConceptName exactName = getNameInLocale(locale);
660+
661+
if (exactName != null || exact) {
662+
return exactName;
674663
}
664+
665+
//just get any name
666+
return getName();
667+
}
668+
669+
/**
670+
* Gets the best name in the specified locale.
671+
* @param locale
672+
* @return null if name in given locale doesn't exist
673+
*/
674+
private ConceptName getNameInLocale(Locale locale) {
675+
ConceptName preferredName = getPreferredName(locale);
676+
if (preferredName != null)
677+
return preferredName;
678+
679+
ConceptName fullySpecifiedName = getFullySpecifiedName(locale);
680+
if (fullySpecifiedName != null)
681+
return fullySpecifiedName;
682+
else if (getSynonyms(locale).size() > 0)
683+
return getSynonyms(locale).iterator().next();
684+
685+
return null;
675686
}
676687

677688
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* The contents of this file are subject to the OpenMRS Public License
3+
* Version 1.0 (the "License"); you may not use this file except in
4+
* compliance with the License. You may obtain a copy of the License at
5+
* http://license.openmrs.org
6+
*
7+
* Software distributed under the License is distributed on an "AS IS"
8+
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9+
* License for the specific language governing rights and limitations
10+
* under the License.
11+
*
12+
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
13+
*/
14+
package org.openmrs;
15+
16+
import org.junit.Test;
17+
import org.openmrs.test.BaseContextSensitiveTest;
18+
19+
import java.util.Locale;
20+
21+
import static org.junit.Assert.assertEquals;
22+
23+
/**
24+
* Contains integration tests of the Concept class.
25+
*/
26+
public class ConceptComponentTest extends BaseContextSensitiveTest {
27+
28+
/**
29+
* @verifies return a name in the matching locale if exact is set to false
30+
* @see Concept#getName(java.util.Locale, boolean)
31+
*/
32+
@Test
33+
public void getName_shouldReturnANameInTheMatchingLocaleIfExactIsSetToFalse() throws Exception {
34+
Concept concept = new Concept();
35+
ConceptName frenchConceptName = new ConceptName("frenchName", Locale.FRENCH);
36+
ConceptName englishConceptName = new ConceptName("enqlishName", Locale.ENGLISH);
37+
38+
concept.addName(englishConceptName);
39+
concept.addName(frenchConceptName);
40+
41+
assertEquals(frenchConceptName, concept.getName(Locale.FRENCH));
42+
}
43+
}

0 commit comments

Comments
 (0)
Please sign in to comment.