@@ -19,6 +19,18 @@ class IterableMatchersTest {
19
19
)
20
20
}
21
21
22
+ @Test
23
+ fun `assertContains should fail` () {
24
+ val list: List <Int > = listOf (1 , 2 , 3 )
25
+ val element = 4
26
+ val exception: AssertionError = assertFailsWith { list.assertContains(element) }
27
+ assertTrue(
28
+ exception.message ==
29
+ " Expected the collection to contain the element.\n " +
30
+ " Collection <[1, 2, 3]>, element <4>."
31
+ )
32
+ }
33
+
22
34
@Test
23
35
fun `assertContains should work with different types` () {
24
36
val list: List <Double > = listOf (1.0 , 2.0 , 3.0 )
@@ -27,6 +39,57 @@ class IterableMatchersTest {
27
39
assertTrue(result == = list)
28
40
}
29
41
42
+ @Test
43
+ fun `assertContains should work` () {
44
+ val list: List <String > = listOf (" AA" , " BB" , " CC" )
45
+ val element = " BB"
46
+ val result: List <String > = list.assertContains(element)
47
+ assertTrue(result == = list)
48
+ }
49
+
50
+ @Test
51
+ fun `assertContainsExactly should fail with custom message` () {
52
+ val list: List <Int > = listOf (1 , 2 , 3 )
53
+ val elements = listOf (1 , 2 , 3 , 4 )
54
+ val message = " Custom error"
55
+ val exception: AssertionError = assertFailsWith {
56
+ list.assertContainsExactly(elements, message)
57
+ }
58
+ assertTrue(exception.message == " Custom error expected:<[1, 2, 3]> but was:<[1, 2, 3, 4]>" )
59
+ }
60
+
61
+ @Test
62
+ fun `assertContainsExactly should fail` () {
63
+ val list: List <Int > = listOf (1 , 2 , 3 )
64
+ val elements: List <Int > = listOf (1 , 2 , 3 , 4 )
65
+ val exception: AssertionError = assertFailsWith { list.assertContainsExactly(elements) }
66
+ assertTrue(exception.message == " expected:<[1, 2, 3]> but was:<[1, 2, 3, 4]>" )
67
+ }
68
+
69
+ @Test
70
+ fun `assertContainsExactly should fail with more items` () {
71
+ val list: List <Int > = listOf (1 , 2 , 3 , 4 , 5 )
72
+ val elements: List <Int > = listOf (1 , 2 , 3 , 4 )
73
+ val exception: AssertionError = assertFailsWith { list.assertContainsExactly(elements) }
74
+ assertTrue(exception.message == " expected:<[1, 2, 3, 4, 5]> but was:<[1, 2, 3, 4]>" )
75
+ }
76
+
77
+ @Test
78
+ fun `assertContainsExactly should work with different types` () {
79
+ val list: List <Double > = listOf (1.0 , 2.0 , 3.0 )
80
+ val elements: List <Double > = listOf (1.0 , 2.0 , 3.0 )
81
+ val result: List <Double > = list.assertContainsExactly(elements)
82
+ assertTrue(result == = list)
83
+ }
84
+
85
+ @Test
86
+ fun `assertContainsExactly should work` () {
87
+ val list: List <String > = listOf (" AA" , " BB" , " CC" )
88
+ val elements: List <String > = listOf (" AA" , " BB" , " CC" )
89
+ val result: List <String > = list.assertContainsExactly(elements)
90
+ assertTrue(result == = list)
91
+ }
92
+
30
93
@Test
31
94
fun `assertCount should pass when count matches` () {
32
95
val list: List <Int > = listOf (1 , 2 , 3 )
0 commit comments