@Test
public void testFallback() throws Exception {

    String[] stagingProfiles = {SystemInfo.STAGE_TESTING, SystemInfo.STAGE_DEVELOPMENT, SystemInfo.STAGE_PRODUCTION};
    final Path file0 = IO.toPath(FormatterApiIntegrationTest.class.getResource("template-cache-test/formatter/file0.txt").toURI());
    final Path file1 = IO.toPath(FormatterApiIntegrationTest.class.getResource("template-cache-test/schema1/formatter/file1.txt").toURI());
    final Path file2 = IO.toPath(FormatterApiIntegrationTest.class.getResource("template-cache-test/schema2/formatter/file2.txt").toURI());
    final Path file3 = IO.toPath(FormatterApiIntegrationTest.class.getResource("template-cache-test/file3.txt").toURI());
    for (String profile : stagingProfiles) {
        SchemaManager schemaManager = Mockito.mock(SchemaManager.class);
        Mockito.when(schemaManager.getSchemaDir("schema1")).thenReturn(file1.getParent().getParent());
        Mockito.when(schemaManager.getSchemaDir("schema2")).thenReturn(file2.getParent().getParent());
        ConfigurableApplicationContext context = Mockito.mock(ConfigurableApplicationContext.class);
        ApplicationContextHolder.set(context);
        Mockito.when(context.getBean(SystemInfo.class)).thenReturn(SystemInfo.createForTesting(SystemInfo.STAGE_PRODUCTION));
        Mockito.when(context.getBean(SchemaManager.class)).thenReturn(schemaManager);
        final TemplateCache templateCache = new TemplateCache();
        templateCache.xmlTemplateParser = AbstractTemplateParserTest.createTestParser(SystemInfo.STAGE_TESTING);
        final Path schemaAndRootDir = file0.getParent().getParent();
        final Map<String, Object> emptyMap = Collections.emptyMap();
        FileResult fileResult = templateCache.createFileResult(file0.getParent(), schemaAndRootDir,
            schemaAndRootDir, file0.getFileName().toString(), emptyMap);
        assertEquals(new String(Files.readAllBytes(file0), Constants.CHARSET).length(), fileResult.toString().length());
        fileResult = templateCache.createFileResult(file0.getParent(), schemaAndRootDir,
            schemaAndRootDir, file1.getFileName().toString(), emptyMap);
        assertEquals(new String(Files.readAllBytes(file1), Constants.CHARSET).length(), fileResult.toString().length());
        fileResult = templateCache.createFileResult(file0.getParent(), schemaAndRootDir,
            schemaAndRootDir, file2.getFileName().toString(), emptyMap);
        assertEquals(new String(Files.readAllBytes(file2), Constants.CHARSET).length(), fileResult.toString().length());
        fileResult = templateCache.createFileResult(file0.getParent(), schemaAndRootDir,
            schemaAndRootDir, file3.getFileName().toString(), emptyMap);
        assertEquals(new String(Files.readAllBytes(file3), Constants.CHARSET).length(), fileResult.toString().length());
    }
}