-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #607 from pimterry/theory-enum-failure-messages
Theories failure messages describe enum arguments unhelpfully
- Loading branch information
Showing
4 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/org/junit/tests/experimental/theories/PotentialAssignmentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.junit.tests.experimental.theories; | ||
|
||
import static org.junit.Assert.*; | ||
import org.junit.Test; | ||
import org.junit.experimental.theories.PotentialAssignment; | ||
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters