File tree Expand file tree Collapse file tree
src/test/kotlin/cz/vutbr/fit/interlockSim Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,11 +16,11 @@ import cz.vutbr.fit.interlockSim.util.Point
1616import cz.vutbr.fit.interlockSim.xml.XMLContextFactory
1717import assertk.assertThat
1818import assertk.assertions.contains
19- import assertk.assertions.containsAnyOf
2019import assertk.assertions.hasSize
21- import assertk.assertions.hasSizeGreaterThanOrEqualTo
2220import assertk.assertions.isEmpty
2321import assertk.assertions.isEqualTo
22+ import cz.vutbr.fit.interlockSim.testutil.containsAnyOf
23+ import cz.vutbr.fit.interlockSim.testutil.hasSizeGreaterThanOrEqualTo
2424import org.junit.jupiter.api.BeforeEach
2525import org.junit.jupiter.api.DisplayName
2626import org.junit.jupiter.api.Test
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ class CellTest {
9898 clazz == RailSemaphore ::class .java -> RailSemaphore (o, t) as OrientedNodeCell
9999 clazz == InOut ::class .java -> InOut (" xx" , o, t) as OrientedNodeCell
100100 else -> {
101- fail< OrientedNodeCell > (" Unexpected cell class: $clazz , objects: ${objects.contentToString()} " )
101+ fail(" Unexpected cell class: $clazz , objects: ${objects.contentToString()} " )
102102 }
103103 }
104104}
Original file line number Diff line number Diff line change @@ -76,3 +76,23 @@ fun <T> Assert<KProperty0<T?>>.isNotNull() = given { actual ->
7676fun <T > Assert<T>.withMessage (message : String ): Assert <T > = transform { actual ->
7777 assertk.assertThat(actual, name = message)
7878}
79+
80+ /* *
81+ * Extension function to assert that a collection has size greater than or equal to expected.
82+ *
83+ * Usage: assertThat(collection).hasSizeGreaterThanOrEqualTo(1)
84+ */
85+ fun <T > Assert<Collection<T>>.hasSizeGreaterThanOrEqualTo (expected : Int ) = given { actual ->
86+ if (actual.size >= expected) return @given
87+ expected(" to have size at least:${show(expected)} but was:${show(actual.size)} " )
88+ }
89+
90+ /* *
91+ * Extension function to assert that a collection contains any of the given elements.
92+ *
93+ * Usage: assertThat(collection).containsAnyOf(element1, element2)
94+ */
95+ fun <T > Assert<Collection<T>>.containsAnyOf (vararg elements : T ) = given { actual ->
96+ if (elements.any { it in actual }) return @given
97+ expected(" to contain any of:${show(elements.toList())} but was:${show(actual)} " )
98+ }
You can’t perform that action at this time.
0 commit comments