use of org.apache.sling.commons.classloader.ClassLoaderWriter in project sling by apache.
the class SightlyScriptEngineFactoryTest method testActivateOverPreviousVersion.
@Test
public void testActivateOverPreviousVersion() {
SightlyScriptEngineFactory scriptEngineFactory = new SightlyScriptEngineFactory();
ClassLoaderWriter classLoaderWriter = mock(ClassLoaderWriter.class);
try {
when(classLoaderWriter.getInputStream(SightlyScriptEngineFactory.SIGHTLY_CONFIG_FILE)).thenReturn(IOUtils.toInputStream("1.0.16", "UTF-8"));
} catch (IOException e) {
fail("IOException while setting tests.");
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
when(classLoaderWriter.getOutputStream(SightlyScriptEngineFactory.SIGHTLY_CONFIG_FILE)).thenReturn(outputStream);
when(classLoaderWriter.delete(sightlyEngineConfiguration.getScratchFolder())).thenReturn(true);
Whitebox.setInternalState(scriptEngineFactory, "classLoaderWriter", classLoaderWriter);
Whitebox.setInternalState(scriptEngineFactory, "sightlyEngineConfiguration", sightlyEngineConfiguration);
scriptEngineFactory.activate();
verify(classLoaderWriter).delete(sightlyEngineConfiguration.getScratchFolder());
assertEquals("1.0.17-SNAPSHOT", outputStream.toString());
}
Aggregations