AbstractAggregatorImpl extends HttpServlet implements IAggregator { protected File initWorkingDirectory(File defaultLocation, Map<String, String> configMap, String versionString) throws FileNotFoundException { return initWorkingDirectory(defaultLocation, configMap, versionString, Collections.<String>emptySet()); }  @Override void init(ServletConfig servletConfig); @Override void destroy(); @Override boolean reloadConfig(); @Override IDependencies getDependencies(); @Override String getName(); @Override IConfig getConfig(); @Override ICacheManager getCacheManager(); @Override InitParams getInitParams(); @Override HttpServlet asServlet(); @Override IHttpTransport getTransport(); @Override IResourceFactory getResourceFactory(Mutable<URI> uriRef); @Override IResource newResource(URI uri); @Override IResource runConverters(IResource resource); @Override IModuleBuilder getModuleBuilder(String mid, IResource res); @Override Iterable<IAggregatorExtension> getExtensions(String extensionPointId); @Override IModule newModule(String mid, URI uri); @Override ILayerCache newLayerCache(); @Override IModuleCache newModuleCache(); @Override IGzipCache newGzipCache(); @Override String substituteProps(String str); @Override String substituteProps(String str, SubstitutionTransformer transformer); String getPropValue(String propName); @Override abstract IOptions getOptions(); @Override abstract IExecutors getExecutors(); @Override IPlatformServices getPlatformServices(); void initialize(IConfig config); @Override String setForceError(String forceError); @Override Future<?> buildAsync(final Callable<?> builder, final HttpServletRequest req); @Override HttpServletRequest getCurrentRequest();  }
@Test public void testInitWorkingDirectory() throws Exception { File defaultDir = Files.createTempDir(); File optionsDir = Files.createTempDir(); try { final IOptions mockOptions = EasyMock.createMock(IOptions.class); EasyMock.expect(mockOptions.getCacheDirectory()).andReturn(null).anyTimes(); TestAggregatorImpl aggregator = EasyMock.createMockBuilder(TestAggregatorImpl.class) .addMockedMethod("getOptions") .addMockedMethod("getName") .createMock(); EasyMock.expect(aggregator.getOptions()).andAnswer(new IAnswer<IOptions>() { public IOptions answer() throws Throwable { return mockOptions; } }).anyTimes(); EasyMock.expect(aggregator.getName()).andReturn("tester").anyTimes(); EasyMock.replay(mockOptions, aggregator); File result = aggregator.initWorkingDirectory(defaultDir, null, "69"); Assert.assertEquals(new File(defaultDir, "69/tester"), result); Assert.assertTrue(new File(defaultDir, "69/tester").exists()); result = aggregator.initWorkingDirectory(defaultDir, null, "70"); Assert.assertEquals(new File(defaultDir, "70/tester"), result); Assert.assertTrue(new File(defaultDir, "70/tester").exists()); Assert.assertFalse(new File(defaultDir, "69/tester").exists()); result = aggregator.initWorkingDirectory(defaultDir, null, "71", Arrays.asList(new String[]{"70"})); Assert.assertEquals(new File(defaultDir, "71/tester"), result); Assert.assertTrue(new File(defaultDir, "71/tester").exists()); Assert.assertTrue(new File(defaultDir, "70/tester").exists()); EasyMock.verify(mockOptions); EasyMock.reset(mockOptions); EasyMock.expect(mockOptions.getCacheDirectory()).andReturn(optionsDir.toString()).times(1); EasyMock.replay(mockOptions); result = aggregator.initWorkingDirectory(defaultDir, null, "70"); Assert.assertEquals(new File(optionsDir, "70/tester"), result); Assert.assertTrue(new File(optionsDir, "70/tester").exists()); EasyMock.verify(mockOptions, aggregator); } finally { TestUtils.deleteRecursively(defaultDir); TestUtils.deleteRecursively(optionsDir); } }