Skip to content

Commit 28b12f5

Browse files
authored
Merge pull request #2091 from TomerPacific/feature/migrate-iterable-not-to-have-elements-or-all-expectations-spec-to-kotlin-test
Feature/migrate iterable not to have elements or all expectations spec to kotlin test
2 parents 52af3d2 + d8a87bf commit 28b12f5

File tree

6 files changed

+211
-171
lines changed

6 files changed

+211
-171
lines changed

apis/fluent/atrium-api-fluent/src/commonTest/kotlin/ch/tutteli/atrium/api/fluent/en_GB/IterableNotToHaveElementsOrAllExpectationsSpec.kt

Lines changed: 0 additions & 31 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ch.tutteli.atrium.api.fluent.en_GB
2+
3+
import ch.tutteli.atrium.api.verbs.internal.expect
4+
import ch.tutteli.atrium.creating.Expect
5+
import ch.tutteli.atrium.specs.fun1
6+
import ch.tutteli.atrium.specs.withNullableSuffix
7+
import kotlin.test.Test
8+
9+
class IterableNotToHaveElementsOrAllExpectationsTest :
10+
ch.tutteli.atrium.specs.integration.AbstractIterableNotToHaveElementsOrAllExpectationsTest(
11+
fun1(Expect<Iterable<Double>>::notToHaveElementsOrAll),
12+
fun1(Expect<Iterable<Double?>>::notToHaveElementsOrAll).withNullableSuffix()
13+
) {
14+
15+
@Suppress("AssignedValueIsNeverRead")
16+
@Test
17+
fun ambiguityTest() {
18+
var list: Expect<List<Number>> = expect(listOf(2.1))
19+
var nSet: Expect<Set<Number?>> = expect(setOf(2.1))
20+
var subList: Expect<ArrayList<out Number>> = expect(arrayListOf(2.1))
21+
var starSet: Expect<Set<*>> = ch.tutteli.atrium.api.verbs.expect(emptySet<Number>())
22+
var starCollection: Expect<Collection<*>> = ch.tutteli.atrium.api.verbs.expect(listOf(1.1, "asdf"))
23+
24+
list = list.notToHaveElementsOrAll {
25+
toEqual(2.1)
26+
}
27+
nSet = nSet.notToHaveElementsOrAll {
28+
toEqual(2.1)
29+
}
30+
subList = subList.notToHaveElementsOrAll {
31+
toEqual(2.1)
32+
}
33+
starSet = starSet.notToHaveElementsOrAll {
34+
toEqual(2.1)
35+
}
36+
starCollection = starCollection.notToHaveElementsOrAll {
37+
notToEqual(2.1)
38+
}
39+
}
40+
}
41+
42+

apis/infix/atrium-api-infix/src/commonTest/kotlin/ch/tutteli/atrium/api/infix/en_GB/IterableNotToHaveElementsOrAllExpectationsSpec.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ch.tutteli.atrium.api.infix.en_GB
2+
3+
import ch.tutteli.atrium.api.verbs.internal.expect
4+
import ch.tutteli.atrium.creating.Expect
5+
import ch.tutteli.atrium.specs.fun1
6+
import ch.tutteli.atrium.specs.withNullableSuffix
7+
import kotlin.test.Test
8+
9+
class IterableNotToHaveElementsOrAllExpectationsTest :
10+
ch.tutteli.atrium.specs.integration.AbstractIterableNotToHaveElementsOrAllExpectationsTest(
11+
fun1(Expect<Iterable<Double>>::notToHaveElementsOrAll),
12+
fun1(Expect<Iterable<Double?>>::notToHaveElementsOrAll).withNullableSuffix()
13+
) {
14+
15+
16+
@Suppress("AssignedValueIsNeverRead")
17+
@Test
18+
fun ambiguityTest() {
19+
var list: Expect<List<Number>> = expect(listOf(1, 1.2))
20+
var nSet: Expect<Set<Number?>> = expect(setOf(1, 1.2))
21+
var subList: Expect<ArrayList<out Number>> = expect(arrayListOf(1, 1.2))
22+
var starSet: Expect<Set<*>> = ch.tutteli.atrium.api.verbs.expect(emptySet<Number>())
23+
var starCollection: Expect<Collection<*>> = expect(listOf(1, "asdf"))
24+
25+
list = list notToHaveElementsOrAll {
26+
it notToEqual 2
27+
}
28+
nSet = nSet notToHaveElementsOrAll {
29+
it notToEqual 2
30+
}
31+
subList = subList notToHaveElementsOrAll {
32+
it notToEqual 2
33+
}
34+
starSet = starSet.notToHaveElementsOrAll {
35+
toEqual(2.1)
36+
}
37+
starCollection = starCollection notToHaveElementsOrAll {
38+
it notToEqual 2
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package ch.tutteli.atrium.specs.integration
2+
3+
import ch.tutteli.atrium.api.fluent.en_GB.*
4+
import ch.tutteli.atrium.core.polyfills.format
5+
import ch.tutteli.atrium.creating.Expect
6+
import ch.tutteli.atrium.logic.utils.expectLambda
7+
import ch.tutteli.atrium.specs.*
8+
import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.fluentEmpty
9+
import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.mismatches
10+
import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.oneToSeven
11+
import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.oneToSevenNullable
12+
import ch.tutteli.atrium.specs.integration.IterableToContainSpecBase.Companion.separator
13+
import ch.tutteli.atrium.specs.integration.utils.ExpectationCreatorTestData
14+
import ch.tutteli.atrium.specs.integration.utils.SubjectLessTestData
15+
import ch.tutteli.atrium.testfactories.TestFactory
16+
import ch.tutteli.atrium.translations.DescriptionIterableLikeExpectation
17+
18+
@Suppress("FunctionName")
19+
abstract class AbstractIterableNotToHaveElementsOrAllExpectationsTest(
20+
private val notToHaveElementsOrAllSpec: Fun1<Iterable<Double>, Expect<Double>.() -> Unit>,
21+
private val notToHaveElementsOrAllNullableSpec: Fun1<Iterable<Double?>, (Expect<Double>.() -> Unit)?>,
22+
) : ExpectationFunctionBaseTest() {
23+
24+
@TestFactory
25+
fun subjectLessTest() = subjectLessTestFactory(
26+
SubjectLessTestData<Iterable<Double>>(
27+
notToHaveElementsOrAllSpec.first to expectLambda {
28+
notToHaveElementsOrAllSpec.second(this) {
29+
toEqual(2.5)
30+
}
31+
}
32+
),
33+
SubjectLessTestData<Iterable<Double?>>(
34+
"${notToHaveElementsOrAllNullableSpec.first} for nullable" to expectLambda {
35+
notToHaveElementsOrAllNullableSpec.second(this, null)
36+
}
37+
)
38+
)
39+
40+
@TestFactory
41+
fun expectationCreatorTest() = expectationCreatorTestFactory(
42+
ExpectationCreatorTestData(
43+
oneToSeven().toList().asIterable(),
44+
notToHaveElementsOrAllSpec.forExpectationCreatorTest("$toBeGreaterThanDescr: 0.0") { toBeGreaterThan(0.0) }
45+
),
46+
ExpectationCreatorTestData(
47+
oneToSeven().toList().asIterable(),
48+
notToHaveElementsOrAllNullableSpec.forExpectationCreatorTest("$toBeGreaterThanDescr: 0.0") {
49+
toBeGreaterThan(
50+
0.0
51+
)
52+
}
53+
)
54+
)
55+
56+
val allElementsDescr = DescriptionIterableLikeExpectation.NOT_TO_HAVE_ELEMENTS_OR_ALL.getDefault()
57+
58+
val explanatoryPointWithIndent = "$indentRootBulletPoint$indentListBulletPoint$explanatoryBulletPoint"
59+
60+
fun index(index: Int) = listBulletPoint + DescriptionIterableLikeExpectation.INDEX.getDefault().format(index)
61+
62+
63+
@TestFactory
64+
fun empty_collection__does_not_throw() = nonNullableCases(
65+
notToHaveElementsOrAllSpec,
66+
notToHaveElementsOrAllNullableSpec
67+
) { noToHaveElementsOrAllFun ->
68+
expect(fluentEmpty()).noToHaveElementsOrAllFun { toBeLessThan(1.1) }
69+
}
70+
71+
@TestFactory
72+
fun one_to_7__throws() = nonNullableCases(
73+
notToHaveElementsOrAllSpec,
74+
notToHaveElementsOrAllNullableSpec
75+
) { notToHaveElementsOrAllFun ->
76+
expect {
77+
expect(oneToSeven()).notToHaveElementsOrAllFun { toBeGreaterThan(2.5); toBeLessThan(7.1) }
78+
}.toThrow<AssertionError> {
79+
message {
80+
toContain.exactly(1).values(
81+
"$rootBulletPoint$allElementsDescr: $separator",
82+
"$explanatoryPointWithIndent$toBeGreaterThanDescr: 2.5",
83+
"$explanatoryPointWithIndent$toBeLessThanDescr: 7.1",
84+
"$warningBulletPoint$mismatches:",
85+
"${index(0)}: 1.1",
86+
"${index(1)}: 2.1",
87+
"${index(9)}: 7.1"
88+
)
89+
}
90+
}
91+
}
92+
93+
@TestFactory
94+
fun one_to_seven__does_not_throw() = nonNullableCases(
95+
notToHaveElementsOrAllSpec,
96+
notToHaveElementsOrAllNullableSpec
97+
) { notToHaveElementsOrAllFun ->
98+
expect(oneToSeven()).notToHaveElementsOrAllFun { toBeGreaterThan(0.5); toBeLessThan(7.5) }
99+
}
100+
101+
@TestFactory
102+
fun nullable_cases() = testFactory(notToHaveElementsOrAllNullableSpec)
103+
{
104+
val iterableOfNulls = { sequenceOf<Double?>(null, null).constrainOnce().asIterable() }
105+
describe("iterable ${iterableOfNulls()}") {
106+
it("all are `null` does not throw") {
107+
expect(iterableOfNulls()).notToHaveElementsOrAll(null)
108+
}
109+
}
110+
describe("iterable ${oneToSevenNullable().toList()}") {
111+
it("$toBeGreaterThanDescr(0.5) throws because two are `null`") {
112+
expect {
113+
expect(oneToSevenNullable()).notToHaveElementsOrAll { toBeGreaterThan(0.5) }
114+
}.toThrow<AssertionError> {
115+
message {
116+
toContain.exactly(1).values(
117+
"$rootBulletPoint$allElementsDescr: $separator",
118+
"$explanatoryPointWithIndent$toBeGreaterThanDescr: 0.5",
119+
"$warningBulletPoint$mismatches:",
120+
"${index(1)}: null",
121+
"${index(5)}: null"
122+
)
123+
}
124+
}
125+
}
126+
}
127+
}
128+
}

misc/atrium-specs/src/commonMain/kotlin/ch/tutteli/atrium/specs/integration/IterableNotToHaveElementsOrAllExpectationsSpec.kt

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)