Example usage for java.lang.reflect Field set

List of usage examples for java.lang.reflect Field set

Introduction

In this page you can find the example usage for java.lang.reflect Field set.

Prototype

@CallerSensitive
@ForceInline 
public void set(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException 

Source Link

Document

Sets the field represented by this Field object on the specified object argument to the specified new value.

Usage

From source file:de.thkwalter.et.schlupfbezifferung.BetriebspunktTest.java

/**
 * Test der Methode {@link Betriebspunkt#getI_1x()}.
 * /*  w  ww .  j  a v  a 2  s . c om*/
 * @throws SecurityException 
 * @throws NoSuchFieldException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 */
@Test
public void testGetI_1x()
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    // Die in diesem Test verwendete komplexe Stnderstromstrke (in A) wird erzeugt.
    Complex testI_1 = new Complex(4.0, 2.0);

    // Die in diesem Test verwendete komplexe Stnderstromstrke (in A) wird im Prfling gespeichert.
    Field i_1Feld = Betriebspunkt.class.getDeclaredField("i_1");
    i_1Feld.setAccessible(true);
    i_1Feld.set(this.betriebspunkt, testI_1);

    // Es wird berprft, ob die x-Komponente der komplexen Stnderstromstrke (in A) korrekt zurckgegeben wird.
    assertEquals(-2.0, this.betriebspunkt.getI_1x(), 0.0);
}

From source file:net.vexelon.myglob.utils.TrustAllSocketFactory.java

/**
 * Prevents the reverse DNS lookup from being made. Fixed in Android 4.0, but still needs
 * workaround for earlier versions. /*from w w w .  java  2s .c o  m*/
 * Source: http://code.google.com/p/android/issues/detail?id=13117#c14
 * @param socket
 * @param host
 */
private void injectHostname(Socket socket, String host) {
    try {
        Field field = InetAddress.class.getDeclaredField("hostName");
        field.setAccessible(true);
        field.set(socket.getInetAddress(), host);
    } catch (Exception ignored) {
        // uhm
    }
}

From source file:com.comcast.cats.TelnetConnectionTest.java

@Before
public void setUp()
        throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    telnetConnecton = new TelnetConnection(host, port, defaultPromptString);

    if (enableMock) {
        telnetClient = EasyMock.createMock(TelnetClient.class);
        is = EasyMock.createMock(InputStream.class);
        os = EasyMock.createMock(OutputStream.class);

        Field field = telnetConnecton.getClass().getDeclaredField("telnetClient");
        field.setAccessible(true);//ww w  . j  a  va2s  .com
        field.set(telnetConnecton, telnetClient);

        System.out.println("telnetClient setUp " + telnetClient);
    }
}

From source file:name.richardson.james.bukkit.utilities.persistence.database.AbstractDatabaseLoader.java

/**
 * Ebean by default outputs a ton of exception data to the console which is ignored by the generator itself. This makes it difficult to actually find real
 * exceptions. This method disables this using reflection.
 *
 * @param generator//from ww  w  . ja  v a2 s  .  com
 * @param value
 */
protected final void setGeneratorDebug(DdlGenerator generator, boolean value) {
    try {
        Field field = generator.getClass().getDeclaredField("debug");
        field.setAccessible(true);
        field.set(generator, value);
    } catch (Exception e) {
        logger.warning("Unable to supress generator messages!");
    }
}

From source file:info.raack.appliancelabeler.datacollector.EnergyDataLoaderTest.java

@Before
public void setup() throws SecurityException, NoSuchFieldException, IllegalArgumentException,
        IllegalAccessException, JAXBException, SAXException {
    dataService = mock(DataService.class);
    database = mock(Database.class);
    errorService = mock(ErrorService.class);
    configurationLoaders = new ArrayList<ConfigurationLoader>();
    emailSender = mock(EmailSender.class);

    loader = new EnergyDataLoader();
    Class<?> c = loader.getClass();
    Field f = c.getDeclaredField("dataService");
    f.setAccessible(true);//from   w w  w  . j a v a  2s  .  co  m
    f.set(loader, dataService);

    f = c.getDeclaredField("configurationLoaders");
    f.setAccessible(true);
    f.set(loader, configurationLoaders);

    f = c.getDeclaredField("errorService");
    f.setAccessible(true);
    f.set(loader, errorService);

    f = c.getDeclaredField("database");
    f.setAccessible(true);
    f.set(loader, database);

    f = c.getDeclaredField("emailSender");
    f.setAccessible(true);
    f.set(loader, emailSender);

    f = c.getDeclaredField("energyPollingFrequency");
    f.setAccessible(true);
    f.set(loader, 30);

    f = c.getDeclaredField("energylabelerUrl");
    f.setAccessible(true);
    f.set(loader, "http://www.energylabelerurl.com");
}

From source file:de.thkwalter.et.schlupfbezifferung.BetriebspunktTest.java

/**
 * Test der Methode {@link Betriebspunkt#getI_1y()}.
 * /*from   w  w w. j ava2  s . c  om*/
 * @throws SecurityException 
 * @throws NoSuchFieldException 
 * @throws IllegalAccessException 
 * @throws IllegalArgumentException 
 */
@Test
public void testGetI_1y()
        throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    // Die in diesem Test verwendete komplexe Stnderstromstrke (in A) wird erzeugt.
    Complex testI_1 = new Complex(4.0, 2.0);

    // Die in diesem Test verwendete komplexe Stnderstromstrke (in A) wird im Prfling gespeichert.
    Field i_1Feld = Betriebspunkt.class.getDeclaredField("i_1");
    i_1Feld.setAccessible(true);
    i_1Feld.set(this.betriebspunkt, testI_1);

    // Es wird berprft, ob die x-Komponente der komplexen Stnderstromstrke (in A) korrekt zurckgegeben wird.
    assertEquals(4.0, this.betriebspunkt.getI_1y(), 0.0);

    // Es wird berprft, ob der Schlupf korrekt initialisiert worden ist.
    assertTrue(Double.isNaN(this.betriebspunkt.getS()));
}

From source file:com.codenvy.ide.git.VFSPermissionsFilterTest.java

@BeforeMethod
public void before() throws Exception {
    System.setProperty("organization.application.server.url", "orgPath");
    // Json helper mocking
    Field f = HttpJsonHelper.class.getDeclaredField("httpJsonHelperImpl");
    f.setAccessible(true);//  ww  w.  ja va2s  . c o m
    f.set(null, httpJsonHelper);
    filter.init(null);

    Field api = VFSPermissionsFilter.class.getDeclaredField("apiEndPoint");
    api.setAccessible(true);
    api.set(filter, ENDPOINT);

    Field path = VFSPermissionsFilter.class.getDeclaredField("vfsRoot");
    path.setAccessible(true);
    path.set(filter, "/");

    Field uriPrefix = VFSPermissionsFilter.class.getDeclaredField("gitServerUriPrefix");
    uriPrefix.setAccessible(true);
    uriPrefix.set(filter, GIT_SERVER_URI_PREFIX);

    when((request).getRequestURL()).thenReturn(new StringBuffer("http://host.com/")
            .append(GIT_SERVER_URI_PREFIX).append("/").append(WORKSPACE).append("/testProject"));
}

From source file:info.magnolia.objectfactory.ClassesTest.java

private void resetCFP() throws NoSuchFieldException, IllegalAccessException {
    // reset the classFactoryProvider field. TODO: really wish i could have made this one final ...
    final Field cfpField = Classes.class.getDeclaredField("cfp");
    cfpField.setAccessible(true);//from   w  w  w.  j a  v  a2  s. com
    cfpField.set(null, new Classes.ClassFactoryProvider(new DefaultClassFactory()));
}

From source file:edu.syr.pcpratts.rootbeer.runtime.Serializer.java

public void writeStaticField(Class cls, String name, Object value) {
    while (true) {
        try {/* w w w . j  ava  2 s.  com*/
            Field f = cls.getDeclaredField(name);
            f.setAccessible(true);
            f.set(null, value);
            return;
        } catch (Exception ex) {
            cls = cls.getSuperclass();
        }
    }
}

From source file:org.echocat.jomon.spring.application.DefaultApplication.java

protected void setShutdownHook(@Nonnull Thread thread, @Nonnull AbstractApplicationContext to) {
    try {//from   w  w w .j  a v a2s.  co m
        final Field field = AbstractApplicationContext.class.getDeclaredField("shutdownHook");
        field.setAccessible(true);
        field.set(to, thread);
    } catch (final Exception e) {
        LOG.warn("Could not register shutdownHook at " + to
                + " this could cause to much memory consume of the JVM.", e);
    }
}