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 @@ -8,49 +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.EitherShouldContainInstanceOf.shouldContainOnLeftInstanceOf;
import static org.assertj.vavr.api.VavrAssertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

class EitherAssert_containsLeftInstanceOf_Test {

@Test
void should_fail_if_either_is_null() {
Either<Object, Object> 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<String, Object> 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
Expand All @@ -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<Object, ParentClass> 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* <p>
Expand All @@ -8,29 +8,28 @@
* 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.
* <p>
* 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<String, String>) null).containsLeftSame("something"),
actualIsNull()
);
assertThatThrownBy(
() -> assertThat((Either<String, String>) null).containsLeftSame("something")
)
.isInstanceOf(AssertionError.class)
.hasMessage(actualIsNull());
}

@Test
Expand All @@ -44,22 +43,23 @@ void should_fail_if_either_does_not_contain_same_instance_on_left_side() {
Either<String, String> 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
void should_fail_if_either_is_right() {
Either<String, String> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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
* <p>
Expand All @@ -8,29 +8,28 @@
* 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.
* <p>
* 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<String, String>) null).containsOnLeft("something"),
actualIsNull()
);
assertThatThrownBy(
() -> assertThat((Either<String, String>) null).containsOnLeft("something")
)
.isInstanceOf(AssertionError.class)
.hasMessage(actualIsNull());
}

@Test
Expand All @@ -43,22 +42,22 @@ void should_fail_if_either_does_not_contain_expected_value_on_left_side() {
Either<String, String> 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
void should_fail_if_either_is_right() {
Either<String, String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,65 @@
* 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<Foo, String>) null)
.usingFieldByFieldValueComparator()
.containsOnLeft(new Foo("something")),
actualIsNull()
);
assertThatThrownBy(
() -> assertThat((Either<Foo, String>) null)
.usingFieldByFieldValueComparator()
.containsOnLeft(new Foo("something"))
)
.isInstanceOf(AssertionError.class)
.hasMessage(actualIsNull());
}

@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
void should_fail_if_left_sided_either_does_not_contain_expected_value() {
Either<Foo, String> 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
void should_fail_if_either_is_right_sided() {
Foo expectedValue = new Foo("test");
final Either<Object, Foo> 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 {
Expand Down
Loading