Coverage Summary for Class: ListReplaceAllTester (com.google.common.collect.testing.testers)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| ListReplaceAllTester | 100% (1/1) | 100% (4/4) | 88.2% (15/17) |
1 /* 2 * Copyright (C) 2015 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.ZERO; 20 import static com.google.common.collect.testing.features.ListFeature.SUPPORTS_SET; 21 22 import com.google.common.annotations.GwtCompatible; 23 import com.google.common.collect.testing.features.CollectionSize; 24 import com.google.common.collect.testing.features.ListFeature; 25 import java.util.Collections; 26 import java.util.List; 27 import org.junit.Ignore; 28 29 /** 30 * A generic JUnit test which tests {@link List#replaceAll}. Can't be invoked directly; please see 31 * {@link com.google.common.collect.testing.ListTestSuiteBuilder}. 32 * 33 * @author Louis Wasserman 34 */ 35 @GwtCompatible 36 @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests. 37 public class ListReplaceAllTester<E> extends AbstractListTester<E> { 38 @ListFeature.Require(SUPPORTS_SET) 39 public void testReplaceAll() { 40 getList().replaceAll(e -> samples.e3()); 41 expectContents(Collections.nCopies(getNumElements(), samples.e3())); 42 } 43 44 @ListFeature.Require(SUPPORTS_SET) 45 public void testReplaceAll_changesSome() { 46 getList().replaceAll(e -> e.equals(samples.e0()) ? samples.e3() : e); 47 E[] expected = createSamplesArray(); 48 for (int i = 0; i < expected.length; i++) { 49 if (expected[i].equals(samples.e0())) { 50 expected[i] = samples.e3(); 51 } 52 } 53 expectContents(expected); 54 } 55 56 @CollectionSize.Require(absent = ZERO) 57 @ListFeature.Require(absent = SUPPORTS_SET) 58 public void testReplaceAll_unsupported() { 59 try { 60 getList().replaceAll(e -> e); 61 fail("replaceAll() should throw UnsupportedOperationException"); 62 } catch (UnsupportedOperationException expected) { 63 } 64 expectUnchanged(); 65 } 66 }