diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftInstanceOf_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftInstanceOf_Test.java index 33217817..736e2738 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftInstanceOf_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftInstanceOf_Test.java @@ -8,19 +8,18 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; - import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft; import static org.assertj.vavr.api.EitherShouldContainInstanceOf.shouldContainOnLeftInstanceOf; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsLeftInstanceOf_Test { @@ -28,29 +27,29 @@ class EitherAssert_containsLeftInstanceOf_Test { void should_fail_if_either_is_null() { Either actual = null; - assertThrows( - AssertionError.class, - () -> assertThat(actual).containsLeftInstanceOf(Object.class), - actualIsNull() - ); + assertThatThrownBy( + () -> assertThat(actual).containsLeftInstanceOf(Object.class) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_either_is_right() { Either actual = Either.right("some"); - assertThrows( - AssertionError.class, - () -> assertThat(actual).containsLeftInstanceOf(Object.class), - shouldBeLeft(actual).create() - ); + assertThatThrownBy( + () -> assertThat(actual).containsLeftInstanceOf(Object.class) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeLeft(actual).create()); } @Test void should_pass_if_either_contains_required_type_on_left() { assertThat(Either.left("something")) - .containsLeftInstanceOf(String.class) - .containsLeftInstanceOf(Object.class); + .containsLeftInstanceOf(String.class) + .containsLeftInstanceOf(Object.class); } @Test @@ -62,11 +61,11 @@ void should_pass_if_either_contains_required_type_subclass_on_left() { void should_fail_if_either_contains_other_type_on_left_than_required() { Either actual = Either.left(new ParentClass()); - assertThrows( - AssertionError.class, - () -> assertThat(actual).containsLeftInstanceOf(OtherClass.class), - shouldContainOnLeftInstanceOf(actual, OtherClass.class).create() - ); + assertThatThrownBy( + () -> assertThat(actual).containsLeftInstanceOf(OtherClass.class) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnLeftInstanceOf(actual, OtherClass.class).create()); } private static class ParentClass { diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftSame_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftSame_Test.java index 7cf069fb..937f7a09 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftSame_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftSame_Test.java @@ -1,4 +1,4 @@ -/** +/* * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at *

@@ -8,38 +8,37 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. *

- * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; - import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft; import static org.assertj.vavr.api.EitherShouldContain.shouldContainSameOnLeft; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsLeftSame_Test { @Test void should_fail_when_either_is_null() { - assertThrows( - AssertionError.class, - () -> assertThat((Either) null).containsLeftSame("something"), - actualIsNull() - ); + assertThatThrownBy( + () -> assertThat((Either) null).containsLeftSame("something") + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_expected_value_is_null() { - assertThrows( - IllegalArgumentException.class, - () -> assertThat(Either.left("something")).containsLeftSame(null), - "The expected value should not be ." - ); + assertThatThrownBy( + () -> assertThat(Either.left("something")).containsLeftSame(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); } @Test @@ -53,11 +52,12 @@ void should_fail_if_either_does_not_contain_same_instance_on_left_side() { Either actual = Either.left("something"); final String expectedValue = new String("something"); - assertThrows( - AssertionError.class, - () -> assertThat(actual).containsLeftSame(expectedValue), - shouldContainSameOnLeft(actual, expectedValue).create() - ); + assertThatThrownBy( + () -> assertThat(actual).containsLeftSame(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainSameOnLeft(actual, expectedValue).create() + ); } @Test @@ -65,10 +65,10 @@ void should_fail_if_either_is_right() { Either actual = Either.right("nothing"); String expectedValue = "something"; - assertThrows( - AssertionError.class, - () -> assertThat(actual).containsLeftSame(expectedValue), - shouldBeLeft(actual).create() - ); + assertThatThrownBy( + () -> assertThat(actual).containsLeftSame(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeLeft(actual).create()); } } diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeft_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeft_Test.java index 71fa64e2..e6f682f9 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeft_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsLeft_Test.java @@ -1,4 +1,4 @@ -/** +/* * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at *

@@ -8,38 +8,37 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. *

- * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; - import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft; import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnLeft; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsLeft_Test { @Test void should_fail_when_either_is_null() { - assertThrows( - AssertionError.class, - () -> assertThat((Either) null).containsOnLeft("something"), - actualIsNull() - ); + assertThatThrownBy( + () -> assertThat((Either) null).containsOnLeft("something") + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_expected_value_is_null() { - assertThrows( - IllegalArgumentException.class, - () -> assertThat(Either.left("something")).containsOnLeft(null), - "The expected value should not be ." - ); + assertThatThrownBy( + () -> assertThat(Either.left("something")).containsOnLeft(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); } @Test @@ -52,11 +51,11 @@ void should_fail_if_either_does_not_contain_expected_value_on_left_side() { Either actual = Either.left("something"); String expectedValue = "nothing"; - assertThrows( - AssertionError.class, - () -> assertThat(actual).containsOnLeft(expectedValue), - shouldContainOnLeft(actual, expectedValue).create() - ); + assertThatThrownBy( + () -> assertThat(actual).containsOnLeft(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnLeft(actual, expectedValue).create()); } @Test @@ -64,10 +63,10 @@ void should_fail_if_either_is_right() { Either actual = Either.right("nothing"); String expectedValue = "something"; - assertThrows( - AssertionError.class, - () -> assertThat(actual).containsOnLeft(expectedValue), - shouldBeLeft(actual).create() - ); + assertThatThrownBy( + () -> assertThat(actual).containsOnLeft(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeLeft(actual).create()); } } diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingFieldByFieldValueComparator_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingFieldByFieldValueComparator_Test.java index 338cd9d0..c6162599 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingFieldByFieldValueComparator_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingFieldByFieldValueComparator_Test.java @@ -8,48 +8,48 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft; import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnLeft; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsOnLeft_usingFieldByFieldValueComparator_Test { @Test void should_fail_when_either_is_null() { - assertThrows( - AssertionError.class, - () -> assertThat((Either) null) - .usingFieldByFieldValueComparator() - .containsOnLeft(new Foo("something")), - actualIsNull() - ); + assertThatThrownBy( + () -> assertThat((Either) null) + .usingFieldByFieldValueComparator() + .containsOnLeft(new Foo("something")) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_expected_value_is_null() { - assertThrows( - IllegalArgumentException.class, - () -> assertThat(Either.left(new Foo("something"))) - .usingFieldByFieldValueComparator() - .containsOnLeft(null), - "The expected value should not be ." - ); + assertThatThrownBy( + () -> assertThat(Either.left(new Foo("something"))) + .usingFieldByFieldValueComparator() + .containsOnLeft(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); } @Test void should_pass_if_left_sided_either_contains_expected_value() { assertThat(Either.left(new Foo("something"))) - .usingFieldByFieldValueComparator() - .containsOnLeft(new Foo("something")); + .usingFieldByFieldValueComparator() + .containsOnLeft(new Foo("something")); } @Test @@ -57,13 +57,13 @@ void should_fail_if_left_sided_either_does_not_contain_expected_value() { Either actual = Either.left(new Foo("something")); Foo expectedValue = new Foo("something else"); - assertThrows( - AssertionError.class, - () -> assertThat(actual) - .usingFieldByFieldValueComparator() - .containsOnLeft(expectedValue), - shouldContainOnLeft(actual, expectedValue).create() - ); + assertThatThrownBy( + () -> assertThat(actual) + .usingFieldByFieldValueComparator() + .containsOnLeft(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnLeft(actual, expectedValue).create()); } @Test @@ -71,13 +71,13 @@ void should_fail_if_either_is_right_sided() { Foo expectedValue = new Foo("test"); final Either actual = Either.right(new Foo("something else")); - assertThrows( - AssertionError.class, - () -> assertThat(actual) - .usingFieldByFieldValueComparator() - .containsOnLeft(expectedValue), - shouldBeLeft(actual).create() - ); + assertThatThrownBy( + () -> assertThat(actual) + .usingFieldByFieldValueComparator() + .containsOnLeft(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeLeft(actual).create()); } private static class Foo { diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingValueComparator_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingValueComparator_Test.java index 612f08ba..70de95cb 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingValueComparator_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingValueComparator_Test.java @@ -8,7 +8,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; @@ -17,57 +17,57 @@ import java.util.Comparator; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft; import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnLeft; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsOnLeft_usingValueComparator_Test { private static Comparator FOO_COMPARATOR = Comparator - .comparing(o -> o.getValue().toLowerCase()); + .comparing(o -> o.getValue().toLowerCase()); @Test void should_fail_when_either_is_null() { - assertThrows( - AssertionError.class, - () -> assertThat((Either) null) - .usingValueComparator(FOO_COMPARATOR) - .containsOnLeft(new Foo("something")), - actualIsNull() - ); + assertThatThrownBy( + () -> assertThat((Either) null) + .usingValueComparator(FOO_COMPARATOR) + .containsOnLeft(new Foo("something")) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_either_is_right_sided() { final Either actual = Either.right(new Foo("something")); - assertThrows( - AssertionError.class, - () -> assertThat(actual) - .usingValueComparator(FOO_COMPARATOR) - .containsOnLeft(new Object()), - shouldBeLeft(actual).create() - ); + assertThatThrownBy( + () -> assertThat(actual) + .usingValueComparator(FOO_COMPARATOR) + .containsOnLeft(new Object()) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeLeft(actual).create()); } @Test void should_fail_if_expected_value_is_null() { - assertThrows( - IllegalArgumentException.class, - () -> assertThat(Either.left(new Foo("something"))) - .usingValueComparator(FOO_COMPARATOR) - .containsOnLeft(null), - "The expected value should not be ." - ); + assertThatThrownBy( + () -> assertThat(Either.left(new Foo("something"))) + .usingValueComparator(FOO_COMPARATOR) + .containsOnLeft(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); } @Test void should_pass_if_left_sided_either_contains_expected_value() { assertThat(Either.left(new Foo("something"))) - .usingValueComparator(FOO_COMPARATOR) - .containsOnLeft(new Foo("SoMething")); + .usingValueComparator(FOO_COMPARATOR) + .containsOnLeft(new Foo("SoMething")); } @Test @@ -75,13 +75,13 @@ void should_fail_if_left_sided_either_does_not_contain_expected_value() { Either actual = Either.left(new Foo("something")); Foo expectedValue = new Foo("something else"); - assertThrows( - AssertionError.class, - () -> assertThat(actual) - .usingValueComparator(FOO_COMPARATOR) - .containsOnLeft(expectedValue), - shouldContainOnLeft(actual, expectedValue).create() - ); + assertThatThrownBy( + () -> assertThat(actual) + .usingValueComparator(FOO_COMPARATOR) + .containsOnLeft(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnLeft(actual, expectedValue).create()); } private static class Foo { diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingFieldByFieldValueComparator_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingFieldByFieldValueComparator_Test.java index 92adf9db..3480cbc9 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingFieldByFieldValueComparator_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingFieldByFieldValueComparator_Test.java @@ -8,77 +8,86 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeRight.shouldBeRight; import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnRight; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsOnRight_usingFieldByFieldValueComparator_Test { - @Test - void should_fail_when_either_is_null() { - assertThrows(AssertionError.class, () -> assertThat((Either) null) - .usingFieldByFieldValueComparator().containsOnRight(new Foo("something")), actualIsNull()); - } + @Test + void should_fail_when_either_is_null() { + assertThatThrownBy(() -> assertThat((Either) null) + .usingFieldByFieldValueComparator().containsOnRight(new Foo("something")) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); + } - @Test - void should_fail_if_expected_value_is_null() { - assertThrows( - IllegalArgumentException.class, () -> assertThat(Either.right(new Foo("something"))) - .usingFieldByFieldValueComparator().containsOnRight(null), - "The expected value should not be ."); - } + @Test + void should_fail_if_expected_value_is_null() { + assertThatThrownBy( + () -> assertThat(Either.right(new Foo("something"))) + .usingFieldByFieldValueComparator().containsOnRight(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); + } - @Test - void should_pass_if_right_sided_either_contains_expected_value() { - assertThat(Either.right(new Foo("something"))).usingFieldByFieldValueComparator() - .containsOnRight(new Foo("something")); - } + @Test + void should_pass_if_right_sided_either_contains_expected_value() { + assertThat(Either.right(new Foo("something"))).usingFieldByFieldValueComparator() + .containsOnRight(new Foo("something")); + } - @Test - void should_fail_if_right_sided_either_does_not_contain_expected_value() { - Either actual = Either.right(new Foo("something")); - Foo expectedValue = new Foo("something else"); + @Test + void should_fail_if_right_sided_either_does_not_contain_expected_value() { + Either actual = Either.right(new Foo("something")); + Foo expectedValue = new Foo("something else"); - assertThrows(AssertionError.class, - () -> assertThat(actual).usingFieldByFieldValueComparator().containsOnRight(expectedValue), - shouldContainOnRight(actual, expectedValue).create()); - } + assertThatThrownBy( + () -> assertThat(actual).usingFieldByFieldValueComparator().containsOnRight(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnRight(actual, expectedValue).create()); + } - @Test - void should_fail_if_either_is_left_sided() { - Foo expectedValue = new Foo("test"); - final Either actual = Either.left(new Foo("something else")); + @Test + void should_fail_if_either_is_left_sided() { + Foo expectedValue = new Foo("test"); + final Either actual = Either.left(new Foo("something else")); - assertThrows(AssertionError.class, - () -> assertThat(actual).usingFieldByFieldValueComparator().containsOnRight(expectedValue), - shouldBeRight(actual).create()); - } + assertThatThrownBy( + () -> assertThat(actual).usingFieldByFieldValueComparator().containsOnRight(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeRight(actual).create()); + } - private static class Foo { + private static class Foo { - private final String value; + private final String value; - Foo(String value) { - this.value = value; - } + Foo(String value) { + this.value = value; + } - @SuppressWarnings("unused") - String getValue() { - return value; - } + @SuppressWarnings("unused") + String getValue() { + return value; + } - @Override - public String toString() { - return "Foo{" + "value='" + value + '\'' + '}'; - } - } + @Override + public String toString() { + return "Foo{" + "value='" + value + '\'' + '}'; + } + } } diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingValueComparator_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingValueComparator_Test.java index c803a910..3726b444 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingValueComparator_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsOnRight_usingValueComparator_Test.java @@ -8,7 +8,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; @@ -17,47 +17,52 @@ import java.util.Comparator; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeRight.shouldBeRight; import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnRight; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsOnRight_usingValueComparator_Test { private static Comparator FOO_COMPARATOR = Comparator - .comparing(o -> o.getValue().toLowerCase()); + .comparing(o -> o.getValue().toLowerCase()); @Test void should_fail_when_either_is_null() { - assertThrows(AssertionError.class, - () -> assertThat((Either) null).usingValueComparator(FOO_COMPARATOR) - .containsOnRight(new Foo("something")), - actualIsNull()); + assertThatThrownBy(() -> assertThat((Either) null).usingValueComparator(FOO_COMPARATOR) + .containsOnRight(new Foo("something")) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_expected_value_is_null() { - assertThrows(IllegalArgumentException.class, - () -> assertThat(Either.right(new Foo("something"))).usingValueComparator(FOO_COMPARATOR).containsOnRight(null), - "The expected value should not be ."); + assertThatThrownBy( + () -> assertThat(Either.right(new Foo("something"))).usingValueComparator(FOO_COMPARATOR).containsOnRight(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); } @Test void should_fail_if_either_is_left_sided() { final Either actual = Either.left(new Foo("something")); - assertThrows(AssertionError.class, + assertThatThrownBy( () -> assertThat(actual).usingValueComparator(FOO_COMPARATOR) - .containsOnRight(new Object()), - shouldBeRight(actual).create()); + .containsOnRight(new Object()) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeRight(actual).create()); } @Test void should_pass_if_right_sided_either_contains_expected_value() { assertThat(Either.right(new Foo("something"))) - .usingValueComparator(FOO_COMPARATOR) - .containsOnRight(new Foo("SoMething")); + .usingValueComparator(FOO_COMPARATOR) + .containsOnRight(new Foo("SoMething")); } @Test @@ -65,9 +70,11 @@ void should_fail_if_right_sided_either_does_not_contain_expected_value() { Either actual = Either.right(new Foo("something")); Foo expectedValue = new Foo("something else"); - assertThrows(AssertionError.class, - () -> assertThat(actual).usingValueComparator(FOO_COMPARATOR).containsOnRight(expectedValue), - shouldContainOnRight(actual, expectedValue).create()); + assertThatThrownBy( + () -> assertThat(actual).usingValueComparator(FOO_COMPARATOR).containsOnRight(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnRight(actual, expectedValue).create()); } private static class Foo { diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightInstanceOf_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightInstanceOf_Test.java index d6123047..79cb80ee 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightInstanceOf_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightInstanceOf_Test.java @@ -8,18 +8,18 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeRight.shouldBeRight; import static org.assertj.vavr.api.EitherShouldContainInstanceOf.shouldContainOnRightInstanceOf; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsRightInstanceOf_Test { @@ -27,24 +27,28 @@ class EitherAssert_containsRightInstanceOf_Test { void should_fail_if_either_is_null() { Either actual = null; - assertThrows(AssertionError.class, - () -> assertThat(actual).containsRightInstanceOf(Object.class), - actualIsNull()); + assertThatThrownBy( + () -> assertThat(actual).containsRightInstanceOf(Object.class) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_either_is_left() { Either actual = Either.left("some"); - assertThrows(AssertionError.class, - () -> assertThat(actual).containsRightInstanceOf(Object.class), - shouldBeRight(actual).create()); + assertThatThrownBy( + () -> assertThat(actual).containsRightInstanceOf(Object.class) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeRight(actual).create()); } @Test void should_pass_if_either_contains_required_type_on_right() { assertThat(Either.right("something")).containsRightInstanceOf(String.class) - .containsRightInstanceOf(Object.class); + .containsRightInstanceOf(Object.class); } @Test @@ -56,9 +60,11 @@ void should_pass_if_either_contains_required_type_subclass_on_right() { void should_fail_if_either_contains_other_type_on_right_than_required() { Either actual = Either.right(new ParentClass()); - assertThrows(AssertionError.class, - () -> assertThat(actual).containsRightInstanceOf(OtherClass.class), - shouldContainOnRightInstanceOf(actual, OtherClass.class).create()); + assertThatThrownBy( + () -> assertThat(actual).containsRightInstanceOf(OtherClass.class) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnRightInstanceOf(actual, OtherClass.class).create()); } private static class ParentClass { diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightSame_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightSame_Test.java index c405f58d..07cb1ae0 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightSame_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsRightSame_Test.java @@ -1,4 +1,4 @@ -/** +/* * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at *

@@ -8,33 +8,37 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. *

- * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeRight.shouldBeRight; import static org.assertj.vavr.api.EitherShouldContain.shouldContainSameOnRight; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsRightSame_Test { @Test void should_fail_when_either_is_null() { - assertThrows(AssertionError.class, - () -> assertThat((Either) null).containsRightSame("something"), - actualIsNull()); + assertThatThrownBy( + () -> assertThat((Either) null).containsRightSame("something") + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_expected_value_is_null() { - assertThrows(IllegalArgumentException.class, - () -> assertThat(Either.right("something")).containsRightSame(null), - "The expected value should not be ."); + assertThatThrownBy( + () -> assertThat(Either.right("something")).containsRightSame(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); } @Test @@ -48,9 +52,11 @@ void should_fail_if_either_does_not_contain_same_instance_on_right_side() { Either actual = Either.right("something"); final String expectedValue = new String("something"); - assertThrows(AssertionError.class, - () -> assertThat(actual).containsRightSame(expectedValue), - shouldContainSameOnRight(actual, expectedValue).create()); + assertThatThrownBy( + () -> assertThat(actual).containsRightSame(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainSameOnRight(actual, expectedValue).create()); } @Test @@ -58,8 +64,10 @@ void should_fail_if_either_is_left() { Either actual = Either.left("nothing"); String expectedValue = "something"; - assertThrows(AssertionError.class, - () -> assertThat(actual).containsRightSame(expectedValue), - shouldBeRight(actual).create()); + assertThatThrownBy( + () -> assertThat(actual).containsRightSame(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeRight(actual).create()); } } diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_containsRight_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_containsRight_Test.java index e07f587d..dff12739 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_containsRight_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_containsRight_Test.java @@ -1,4 +1,4 @@ -/** +/* * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at *

@@ -8,33 +8,37 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. *

- * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeRight.shouldBeRight; import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnRight; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_containsRight_Test { @Test void should_fail_when_either_is_null() { - assertThrows(AssertionError.class, - () -> assertThat((Either) null).containsOnRight("something"), - actualIsNull()); + assertThatThrownBy( + () -> assertThat((Either) null).containsOnRight("something") + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_expected_value_is_null() { - assertThrows(IllegalArgumentException.class, - () -> assertThat(Either.right("something")).containsOnRight(null), - "The expected value should not be ."); + assertThatThrownBy( + () -> assertThat(Either.right("something")).containsOnRight(null) + ) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("The expected value should not be ."); } @Test @@ -47,9 +51,11 @@ void should_fail_if_either_does_not_contain_expected_value_on_right_side() { Either actual = Either.right("something"); String expectedValue = "nothing"; - assertThrows(AssertionError.class, - () -> assertThat(actual).containsOnRight(expectedValue), - shouldContainOnRight(actual, expectedValue).create()); + assertThatThrownBy( + () -> assertThat(actual).containsOnRight(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldContainOnRight(actual, expectedValue).create()); } @Test @@ -57,8 +63,10 @@ void should_fail_if_either_is_left() { Either actual = Either.left("nothing"); String expectedValue = "something"; - assertThrows(AssertionError.class, - () -> assertThat(actual).containsOnRight(expectedValue), - shouldBeRight(actual).create()); + assertThatThrownBy( + () -> assertThat(actual).containsOnRight(expectedValue) + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeRight(actual).create()); } } diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_isLeft_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_isLeft_Test.java index 033e5882..df61d69c 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_isLeft_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_isLeft_Test.java @@ -8,17 +8,17 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. *

- * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_isLeft_Test { @@ -29,17 +29,21 @@ void should_pass_if_Either_is_left() { @Test void should_fail_when_Either_is_null() { - assertThrows(AssertionError.class, - () -> assertThat((Either) null).isLeft(), - actualIsNull()); + assertThatThrownBy( + () -> assertThat((Either) null).isLeft() + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_Either_is_right() { Either actual = Either.right("right"); - assertThrows(AssertionError.class, - () -> assertThat(actual).isLeft(), - shouldBeLeft(actual).create()); + assertThatThrownBy( + () -> assertThat(actual).isLeft() + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeLeft(actual).create()); } } diff --git a/src/test/java/org/assertj/vavr/api/EitherAssert_isRight_Test.java b/src/test/java/org/assertj/vavr/api/EitherAssert_isRight_Test.java index 0b1eb041..2b1629da 100644 --- a/src/test/java/org/assertj/vavr/api/EitherAssert_isRight_Test.java +++ b/src/test/java/org/assertj/vavr/api/EitherAssert_isRight_Test.java @@ -8,17 +8,17 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. *

- * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. */ package org.assertj.vavr.api; import io.vavr.control.Either; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.FailureMessages.actualIsNull; import static org.assertj.vavr.api.EitherShouldBeRight.shouldBeRight; import static org.assertj.vavr.api.VavrAssertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; class EitherAssert_isRight_Test { @@ -29,17 +29,21 @@ void should_pass_if_Either_is_right() { @Test void should_fail_when_Either_is_null() { - assertThrows(AssertionError.class, - () -> assertThat((Either) null).isRight(), - actualIsNull()); + assertThatThrownBy( + () -> assertThat((Either) null).isRight() + ) + .isInstanceOf(AssertionError.class) + .hasMessage(actualIsNull()); } @Test void should_fail_if_Either_is_left() { Either actual = Either.left("left"); - assertThrows(AssertionError.class, - () -> assertThat(actual).isRight(), - shouldBeRight(actual).create()); + assertThatThrownBy( + () -> assertThat(actual).isRight() + ) + .isInstanceOf(AssertionError.class) + .hasMessage(shouldBeRight(actual).create()); } }