|
26 | 26 | import java.util.ArrayList;
|
27 | 27 | import java.util.List;
|
28 | 28 | import java.util.ListIterator;
|
| 29 | +import org.hamcrest.core.IsEqual; |
29 | 30 | import org.junit.jupiter.api.Test;
|
30 | 31 | import org.llorllale.cactoos.matchers.Assertion;
|
| 32 | +import org.llorllale.cactoos.matchers.IsTrue; |
31 | 33 | import org.llorllale.cactoos.matchers.Throws;
|
32 | 34 |
|
33 | 35 | /**
|
@@ -141,4 +143,87 @@ void getThrowsErrorIfListIteratorPreviousValueIsNullValue() {
|
141 | 143 | )
|
142 | 144 | ).affirm();
|
143 | 145 | }
|
| 146 | + |
| 147 | + @Test |
| 148 | + void indexOfThrowsErrorIfArgumentIsNull() { |
| 149 | + new Assertion<>( |
| 150 | + "must throw error if searched value is null", |
| 151 | + () -> new NoNulls<>( |
| 152 | + new ListOf<>(1, 2, 3) |
| 153 | + ).indexOf(null), |
| 154 | + new Throws<>( |
| 155 | + "Item can't be NULL in #indexOf(T)", |
| 156 | + IllegalArgumentException.class |
| 157 | + ) |
| 158 | + ).affirm(); |
| 159 | + } |
| 160 | + |
| 161 | + @Test |
| 162 | + void indexOfTest() { |
| 163 | + new Assertion<>( |
| 164 | + "must return first index", |
| 165 | + new NoNulls<>( |
| 166 | + new ListOf<>(1, 2, 2, 2, 5) |
| 167 | + ).indexOf(2), |
| 168 | + new IsEqual<>(1) |
| 169 | + ).affirm(); |
| 170 | + } |
| 171 | + |
| 172 | + @Test |
| 173 | + void lastIndexOfThrowsErrorIfArgumentIsNull() { |
| 174 | + new Assertion<>( |
| 175 | + "must throw error if searched value is null", |
| 176 | + () -> new NoNulls<>( |
| 177 | + new ListOf<>(1, 2, 3) |
| 178 | + ).lastIndexOf(null), |
| 179 | + new Throws<>( |
| 180 | + "Item can't be NULL in #lastIndexOf(T)", |
| 181 | + IllegalArgumentException.class |
| 182 | + ) |
| 183 | + ).affirm(); |
| 184 | + } |
| 185 | + |
| 186 | + @Test |
| 187 | + void lastIndexOfTest() { |
| 188 | + new Assertion<>( |
| 189 | + "must return last index", |
| 190 | + new NoNulls<>( |
| 191 | + new ListOf<>(1, 2, 2, 2, 5) |
| 192 | + ).lastIndexOf(2), |
| 193 | + new IsEqual<>(3) |
| 194 | + ).affirm(); |
| 195 | + } |
| 196 | + |
| 197 | + @Test |
| 198 | + void sizeTest() { |
| 199 | + new Assertion<>( |
| 200 | + "must return list size", |
| 201 | + new NoNulls<>( |
| 202 | + new ListOf<>(1, 2, 2, 2, 5) |
| 203 | + ).size(), |
| 204 | + new IsEqual<>(5) |
| 205 | + ).affirm(); |
| 206 | + } |
| 207 | + |
| 208 | + @Test |
| 209 | + void isEmptyTrueTest() { |
| 210 | + new Assertion<>( |
| 211 | + "must return true if list is empty", |
| 212 | + new NoNulls<>( |
| 213 | + new ListOf<>() |
| 214 | + ).isEmpty(), |
| 215 | + new IsTrue() |
| 216 | + ).affirm(); |
| 217 | + } |
| 218 | + |
| 219 | + @Test |
| 220 | + void isEmptyFalseTest() { |
| 221 | + new Assertion<>( |
| 222 | + "must return false if list is not empty", |
| 223 | + new NoNulls<>( |
| 224 | + new ListOf<>(1, 2, 3) |
| 225 | + ).isEmpty(), |
| 226 | + new IsEqual<>(false) |
| 227 | + ).affirm(); |
| 228 | + } |
144 | 229 | }
|
0 commit comments