Incorrect exceptions order in message if cause is not instance of expected type (fixes
add a test
*/
package org.assertj.core.api.throwable;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.test.ExpectedException.none;
import static org.mockito.Mockito.verify;
import org.assertj.core.api.ThrowableAssert;
import org.assertj.core.api.ThrowableAssertBaseTest;
+import org.assertj.core.test.ExpectedException;
+import org.junit.Rule;
+import org.junit.Test;
public class ThrowableAssert_hasCause_Test extends ThrowableAssertBaseTest {
+ @Rule
+ public ExpectedException thrown = none();
+
private Throwable npe = new NullPointerException();
@Override
@@ -30,4 +38,14 @@ public class ThrowableAssert_hasCause_Test extends ThrowableAssertBaseTest {
protected void verify_internal_effects() {
verify(throwables).assertHasCause(getInfo(assertions), getActual(assertions), npe);
}
+
+ @Test
+ public void should_fail_if_actual_and_expected_cause_have_different_types() {
+ thrown.expectAssertionError("%n" +
+ "Expecting a cause with type:%n" +
+ " <\"java.lang.NullPointerException\">%n" +
+ "but type was:%n" +
+ " <\"java.lang.IllegalStateException\">.");
+ assertThat(new IllegalArgumentException(new IllegalStateException())).hasCause(new NullPointerException());
+ }
}
