Coverage Summary for Class: SortedSetNavigationTester (com.google.common.collect.testing.testers)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| SortedSetNavigationTester | 100% (1/1) | 100% (8/8) | 87.5% (28/32) |
1 /* 2 * Copyright (C) 2010 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.CollectionSize.ONE; 20 import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; 21 import static com.google.common.collect.testing.features.CollectionSize.ZERO; 22 23 import com.google.common.annotations.GwtCompatible; 24 import com.google.common.collect.testing.Helpers; 25 import com.google.common.collect.testing.features.CollectionSize; 26 import java.util.Collections; 27 import java.util.List; 28 import java.util.NoSuchElementException; 29 import java.util.SortedSet; 30 import org.junit.Ignore; 31 32 /** 33 * A generic JUnit test which tests operations on a SortedSet. Can't be invoked directly; please see 34 * {@code SortedSetTestSuiteBuilder}. 35 * 36 * @author Jesse Wilson 37 * @author Louis Wasserman 38 */ 39 @GwtCompatible 40 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 41 public class SortedSetNavigationTester<E> extends AbstractSetTester<E> { 42 43 private SortedSet<E> sortedSet; 44 private List<E> values; 45 private E a; 46 private E b; 47 private E c; 48 49 @Override 50 public void setUp() throws Exception { 51 super.setUp(); 52 sortedSet = (SortedSet<E>) getSet(); 53 values = 54 Helpers.copyToList( 55 getSubjectGenerator() 56 .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); 57 Collections.sort(values, sortedSet.comparator()); 58 59 // some tests assume SEVERAL == 3 60 if (values.size() >= 1) { 61 a = values.get(0); 62 if (values.size() >= 3) { 63 b = values.get(1); 64 c = values.get(2); 65 } 66 } 67 } 68 69 @CollectionSize.Require(ZERO) 70 public void testEmptySetFirst() { 71 try { 72 sortedSet.first(); 73 fail(); 74 } catch (NoSuchElementException e) { 75 } 76 } 77 78 @CollectionSize.Require(ZERO) 79 public void testEmptySetLast() { 80 try { 81 sortedSet.last(); 82 fail(); 83 } catch (NoSuchElementException e) { 84 } 85 } 86 87 @CollectionSize.Require(ONE) 88 public void testSingletonSetFirst() { 89 assertEquals(a, sortedSet.first()); 90 } 91 92 @CollectionSize.Require(ONE) 93 public void testSingletonSetLast() { 94 assertEquals(a, sortedSet.last()); 95 } 96 97 @CollectionSize.Require(SEVERAL) 98 public void testFirst() { 99 assertEquals(a, sortedSet.first()); 100 } 101 102 @CollectionSize.Require(SEVERAL) 103 public void testLast() { 104 assertEquals(c, sortedSet.last()); 105 } 106 }