Search in sources :

Example 1 with DummyEnvironment

use of org.springframework.core.env.DummyEnvironment in project spring-framework by spring-projects.

the class DispatcherServletTests method environmentOperations.

@Test
public void environmentOperations() {
    DispatcherServlet servlet = new DispatcherServlet();
    ConfigurableEnvironment defaultEnv = servlet.getEnvironment();
    assertThat(defaultEnv, notNullValue());
    ConfigurableEnvironment env1 = new StandardServletEnvironment();
    // should succeed
    servlet.setEnvironment(env1);
    assertThat(servlet.getEnvironment(), sameInstance(env1));
    try {
        servlet.setEnvironment(new DummyEnvironment());
        fail("expected IllegalArgumentException for non-configurable Environment");
    } catch (IllegalArgumentException ex) {
    }
    class CustomServletEnvironment extends StandardServletEnvironment {
    }
    @SuppressWarnings("serial") DispatcherServlet custom = new DispatcherServlet() {

        @Override
        protected ConfigurableWebEnvironment createEnvironment() {
            return new CustomServletEnvironment();
        }
    };
    assertThat(custom.getEnvironment(), instanceOf(CustomServletEnvironment.class));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) DummyEnvironment(org.springframework.core.env.DummyEnvironment) StandardServletEnvironment(org.springframework.web.context.support.StandardServletEnvironment) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 DummyEnvironment (org.springframework.core.env.DummyEnvironment)1 StandardServletEnvironment (org.springframework.web.context.support.StandardServletEnvironment)1