/** {@inheritDoc} */ @Override public VariableReference getRandomObject(int position) { List<VariableReference> variables = getObjects(position); if (variables.isEmpty()) return null; return Randomness.choice(variables); }
/** {@inheritDoc} */ @Override public VariableReference getRandomObject(Type type, int position) throws ConstructionFailedException { assert (type != null); List<VariableReference> variables = getObjects(type, position); if (variables.isEmpty()) throw new ConstructionFailedException("Found no variables of type " + type + " at position " + position); return Randomness.choice(variables); }
/** {@inheritDoc} */ @Override public VariableReference getRandomNonNullObject(Type type, int position) throws ConstructionFailedException { Inputs.checkNull(type); List<VariableReference> variables = getObjects(type, position); Iterator<VariableReference> iterator = variables.iterator(); while (iterator.hasNext()) { VariableReference ref = iterator.next(); if (ref instanceof NullReference || (this.getStatement(ref.getStPosition()) instanceof FunctionalMockStatement) ) { iterator.remove(); } } if (variables.isEmpty()) throw new ConstructionFailedException("Found no variables of type " + type + " at position " + position); return Randomness.choice(variables); }
/** {@inheritDoc} */ @Override public VariableReference getRandomNonNullNonPrimitiveObject(Type type, int position) throws ConstructionFailedException { Inputs.checkNull(type); List<VariableReference> variables = getObjects(type, position); Iterator<VariableReference> iterator = variables.iterator(); while (iterator.hasNext()) { VariableReference var = iterator.next(); if (var instanceof NullReference) iterator.remove(); else if (getStatement(var.getStPosition()) instanceof PrimitiveStatement) iterator.remove(); else if (var.isPrimitive() || var.isWrapperType()) iterator.remove(); else if(this.getStatement(var.getStPosition()) instanceof FunctionalMockStatement && !(this.getStatement(var.getStPosition()) instanceof FunctionalMockForAbstractClassStatement)) iterator.remove(); } if (variables.isEmpty()) throw new ConstructionFailedException("Found no variables of type " + type + " at position " + position); return Randomness.choice(variables); }