/** * Create or reuse a variable that can be assigned to Object.class * * @param test * @param position * @param recursionDepth * @param exclude * @return */ private VariableReference createOrReuseObjectVariable(TestCase test, int position, int recursionDepth, VariableReference exclude, boolean allowNull, boolean canUseMocks) throws ConstructionFailedException { double reuse = Randomness.nextDouble(); // Only reuse objects if they are related to a target call if (reuse <= Properties.PRIMITIVE_REUSE_PROBABILITY) { List<VariableReference> candidates = getCandidatesForReuse(test, Object.class, position, exclude, allowNull, canUseMocks); //List<VariableReference> candidates = test.getObjects(Object.class, position); filterVariablesByCastClasses(candidates); //filterVariablesByClass(candidates, Object.class); logger.debug("Choosing object from: {}", candidates); if (!candidates.isEmpty()) return Randomness.choice(candidates); } logger.debug("Attempting object generation"); return attemptObjectGeneration(test, position, recursionDepth, allowNull); }