List of usage examples for org.apache.commons.lang3.reflect FieldUtils writeField
public static void writeField(final Object target, final String fieldName, final Object value, final boolean forceAccess) throws IllegalAccessException
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileFileToFileWithForceFalseAndOutputNotExists() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); when(outputFile.exists()).thenReturn(false); whenNew(LessSource.class).withArguments(inputFile).thenReturn(lessSource); when(lessSource.getNormalizedContent()).thenReturn(less); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css); mockStatic(FileUtils.class); lessCompiler.compile(inputFile, outputFile, false); verifyNew(LessSource.class).withArguments(inputFile); verify(outputFile).exists();/*w w w. j av a 2 s.c o m*/ verify(lessSource).getNormalizedContent(); verify(doIt).call(cx, scope, null, new Object[] { less, false }); verifyStatic(); FileUtils.writeStringToFile(outputFile, css, (String) null); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileFileToFileWithForceFalseAndOutputExistsAndLessSourceModified() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); whenNew(LessSource.class).withArguments(inputFile).thenReturn(lessSource); when(outputFile.exists()).thenReturn(true); when(outputFile.lastModified()).thenReturn(1l); when(lessSource.getLastModifiedIncludingImports()).thenReturn(2l); when(lessSource.getNormalizedContent()).thenReturn(less); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css); mockStatic(FileUtils.class); lessCompiler.compile(inputFile, outputFile, false); verifyNew(LessSource.class).withArguments(inputFile); verify(outputFile).exists();//from w ww . ja v a2s. co m verify(outputFile).lastModified(); verify(lessSource).getLastModifiedIncludingImports(); verify(lessSource).getNormalizedContent(); verify(doIt).call(cx, scope, null, new Object[] { less, false }); verifyStatic(); FileUtils.writeStringToFile(outputFile, css, (String) null); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileFileToFileWithForceFalseAndOutputExistsAndLessSourceNotModified() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); whenNew(LessSource.class).withArguments(inputFile).thenReturn(lessSource); when(outputFile.exists()).thenReturn(true); when(outputFile.lastModified()).thenReturn(2l); when(lessSource.getLastModifiedIncludingImports()).thenReturn(1l); lessCompiler.compile(inputFile, outputFile, false); verifyNew(LessSource.class).withArguments(inputFile); verify(outputFile).exists();/* www . ja va2 s . c o m*/ verify(outputFile).lastModified(); verify(lessSource).getLastModifiedIncludingImports(); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileLessSourceToString() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); when(lessSource.getNormalizedContent()).thenReturn(less); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css); assertEquals(css, lessCompiler.compile(lessSource)); verify(lessSource).getNormalizedContent(); verify(doIt).call(cx, scope, null, new Object[] { less, false }); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileLessSourceToFile() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); when(lessSource.getNormalizedContent()).thenReturn(less); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css); mockStatic(FileUtils.class); lessCompiler.compile(lessSource, outputFile); verify(lessSource).getNormalizedContent(); verify(doIt).call(cx, scope, null, new Object[] { less, false }); verifyStatic();/*from w w w . ja va2 s . c o m*/ FileUtils.writeStringToFile(outputFile, css, (String) null); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileLessSourceToFileWithForceTrue() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); when(lessSource.getNormalizedContent()).thenReturn(less); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css); mockStatic(FileUtils.class); lessCompiler.compile(lessSource, outputFile, true); verify(lessSource).getNormalizedContent(); verify(doIt).call(cx, scope, null, new Object[] { less, false }); verifyStatic();/*from www . ja va2 s . c o m*/ FileUtils.writeStringToFile(outputFile, css, (String) null); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileLessSourceToFileWithForceFalseAndOutputNotExists() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); when(outputFile.exists()).thenReturn(false); when(lessSource.getNormalizedContent()).thenReturn(less); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css); mockStatic(FileUtils.class); lessCompiler.compile(lessSource, outputFile, false); verify(outputFile).exists();// w w w.j a va 2 s. c o m verify(lessSource).getNormalizedContent(); verify(doIt).call(cx, scope, null, new Object[] { less, false }); verifyStatic(); FileUtils.writeStringToFile(outputFile, css, (String) null); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileLessSourceToFileWithForceFalseAndOutputExistsAndLessSourceModified() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); when(outputFile.exists()).thenReturn(true); when(outputFile.lastModified()).thenReturn(1l); when(lessSource.getLastModifiedIncludingImports()).thenReturn(2l); when(lessSource.getNormalizedContent()).thenReturn(less); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css); mockStatic(FileUtils.class); lessCompiler.compile(lessSource, outputFile, false); verify(outputFile).exists();//w w w . j av a 2s. c o m verify(outputFile).lastModified(); verify(lessSource).getLastModifiedIncludingImports(); verify(lessSource).getNormalizedContent(); verify(doIt).call(cx, scope, null, new Object[] { less, false }); verifyStatic(); FileUtils.writeStringToFile(outputFile, css, (String) null); }
From source file:org.lesscss.LessCompilerTest.java
@Test public void testCompileLessSourceToFileWithForceFalseAndOutputExistsAndLessSourceNotModified() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); when(outputFile.exists()).thenReturn(true); when(outputFile.lastModified()).thenReturn(2l); when(lessSource.getLastModifiedIncludingImports()).thenReturn(1l); lessCompiler.compile(lessSource, outputFile, false); verify(outputFile).exists();// ww w .j a v a 2 s.c o m verify(outputFile).lastModified(); verify(lessSource).getLastModifiedIncludingImports(); }
From source file:org.lesscss.LessCompilerTest.java
@Test(expected = LessException.class) public void testCompileThrowsLessExceptionWhenCompilationFails() throws Exception { mockStatic(Context.class); when(Context.enter()).thenReturn(cx); FieldUtils.writeField(lessCompiler, "scope", scope, true); FieldUtils.writeField(lessCompiler, "doIt", doIt, true); JavaScriptException javaScriptException = new JavaScriptException(null, null, 0); when(doIt.call(cx, scope, null, new Object[] { less, false })).thenThrow(javaScriptException); assertEquals(css, lessCompiler.compile(less)); }