@Test
 public void should_use_AssertionErrorFactory_when_overriding_error_message_is_not_specified() {
   MyOwnAssertionError expectedError = new MyOwnAssertionError("[description] my message");
   Description description = new TestDescription("description");
   info.description(description);
   when(errorFactory.newAssertionError(description)).thenReturn(expectedError);
   AssertionError failure = failures.failure(info, errorFactory);
   assertSame(expectedError, failure);
 }
Example #2
0
 /**
  * Creates a <code>{@link AssertionError}</code> following this pattern:
  *
  * <ol>
  *   <li>creates a <code>{@link AssertionError}</code> using <code>
  *       {@link AssertionInfo#overridingErrorMessage()}</code> as the error message if such value
  *       is not {@code null}, or
  *   <li>uses the given <code>{@link AssertionErrorFactory}</code> to create an <code>
  *       {@link AssertionError}</code>, prepending the value of <code>
  *       {@link AssertionInfo#description()}</code> to the error message
  * </ol>
  *
  * @param info contains information about the failed assertion.
  * @param factory knows how to create {@code AssertionError}s.
  * @return the created <code>{@link AssertionError}</code>.
  */
 public AssertionError failure(AssertionInfo info, AssertionErrorFactory factory) {
   AssertionError error = failureIfErrorMessageIsOverridden(info);
   if (error != null) return error;
   printThreadDumpIfNeeded();
   return factory.newAssertionError(info.description(), info.representation());
 }