public Object[] getActualValues(int start, int stop) throws CouldNotGenerateValueException { Object[] values = new Object[stop - start]; for (int i = start; i < stop; i++) { values[i - start] = fAssigned.get(i).getValue(); } return values; }
public Object[] getArgumentStrings(boolean nullsOk) throws CouldNotGenerateValueException { Object[] values = new Object[fAssigned.size()]; for (int i = 0; i < values.length; i++) { values[i] = fAssigned.get(i).getDescription(); } return values; }
@Test public void shouldUseQuotedValueInDescription() throws CouldNotGenerateValueException { String name = "stringDatapoint"; Object value = new Object() { @Override public String toString() { return "string value"; } }; PotentialAssignment assignment = PotentialAssignment.forValue(name, value); assertEquals("\"string value\" <from stringDatapoint>", assignment.getDescription()); }
@Test public void shouldNotUseQuotesForNullValueDescriptions() throws CouldNotGenerateValueException { String name = "nullDatapoint"; Object value = null; PotentialAssignment assignment = PotentialAssignment.forValue(name, value); assertEquals("null <from nullDatapoint>", assignment.getDescription()); }
@Test public void shouldIncludeFailureInDescriptionIfToStringFails() throws CouldNotGenerateValueException { String name = "explodingValue"; Object value = new Object() { @Override public String toString() { throw new RuntimeException("Oh no!"); } }; PotentialAssignment assignment = PotentialAssignment.forValue(name, value); assertEquals("[toString() threw RuntimeException: Oh no!] <from explodingValue>", assignment.getDescription()); }
private List<String> getStringValuesFromAssignments(List<PotentialAssignment> assignments) throws CouldNotGenerateValueException { List<String> stringValues = new ArrayList<String>(); for (PotentialAssignment assignment : assignments) { stringValues.add((String) assignment.getValue()); } return stringValues; }
private Statement methodCompletesWithParameters( final FrameworkMethod method, final Assignments complete, final Object freshInstance) { return new Statement() { @Override public void evaluate() throws Throwable { try { final Object[] values = complete.getMethodArguments( nullsOk()); method.invokeExplosively(freshInstance, values); } catch (CouldNotGenerateValueException e) { // ignore } } }; }
public Object[] getActualValues(int start, int stop, boolean nullsOk) throws CouldNotGenerateValueException { Object[] values = new Object[stop - start]; for (int i = start; i < stop; i++) { Object value = fAssigned.get(i).getValue(); if (value == null && !nullsOk) { throw new CouldNotGenerateValueException(); } values[i - start] = value; } return values; }
public Object[] getConstructorArguments() throws CouldNotGenerateValueException { return getActualValues(0, getConstructorParameterCount()); }
public Object[] getMethodArguments() throws CouldNotGenerateValueException { return getActualValues(getConstructorParameterCount(), fAssigned.size()); }
public Object[] getAllArguments() throws CouldNotGenerateValueException { return getActualValues(0, fAssigned.size()); }
@Test public void shouldReturnGivenValue() throws CouldNotGenerateValueException { Object value = new Object(); PotentialAssignment assignment = PotentialAssignment.forValue("name", value); assertEquals(value, assignment.getValue()); }
public Object[] getConstructorArguments(boolean nullsOk) throws CouldNotGenerateValueException { return getActualValues(0, getConstructorParameterCount(), nullsOk); }
public Object[] getMethodArguments(boolean nullsOk) throws CouldNotGenerateValueException { return getActualValues(getConstructorParameterCount(), fAssigned.size(), nullsOk); }
public Object[] getAllArguments(boolean nullsOk) throws CouldNotGenerateValueException { return getActualValues(0, fAssigned.size(), nullsOk); }