List of usage examples for org.springframework.util ReflectionUtils makeAccessible
@SuppressWarnings("deprecation") public static void makeAccessible(Field field)
From source file:com.ciphertool.genetics.algorithms.selection.TournamentSelectionAlgorithmTest.java
@Test public void testSetGroupSize() { Integer groupSizeToSet = 3;// w ww . j a va 2 s. co 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: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 w w w . j av a 2 s . c o m assertEquals(concurrencyBatchSizeToSet, concurrencyBatchSizeFromObject); }
From source file:com.mariadb.embedded.MariadbServerTests.java
/** * Get {@link DBConfiguration} in {@link MariadbServer}. * /* w w w . j av a 2 s. c o m*/ * @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:org.jdal.ui.bind.DirectFieldAccessor.java
@Override public Object getPropertyValue(String propertyName) throws BeansException { Field field = this.fieldMap.get(propertyName); if (field == null) { throw new NotReadablePropertyException(this.target.getClass(), propertyName, "Field '" + propertyName + "' does not exist"); }/*from w w w. jav a2s . c o m*/ try { ReflectionUtils.makeAccessible(field); return field.get(this.target); } catch (IllegalAccessException ex) { throw new InvalidPropertyException(this.target.getClass(), propertyName, "Field is not accessible", ex); } }
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);/*from w w w .j a v a 2s. c o m*/ assertEquals(concurrencyBatchSizeToSet, concurrencyBatchSizeFromObject); }
From source file:at.ac.tuwien.infosys.jcloudscale.test.integration.base.TestFieldHandling.java
@Test public void testPrivateFieldSetViaReflection() throws Exception { assertEquals(0, cs.countCloudObjects()); FieldCloudObject ob = new FieldCloudObject(); assertEquals(1, cs.countCloudObjects()); // we need to go to the superclass as this is in fact a dynamic proxy generated // by CGLib//from w w w .j a va2s. co m Field field = ob.getClass().getSuperclass().getDeclaredField("privateField"); ReflectionUtils.makeAccessible(field); field.set(ob, "private_changed"); assertEquals(ob.getPrivateField(), "private_changed"); }
From source file:com.ciphertool.genetics.algorithms.crossover.LiberalCrossoverAlgorithmTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test/* ww w. jav a 2 s .com*/ 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); }