Skip to content

Commit da1b8bf

Browse files
authored
#305 - Initializer Message Source should not throw an Exception if lo… (#306)
1 parent f9fdc57 commit da1b8bf

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

api/src/main/java/org/openmrs/module/initializer/InitializerMessageSource.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,15 @@ public synchronized void refreshCache() {
180180
Properties properties = resources.get(resourceName);
181181
String nameWithoutExtension = FilenameUtils.removeExtension(resourceName);
182182
Locale locale = getLocaleFromFileBaseName(nameWithoutExtension);
183-
log.trace("Adding " + properties.size() + " messages from " + resourceName + " in locale: " + locale);
184-
for (Object property : properties.keySet()) {
185-
String key = property.toString();
186-
String value = properties.getProperty(key);
187-
addPresentation(new PresentationMessage(key, locale, value, ""));
183+
if (locale == null) {
184+
log.warn("No valid locale could be inferred from resource: '" + resourceName + "', skipping");
185+
} else {
186+
log.trace("Adding " + properties.size() + " messages from " + resourceName + " in locale: " + locale);
187+
for (Object property : properties.keySet()) {
188+
String key = property.toString();
189+
String value = properties.getProperty(key);
190+
addPresentation(new PresentationMessage(key, locale, value, ""));
191+
}
188192
}
189193
}
190194
stopWatch.stop();
@@ -279,8 +283,7 @@ protected Locale getLocaleFromFileBaseName(String baseName) throws IllegalArgume
279283
log.trace(candidate + " is not a valid locale");
280284
}
281285
}
282-
String msg = "No valid locale could be inferred from the following file base name: '" + baseName + "'.";
283-
throw new IllegalArgumentException(msg);
286+
return null;
284287
}
285288

286289
/**

api/src/test/java/org/openmrs/module/initializer/InitializerMessageSourceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Locale;
1717

1818
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertNull;
1920

2021
public class InitializerMessageSourceTest {
2122

@@ -35,9 +36,8 @@ public void getLocaleFromFileBaseName_shouldInferValidLocale() {
3536
}
3637

3738
@Test
38-
public void getLocaleFromFileBaseName_shouldThrowIfNoValidLocaleAsSuffixToFileBaseName() {
39-
expectedException.expect(IllegalArgumentException.class);
40-
src.getLocaleFromFileBaseName("my_base_name");
39+
public void getLocaleFromFileBaseName_shouldReturnNullIfNoValidLocaleAsSuffixToFileBaseName() {
40+
assertNull(src.getLocaleFromFileBaseName("my_base_name"));
4141
}
4242

4343
@Test

0 commit comments

Comments
 (0)