class ShouldHaveRootCause extends BasicErrorMessageFactory {

  public static ErrorMessageFactory shouldHaveRootCauseWithMessage(Throwable actual, Throwable actualCause,
                                                                   String expectedMessage) {
    checkArgument(actual != null, "actual should not be null");
    checkArgument(expectedMessage != null, "expected root cause message should not be null");
    if (actualCause == null) return new ShouldHaveRootCause(actual, expectedMessage);
    return new ShouldHaveRootCause(actual, actualCause, expectedMessage);
  }

  public static ErrorMessageFactory shouldHaveRootCause(Throwable actual, Throwable actualCause, Throwable expectedCause) {<FILL_FUNCTION_BODY>}

  public static ErrorMessageFactory shouldHaveRootCause(Throwable actualCause) {
    return new BasicErrorMessageFactory("Expecting actual throwable to have a root cause but it did not, actual was:%n%s",
                                        actualCause);
  }

  private ShouldHaveRootCause(Throwable actual, Throwable actualCause, Throwable expectedCause) {
    super("%n" +
          "Expecting a root cause with type:%n" +
          "  %s%n" +
          "and message:%n" +
          "  %s%n" +
          "but type was:%n" +
          "  %s%n" +
          "and message was:%n" +
          "  %s." +
          "%n" +
          "Throwable that failed the check:%n" +
          "%n" + escapePercent(getStackTrace(actual)), // to avoid AssertJ default String formatting
          expectedCause.getClass().getName(), expectedCause.getMessage(),
          actualCause.getClass().getName(), actualCause.getMessage());
  }

  private ShouldHaveRootCause(Throwable actual, Throwable expectedCause) {
    super("%n" +
          "Expecting a root cause with type:%n" +
          "  %s%n" +
          "and message:%n" +
          "  %s%n" +
          "but actual had no root cause." +
          "%n" +
          "Throwable that failed the check:%n" +
          "%n" + escapePercent(getStackTrace(actual)), // to avoid AssertJ default String formatting
          expectedCause.getClass().getName(), expectedCause.getMessage());
  }

  private ShouldHaveRootCause(Throwable actual, Throwable actualCause, Class<? extends Throwable> expectedCauseClass) {
    super("%n" +
          "Expecting a root cause with type:%n" +
          "  %s%n" +
          "but type was:%n" +
          "  %s." +
          "%n" +
          "Throwable that failed the check:%n" +
          "%n" + escapePercent(getStackTrace(actual)), // to avoid AssertJ default String formatting
          expectedCauseClass.getName(), actualCause.getClass().getName());
  }

  private ShouldHaveRootCause(Throwable actual, String expectedMessage) {
    super("%n" +
          "Expecting a root cause with message:%n" +
          "  %s%n" +
          "but actual had no root cause." +
          "%n" +
          "Throwable that failed the check:%n" +
          "%n" + escapePercent(getStackTrace(actual)), // to avoid AssertJ default String formatting
          expectedMessage);
  }

  private ShouldHaveRootCause(Throwable actual, Throwable actualCause, String expectedCauseMessage) {
    super("%n" +
          "Expecting a root cause with message:%n" +
          "  %s%n" +
          "but message was:%n" +
          "  %s." +
          "%n" +
          "Throwable that failed the check:%n" +
          "%n" + escapePercent(getStackTrace(actual)), // to avoid AssertJ default String formatting
          expectedCauseMessage, actualCause.getMessage());
  }
}

    checkArgument(actual != null, "actual should not be null");
    checkArgument(expectedCause != null, "expected cause should not be null");
    // actualCause has no cause
    if (actualCause == null) return new ShouldHaveRootCause(actual, expectedCause);
    // same message => different type
    if (Objects.equals(actualCause.getMessage(), expectedCause.getMessage()))
      return new ShouldHaveRootCause(actual, actualCause, expectedCause.getClass());
    // same type => different message
    if (Objects.equals(actualCause.getClass(), expectedCause.getClass()))
      return new ShouldHaveRootCause(actual, actualCause, expectedCause.getMessage());
    return new ShouldHaveRootCause(actual, actualCause, expectedCause);
  
<methods>public transient void <init>(java.lang.String, java.lang.Object[]) ,public java.lang.String create(org.assertj.core.description.Description, org.assertj.core.presentation.Representation) ,public java.lang.String create(org.assertj.core.description.Description) ,public java.lang.String create() ,public boolean equals(java.lang.Object) ,public int hashCode() ,public java.lang.String toString() <variables>protected final non-sealed java.lang.Object[] arguments,protected final non-sealed java.lang.String format,org.assertj.core.error.MessageFormatter formatter