Skip to content

Commit 3be19b9

Browse files
committed
Formatted file using ktlint
1 parent 2476944 commit 3be19b9

File tree

2 files changed

+119
-112
lines changed

2 files changed

+119
-112
lines changed

src/main/kotlin/in/rcard/assertj/arrowcore/AbstractEitherAssert.kt

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -19,93 +19,93 @@ import org.assertj.core.internal.StandardComparisonStrategy
1919
* @author Riccardo Cardin
2020
*/
2121
abstract class AbstractEitherAssert<
22-
SELF : AbstractEitherAssert<SELF, LEFT, RIGHT>, LEFT : Any, RIGHT : Any>(
23-
either: Either<LEFT, RIGHT>?
22+
SELF : AbstractEitherAssert<SELF, LEFT, RIGHT>, LEFT : Any, RIGHT : Any,>(
23+
either: Either<LEFT, RIGHT>?,
2424
) : AbstractObjectAssert<SELF, Either<LEFT, RIGHT>>(either, AbstractEitherAssert::class.java) {
2525

26-
private val comparisonStrategy: ComparisonStrategy = StandardComparisonStrategy.instance()
26+
private val comparisonStrategy: ComparisonStrategy = StandardComparisonStrategy.instance()
2727

28-
/**
29-
* Verifies that the actual [Either] is right.
30-
*
31-
* @return this assertion object.
32-
*/
33-
fun isRight(): SELF {
34-
isNotNull
35-
assertIsRight()
36-
return myself
37-
}
28+
/**
29+
* Verifies that the actual [Either] is right.
30+
*
31+
* @return this assertion object.
32+
*/
33+
fun isRight(): SELF {
34+
isNotNull
35+
assertIsRight()
36+
return myself
37+
}
3838

39-
/**
40-
* Verifies that the actual [Either] is left.
41-
*
42-
* @return this assertion object.
43-
*/
44-
fun isLeft(): SELF {
45-
assertIsLeft()
46-
return myself
47-
}
39+
/**
40+
* Verifies that the actual [Either] is left.
41+
*
42+
* @return this assertion object.
43+
*/
44+
fun isLeft(): SELF {
45+
assertIsLeft()
46+
return myself
47+
}
4848

49-
/**
50-
* Verifies that the actual [Either] is [Either.Right] and contains the given value.
51-
*
52-
* @param expectedValue the expected value inside the [Either].
53-
* @return this assertion object.
54-
*/
55-
fun containsOnRight(expectedValue: RIGHT): SELF {
56-
assertIsRight()
57-
actual.onRight { right ->
58-
if (!comparisonStrategy.areEqual(right, expectedValue)) {
59-
throwAssertionError(shouldContainOnRight(actual, expectedValue))
60-
}
49+
/**
50+
* Verifies that the actual [Either] is [Either.Right] and contains the given value.
51+
*
52+
* @param expectedValue the expected value inside the [Either].
53+
* @return this assertion object.
54+
*/
55+
fun containsOnRight(expectedValue: RIGHT): SELF {
56+
assertIsRight()
57+
actual.onRight { right ->
58+
if (!comparisonStrategy.areEqual(right, expectedValue)) {
59+
throwAssertionError(shouldContainOnRight(actual, expectedValue))
60+
}
61+
}
62+
return myself
6163
}
62-
return myself
63-
}
6464

65-
/**
66-
* Verifies that the actual right-sided [Either] contains a value that is an
67-
* instance of the argument.
68-
*
69-
* @param expectedClass the expected class of the value inside the right-sided [Either].
70-
* @return this assertion object.
71-
*/
72-
fun containsRightInstanceOf(expectedClass: Class<*>): SELF {
73-
assertIsRight()
74-
actual.onRight { right ->
75-
if (!expectedClass.isInstance(right)) {
76-
throwAssertionError(shouldContainOnRightInstanceOf(actual, expectedClass))
77-
}
65+
/**
66+
* Verifies that the actual right-sided [Either] contains a value that is an
67+
* instance of the argument.
68+
*
69+
* @param expectedClass the expected class of the value inside the right-sided [Either].
70+
* @return this assertion object.
71+
*/
72+
fun containsRightInstanceOf(expectedClass: Class<*>): SELF {
73+
assertIsRight()
74+
actual.onRight { right ->
75+
if (!expectedClass.isInstance(right)) {
76+
throwAssertionError(shouldContainOnRightInstanceOf(actual, expectedClass))
77+
}
78+
}
79+
return myself
7880
}
79-
return myself
80-
}
8181

82-
private fun assertIsRight() {
83-
isNotNull
84-
if (!actual.isRight()) {
85-
throwAssertionError(shouldBeRight(actual))
82+
private fun assertIsRight() {
83+
isNotNull
84+
if (!actual.isRight()) {
85+
throwAssertionError(shouldBeRight(actual))
86+
}
8687
}
87-
}
8888

89-
/**
90-
* Verifies that the actual [Either] is [Either.Left] and contains the given value.
91-
*
92-
* @param expectedValue the expected value inside the [Either].
93-
* @return this assertion object.
94-
*/
95-
fun containsOnLeft(expectedValue: LEFT): SELF {
96-
assertIsLeft()
97-
actual.onLeft { left ->
98-
if (!comparisonStrategy.areEqual(left, expectedValue)) {
99-
throwAssertionError(shouldContainOnLeft(actual, expectedValue))
100-
}
89+
/**
90+
* Verifies that the actual [Either] is [Either.Left] and contains the given value.
91+
*
92+
* @param expectedValue the expected value inside the [Either].
93+
* @return this assertion object.
94+
*/
95+
fun containsOnLeft(expectedValue: LEFT): SELF {
96+
assertIsLeft()
97+
actual.onLeft { left ->
98+
if (!comparisonStrategy.areEqual(left, expectedValue)) {
99+
throwAssertionError(shouldContainOnLeft(actual, expectedValue))
100+
}
101+
}
102+
return myself
101103
}
102-
return myself
103-
}
104104

105-
private fun assertIsLeft() {
106-
isNotNull
107-
if (!actual.isLeft()) {
108-
throwAssertionError(shouldBeLeft(actual))
105+
private fun assertIsLeft() {
106+
isNotNull
107+
if (!actual.isLeft()) {
108+
throwAssertionError(shouldBeLeft(actual))
109+
}
109110
}
110-
}
111111
}

src/test/kotlin/in/rcard/assertj/arrowcore/EitherAssert_containsOnRightInstanceOf_Test.kt

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,53 @@ import org.junit.jupiter.api.Test
1212

1313
class EitherAssert_containsOnRightInstanceOf_Test {
1414

15-
@Test
16-
fun `should fail if either is null`() {
17-
val actual: Either<Nothing, Nothing>? = null
18-
Assertions.assertThatThrownBy { assertThat(actual).containsRightInstanceOf(Any::class.java) }
19-
.isInstanceOf(AssertionError::class.java)
20-
.hasMessage(FailureMessages.actualIsNull())
21-
}
22-
23-
@Test
24-
fun `should fail if either is left`() {
25-
val actual: Either<String, Nothing> = "some".left()
26-
Assertions.assertThatThrownBy { assertThat(actual).containsRightInstanceOf(Any::class.java) }
27-
.isInstanceOf(AssertionError::class.java)
28-
.hasMessage(shouldBeRight(actual).create())
29-
}
30-
31-
@Test
32-
fun should_fail_if_either_contains_other_type_on_right_than_required() {
33-
val actual: Either<Any, Int> = 42.right()
34-
Assertions.assertThatThrownBy { assertThat(actual).containsRightInstanceOf(String::class.java) }
35-
.isInstanceOf(AssertionError::class.java)
36-
.hasMessage(
37-
shouldContainOnRightInstanceOf(
15+
@Test
16+
fun `should fail if either is null`() {
17+
val actual: Either<Nothing, Nothing>? = null
18+
Assertions.assertThatThrownBy {
19+
assertThat(actual).containsRightInstanceOf(Any::class.java)
20+
}
21+
.isInstanceOf(AssertionError::class.java)
22+
.hasMessage(FailureMessages.actualIsNull())
23+
}
24+
25+
@Test
26+
fun `should fail if either is left`() {
27+
val actual: Either<String, Nothing> = "some".left()
28+
Assertions.assertThatThrownBy {
29+
assertThat(actual).containsRightInstanceOf(Any::class.java)
30+
}
31+
.isInstanceOf(AssertionError::class.java)
32+
.hasMessage(shouldBeRight(actual).create())
33+
}
34+
35+
@Test
36+
fun should_fail_if_either_contains_other_type_on_right_than_required() {
37+
val actual: Either<Any, Int> = 42.right()
38+
Assertions.assertThatThrownBy {
39+
assertThat(actual).containsRightInstanceOf(String::class.java)
40+
}
41+
.isInstanceOf(AssertionError::class.java)
42+
.hasMessage(
43+
shouldContainOnRightInstanceOf(
3844
actual,
3945
String::class.java,
4046
)
41-
.create())
42-
}
43-
44-
@Test
45-
fun `should pass if either contains required type subclass on right`() {
46-
val actual = Child().right()
47-
assertThat(actual).containsRightInstanceOf(Parent::class.java)
48-
}
49-
50-
@Test
51-
fun `should pass if either contains required type on right`() {
52-
val actual: Either<Nothing, String> = "something".right()
53-
assertThat(actual).containsRightInstanceOf(String::class.java)
54-
}
47+
.create(),
48+
)
49+
}
50+
51+
@Test
52+
fun `should pass if either contains required type subclass on right`() {
53+
val actual = Child().right()
54+
assertThat(actual).containsRightInstanceOf(Parent::class.java)
55+
}
56+
57+
@Test
58+
fun `should pass if either contains required type on right`() {
59+
val actual: Either<Nothing, String> = "something".right()
60+
assertThat(actual).containsRightInstanceOf(String::class.java)
61+
}
5562
}
5663

5764
private open class Parent

0 commit comments

Comments
 (0)