commit
						68637fa86c
					
				| 
						 | 
					@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.io.PrintStream;
 | 
					import java.io.PrintStream;
 | 
				
			||||||
import java.io.UnsupportedEncodingException;
 | 
					import java.io.UnsupportedEncodingException;
 | 
				
			||||||
 | 
					import java.nio.charset.StandardCharsets;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.apache.commons.logging.Log;
 | 
					import org.apache.commons.logging.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -95,9 +96,11 @@ class SpringApplicationBannerPrinter {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private String createStringFromBanner(Banner banner, Environment environment, Class<?> mainApplicationClass)
 | 
						private String createStringFromBanner(Banner banner, Environment environment, Class<?> mainApplicationClass)
 | 
				
			||||||
			throws UnsupportedEncodingException {
 | 
								throws UnsupportedEncodingException {
 | 
				
			||||||
 | 
							String charset = environment.getProperty("spring.banner.charset", StandardCharsets.UTF_8.name());
 | 
				
			||||||
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 | 
							ByteArrayOutputStream baos = new ByteArrayOutputStream();
 | 
				
			||||||
		banner.printBanner(environment, mainApplicationClass, new PrintStream(baos));
 | 
							try (PrintStream printStream = new PrintStream(baos, false, charset)) {
 | 
				
			||||||
		String charset = environment.getProperty("spring.banner.charset", "UTF-8");
 | 
								banner.printBanner(environment, mainApplicationClass, printStream);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return baos.toString(charset);
 | 
							return baos.toString(charset);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,12 +16,19 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package org.springframework.boot;
 | 
					package org.springframework.boot;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.apache.commons.logging.Log;
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.aot.hint.RuntimeHints;
 | 
					import org.springframework.aot.hint.RuntimeHints;
 | 
				
			||||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
 | 
					import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
 | 
				
			||||||
 | 
					import org.springframework.context.support.GenericApplicationContext;
 | 
				
			||||||
 | 
					import org.springframework.core.io.Resource;
 | 
				
			||||||
 | 
					import org.springframework.core.io.ResourceLoader;
 | 
				
			||||||
 | 
					import org.springframework.mock.env.MockEnvironment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static org.assertj.core.api.Assertions.assertThat;
 | 
					import static org.assertj.core.api.Assertions.assertThat;
 | 
				
			||||||
 | 
					import static org.mockito.BDDMockito.then;
 | 
				
			||||||
 | 
					import static org.mockito.Mockito.mock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Tests for {@link SpringApplicationBannerPrinter}.
 | 
					 * Tests for {@link SpringApplicationBannerPrinter}.
 | 
				
			||||||
| 
						 | 
					@ -38,4 +45,15 @@ class SpringApplicationBannerPrinterTests {
 | 
				
			||||||
		assertThat(RuntimeHintsPredicates.resource().forResource("banner.txt")).accepts(runtimeHints);
 | 
							assertThat(RuntimeHintsPredicates.resource().forResource("banner.txt")).accepts(runtimeHints);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test
 | 
				
			||||||
 | 
						void shouldUseUtf8() {
 | 
				
			||||||
 | 
							ResourceLoader resourceLoader = new GenericApplicationContext();
 | 
				
			||||||
 | 
							Resource resource = resourceLoader.getResource("classpath:/banner-utf8.txt");
 | 
				
			||||||
 | 
							SpringApplicationBannerPrinter printer = new SpringApplicationBannerPrinter(resourceLoader,
 | 
				
			||||||
 | 
									new ResourceBanner(resource));
 | 
				
			||||||
 | 
							Log log = mock(Log.class);
 | 
				
			||||||
 | 
							printer.print(new MockEnvironment(), SpringApplicationBannerPrinterTests.class, log);
 | 
				
			||||||
 | 
							then(log).should().info("\uD83D\uDE0D Spring Boot! \uD83D\uDE0D\n\n");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					😍 Spring Boot! 😍
 | 
				
			||||||
		Loading…
	
		Reference in New Issue