Example usage for org.apache.commons.lang3.reflect FieldUtils writeField

List of usage examples for org.apache.commons.lang3.reflect FieldUtils writeField

Introduction

In this page you can find the example usage for org.apache.commons.lang3.reflect FieldUtils writeField.

Prototype

public static void writeField(final Object target, final String fieldName, final Object value,
        final boolean forceAccess) throws IllegalAccessException 

Source Link

Document

Writes a Field .

Usage

From source file:org.treeingwalker.LessCompilerTest.java

@Test
public void testCompileFileToString() throws Exception {
    mockStatic(Context.class);
    when(Context.enter()).thenReturn(cx);
    FieldUtils.writeField(lessCompiler, "scope", scope, true);
    FieldUtils.writeField(lessCompiler, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    whenNew(LessSource.class).withArguments(inputFile).thenReturn(lessSource);
    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    assertEquals(css, lessCompiler.compile(inputFile));

    verify(compiler).call(cx, compileScope, null, new Object[] {});
}

From source file:org.treeingwalker.LessCompilerTest.java

@Test
public void testCompileFileToFile() throws Exception {
    mockStatic(Context.class);
    when(Context.enter()).thenReturn(cx);
    FieldUtils.writeField(lessCompiler, "scope", scope, true);
    FieldUtils.writeField(lessCompiler, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    whenNew(LessSource.class).withArguments(inputFile).thenReturn(lessSource);
    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    mockStatic(FileUtils.class);

    lessCompiler.compile(inputFile, outputFile);

    verify(compiler).call(cx, compileScope, null, new Object[] {});

    verifyStatic();//from   w  w  w. j  a  v a 2  s  .  c  om
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}

From source file:org.treeingwalker.LessCompilerTest.java

@Test
public void testCompileFileToFileWithForceTrue() throws Exception {
    mockStatic(Context.class);
    when(Context.enter()).thenReturn(cx);
    FieldUtils.writeField(lessCompiler, "scope", scope, true);
    FieldUtils.writeField(lessCompiler, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    whenNew(LessSource.class).withArguments(inputFile).thenReturn(lessSource);
    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    mockStatic(FileUtils.class);

    lessCompiler.compile(inputFile, outputFile, true);

    verify(compiler).call(cx, compileScope, null, new Object[] {});

    verifyStatic();/*w  w w  .j  a  v a  2 s  .  co m*/
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}

From source file:org.treeingwalker.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, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    when(outputFile.exists()).thenReturn(false);

    whenNew(LessSource.class).withArguments(inputFile).thenReturn(lessSource);
    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    mockStatic(FileUtils.class);

    lessCompiler.compile(inputFile, outputFile, false);

    verify(outputFile).exists();/*from  w  w w . j a v a  2s.c  o m*/

    verify(compiler).call(cx, compileScope, null, new Object[] {});

    verifyStatic();
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}

From source file:org.treeingwalker.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, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    when(outputFile.exists()).thenReturn(true);
    when(outputFile.lastModified()).thenReturn(1l);

    when(inputFile.lastModified()).thenReturn(2l);

    when(out.toString()).thenReturn(css);

    mockStatic(FileUtils.class);

    lessCompiler.compile(inputFile, outputFile, false);

    verify(outputFile).exists();//w  w w  .java 2 s. com
    verify(outputFile).lastModified();

    verify(compiler).call(cx, compileScope, null, new Object[] {});

    verifyStatic();
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}

From source file:org.treeingwalker.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, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    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);

    verify(outputFile).exists();//from www  . ja  va  2s.  c  o  m
    verify(outputFile).lastModified();

}

From source file:org.treeingwalker.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, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    assertEquals(css, lessCompiler.compile(lessSource));

    verify(lessSource).getNormalizedContent();

    verify(compiler).call(cx, compileScope, null, new Object[] {});
}

From source file:org.treeingwalker.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, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    mockStatic(FileUtils.class);

    lessCompiler.compile(lessSource, outputFile);

    verify(lessSource).getNormalizedContent();

    verify(compiler).call(cx, compileScope, null, new Object[] {});

    verifyStatic();/*  w  ww.j ava  2  s . c o m*/
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}

From source file:org.treeingwalker.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, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    mockStatic(FileUtils.class);

    lessCompiler.compile(lessSource, outputFile, true);

    verify(lessSource).getNormalizedContent();

    verify(compiler).call(cx, compileScope, null, new Object[] {});

    verifyStatic();/*from  w  w  w .  jav a  2s.  c  om*/
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}

From source file:org.treeingwalker.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, "compiler", compiler, true);
    FieldUtils.writeField(lessCompiler, "out", out, true);
    when(cx.newObject(scope)).thenReturn(compileScope);

    when(outputFile.exists()).thenReturn(false);

    when(lessSource.getNormalizedContent()).thenReturn(less);

    when(out.toString()).thenReturn(css);

    mockStatic(FileUtils.class);

    lessCompiler.compile(lessSource, outputFile, false);

    verify(outputFile).exists();//  ww  w.j  av a2  s.c  om

    verify(lessSource).getNormalizedContent();

    verify(compiler).call(cx, compileScope, null, new Object[] {});

    verifyStatic();
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}