Skip to content

Commit f4d828f

Browse files
authored
Fixes #43 (#52)
* Fixes assertions on error messages in Option tests (#45) * Fixes assertions on error messages in Lazy tests (#46) * Fixes assertions on exceptions messages in Seq tests (#47) * Fixes assertions on exceptions messages in Try tests (#48) * Fixes assertions on exceptions messages in Either tests (#50)
1 parent c3d6c01 commit f4d828f

File tree

42 files changed

+765
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+765
-538
lines changed

src/test/java/org/assertj/vavr/api/EitherAssert_containsLeftInstanceOf_Test.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,48 @@
88
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
99
* specific language governing permissions and limitations under the License.
1010
*
11-
* Copyright 2012-2017 the original author or authors.
11+
* Copyright 2012-2019 the original author or authors.
1212
*/
1313
package org.assertj.vavr.api;
1414

1515
import io.vavr.control.Either;
16-
1716
import org.junit.jupiter.api.Test;
1817

18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1919
import static org.assertj.core.util.FailureMessages.actualIsNull;
2020
import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft;
2121
import static org.assertj.vavr.api.EitherShouldContainInstanceOf.shouldContainOnLeftInstanceOf;
2222
import static org.assertj.vavr.api.VavrAssertions.assertThat;
23-
import static org.junit.jupiter.api.Assertions.assertThrows;
2423

2524
class EitherAssert_containsLeftInstanceOf_Test {
2625

2726
@Test
2827
void should_fail_if_either_is_null() {
2928
Either<Object, Object> actual = null;
3029

31-
assertThrows(
32-
AssertionError.class,
33-
() -> assertThat(actual).containsLeftInstanceOf(Object.class),
34-
actualIsNull()
35-
);
30+
assertThatThrownBy(
31+
() -> assertThat(actual).containsLeftInstanceOf(Object.class)
32+
)
33+
.isInstanceOf(AssertionError.class)
34+
.hasMessage(actualIsNull());
3635
}
3736

3837
@Test
3938
void should_fail_if_either_is_right() {
4039
Either<String, Object> actual = Either.right("some");
4140

42-
assertThrows(
43-
AssertionError.class,
44-
() -> assertThat(actual).containsLeftInstanceOf(Object.class),
45-
shouldBeLeft(actual).create()
46-
);
41+
assertThatThrownBy(
42+
() -> assertThat(actual).containsLeftInstanceOf(Object.class)
43+
)
44+
.isInstanceOf(AssertionError.class)
45+
.hasMessage(shouldBeLeft(actual).create());
4746
}
4847

4948
@Test
5049
void should_pass_if_either_contains_required_type_on_left() {
5150
assertThat(Either.left("something"))
52-
.containsLeftInstanceOf(String.class)
53-
.containsLeftInstanceOf(Object.class);
51+
.containsLeftInstanceOf(String.class)
52+
.containsLeftInstanceOf(Object.class);
5453
}
5554

5655
@Test
@@ -62,11 +61,11 @@ void should_pass_if_either_contains_required_type_subclass_on_left() {
6261
void should_fail_if_either_contains_other_type_on_left_than_required() {
6362
Either<Object, ParentClass> actual = Either.left(new ParentClass());
6463

65-
assertThrows(
66-
AssertionError.class,
67-
() -> assertThat(actual).containsLeftInstanceOf(OtherClass.class),
68-
shouldContainOnLeftInstanceOf(actual, OtherClass.class).create()
69-
);
64+
assertThatThrownBy(
65+
() -> assertThat(actual).containsLeftInstanceOf(OtherClass.class)
66+
)
67+
.isInstanceOf(AssertionError.class)
68+
.hasMessage(shouldContainOnLeftInstanceOf(actual, OtherClass.class).create());
7069
}
7170

7271
private static class ParentClass {
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
33
* the License. You may obtain a copy of the License at
44
* <p>
@@ -8,29 +8,28 @@
88
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
99
* specific language governing permissions and limitations under the License.
1010
* <p>
11-
* Copyright 2012-2017 the original author or authors.
11+
* Copyright 2012-2019 the original author or authors.
1212
*/
1313
package org.assertj.vavr.api;
1414

1515
import io.vavr.control.Either;
16-
1716
import org.junit.jupiter.api.Test;
1817

18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1919
import static org.assertj.core.util.FailureMessages.actualIsNull;
2020
import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft;
2121
import static org.assertj.vavr.api.EitherShouldContain.shouldContainSameOnLeft;
2222
import static org.assertj.vavr.api.VavrAssertions.assertThat;
23-
import static org.junit.jupiter.api.Assertions.assertThrows;
2423

2524
class EitherAssert_containsLeftSame_Test {
2625

2726
@Test
2827
void should_fail_when_either_is_null() {
29-
assertThrows(
30-
AssertionError.class,
31-
() -> assertThat((Either<String, String>) null).containsLeftSame("something"),
32-
actualIsNull()
33-
);
28+
assertThatThrownBy(
29+
() -> assertThat((Either<String, String>) null).containsLeftSame("something")
30+
)
31+
.isInstanceOf(AssertionError.class)
32+
.hasMessage(actualIsNull());
3433
}
3534

3635
@Test
@@ -44,22 +43,23 @@ void should_fail_if_either_does_not_contain_same_instance_on_left_side() {
4443
Either<String, String> actual = Either.left("something");
4544
final String expectedValue = new String("something");
4645

47-
assertThrows(
48-
AssertionError.class,
49-
() -> assertThat(actual).containsLeftSame(expectedValue),
50-
shouldContainSameOnLeft(actual, expectedValue).create()
51-
);
46+
assertThatThrownBy(
47+
() -> assertThat(actual).containsLeftSame(expectedValue)
48+
)
49+
.isInstanceOf(AssertionError.class)
50+
.hasMessage(shouldContainSameOnLeft(actual, expectedValue).create()
51+
);
5252
}
5353

5454
@Test
5555
void should_fail_if_either_is_right() {
5656
Either<String, String> actual = Either.right("nothing");
5757
String expectedValue = "something";
5858

59-
assertThrows(
60-
AssertionError.class,
61-
() -> assertThat(actual).containsLeftSame(expectedValue),
62-
shouldBeLeft(actual).create()
63-
);
59+
assertThatThrownBy(
60+
() -> assertThat(actual).containsLeftSame(expectedValue)
61+
)
62+
.isInstanceOf(AssertionError.class)
63+
.hasMessage(shouldBeLeft(actual).create());
6464
}
6565
}
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
33
* the License. You may obtain a copy of the License at
44
* <p>
@@ -8,29 +8,28 @@
88
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
99
* specific language governing permissions and limitations under the License.
1010
* <p>
11-
* Copyright 2012-2017 the original author or authors.
11+
* Copyright 2012-2019 the original author or authors.
1212
*/
1313
package org.assertj.vavr.api;
1414

1515
import io.vavr.control.Either;
16-
1716
import org.junit.jupiter.api.Test;
1817

18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1919
import static org.assertj.core.util.FailureMessages.actualIsNull;
2020
import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft;
2121
import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnLeft;
2222
import static org.assertj.vavr.api.VavrAssertions.assertThat;
23-
import static org.junit.jupiter.api.Assertions.assertThrows;
2423

2524
class EitherAssert_containsLeft_Test {
2625

2726
@Test
2827
void should_fail_when_either_is_null() {
29-
assertThrows(
30-
AssertionError.class,
31-
() -> assertThat((Either<String, String>) null).containsOnLeft("something"),
32-
actualIsNull()
33-
);
28+
assertThatThrownBy(
29+
() -> assertThat((Either<String, String>) null).containsOnLeft("something")
30+
)
31+
.isInstanceOf(AssertionError.class)
32+
.hasMessage(actualIsNull());
3433
}
3534

3635
@Test
@@ -43,22 +42,22 @@ void should_fail_if_either_does_not_contain_expected_value_on_left_side() {
4342
Either<String, String> actual = Either.left("something");
4443
String expectedValue = "nothing";
4544

46-
assertThrows(
47-
AssertionError.class,
48-
() -> assertThat(actual).containsOnLeft(expectedValue),
49-
shouldContainOnLeft(actual, expectedValue).create()
50-
);
45+
assertThatThrownBy(
46+
() -> assertThat(actual).containsOnLeft(expectedValue)
47+
)
48+
.isInstanceOf(AssertionError.class)
49+
.hasMessage(shouldContainOnLeft(actual, expectedValue).create());
5150
}
5251

5352
@Test
5453
void should_fail_if_either_is_right() {
5554
Either<String, String> actual = Either.right("nothing");
5655
String expectedValue = "something";
5756

58-
assertThrows(
59-
AssertionError.class,
60-
() -> assertThat(actual).containsOnLeft(expectedValue),
61-
shouldBeLeft(actual).create()
62-
);
57+
assertThatThrownBy(
58+
() -> assertThat(actual).containsOnLeft(expectedValue)
59+
)
60+
.isInstanceOf(AssertionError.class)
61+
.hasMessage(shouldBeLeft(actual).create());
6362
}
6463
}

src/test/java/org/assertj/vavr/api/EitherAssert_containsOnLeft_usingFieldByFieldValueComparator_Test.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,65 @@
88
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
99
* specific language governing permissions and limitations under the License.
1010
*
11-
* Copyright 2012-2017 the original author or authors.
11+
* Copyright 2012-2019 the original author or authors.
1212
*/
1313
package org.assertj.vavr.api;
1414

1515
import io.vavr.control.Either;
1616
import org.junit.jupiter.api.Test;
1717

18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1819
import static org.assertj.core.util.FailureMessages.actualIsNull;
1920
import static org.assertj.vavr.api.EitherShouldBeLeft.shouldBeLeft;
2021
import static org.assertj.vavr.api.EitherShouldContain.shouldContainOnLeft;
2122
import static org.assertj.vavr.api.VavrAssertions.assertThat;
22-
import static org.junit.jupiter.api.Assertions.assertThrows;
2323

2424
class EitherAssert_containsOnLeft_usingFieldByFieldValueComparator_Test {
2525

2626
@Test
2727
void should_fail_when_either_is_null() {
28-
assertThrows(
29-
AssertionError.class,
30-
() -> assertThat((Either<Foo, String>) null)
31-
.usingFieldByFieldValueComparator()
32-
.containsOnLeft(new Foo("something")),
33-
actualIsNull()
34-
);
28+
assertThatThrownBy(
29+
() -> assertThat((Either<Foo, String>) null)
30+
.usingFieldByFieldValueComparator()
31+
.containsOnLeft(new Foo("something"))
32+
)
33+
.isInstanceOf(AssertionError.class)
34+
.hasMessage(actualIsNull());
3535
}
3636

3737
@Test
3838
void should_pass_if_left_sided_either_contains_expected_value() {
3939
assertThat(Either.left(new Foo("something")))
40-
.usingFieldByFieldValueComparator()
41-
.containsOnLeft(new Foo("something"));
40+
.usingFieldByFieldValueComparator()
41+
.containsOnLeft(new Foo("something"));
4242
}
4343

4444
@Test
4545
void should_fail_if_left_sided_either_does_not_contain_expected_value() {
4646
Either<Foo, String> actual = Either.left(new Foo("something"));
4747
Foo expectedValue = new Foo("something else");
4848

49-
assertThrows(
50-
AssertionError.class,
51-
() -> assertThat(actual)
52-
.usingFieldByFieldValueComparator()
53-
.containsOnLeft(expectedValue),
54-
shouldContainOnLeft(actual, expectedValue).create()
55-
);
49+
assertThatThrownBy(
50+
() -> assertThat(actual)
51+
.usingFieldByFieldValueComparator()
52+
.containsOnLeft(expectedValue)
53+
)
54+
.isInstanceOf(AssertionError.class)
55+
.hasMessage(shouldContainOnLeft(actual, expectedValue).create());
5656
}
5757

5858
@Test
5959
void should_fail_if_either_is_right_sided() {
6060
Foo expectedValue = new Foo("test");
6161
final Either<Object, Foo> actual = Either.right(new Foo("something else"));
6262

63-
assertThrows(
64-
AssertionError.class,
65-
() -> assertThat(actual)
66-
.usingFieldByFieldValueComparator()
67-
.containsOnLeft(expectedValue),
68-
shouldBeLeft(actual).create()
69-
);
63+
assertThatThrownBy(
64+
() -> assertThat(actual)
65+
.usingFieldByFieldValueComparator()
66+
.containsOnLeft(expectedValue)
67+
)
68+
.isInstanceOf(AssertionError.class)
69+
.hasMessage(shouldBeLeft(actual).create());
7070
}
7171

7272
private static class Foo {

0 commit comments

Comments
 (0)