Skip to content

Commit 0823654

Browse files
committed
Update function names
1 parent 642aa4c commit 0823654

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

assertk/src/commonMain/kotlin/assertk/assertions/array.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ fun Assert<Array<*>>.containsExactly(vararg elements: Any?) = given { actual ->
182182
* Asserts the collection contains at least one instance of a given type.
183183
*
184184
* ```
185-
* assertThat(arrayOf<Any>("one", "two", 1)).containsInstanceOf<String>().each {
185+
* assertThat(arrayOf<Any>("one", "two", 1)).havingInstanceOf<String>().each {
186186
* it.hasLength(3)
187187
* }
188188
* ```
189189
*/
190-
inline fun <reified T> Assert<Array<*>>.containsInstanceOf(): Assert<List<T>> {
191-
return transform("contains subtype of ${T::class}") { actual ->
190+
inline fun <reified T> Assert<Array<*>>.havingInstancesOf(): Assert<List<T>> {
191+
return transform("contains instances of ${T::class}") { actual ->
192192
actual.filterIsInstance<T>().also {
193193
if (it.isEmpty()) expected("to contain at least one instance of ${T::class} but was ${actual.asList()}")
194194
}
@@ -199,10 +199,10 @@ inline fun <reified T> Assert<Array<*>>.containsInstanceOf(): Assert<List<T>> {
199199
* Asserts the collection does not contain an instance of a given type.
200200
*
201201
* ```
202-
* assertThat(arrayOf<Any>("one", "two", 1)).doesNotContainInstanceOf<Double>()
202+
* assertThat(arrayOf<Any>("one", "two", 1)).havingInstancesOf<Double>()
203203
* ```
204204
*/
205-
inline fun <reified T> Assert<Array<*>>.doesNotContainInstanceOf() = given { actual ->
205+
inline fun <reified T> Assert<Array<*>>.notHavingInstancesOf() = given { actual ->
206206
if (actual.any { it is T }) expected("to not contain instances of ${T::class} but was ${actual.asList()}")
207207
}
208208

assertk/src/commonMain/kotlin/assertk/assertions/iterable.kt

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package assertk.assertions
22

33
import assertk.Assert
44
import assertk.all
5-
import assertk.assertThat
65
import assertk.collection
76
import assertk.assertions.support.appendName
87
import assertk.assertions.support.expected
98
import assertk.assertions.support.show
10-
import assertk.fail
119

1210
/**
1311
* Asserts the iterable contains the expected element, using `in`.
@@ -137,13 +135,13 @@ internal fun MutableList<*>.removeFirst(value: Any?) {
137135
* Asserts the collection contains at least one instance of a given type.
138136
*
139137
* ```
140-
* assertThat(listOf<Any>("one", "two", 1)).containsInstanceOf<String>().each {
138+
* assertThat(listOf<Any>("one", "two", 1)).havingInstanceOf<String>().each {
141139
* it.hasLength(3)
142140
* }
143141
* ```
144142
*/
145-
inline fun <reified T> Assert<Iterable<*>>.containsInstanceOf(): Assert<List<T>> {
146-
return transform("contains subtype of ${T::class}") { actual ->
143+
inline fun <reified T> Assert<Iterable<*>>.havingInstancesOf(): Assert<List<T>> {
144+
return transform("contains instance of ${T::class}") { actual ->
147145
actual.filterIsInstance<T>().also {
148146
if (it.isEmpty()) expected("to contain at least one instance of ${T::class} but was $actual")
149147
}
@@ -157,7 +155,7 @@ inline fun <reified T> Assert<Iterable<*>>.containsInstanceOf(): Assert<List<T>>
157155
* assertThat(listOf<Any>("one", "two", 1)).doesNotContainInstanceOf<Double>()
158156
* ```
159157
*/
160-
inline fun <reified T> Assert<Iterable<*>>.doesNotContainInstanceOf() = given { actual ->
158+
inline fun <reified T> Assert<Iterable<*>>.notHavingInstancesOf() = given { actual ->
161159
if (actual.any { it is T }) expected("to not contain instances of ${T::class} but was $actual")
162160
}
163161

assertk/src/commonTest/kotlin/test/assertk/assertions/ArrayTest.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,12 @@ class ArrayTest {
324324

325325
//region containsInstanceOf
326326
@Test fun containsInstanceOf_element_present_passes() {
327-
assertThat(arrayOf<Any>(1, "two")).containsInstanceOf<String>().single().isEqualTo("two")
327+
assertThat(arrayOf<Any>(1, "two")).havingInstancesOf<String>().single().isEqualTo("two")
328328
}
329329

330330
@Test fun containsInstanceOf_element_missing_fails() {
331331
val error = assertFailsWith<AssertionError> {
332-
assertThat(arrayOf<Any>(1, "two")).containsInstanceOf<Double>()
332+
assertThat(arrayOf<Any>(1, "two")).havingInstancesOf<Double>()
333333
}
334334
assertEquals("expected to contain at least one instance of class kotlin.Double but was [1, two]", error.message)
335335
}
@@ -338,13 +338,13 @@ class ArrayTest {
338338
//region doesNotContainInstanceOf
339339
@Test fun doesNotContainInstanceOf_element_present_fails() {
340340
val error = assertFailsWith<AssertionError>() {
341-
assertThat(arrayOf<Any>(1, "two")).doesNotContainInstanceOf<String>()
341+
assertThat(arrayOf<Any>(1, "two")).notHavingInstancesOf<String>()
342342
}
343343
assertEquals("expected to not contain instances of class kotlin.String but was [1, two]", error.message)
344344
}
345345

346346
@Test fun doesNotContainInstanceOf_element_missing_passes() {
347-
assertThat(arrayOf<Any>(1, "two")).doesNotContainInstanceOf<Double>()
347+
assertThat(arrayOf<Any>(1, "two")).notHavingInstancesOf<Double>()
348348
}
349349
//endregion
350350

assertk/src/commonTest/kotlin/test/assertk/assertions/IterableTest.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package test.assertk.assertions
22

33
import assertk.all
4-
import assertk.assertFailure
54
import assertk.assertThat
65
import assertk.assertions.any
76
import assertk.assertions.atLeast
@@ -10,11 +9,11 @@ import assertk.assertions.contains
109
import assertk.assertions.containsAtLeast
1110
import assertk.assertions.containsExactly
1211
import assertk.assertions.containsExactlyInAnyOrder
13-
import assertk.assertions.containsInstanceOf
12+
import assertk.assertions.havingInstancesOf
1413
import assertk.assertions.containsNone
1514
import assertk.assertions.containsOnly
1615
import assertk.assertions.doesNotContain
17-
import assertk.assertions.doesNotContainInstanceOf
16+
import assertk.assertions.notHavingInstancesOf
1817
import assertk.assertions.each
1918
import assertk.assertions.exactly
2019
import assertk.assertions.extracting
@@ -234,12 +233,12 @@ class IterableTest {
234233

235234
//region containsInstanceOf
236235
@Test fun containsInstanceOf_element_present_passes() {
237-
assertThat(iterableOf(1, "two")).containsInstanceOf<String>().single().isEqualTo("two")
236+
assertThat(iterableOf(1, "two")).havingInstancesOf<String>().single().isEqualTo("two")
238237
}
239238

240239
@Test fun containsInstanceOf_element_missing_fails() {
241240
val error = assertFailsWith<AssertionError> {
242-
assertThat(iterableOf(1, "two")).containsInstanceOf<Double>()
241+
assertThat(iterableOf(1, "two")).havingInstancesOf<Double>()
243242
}
244243
assertEquals("expected to contain at least one instance of class kotlin.Double but was [1, two]", error.message)
245244
}
@@ -248,13 +247,13 @@ class IterableTest {
248247
//region doesNotContainInstanceOf
249248
@Test fun doesNotContainInstanceOf_element_present_fails() {
250249
val error = assertFailsWith<AssertionError>() {
251-
assertThat(iterableOf(1, "two")).doesNotContainInstanceOf<String>()
250+
assertThat(iterableOf(1, "two")).notHavingInstancesOf<String>()
252251
}
253252
assertEquals("expected to not contain instances of class kotlin.String but was [1, two]", error.message)
254253
}
255254

256255
@Test fun doesNotContainInstanceOf_element_missing_passes() {
257-
assertThat(iterableOf(1, "two")).doesNotContainInstanceOf<Double>()
256+
assertThat(iterableOf(1, "two")).notHavingInstancesOf<Double>()
258257
}
259258
//endregion
260259

0 commit comments

Comments
 (0)