Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jan 18, 2013
1 parent 39d8b9e commit 7a12b70
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ public String toString() {

@Override
public String getDescription() {
String valueString;
if (value == null) {
valueString = "null";
} else {
try {
valueString = format("\"%s\"", value);
} catch (Throwable e) {
valueString = format("[toString() threw %s: %s]",
e.getClass().getSimpleName(), e.getMessage());
}
}
return format("%s <from %s>", valueString, name);
String valueString;

if (value == null) {
valueString = "null";
} else {
try {
valueString = format("\"%s\"", value);
} catch (Throwable e) {
valueString = format("[toString() threw %s: %s]",
e.getClass().getSimpleName(), e.getMessage());
}
}

return format("%s <from %s>", valueString, name);
}
};
}

public abstract Object getValue() throws CouldNotGenerateValueException;

public abstract String getDescription() throws CouldNotGenerateValueException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,52 @@
import org.junit.experimental.theories.PotentialAssignment.CouldNotGenerateValueException;

public class PotentialAssignmentTest {
@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());
}
@Test
public void shouldReturnGivenValue() throws CouldNotGenerateValueException {
Object value = new Object();
PotentialAssignment assignment = PotentialAssignment.forValue("name", value);
assertEquals(value, assignment.getValue());
}

@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());
}

@Test
public void shouldReturnGivenValue() throws CouldNotGenerateValueException {
Object value = new Object();
PotentialAssignment assignment = PotentialAssignment.forValue("name", value);
assertEquals(value, assignment.getValue());
}

}

0 comments on commit 7a12b70

Please sign in to comment.