|
| 1 | +package ch.tutteli.atrium.api.infix.en_GB.samples |
| 2 | + |
| 3 | +import ch.tutteli.atrium.api.infix.en_GB.atLeast |
| 4 | +import ch.tutteli.atrium.api.infix.en_GB.atMost |
| 5 | +import ch.tutteli.atrium.api.infix.en_GB.elementsOf |
| 6 | +import ch.tutteli.atrium.api.infix.en_GB.entries |
| 7 | +import ch.tutteli.atrium.api.infix.en_GB.entry |
| 8 | +import ch.tutteli.atrium.api.infix.en_GB.exactly |
| 9 | +import ch.tutteli.atrium.api.infix.en_GB.inAny |
| 10 | +import ch.tutteli.atrium.api.infix.en_GB.it |
| 11 | +import ch.tutteli.atrium.api.infix.en_GB.o |
| 12 | +import ch.tutteli.atrium.api.infix.en_GB.order |
| 13 | +import ch.tutteli.atrium.api.infix.en_GB.the |
| 14 | +import ch.tutteli.atrium.api.infix.en_GB.toContain |
| 15 | +import ch.tutteli.atrium.api.infix.en_GB.toEqual |
| 16 | +import ch.tutteli.atrium.api.infix.en_GB.value |
| 17 | +import ch.tutteli.atrium.api.infix.en_GB.values |
| 18 | +import ch.tutteli.atrium.api.verbs.expect |
| 19 | +import kotlin.test.Test |
| 20 | + |
| 21 | +class IterableLikeToContainInAnyOrderCreatorSamples { |
| 22 | + @Test |
| 23 | + fun value() { |
| 24 | + expect(listOf("A", "B")) toContain o inAny order exactly 1 value "A" |
| 25 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 value ("A") |
| 26 | + expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 value "B" |
| 27 | + |
| 28 | + fails { |
| 29 | + expect(listOf("A", "B")) toContain o inAny order exactly 2 value "A" |
| 30 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 value "A" |
| 31 | + expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 value "B" |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + fun values() { |
| 37 | + expect(listOf("A", "B")) toContain o inAny order exactly 1 the values("B", "A") |
| 38 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the values("B", "A") |
| 39 | + expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the values("B", "A") |
| 40 | + |
| 41 | + fails { |
| 42 | + expect(listOf("A", "B")) toContain o inAny order exactly 2 the values("B", "A") |
| 43 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 the values("B", "A") |
| 44 | + expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the values("B", "A") |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + fun entry() { |
| 50 | + expect(listOf("A", "B")) toContain o inAny order exactly 1 entry { |
| 51 | + it toEqual "A" |
| 52 | + } |
| 53 | + |
| 54 | + expect(listOf("A", null, null)) toContain o inAny order exactly 2 entry null // null is identified |
| 55 | + |
| 56 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 entry { |
| 57 | + it toEqual "A" |
| 58 | + } |
| 59 | + |
| 60 | + expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 entry { |
| 61 | + it toEqual "A" |
| 62 | + } |
| 63 | + |
| 64 | + fails { // because the count of "A" is not 2 |
| 65 | + expect(listOf("A", "B")) toContain o inAny order exactly 2 entry { |
| 66 | + it toEqual "A" |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + fails { // because all elements are not null |
| 71 | + expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 entry null |
| 72 | + } |
| 73 | + |
| 74 | + fails { // because assertionCreatorOrNull is non-null and has no expectation |
| 75 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order exactly 1 entry { |
| 76 | + /* do nothing */ |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + fails { // because the count of "A" is less than 3 |
| 81 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 entry { |
| 82 | + it toEqual "A" |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + fails { // because the count of "B" is more than 2 |
| 87 | + expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 entry { |
| 88 | + it toEqual "B" |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + fun entries() { |
| 95 | + expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries( |
| 96 | + { it toEqual "B" }, |
| 97 | + { it toEqual "A" } |
| 98 | + ) |
| 99 | + |
| 100 | + expect(listOf("A", null, "A", null)) toContain o inAny order exactly 2 the entries( |
| 101 | + null, |
| 102 | + { it toEqual "A" } |
| 103 | + ) |
| 104 | + |
| 105 | + expect(listOf(null, null)) toContain o inAny order exactly 2 the entries( |
| 106 | + null |
| 107 | + ) |
| 108 | + |
| 109 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 the entries( |
| 110 | + { it toEqual "B" }, |
| 111 | + { it toEqual "A" } |
| 112 | + ) |
| 113 | + |
| 114 | + expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 the entries( |
| 115 | + { it toEqual "B" }, |
| 116 | + { it toEqual "A" } |
| 117 | + ) |
| 118 | + |
| 119 | + fails { // because the count of "A" is not 2 |
| 120 | + expect(listOf("A", "B", "B")) toContain o inAny order exactly 2 the entries( |
| 121 | + { it toEqual "A" }, |
| 122 | + { it toEqual "B" } |
| 123 | + ) |
| 124 | + } |
| 125 | + |
| 126 | + fails { // because all elements are not null |
| 127 | + expect(listOf("A", "B", "C")) toContain o inAny order exactly 1 the entries( |
| 128 | + { it toEqual "A" }, |
| 129 | + null |
| 130 | + ) |
| 131 | + } |
| 132 | + |
| 133 | + fails { // because otherAssertionCreatorsOrNulls contains a lambda which is non-null and has no expectation |
| 134 | + expect(listOf("A", "B")) toContain o inAny order exactly 1 the entries( |
| 135 | + { it toEqual "A" }, |
| 136 | + { /* do nothing */ } |
| 137 | + ) |
| 138 | + } |
| 139 | + |
| 140 | + fails { // because the count of "A" is less than 2 |
| 141 | + expect(listOf("A", "B", "B")) toContain o inAny order atLeast 2 the entries( |
| 142 | + { it toEqual "B" }, |
| 143 | + { it toEqual "A" } |
| 144 | + ) |
| 145 | + } |
| 146 | + |
| 147 | + fails { // because the count of "B" is more than 2 |
| 148 | + expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 the entries( |
| 149 | + { it toEqual "B" }, |
| 150 | + { it toEqual "A" } |
| 151 | + ) |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + fun elementsOf() { |
| 157 | + expect(listOf("A", "B")) toContain o inAny order exactly 1 elementsOf listOf("A", "B") |
| 158 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 2 elementsOf listOf("A", "B") |
| 159 | + expect(listOf("A", "B", "B")) toContain o inAny order atMost 2 elementsOf listOf("A", "B") |
| 160 | + |
| 161 | + fails { |
| 162 | + expect(listOf("A", "B")) toContain o inAny order exactly 2 elementsOf listOf("A", "B") |
| 163 | + expect(listOf("A", "B", "A", "B")) toContain o inAny order atLeast 3 elementsOf listOf("A", "B") |
| 164 | + expect(listOf("A", "B", "B", "B")) toContain o inAny order atMost 2 elementsOf listOf("A", "B") |
| 165 | + } |
| 166 | + } |
| 167 | +} |
0 commit comments