/** * Attempt to generate a non-null object; initialize recursion level to 0 * */ public VariableReference attemptGeneration(TestCase test, Type type, int position) throws ConstructionFailedException { return attemptGeneration(test, type, position, 0, false, null, true, true); }
logger.debug("Attempting generation of object of type " + array.getComponentType()); VariableReference var = attemptGeneration(test, array.getComponentType(), position);
@Override public boolean doSearch(TestChromosome test, int statement, LocalSearchObjective<TestChromosome> objective) { NullStatement nullStatement = (NullStatement) test.getTestCase().getStatement(statement); TestCase newTest = test.getTestCase(); TestCase oldTest = newTest.clone(); ExecutionResult oldResult = test.getLastExecutionResult(); //double oldFitness = test.getFitness(); Map<FitnessFunction<?>, Double> oldFitnesses = test.getFitnessValues(); Map<FitnessFunction<?>, Double> oldLastFitnesses = test.getPreviousFitnessValues(); try { TestFactory.getInstance().attemptGeneration(newTest, nullStatement.getReturnType(), statement); if (!objective.hasImproved(test)) { test.setTestCase(oldTest); test.setLastExecutionResult(oldResult); //test.setFitness(oldFitness); test.setFitnessValues(oldFitnesses); test.setPreviousFitnessValues(oldLastFitnesses); } else { return true; } } catch (ConstructionFailedException e) { // If we can't construct it, then ignore } return false; }
generatorRefToExclude = exclude; VariableReference reference = attemptGeneration(test, parameterType, position, recursionDepth, allowNull, generatorRefToExclude, canUseMocks, canReuseExistingVariables);