Skip to content

Commit 753b05e

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
1 parent 0d029be commit 753b05e

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
@@ -671,23 +671,34 @@ public ConceptName getName(Locale locale, boolean exact) {
671671

672672
if (log.isDebugEnabled())
673673
log.debug("Getting conceptName for locale: " + locale);
674-
if (exact && locale != null) {
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;
686-
687-
} else {
688-
//just get any name
689-
return getName();
674+
675+
ConceptName exactName = getNameInLocale(locale);
676+
677+
if (exactName != null || exact) {
678+
return exactName;
690679
}
680+
681+
//just get any name
682+
return getName();
683+
}
684+
685+
/**
686+
* Gets the best name in the specified locale.
687+
* @param locale
688+
* @return null if name in given locale doesn't exist
689+
*/
690+
private ConceptName getNameInLocale(Locale locale) {
691+
ConceptName preferredName = getPreferredName(locale);
692+
if (preferredName != null)
693+
return preferredName;
694+
695+
ConceptName fullySpecifiedName = getFullySpecifiedName(locale);
696+
if (fullySpecifiedName != null)
697+
return fullySpecifiedName;
698+
else if (getSynonyms(locale).size() > 0)
699+
return getSynonyms(locale).iterator().next();
700+
701+
return null;
691702
}
692703

693704
/**
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 ConceptIT 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.