### Question:
ReplaceFilterFactory implements TokenFilterFactory { public void preloadResources(Properties properties) throws IOException { String filePath = properties.getProperty(FILE_PATH_PARAMETER); Map<String, String> mapping = getMapping(filePath); } ReplaceFilterFactory(MapFileReaderFactory mapFileReaderFactory); TokenFilter createTokenFilter(TokenStream tokenStream, Properties properties); void preloadResources(Properties properties); Map<String, String> getMapping(String filePath); static final String FILE_PATH_PARAMETER; }### Answer:
@Test public void testPreloadResources() throws Exception{ Properties properties = new Properties(); properties.setProperty(ReplaceFilterFactory.FILE_PATH_PARAMETER, TEST_FILE_1); expect(mapFileReaderFactory.createMapFileReader(TEST_FILE_1)).andReturn(mapFileReader); expect(mapFileReader.readMap()).andReturn(mapping); replay(mapFileReaderFactory); replay(mapFileReader); replaceFilterFactory.preloadResources(properties); Map<String, String> cachedMapping = replaceFilterFactory.getCachedMappings().get(TEST_FILE_1); assertEquals(mapping, cachedMapping); verify(mapFileReaderFactory); verify(mapFileReader); reset(mapFileReaderFactory); reset(mapFileReader); replay(mapFileReaderFactory); replay(mapFileReader); replaceFilterFactory.preloadResources(properties); cachedMapping = replaceFilterFactory.getCachedMappings().get(TEST_FILE_1); assertEquals(mapping, cachedMapping); verify(mapFileReaderFactory); verify(mapFileReader); }