List of usage examples for org.springframework.util ReflectionUtils findField
@Nullable public static Field findField(Class<?> clazz, String name)
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 w w . j a v a2 s.c o m*/ assertEquals(concurrencyBatchSizeToSet, concurrencyBatchSizeFromObject); }
From source file:com.ciphertool.genetics.algorithms.crossover.LiberalCrossoverAlgorithmTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test/* w w w .java2s. 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.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.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.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.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.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); }
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 w w w .j a v a 2s . co m assertEquals(taskExecutorToSet, taskExecutorFromObject); }
From source file:com.ciphertool.zodiacengine.fitness.AbstractSolutionEvaluatorBaseTest.java
@Test public void testCalculateAdjacentMatches_NullPlaintextCharacters() { ConcreteSolutionEvaluatorBase abstractSolutionEvaluatorBase = new ConcreteSolutionEvaluatorBase(); Field logField = ReflectionUtils.findField(ConcreteSolutionEvaluatorBase.class, "log"); Logger mockLogger = mock(Logger.class); ReflectionUtils.makeAccessible(logField); ReflectionUtils.setField(logField, abstractSolutionEvaluatorBase, mockLogger); abstractSolutionEvaluatorBase.calculateAdjacentMatches(null); verify(mockLogger, times(1)).warn(/*w w w . j a v a2 s . co m*/ "Attempted to calculate adjacent matches, but the List of plaintextCharacters was null or empty. Returning -1."); }
From source file:org.bahmni.test.builder.DrugOrderBuilder.java
public DrugOrderBuilder withOrderNumber(String orderNum) { java.lang.reflect.Field orderNumberField = ReflectionUtils.findField(DrugOrder.class, "orderNumber"); orderNumberField.setAccessible(true); ReflectionUtils.setField(orderNumberField, order, orderNum); return this; }