Migrate file encoding initializer to listener
parent
4d28e1b601
commit
73c2216732
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.context.initializer;
|
|
||||||
|
|
||||||
import org.junit.Assume;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.boot.TestUtils;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.support.StaticApplicationContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Dave Syer
|
|
||||||
*/
|
|
||||||
public class FileEncodingApplicationContextInitializerTests {
|
|
||||||
|
|
||||||
private FileEncodingApplicationContextInitializer initializer = new FileEncodingApplicationContextInitializer();
|
|
||||||
private ConfigurableApplicationContext context;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void init() {
|
|
||||||
this.context = new StaticApplicationContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
|
||||||
public void testIllegalState() {
|
|
||||||
TestUtils.addEnviroment(this.context, "spring.mandatory_file_encoding:FOO");
|
|
||||||
this.initializer.initialize(this.context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSunnyDayNothingMandated() {
|
|
||||||
this.initializer.initialize(this.context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSunnyDayMandated() {
|
|
||||||
Assume.assumeNotNull(System.getProperty("file.encoding"));
|
|
||||||
TestUtils.addEnviroment(this.context,
|
|
||||||
"spring.mandatory_file_encoding:" + System.getProperty("file.encoding"));
|
|
||||||
this.initializer.initialize(this.context);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.context.listener;
|
||||||
|
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
|
||||||
|
import org.springframework.boot.TestUtils;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
public class FileEncodingApplicationListenerTests {
|
||||||
|
|
||||||
|
private FileEncodingApplicationListener initializer = new FileEncodingApplicationListener();
|
||||||
|
private ConfigurableEnvironment environment = new StandardEnvironment();
|
||||||
|
private SpringApplicationEnvironmentAvailableEvent event = new SpringApplicationEnvironmentAvailableEvent(
|
||||||
|
new SpringApplication(), this.environment, new String[0]);
|
||||||
|
|
||||||
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void testIllegalState() {
|
||||||
|
TestUtils.addEnviroment(this.environment, "spring.mandatory_file_encoding:FOO");
|
||||||
|
this.initializer.onApplicationEvent(this.event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSunnyDayNothingMandated() {
|
||||||
|
this.initializer.onApplicationEvent(this.event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSunnyDayMandated() {
|
||||||
|
Assume.assumeNotNull(System.getProperty("file.encoding"));
|
||||||
|
TestUtils.addEnviroment(this.environment, "spring.mandatory_file_encoding:"
|
||||||
|
+ System.getProperty("file.encoding"));
|
||||||
|
this.initializer.onApplicationEvent(this.event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue