Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 修复i18n MessageSource测试类 #301

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@

package org.ballcat.i18n;

import java.io.IOException;
import java.util.Locale;

import org.junit.jupiter.api.Test;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class HierarchicalMessageSourceTest {

MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new WildcardReloadableResourceBundleMessageSource();
// Specify the location of the properties file
messageSource.setBasename("classpath:test-*");
messageSource.setBasename("classpath*:test-*");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setFallbackToSystemLocale(false);

Expand All @@ -40,6 +44,17 @@ MessageSource messageSource() {
return dynamicMessageSource;
}

@Test
void testResourcePatternResolver() throws IOException {
final PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath:test*" + ".properties");
assertNotNull(resources);
assertEquals(0, resources.length);
resources = resolver.getResources("classpath*:test*" + ".properties");
assertNotNull(resources);
assertEquals(3, resources.length);
}

@Test
void testParentMessageSource() {
MessageSource messageSource = messageSource();
Expand Down
Loading