List of usage examples for org.springframework.util ReflectionUtils getField
@Nullable public static Object getField(Field field, @Nullable Object target)
From source file:com.ciphertool.genetics.algorithms.crossover.ConservativeSinglePointCrossoverAlgorithmTest.java
@Test public void testSetRandomListElementSelector() { RandomListElementSelector randomListElementSelectorToSet = mock(RandomListElementSelector.class); ConservativeSinglePointCrossoverAlgorithm conservativeSinglePointCrossoverAlgorithm = new ConservativeSinglePointCrossoverAlgorithm(); conservativeSinglePointCrossoverAlgorithm.setRandomListElementSelector(randomListElementSelectorToSet); Field randomListElementSelectorField = ReflectionUtils .findField(ConservativeSinglePointCrossoverAlgorithm.class, "randomListElementSelector"); ReflectionUtils.makeAccessible(randomListElementSelectorField); RandomListElementSelector randomListElementSelectorFromObject = (RandomListElementSelector) ReflectionUtils .getField(randomListElementSelectorField, conservativeSinglePointCrossoverAlgorithm); assertSame(randomListElementSelectorToSet, randomListElementSelectorFromObject); }
From source file:com.ciphertool.genetics.algorithms.crossover.LiberalUnevaluatedCrossoverAlgorithmTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test// w w w . ja va2s . c o m public void testSetMutationAlgorithm() { MutationAlgorithm mutationAlgorithmToSet = mock(MutationAlgorithm.class); LiberalUnevaluatedCrossoverAlgorithm liberalUnevaluatedCrossoverAlgorithm = new LiberalUnevaluatedCrossoverAlgorithm(); liberalUnevaluatedCrossoverAlgorithm.setMutationAlgorithm(mutationAlgorithmToSet); Field mutationAlgorithmField = ReflectionUtils.findField(LiberalUnevaluatedCrossoverAlgorithm.class, "mutationAlgorithm"); ReflectionUtils.makeAccessible(mutationAlgorithmField); MutationAlgorithm mutationAlgorithmFromObject = (MutationAlgorithm) ReflectionUtils .getField(mutationAlgorithmField, liberalUnevaluatedCrossoverAlgorithm); assertSame(mutationAlgorithmToSet, mutationAlgorithmFromObject); }
From source file:com.ciphertool.genetics.algorithms.mutation.ConservativeMutationAlgorithmTest.java
@Test public void testSetMaxMutationsPerChromosome() { Integer maxMutationsPerChromosomeToSet = 3; ConservativeMutationAlgorithm conservativeMutationAlgorithm = new ConservativeMutationAlgorithm(); conservativeMutationAlgorithm.setMaxMutationsPerChromosome(maxMutationsPerChromosomeToSet); Field maxMutationsPerChromosomeField = ReflectionUtils.findField(ConservativeMutationAlgorithm.class, "maxMutationsPerChromosome"); ReflectionUtils.makeAccessible(maxMutationsPerChromosomeField); Integer maxMutationsPerChromosomeFromObject = (Integer) ReflectionUtils .getField(maxMutationsPerChromosomeField, conservativeMutationAlgorithm); assertSame(maxMutationsPerChromosomeToSet, maxMutationsPerChromosomeFromObject); }
From source file:com.ciphertool.genetics.PopulationTest.java
@Test public void testSetBreeder() { Population population = new Population(); MockBreeder mockBreeder = new MockBreeder(); population.setBreeder(mockBreeder);/*w w w.j av a2 s . com*/ Field breederField = ReflectionUtils.findField(Population.class, "breeder"); ReflectionUtils.makeAccessible(breederField); MockBreeder breederFromObject = (MockBreeder) ReflectionUtils.getField(breederField, population); assertSame(mockBreeder, breederFromObject); }
From source file:com.ciphertool.genetics.algorithms.mutation.SingleSequenceMutationAlgorithmTest.java
@Test public void testSetMaxMutationsPerChromosome() { Integer maxMutationsPerChromosomeToSet = 3; SingleSequenceMutationAlgorithm singleSequenceMutationAlgorithm = new SingleSequenceMutationAlgorithm(); singleSequenceMutationAlgorithm.setMaxMutationsPerChromosome(maxMutationsPerChromosomeToSet); Field maxMutationsPerChromosomeField = ReflectionUtils.findField(SingleSequenceMutationAlgorithm.class, "maxMutationsPerChromosome"); ReflectionUtils.makeAccessible(maxMutationsPerChromosomeField); Integer maxMutationsPerChromosomeFromObject = (Integer) ReflectionUtils .getField(maxMutationsPerChromosomeField, singleSequenceMutationAlgorithm); assertSame(maxMutationsPerChromosomeToSet, maxMutationsPerChromosomeFromObject); }
From source file:com.ciphertool.genetics.algorithms.selection.TournamentSelectionAlgorithmTest.java
@Test public void testSetGroupSize() { Integer groupSizeToSet = 3;/* w w w . j av a 2 s . c o m*/ TournamentSelectionAlgorithm tournamentSelectionAlgorithm = new TournamentSelectionAlgorithm(); tournamentSelectionAlgorithm.setGroupSize(groupSizeToSet); Field groupSizeField = ReflectionUtils.findField(TournamentSelectionAlgorithm.class, "groupSize"); ReflectionUtils.makeAccessible(groupSizeField); Integer groupSizeFromObject = (Integer) ReflectionUtils.getField(groupSizeField, tournamentSelectionAlgorithm); assertSame(groupSizeToSet, groupSizeFromObject); }
From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithmTest.java
@Test public void testSetGeneDao() { GeneDao geneDaoToSet = mock(GeneDao.class); LiberalMutationAlgorithm liberalMutationAlgorithm = new LiberalMutationAlgorithm(); liberalMutationAlgorithm.setGeneDao(geneDaoToSet); Field geneDaoField = ReflectionUtils.findField(LiberalMutationAlgorithm.class, "geneDao"); ReflectionUtils.makeAccessible(geneDaoField); GeneDao geneDaoFromObject = (GeneDao) ReflectionUtils.getField(geneDaoField, liberalMutationAlgorithm); assertSame(geneDaoToSet, geneDaoFromObject); }
From source file:org.socialsignin.spring.data.dynamodb.repository.support.FieldAndGetterReflectionEntityInformation.java
@SuppressWarnings("unchecked") public ID getId(T entity) { if (method != null) { return entity == null ? null : (ID) ReflectionUtils.invokeMethod(method, entity); } else {/*from w ww . j ava 2s .com*/ return entity == null ? null : (ID) ReflectionUtils.getField(field, entity); } }
From source file:com.ciphertool.genetics.algorithms.mutation.GroupMutationAlgorithmTest.java
@Test public void testSetGeneDao() { VariableLengthGeneDao geneDaoToSet = mock(VariableLengthGeneDao.class); GroupMutationAlgorithm groupMutationAlgorithm = new GroupMutationAlgorithm(); groupMutationAlgorithm.setGeneDao(geneDaoToSet); Field geneDaoField = ReflectionUtils.findField(GroupMutationAlgorithm.class, "geneDao"); ReflectionUtils.makeAccessible(geneDaoField); GeneDao geneDaoFromObject = (GeneDao) ReflectionUtils.getField(geneDaoField, groupMutationAlgorithm); assertSame(geneDaoToSet, geneDaoFromObject); }
From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java
@Test public void testSetConcurrencyBatchSize() { int concurrencyBatchSizeToSet = 250; WordListImporterImpl wordListImporterImpl = new WordListImporterImpl(); wordListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet); Field concurrencyBatchSizeField = ReflectionUtils.findField(WordListImporterImpl.class, "concurrencyBatchSize"); ReflectionUtils.makeAccessible(concurrencyBatchSizeField); int concurrencyBatchSizeFromObject = (int) ReflectionUtils.getField(concurrencyBatchSizeField, wordListImporterImpl);/*from ww w. ja v a 2 s. co m*/ assertEquals(concurrencyBatchSizeToSet, concurrencyBatchSizeFromObject); }