| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.common.collect.testing.testers; |
| 18 |
|
| 19 |
import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; |
| 20 |
import static com.google.common.collect.testing.features.CollectionSize.ZERO; |
| 21 |
|
| 22 |
import com.google.common.annotations.GwtCompatible; |
| 23 |
import com.google.common.collect.testing.WrongType; |
| 24 |
import com.google.common.collect.testing.features.CollectionFeature; |
| 25 |
import com.google.common.collect.testing.features.CollectionSize; |
| 26 |
import org.checkerframework.checker.nullness.qual.Nullable; |
| 27 |
import org.junit.Ignore; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
@GwtCompatible |
| 35 |
@Ignore |
| 36 |
public abstract class AbstractListIndexOfTester<E> extends AbstractListTester<E> { |
| 37 |
|
| 38 |
protected abstract int find(@Nullable Object o); |
| 39 |
|
| 40 |
|
| 41 |
protected abstract String getMethodName(); |
| 42 |
|
| 43 |
@CollectionSize.Require(absent = ZERO) |
| 44 |
public void testFind_yes() { |
| 45 |
assertEquals( |
| 46 |
getMethodName() + "(firstElement) should return 0", 0, find(getOrderedElements().get(0))); |
| 47 |
} |
| 48 |
|
| 49 |
public void testFind_no() { |
| 50 |
assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3())); |
| 51 |
} |
| 52 |
|
| 53 |
@CollectionFeature.Require(ALLOWS_NULL_VALUES) |
| 54 |
public void testFind_nullNotContainedButSupported() { |
| 55 |
assertEquals(getMethodName() + "(nullNotPresent) should return -1", -1, find(null)); |
| 56 |
} |
| 57 |
|
| 58 |
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) |
| 59 |
public void testFind_nullNotContainedAndUnsupported() { |
| 60 |
try { |
| 61 |
assertEquals(getMethodName() + "(nullNotPresent) should return -1 or throw", -1, find(null)); |
| 62 |
} catch (NullPointerException tolerated) { |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
@CollectionFeature.Require(ALLOWS_NULL_VALUES) |
| 67 |
@CollectionSize.Require(absent = ZERO) |
| 68 |
public void testFind_nonNullWhenNullContained() { |
| 69 |
initCollectionWithNullElement(); |
| 70 |
assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3())); |
| 71 |
} |
| 72 |
|
| 73 |
@CollectionFeature.Require(ALLOWS_NULL_VALUES) |
| 74 |
@CollectionSize.Require(absent = ZERO) |
| 75 |
public void testFind_nullContained() { |
| 76 |
initCollectionWithNullElement(); |
| 77 |
assertEquals( |
| 78 |
getMethodName() + "(null) should return " + getNullLocation(), |
| 79 |
getNullLocation(), |
| 80 |
find(null)); |
| 81 |
} |
| 82 |
|
| 83 |
public void testFind_wrongType() { |
| 84 |
try { |
| 85 |
assertEquals( |
| 86 |
getMethodName() + "(wrongType) should return -1 or throw", -1, find(WrongType.VALUE)); |
| 87 |
} catch (ClassCastException tolerated) { |
| 88 |
} |
| 89 |
} |
| 90 |
} |