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.gerzog.spock.injectmock.internal.accessors.FieldAccessor.java

@Override
protected void internalSet(final Object target, final String name, final Object value) {
    try {/*from   w ww.  ja  v  a2 s .  co  m*/
        FieldUtils.writeField(target, name, value, true);
    } catch (IllegalAccessException e) {
        throw new InvalidSpecException("Cannot write injectable value to field <"
                + target.getClass().getSimpleName() + "." + name + ">", e);
    }
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.util.ReflectionUtilsTest.java

protected void setFieldValue(Object instance, String fieldName, Object value) {
    try {/*w w  w .jav  a 2s.  c  o m*/
        FieldUtils.writeField(instance, fieldName, value, true);
    } catch (IllegalAccessException e) {
        throw new Error(e);
    }
}

From source file:org.ktc.soapui.maven.extension.impl.AbstractTestErrorHandler.java

private void initializeFailedTests() throws IllegalAccessException {
    List<TestCase> failedTests = new ArrayList<TestCase>();
    failedTests.add(mock(TestCase.class));
    Field field = FieldUtils.getField(SoapUIProTestCaseRunner.class, "failedTests", true);
    FieldUtils.writeField(field, runner, failedTests, true);
}

From source file:org.ktc.soapui.maven.extension.impl.AbstractTestErrorHandler.java

private void initializeFailedAssertions() throws IllegalAccessException {
    List<TestAssertion> failedAssertions = new ArrayList<TestAssertion>();
    failedAssertions.add(mock(TestAssertion.class));
    Field field = FieldUtils.getField(SoapUIProTestCaseRunner.class, "assertions", true);
    FieldUtils.writeField(field, runner, failedAssertions, true);
}

From source file:org.ktc.soapui.maven.extension.impl.runner.SoapUIProExtensionMockServiceRunner.java

private void setCoverageBuilder(CoverageBuilder coverageBuilder) {
    try {/*from ww  w .  j a va 2s  . c  o  m*/
        FieldUtils.writeField(this, COVERAGE_BUILDER_FIELD_NAME, coverageBuilder, true);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Unable to write field " + COVERAGE_BUILDER_FIELD_NAME, e);
    }
}

From source file:org.lesscss.LessCompilerTest.java

@Before
public void setUp() throws Exception {
    lessCompiler = new LessCompiler();

    when(log.isDebugEnabled()).thenReturn(false);
    FieldUtils.writeField(lessCompiler, "log", log, true);
}

From source file:org.lesscss.LessCompilerTest.java

@Test
public void testCompileStringToString() throws Exception {
    mockStatic(Context.class);
    when(Context.enter()).thenReturn(cx);
    FieldUtils.writeField(lessCompiler, "scope", scope, true);
    FieldUtils.writeField(lessCompiler, "doIt", doIt, true);

    when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css);

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

    verify(doIt).call(cx, scope, null, new Object[] { less, false });
}

From source file:org.lesscss.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, "doIt", doIt, true);

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

    when(doIt.call(cx, scope, null, new Object[] { less, false })).thenReturn(css);

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

    verifyNew(LessSource.class).withArguments(inputFile);
    verify(lessSource).getNormalizedContent();

    verify(doIt).call(cx, scope, null, new Object[] { less, false });
}

From source file:org.lesscss.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, "doIt", doIt, true);

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

    verifyNew(LessSource.class).withArguments(inputFile);
    verify(lessSource).getNormalizedContent();

    verify(doIt).call(cx, scope, null, new Object[] { less, false });

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

From source file:org.lesscss.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, "doIt", doIt, true);

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

    verifyNew(LessSource.class).withArguments(inputFile);
    verify(lessSource).getNormalizedContent();

    verify(doIt).call(cx, scope, null, new Object[] { less, false });

    verifyStatic();//from w  w w  .  ja  v  a2  s .  c  o m
    FileUtils.writeStringToFile(outputFile, css, (String) null);
}