Example usage for org.springframework.util ReflectionUtils getField

List of usage examples for org.springframework.util ReflectionUtils getField

Introduction

In this page you can find the example usage for org.springframework.util ReflectionUtils getField.

Prototype

@Nullable
public static Object getField(Field field, @Nullable Object target) 

Source Link

Document

Get the field represented by the supplied Field field object on the specified Object target object .

Usage

From source file:com.mariadb.embedded.MariadbServerTests.java

/**
 * Get {@link DBConfiguration} in {@link MariadbServer}.
 * /*from  w ww . j  a  va2s .c om*/
 * @param server {@link MariadbServer}
 * @return {@link DBConfiguration}
 */
private DBConfiguration getConfiguration(MariadbServer server) {

    Field field = ReflectionUtils.findField(MariadbServer.class, "config");
    ReflectionUtils.makeAccessible(field);

    return (DBConfiguration) ReflectionUtils.getField(field, server);
}

From source file:com.ciphertool.zodiacengine.service.GeneticCipherSolutionServiceTest.java

@Test
public void testSetSolutionDao() {
    SolutionDao solutionDaoToSet = mock(SolutionDao.class);
    GeneticCipherSolutionService geneticCipherSolutionService = new GeneticCipherSolutionService();
    geneticCipherSolutionService.setSolutionDao(solutionDaoToSet);

    Field solutionDaoField = ReflectionUtils.findField(GeneticCipherSolutionService.class, "solutionDao");
    ReflectionUtils.makeAccessible(solutionDaoField);
    SolutionDao solutionDaoFromObject = (SolutionDao) ReflectionUtils.getField(solutionDaoField,
            geneticCipherSolutionService);

    assertSame(solutionDaoToSet, solutionDaoFromObject);
}

From source file:com.ciphertool.sentencebuilder.etl.importers.FrequencyListImporterImplTest.java

@Test
public void testSetConcurrencyBatchSize() {
    int concurrencyBatchSizeToSet = 250;
    FrequencyListImporterImpl frequencyListImporterImpl = new FrequencyListImporterImpl();
    frequencyListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet);

    Field concurrencyBatchSizeField = ReflectionUtils.findField(FrequencyListImporterImpl.class,
            "concurrencyBatchSize");
    ReflectionUtils.makeAccessible(concurrencyBatchSizeField);
    int concurrencyBatchSizeFromObject = (int) ReflectionUtils.getField(concurrencyBatchSizeField,
            frequencyListImporterImpl);/* w  ww .  jav a2 s .co m*/

    assertEquals(concurrencyBatchSizeToSet, concurrencyBatchSizeFromObject);
}

From source file:com.ciphertool.genetics.algorithms.crossover.LiberalCrossoverAlgorithmTest.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test//from  ww  w  .  ja  va  2 s .c o  m
public void testSetMutationAlgorithm() {
    MutationAlgorithm mutationAlgorithmToSet = mock(MutationAlgorithm.class);

    LiberalCrossoverAlgorithm liberalCrossoverAlgorithm = new LiberalCrossoverAlgorithm();
    liberalCrossoverAlgorithm.setMutationAlgorithm(mutationAlgorithmToSet);

    Field mutationAlgorithmField = ReflectionUtils.findField(LiberalCrossoverAlgorithm.class,
            "mutationAlgorithm");
    ReflectionUtils.makeAccessible(mutationAlgorithmField);
    MutationAlgorithm mutationAlgorithmFromObject = (MutationAlgorithm) ReflectionUtils
            .getField(mutationAlgorithmField, liberalCrossoverAlgorithm);

    assertSame(mutationAlgorithmToSet, mutationAlgorithmFromObject);
}

From source file:com.ciphertool.genetics.PopulationTest.java

@Test
public void testSetFitnessEvaluator() {
    Population population = new Population();

    FitnessEvaluator fitnessEvaluatorMock = mock(FitnessEvaluator.class);
    when(fitnessEvaluatorMock.evaluate(any(Chromosome.class))).thenReturn(DEFAULT_FITNESS_VALUE);
    population.setFitnessEvaluator(fitnessEvaluatorMock);

    Field fitnessEvaluatorField = ReflectionUtils.findField(Population.class, "fitnessEvaluator");
    ReflectionUtils.makeAccessible(fitnessEvaluatorField);
    FitnessEvaluator fitnessEvaluatorFromObject = (FitnessEvaluator) ReflectionUtils
            .getField(fitnessEvaluatorField, population);

    assertSame(fitnessEvaluatorMock, fitnessEvaluatorFromObject);
}

From source file:com.ciphertool.genetics.algorithms.selection.TournamentSelectionAlgorithmTest.java

@Test
public void testSetGroupSelector() {
    TournamentSelector groupSelectorToSet = new TournamentSelector();

    TournamentSelectionAlgorithm tournamentSelectionAlgorithm = new TournamentSelectionAlgorithm();
    tournamentSelectionAlgorithm.setGroupSelector(groupSelectorToSet);

    Field groupSelectorField = ReflectionUtils.findField(TournamentSelectionAlgorithm.class, "groupSelector");
    ReflectionUtils.makeAccessible(groupSelectorField);
    Selector groupSelectorFromObject = (Selector) ReflectionUtils.getField(groupSelectorField,
            tournamentSelectionAlgorithm);

    assertSame(groupSelectorToSet, groupSelectorFromObject);
}

From source file:com.ciphertool.genetics.algorithms.crossover.LiberalUnevaluatedCrossoverAlgorithmTest.java

@Test
public void testSetMutateDuringCrossover() {
    boolean mutateDuringCrossoverToSet = true;

    LiberalUnevaluatedCrossoverAlgorithm liberalUnevaluatedCrossoverAlgorithm = new LiberalUnevaluatedCrossoverAlgorithm();
    liberalUnevaluatedCrossoverAlgorithm.setMutateDuringCrossover(mutateDuringCrossoverToSet);

    Field mutateDuringCrossoverField = ReflectionUtils.findField(LiberalUnevaluatedCrossoverAlgorithm.class,
            "mutateDuringCrossover");
    ReflectionUtils.makeAccessible(mutateDuringCrossoverField);
    boolean mutateDuringCrossoverFromObject = (boolean) ReflectionUtils.getField(mutateDuringCrossoverField,
            liberalUnevaluatedCrossoverAlgorithm);

    assertEquals(mutateDuringCrossoverToSet, mutateDuringCrossoverFromObject);
}

From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithmTest.java

@Test
public void testSetChromosomeHelper() {
    KeylessChromosomeHelper chromosomeHelperToSet = new KeylessChromosomeHelper();

    LiberalMutationAlgorithm liberalMutationAlgorithm = new LiberalMutationAlgorithm();
    liberalMutationAlgorithm.setChromosomeHelper(chromosomeHelperToSet);

    Field chromosomeHelperField = ReflectionUtils.findField(LiberalMutationAlgorithm.class,
            "keylessChromosomeHelper");
    ReflectionUtils.makeAccessible(chromosomeHelperField);
    KeylessChromosomeHelper chromosomeHelperFromObject = (KeylessChromosomeHelper) ReflectionUtils
            .getField(chromosomeHelperField, liberalMutationAlgorithm);

    assertSame(chromosomeHelperToSet, chromosomeHelperFromObject);
}

From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java

@Test
public void testSetTaskExecutor() {
    TaskExecutor taskExecutorToSet = mock(TaskExecutor.class);
    WordListImporterImpl wordListImporterImpl = new WordListImporterImpl();
    wordListImporterImpl.setTaskExecutor(taskExecutorToSet);

    Field taskExecutorField = ReflectionUtils.findField(WordListImporterImpl.class, "taskExecutor");
    ReflectionUtils.makeAccessible(taskExecutorField);
    TaskExecutor taskExecutorFromObject = (TaskExecutor) ReflectionUtils.getField(taskExecutorField,
            wordListImporterImpl);/*from  www .j a  v  a2 s .c  om*/

    assertEquals(taskExecutorToSet, taskExecutorFromObject);
}

From source file:com.ciphertool.genetics.algorithms.mutation.GroupMutationAlgorithmTest.java

@Test
public void testSetMaxMutationsPerChromosome() {
    Integer maxMutationsPerChromosomeToSet = 3;

    GroupMutationAlgorithm groupMutationAlgorithm = new GroupMutationAlgorithm();
    groupMutationAlgorithm.setMaxMutationsPerChromosome(maxMutationsPerChromosomeToSet);

    Field maxMutationsPerChromosomeField = ReflectionUtils.findField(GroupMutationAlgorithm.class,
            "maxMutationsPerChromosome");
    ReflectionUtils.makeAccessible(maxMutationsPerChromosomeField);
    Integer maxMutationsPerChromosomeFromObject = (Integer) ReflectionUtils
            .getField(maxMutationsPerChromosomeField, groupMutationAlgorithm);

    assertSame(maxMutationsPerChromosomeToSet, maxMutationsPerChromosomeFromObject);
}