Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public SELF containsInvalid(INVALID expectedErrorValue) {
*/
public SELF containsValidSame(VALID expectedValue) {
assertIsValid();
checkNotNull(expectedValue);
if (actual.get() != expectedValue)
throwAssertionError(shouldContainValidSame(actual, expectedValue));
return myself;
Expand All @@ -122,7 +123,7 @@ public SELF containsValidSame(VALID expectedValue) {
* @param expectedErrorValue the expected value inside the {@link io.vavr.control.Validation}.
* @return this assertion object.
*/
public SELF containsInvalidSame(VALID expectedErrorValue) {
public SELF containsInvalidSame(INVALID expectedErrorValue) {
assertIsInvalid();
checkNotNull(expectedErrorValue);
if (actual.getError() != expectedErrorValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static <INVALID, VALID> ValidationShouldContain shouldContainValidSame(Validatio
* @param <VALID> type of the value in the case of the valid {@link Validation}.
* @return an error message factory
*/
static <INVALID, VALID> ValidationShouldContain shouldContainInvalidSame(Validation<INVALID, VALID> validation, VALID expectedErrorValue) {
static <INVALID, VALID> ValidationShouldContain shouldContainInvalidSame(Validation<INVALID, VALID> validation, INVALID expectedErrorValue) {
return validation.isInvalid() ?
new ValidationShouldContain(EXPECTING_TO_CONTAIN_SAME, validation, expectedErrorValue) :
shouldContainButIsValid(validation, expectedErrorValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ void should_fail_when_validation_is_null() {
.hasMessage(actualIsNull());
}

@Test
void should_fail_if_expected_value_is_null() {
assertThatThrownBy(
() -> assertThat(Validation.valid("something")).containsValidSame(null)
)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("The expected value should not be <null>.");
}

@Test
void should_pass_if_validation_contains_same_instance_as_valid_value() {
final String value = "something";
Expand Down