Coverage Summary for Class: ListAddTester (com.google.common.collect.testing.testers)

Class Class, % Method, % Line, %
ListAddTester 100% (1/1) 100% (5/5) 88.2% (15/17)


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.CollectionFeature.SUPPORTS_ADD; 21 import static com.google.common.collect.testing.features.CollectionSize.ZERO; 22  23 import com.google.common.annotations.GwtCompatible; 24 import com.google.common.annotations.GwtIncompatible; 25 import com.google.common.collect.testing.Helpers; 26 import com.google.common.collect.testing.features.CollectionFeature; 27 import com.google.common.collect.testing.features.CollectionSize; 28 import java.lang.reflect.Method; 29 import java.util.List; 30 import org.junit.Ignore; 31  32 /** 33  * A generic JUnit test which tests {@code add(Object)} operations on a list. Can't be invoked 34  * directly; please see {@link com.google.common.collect.testing.ListTestSuiteBuilder}. 35  * 36  * @author Chris Povirk 37  */ 38 @SuppressWarnings("unchecked") // too many "unchecked generic array creations" 39 @GwtCompatible(emulated = true) 40 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 41 public class ListAddTester<E> extends AbstractListTester<E> { 42  @CollectionFeature.Require(SUPPORTS_ADD) 43  @CollectionSize.Require(absent = ZERO) 44  public void testAdd_supportedPresent() { 45  assertTrue("add(present) should return true", getList().add(e0())); 46  expectAdded(e0()); 47  } 48  49  @CollectionFeature.Require(absent = SUPPORTS_ADD) 50  @CollectionSize.Require(absent = ZERO) 51  /* 52  * absent = ZERO isn't required, since unmodList.add() must 53  * throw regardless, but it keeps the method name accurate. 54  */ 55  public void testAdd_unsupportedPresent() { 56  try { 57  getList().add(e0()); 58  fail("add(present) should throw"); 59  } catch (UnsupportedOperationException expected) { 60  } 61  } 62  63  @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}) 64  @CollectionSize.Require(absent = ZERO) 65  public void testAdd_supportedNullPresent() { 66  E[] array = createArrayWithNullElement(); 67  collection = getSubjectGenerator().create(array); 68  assertTrue("add(nullPresent) should return true", getList().add(null)); 69  70  List<E> expected = Helpers.copyToList(array); 71  expected.add(null); 72  expectContents(expected); 73  } 74  75  /** 76  * Returns the {@link Method} instance for {@link #testAdd_supportedNullPresent()} so that tests 77  * can suppress it. See {@link CollectionAddTester#getAddNullSupportedMethod()} for details. 78  */ 79  @GwtIncompatible // reflection 80  public static Method getAddSupportedNullPresentMethod() { 81  return Helpers.getMethod(ListAddTester.class, "testAdd_supportedNullPresent"); 82  } 83 }