### Question:
DefaultLESSCompiler extends AbstractCachedCompiler<String> implements LESSCompiler,
    Initializable { @Override public String compile(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, boolean force) throws LESSCompilerException { return super.getResult(lessResourceReference, includeSkinStyle, useVelocity, force); }  @Override void initialize(); @Override String compile(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,
                          boolean force); @Override String compile(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,
                         String skin, boolean force);  }### Answer:
@Test public void compileWhenInCache() throws Exception { when(cache.get(eq(lessResourceReference), eq(new FSSkinReference("skin")), eq(new NamedColorThemeReference("colorTheme")))).thenReturn("cached output"); assertEquals("cached output", mocker.getComponentUnderTest().compile(lessResourceReference, false, false, false)); verify(cache, never()).set(eq(lessResourceReference), eq(skinReference), eq(colorThemeReference), eq("cache output")); }
@Test public void compileWhenNotInCache() throws Exception { when(cachedLESSCompiler.compute(eq(lessResourceReference), eq(false), eq(false), eq(true), eq("skin"))). thenReturn("compiled output"); assertEquals("compiled output", mocker.getComponentUnderTest().compile(lessResourceReference, false, false, false)); verify(cache).set(eq(lessResourceReference), eq(skinReference), eq(colorThemeReference), eq("compiled output")); }
@Test public void compileWhenInCacheButForced() throws Exception { when(cachedLESSCompiler.compute(eq(lessResourceReference), eq(false), eq(false), eq(true), eq("skin"))). thenReturn("compiled output"); assertEquals("compiled output", mocker.getComponentUnderTest().compile( lessResourceReference, false, false, "skin", true)); verify(cache, times(1)).set(any(LESSResourceReference.class), any(SkinReference.class), any(ColorThemeReference.class), any()); verify(cache, never()).get(eq(lessResourceReference), eq(skinReference), eq(colorThemeReference)); }
@Test public void compileSkinFileWhenInCacheButCacheDisabled() throws Exception { when(lessContext.isCacheDisabled()).thenReturn(true); when(cachedLESSCompiler.compute(eq(lessResourceReference), eq(false), eq(false),eq(true), eq("skin"))). thenReturn("compiled output"); assertEquals("compiled output", mocker.getComponentUnderTest().compile(lessResourceReference, false, false, "skin", true)); verifyZeroInteractions(cache); }
@Test public void compileWhenInCacheAndHTMLExport() throws Exception { when(cache.get(eq(lessResourceReference), eq(skinReference), eq(colorThemeReference))).thenReturn("cached output"); when(lessContext.isHtmlExport()).thenReturn(true); assertEquals("cached output", mocker.getComponentUnderTest().compile(lessResourceReference, false, true, false)); verify(cachedLESSCompiler).compute(eq(lessResourceReference), eq(false), eq(true), eq(false), eq("skin")); verify(cache, never()).set(any(LESSResourceReference.class), any(SkinReference.class), any(ColorThemeReference.class), any()); }
@Test public void compileWhenError() throws Exception { LESSCompilerException expectedException = new LESSCompilerException("an exception"); when(cachedLESSCompiler.compute(any(LESSResourceReference.class), anyBoolean(), anyBoolean(), anyBoolean(), any())).thenThrow(expectedException); String result = mocker.getComponentUnderTest().compile(lessResourceReference, false, false, false); assertTrue(StringUtils.startsWith(result, "")); verify(cache).set(eq(lessResourceReference), eq(skinReference), eq(colorThemeReference), eq(result)); verify(mocker.getMockedLogger()).error(eq("Error during the compilation of the resource [{}]."), eq(lessResourceReference), eq(expectedException)); }