Coverage Summary for Class: AbstractListIndexOfTester (com.google.common.collect.testing.testers)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| AbstractListIndexOfTester | 100% (1/1) | 100% (8/8) | 92.3% (24/26) |
1 /* 2 * Copyright (C) 2007 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 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.junit.Ignore; 27 28 /** 29 * Common parent class for {@link ListIndexOfTester} and {@link ListLastIndexOfTester}. 30 * 31 * @author Chris Povirk 32 */ 33 @GwtCompatible 34 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 35 public abstract class AbstractListIndexOfTester<E> extends AbstractListTester<E> { 36 /** Override to call {@code indexOf()} or {@code lastIndexOf()}. */ 37 protected abstract int find(Object o); 38 39 /** Override to return "indexOf" or "lastIndexOf()" for use in failure messages. */ 40 protected abstract String getMethodName(); 41 42 @CollectionSize.Require(absent = ZERO) 43 public void testFind_yes() { 44 assertEquals( 45 getMethodName() + "(firstElement) should return 0", 0, find(getOrderedElements().get(0))); 46 } 47 48 public void testFind_no() { 49 assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3())); 50 } 51 52 @CollectionFeature.Require(ALLOWS_NULL_VALUES) 53 public void testFind_nullNotContainedButSupported() { 54 assertEquals(getMethodName() + "(nullNotPresent) should return -1", -1, find(null)); 55 } 56 57 @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) 58 public void testFind_nullNotContainedAndUnsupported() { 59 try { 60 assertEquals(getMethodName() + "(nullNotPresent) should return -1 or throw", -1, find(null)); 61 } catch (NullPointerException tolerated) { 62 } 63 } 64 65 @CollectionFeature.Require(ALLOWS_NULL_VALUES) 66 @CollectionSize.Require(absent = ZERO) 67 public void testFind_nonNullWhenNullContained() { 68 initCollectionWithNullElement(); 69 assertEquals(getMethodName() + "(notPresent) should return -1", -1, find(e3())); 70 } 71 72 @CollectionFeature.Require(ALLOWS_NULL_VALUES) 73 @CollectionSize.Require(absent = ZERO) 74 public void testFind_nullContained() { 75 initCollectionWithNullElement(); 76 assertEquals( 77 getMethodName() + "(null) should return " + getNullLocation(), 78 getNullLocation(), 79 find(null)); 80 } 81 82 public void testFind_wrongType() { 83 try { 84 assertEquals( 85 getMethodName() + "(wrongType) should return -1 or throw", -1, find(WrongType.VALUE)); 86 } catch (ClassCastException tolerated) { 87 } 88 } 89 }