ApplicationContextRunner для тестирования нашего весеннего загрузчика: есть ли способ переименовать ресурсы classpath для конкретного теста c? - PullRequest
0 голосов
/ 18 апреля 2020

У меня есть этот тест:

public class OptaPlannerAutoConfigurationTest {

    private final ApplicationContextRunner contextRunner;

    public OptaPlannerAutoConfigurationTest() {
        this.contextRunner = new ApplicationContextRunner()
                .withConfiguration(AutoConfigurations.of(OptaPlannerAutoConfiguration.class))
                .withUserConfiguration(TestConfiguration.class);
    }

    @Test
    public void solverConfigXml_none() {
        contextRunner
                 // 95% of tests do this
                .withClassLoader(new FilteredClassLoader(new ClassPathResource("solverConfig.xml")))
        ...
    }   

    @Test
    public void solverConfigXml_default() {
        contextRunner
                // no filter, 5% of tests
        ...
    }
}

Но я не хочу фильтровать наши те solverConfig.xml для 95% моих тестов. Я предпочел бы переименовать этот файл в movingSolverConfig.xml и сделать это в одном тесте, который нуждается в этом:

    @Test
    public void solverConfigXml_default() {
        contextRunner
                 // Rename it on the fly for that 5% of tests
                .withClassLoader(new RenameClassLoader(new ClassPathResource("movingSolverConfig.xml"), "solverConfig.xml"))
        ...
    } 

Есть ли что-то подобное RenameClassLoader?

...