### Question:
MessageSourceLoader { public static MessageSource loadMessageSource(ExecutionContext exContext, ResourceContainer resourceContainer, RepositoryService repository) { List<ResourceReference> resources = resourceContainer.getResources(); Map<String, RepositoryResourceKey> map = new LinkedHashMap<String, RepositoryResourceKey>(); Set<String> baseNames = new LinkedHashSet<String>(); for (ResourceReference resRef : resources) { Resource genericResource = getResource(exContext, repository, resRef); if (!isBundle(genericResource)) { continue; } FileResource resource = (FileResource) genericResource; String fileName = resource.getName(); map.put(fileName, new RepositoryResourceKey(resource)); String baseName = ResourceBundleHelper.getBaseName(fileName); if (!baseName.isEmpty()) { baseNames.add(baseName); } } if (map.isEmpty()) { return null; } else { setupThreadRepositoryContext(exContext, repository); JasperResourceBundleMessageSource messageSource = new JasperResourceBundleMessageSource(); messageSource.setBundleClassLoader( new RepositoryResourceClassLoader( Thread.currentThread().getContextClassLoader(), map, false, RepositoryUtil.getThreadRepositoryContext())); messageSource.setBasenames(baseNames.toArray(new String[baseNames.size()])); return messageSource; } }  static MessageSource loadMessageSource(ExecutionContext exContext, ResourceContainer resourceContainer, RepositoryService repository); static List<String> getBaseNames(ExecutionContext exContext, ResourceContainer resourceContainer, RepositoryService repository);  }### Answer:
@Test public void ensureBundleUseLocalizedMessageIfPresent() throws Exception { final FileResource resource1 = createResource(FileResource.class.getName(), "bundle.properties", "prop", "prop1=prop1.base"); final FileResource resource2 = createResource(FileResource.class.getName(), "bundle_yy.properties", "prop", "prop1=prop1.yy\r\nprop2=prop2.yy"); final FileResource resource3 = createResource(FileResource.class.getName(), "bundle_xx.properties", "prop", "prop1=prop1.xx\r\nprop3=prop3.xx"); final ResourceContainer resourceContainer = createResourceContainer(resource1, resource2, resource3); final RepositoryService repositoryService = createRepositoryService(resource1, resource2, resource3); MessageSource messageSource = MessageSourceLoader.loadMessageSource(null, resourceContainer, repositoryService); assertEquals("prop1.base", messageSource.getMessage("prop1", null, new Locale("zz"))); assertEquals("prop1.yy", messageSource.getMessage("prop1", null, new Locale("yy"))); assertEquals("prop2.yy", messageSource.getMessage("prop2", null, new Locale("yy"))); assertEquals("prop1.xx", messageSource.getMessage("prop1", null, new Locale("xx"))); assertEquals("prop3.xx", messageSource.getMessage("prop3", null, new Locale("xx"))); }
@Test public void ensureExceptionIsThrownIfNoBundles() throws Exception { final ResourceContainer resourceContainer = createResourceContainer(); final RepositoryService repositoryService = createRepositoryService(); MessageSource messageSource = MessageSourceLoader.loadMessageSource(null, resourceContainer, repositoryService); assertNull(messageSource); }