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

Class Class, % Method, % Line, %
ListEqualsTester 100% (1/1) 100% (8/8) 100% (31/31)


1 /* 2  * Copyright (C) 2008 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  21 import com.google.common.annotations.GwtCompatible; 22 import com.google.common.collect.testing.MinimalSet; 23 import com.google.common.collect.testing.features.CollectionFeature; 24 import com.google.common.collect.testing.features.CollectionSize; 25 import java.util.ArrayList; 26 import java.util.Collection; 27 import java.util.List; 28 import org.junit.Ignore; 29  30 /** 31  * Tests {@link List#equals}. 32  * 33  * @author George van den Driessche 34  */ 35 @GwtCompatible 36 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 37 public class ListEqualsTester<E> extends AbstractListTester<E> { 38  public void testEquals_otherListWithSameElements() { 39  assertTrue( 40  "A List should equal any other List containing the same elements.", 41  getList().equals(new ArrayList<E>(getOrderedElements()))); 42  } 43  44  @CollectionSize.Require(absent = CollectionSize.ZERO) 45  public void testEquals_otherListWithDifferentElements() { 46  ArrayList<E> other = new ArrayList<>(getSampleElements()); 47  other.set(other.size() / 2, getSubjectGenerator().samples().e3()); 48  assertFalse( 49  "A List should not equal another List containing different elements.", 50  getList().equals(other)); 51  } 52  53  @CollectionSize.Require(absent = CollectionSize.ZERO) 54  public void testEquals_otherListContainingNull() { 55  List<E> other = new ArrayList<>(getSampleElements()); 56  other.set(other.size() / 2, null); 57  assertFalse( 58  "Two Lists should not be equal if exactly one of them has null at a given index.", 59  getList().equals(other)); 60  } 61  62  @CollectionSize.Require(absent = CollectionSize.ZERO) 63  @CollectionFeature.Require(ALLOWS_NULL_VALUES) 64  public void testEquals_containingNull() { 65  ArrayList<E> elements = new ArrayList<>(getSampleElements()); 66  elements.set(elements.size() / 2, null); 67  collection = getSubjectGenerator().create(elements.toArray()); 68  List<E> other = new ArrayList<>(getSampleElements()); 69  assertFalse( 70  "Two Lists should not be equal if exactly one of them has null at a given index.", 71  getList().equals(other)); 72  } 73  74  @CollectionSize.Require(absent = CollectionSize.ZERO) 75  public void testEquals_shorterList() { 76  Collection<E> fewerElements = getSampleElements(getNumElements() - 1); 77  assertFalse( 78  "Lists of different sizes should not be equal.", 79  getList().equals(new ArrayList<E>(fewerElements))); 80  } 81  82  public void testEquals_longerList() { 83  Collection<E> moreElements = getSampleElements(getNumElements() + 1); 84  assertFalse( 85  "Lists of different sizes should not be equal.", 86  getList().equals(new ArrayList<E>(moreElements))); 87  } 88  89  public void testEquals_set() { 90  assertFalse("A List should never equal a Set.", getList().equals(MinimalSet.from(getList()))); 91  } 92 }