The following issues were found

android/guava-tests/test/com/google/common/collect/ForwardingCollectionTest.java
5 issues
This class has too many methods, consider refactoring it.
Design

Line: 41

               * @author Louis Wasserman
 */
public class ForwardingCollectionTest extends TestCase {
  static final class StandardImplForwardingCollection<T> extends ForwardingCollection<T> {
    private final Collection<T> backingCollection;

    StandardImplForwardingCollection(Collection<T> backingCollection) {
      this.backingCollection = backingCollection;
    }

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 42

               */
public class ForwardingCollectionTest extends TestCase {
  static final class StandardImplForwardingCollection<T> extends ForwardingCollection<T> {
    private final Collection<T> backingCollection;

    StandardImplForwardingCollection(Collection<T> backingCollection) {
      this.backingCollection = backingCollection;
    }


            

Reported by PMD.

JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 104

                  }
  }

  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTestSuite(ForwardingCollectionTest.class);
    suite.addTest(
        CollectionTestSuiteBuilder.using(

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 138

                  return suite;
  }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Collection.class,
            new Function<Collection, Collection>() {

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 139

                }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public void testForwarding() {
    new ForwardingWrapperTester()
        .testForwarding(
            Collection.class,
            new Function<Collection, Collection>() {
              @Override

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/math/LongMathBenchmark.java
5 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 42

                private static final long[] nonnegative = new long[ARRAY_SIZE];
  private static final long[] longs = new long[ARRAY_SIZE];

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      exponents[i] = randomExponent();
      positive[i] = randomPositiveBigInteger(Long.SIZE - 1).longValue();
      nonnegative[i] = randomNonNegativeBigInteger(Long.SIZE - 1).longValue();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 46

                void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      exponents[i] = randomExponent();
      positive[i] = randomPositiveBigInteger(Long.SIZE - 1).longValue();
      nonnegative[i] = randomNonNegativeBigInteger(Long.SIZE - 1).longValue();
      longs[i] = RANDOM_SOURCE.nextLong();
      factorialArguments[i] = RANDOM_SOURCE.nextInt(30);
      binomialArguments[i][1] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials.length);
      int k = binomialArguments[i][1];

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 47

                  for (int i = 0; i < ARRAY_SIZE; i++) {
      exponents[i] = randomExponent();
      positive[i] = randomPositiveBigInteger(Long.SIZE - 1).longValue();
      nonnegative[i] = randomNonNegativeBigInteger(Long.SIZE - 1).longValue();
      longs[i] = RANDOM_SOURCE.nextLong();
      factorialArguments[i] = RANDOM_SOURCE.nextInt(30);
      binomialArguments[i][1] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials.length);
      int k = binomialArguments[i][1];
      binomialArguments[i][0] = RANDOM_SOURCE.nextInt(MathBenchmarking.biggestBinomials[k] - k) + k;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '108'-'112').
Error

Line: 108

              
  @Benchmark
  int isPrime(int reps) {
    int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (LongMath.isPrime(positive[j])) {
        tmp++;
      }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '112'-'112').
Error

Line: 112

                  for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (LongMath.isPrime(positive[j])) {
        tmp++;
      }
    }
    return tmp;
  }
}

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/MultimapsFilterEntriesAsMapTest.java
5 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 46

              
  private Multimap<String, Integer> createMultimap() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("zero", 55556);
    unfiltered.put("one", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, PREDICATE);
  }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 47

                private Multimap<String, Integer> createMultimap() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("zero", 55556);
    unfiltered.put("one", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, PREDICATE);
  }

  @Override

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 48

                  Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("zero", 55556);
    unfiltered.put("one", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, PREDICATE);
  }

  @Override
  protected Map<String, Collection<Integer>> makeEmptyMap() {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 55

                @Override
  protected Map<String, Collection<Integer>> makeEmptyMap() {
    Multimap<String, Integer> multimap = createMultimap();
    return multimap.asMap();
  }

  @Override
  protected Map<String, Collection<Integer>> makePopulatedMap() {
    Multimap<String, Integer> multimap = createMultimap();

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 62

                protected Map<String, Collection<Integer>> makePopulatedMap() {
    Multimap<String, Integer> multimap = createMultimap();
    populate(multimap);
    return multimap.asMap();
  }
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/testing/EquivalenceTester.java
5 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 57

              public final class EquivalenceTester<T> {
  private static final int REPETITIONS = 3;

  private final Equivalence<? super T> equivalence;
  private final RelationshipTester<T> delegate;
  private final List<T> items = Lists.newArrayList();

  private EquivalenceTester(Equivalence<? super T> equivalence) {
    this.equivalence = checkNotNull(equivalence);

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 58

                private static final int REPETITIONS = 3;

  private final Equivalence<? super T> equivalence;
  private final RelationshipTester<T> delegate;
  private final List<T> items = Lists.newArrayList();

  private EquivalenceTester(Equivalence<? super T> equivalence) {
    this.equivalence = checkNotNull(equivalence);
    this.delegate =

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 59

              
  private final Equivalence<? super T> equivalence;
  private final RelationshipTester<T> delegate;
  private final List<T> items = Lists.newArrayList();

  private EquivalenceTester(Equivalence<? super T> equivalence) {
    this.equivalence = checkNotNull(equivalence);
    this.delegate =
        new RelationshipTester<T>(equivalence, "equivalent", "hash", new ItemReporter());

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 87

                }

  /** Run tests on equivalence methods, throwing a failure on an invalid test */
  public EquivalenceTester<T> test() {
    for (int run = 0; run < REPETITIONS; run++) {
      testItems();
      delegate.test();
    }
    return this;

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 95

                  return this;
  }

  private void testItems() {
    for (T item : items) {
      /*
       * TODO(cpovirk): consider no longer running these equivalent() tests on every Equivalence,
       * since the Equivalence base type now implements this logic itself
       */

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/AbstractListTester.java
5 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 54

                protected void expectContents(Collection<E> expectedCollection) {
    List<E> expectedList = Helpers.copyToList(expectedCollection);
    // Avoid expectEquals() here to delay reason manufacture until necessary.
    if (getList().size() != expectedList.size()) {
      fail("size mismatch: " + reportContext(expectedList));
    }
    for (int i = 0; i < expectedList.size(); i++) {
      E expected = expectedList.get(i);
      E actual = getList().get(i);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 54

                protected void expectContents(Collection<E> expectedCollection) {
    List<E> expectedList = Helpers.copyToList(expectedCollection);
    // Avoid expectEquals() here to delay reason manufacture until necessary.
    if (getList().size() != expectedList.size()) {
      fail("size mismatch: " + reportContext(expectedList));
    }
    for (int i = 0; i < expectedList.size(); i++) {
      E expected = expectedList.get(i);
      E actual = getList().get(i);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 59

                  }
    for (int i = 0; i < expectedList.size(); i++) {
      E expected = expectedList.get(i);
      E actual = getList().get(i);
      if (expected != actual && (expected == null || !expected.equals(actual))) {
        fail("mismatch at index " + i + ": " + reportContext(expectedList));
      }
    }
  }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 60

                  for (int i = 0; i < expectedList.size(); i++) {
      E expected = expectedList.get(i);
      E actual = getList().get(i);
      if (expected != actual && (expected == null || !expected.equals(actual))) {
        fail("mismatch at index " + i + ": " + reportContext(expectedList));
      }
    }
  }


            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 60

                  for (int i = 0; i < expectedList.size(); i++) {
      E expected = expectedList.get(i);
      E actual = getList().get(i);
      if (expected != actual && (expected == null || !expected.equals(actual))) {
        fail("mismatch at index " + i + ": " + reportContext(expectedList));
      }
    }
  }


            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/math/DoubleMathBenchmark.java
5 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 38

                private static final int[] factorials = new int[ARRAY_SIZE];
  private static final double[] doubles = new double[ARRAY_SIZE];

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      positiveDoubles[i] = randomPositiveDouble();
      doubles[i] = randomDouble(Long.SIZE);
      factorials[i] = RANDOM_SOURCE.nextInt(100);

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '69'-'73').
Error

Line: 69

              
  @Benchmark
  int isMathematicalInteger(int reps) {
    int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (DoubleMath.isMathematicalInteger(doubles[j])) {
        tmp++;
      }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '73'-'73').
Error

Line: 73

                  for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (DoubleMath.isMathematicalInteger(doubles[j])) {
        tmp++;
      }
    }
    return tmp;
  }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '81'-'85').
Error

Line: 81

              
  @Benchmark
  int isPowerOfTwo(int reps) {
    int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (DoubleMath.isPowerOfTwo(doubles[j])) {
        tmp++;
      }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'tmp' (lines '85'-'85').
Error

Line: 85

                  for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      if (DoubleMath.isPowerOfTwo(doubles[j])) {
        tmp++;
      }
    }
    return tmp;
  }
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListRemoveAllTester.java
5 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 39

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListRemoveAllTester<E> extends AbstractListTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testRemoveAll_duplicate() {
    ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
    collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
    E duplicate = arrayAndDuplicate.duplicate;

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 41

              public class ListRemoveAllTester<E> extends AbstractListTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testRemoveAll_duplicate() {
    ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
    collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
    E duplicate = arrayAndDuplicate.duplicate;

    assertTrue(

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 43

                @CollectionSize.Require(absent = {ZERO, ONE})
  public void testRemoveAll_duplicate() {
    ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
    collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
    E duplicate = arrayAndDuplicate.duplicate;

    assertTrue(
        "removeAll(intersectingCollection) should return true",
        getList().removeAll(MinimalCollection.of(duplicate)));

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 48

              
    assertTrue(
        "removeAll(intersectingCollection) should return true",
        getList().removeAll(MinimalCollection.of(duplicate)));
    assertFalse(
        "after removeAll(e), a collection should not contain e even "
            + "if it initially contained e more than once.",
        getList().contains(duplicate));
  }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 52

                  assertFalse(
        "after removeAll(e), a collection should not contain e even "
            + "if it initially contained e more than once.",
        getList().contains(duplicate));
  }

  // All other cases are covered by CollectionRemoveAllTester.
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListToArrayTester.java
5 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 37

              public class ListToArrayTester<E> extends AbstractListTester<E> {
  // CollectionToArrayTester tests everything except ordering.

  public void testToArray_noArg() {
    Object[] actual = getList().toArray();
    assertArrayEquals("toArray() order should match list", createOrderedArray(), actual);
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 38

                // CollectionToArrayTester tests everything except ordering.

  public void testToArray_noArg() {
    Object[] actual = getList().toArray();
    assertArrayEquals("toArray() order should match list", createOrderedArray(), actual);
  }

  @CollectionSize.Require(absent = ZERO)
  public void testToArray_tooSmall() {

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 42

                  assertArrayEquals("toArray() order should match list", createOrderedArray(), actual);
  }

  @CollectionSize.Require(absent = ZERO)
  public void testToArray_tooSmall() {
    Object[] actual = getList().toArray(new Object[0]);
    assertArrayEquals("toArray(tooSmall) order should match list", createOrderedArray(), actual);
  }


            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 48

                  assertArrayEquals("toArray(tooSmall) order should match list", createOrderedArray(), actual);
  }

  public void testToArray_largeEnough() {
    Object[] actual = getList().toArray(new Object[getNumElements()]);
    assertArrayEquals("toArray(largeEnough) order should match list", createOrderedArray(), actual);
  }

  private static void assertArrayEquals(String message, Object[] expected, Object[] actual) {

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 53

                  assertArrayEquals("toArray(largeEnough) order should match list", createOrderedArray(), actual);
  }

  private static void assertArrayEquals(String message, Object[] expected, Object[] actual) {
    assertEquals(message, Arrays.asList(expected), Arrays.asList(actual));
  }
}

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/SetMultimapTestSuiteBuilder.java
5 issues
Potential violation of Law of Demeter (object not created locally)
Design

Line: 56

                @Override
  protected List<Class<? extends AbstractTester>> getTesters() {
    List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
    testers.add(SetMultimapAsMapTester.class);
    testers.add(SetMultimapEqualsTester.class);
    testers.add(SetMultimapPutTester.class);
    testers.add(SetMultimapPutAllTester.class);
    testers.add(SetMultimapReplaceValuesTester.class);
    return testers;

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 57

                protected List<Class<? extends AbstractTester>> getTesters() {
    List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
    testers.add(SetMultimapAsMapTester.class);
    testers.add(SetMultimapEqualsTester.class);
    testers.add(SetMultimapPutTester.class);
    testers.add(SetMultimapPutAllTester.class);
    testers.add(SetMultimapReplaceValuesTester.class);
    return testers;
  }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 58

                  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
    testers.add(SetMultimapAsMapTester.class);
    testers.add(SetMultimapEqualsTester.class);
    testers.add(SetMultimapPutTester.class);
    testers.add(SetMultimapPutAllTester.class);
    testers.add(SetMultimapReplaceValuesTester.class);
    return testers;
  }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 59

                  testers.add(SetMultimapAsMapTester.class);
    testers.add(SetMultimapEqualsTester.class);
    testers.add(SetMultimapPutTester.class);
    testers.add(SetMultimapPutAllTester.class);
    testers.add(SetMultimapReplaceValuesTester.class);
    return testers;
  }

  @Override

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 60

                  testers.add(SetMultimapEqualsTester.class);
    testers.add(SetMultimapPutTester.class);
    testers.add(SetMultimapPutAllTester.class);
    testers.add(SetMultimapReplaceValuesTester.class);
    return testers;
  }

  @Override
  TestSuite computeMultimapGetTestSuite(

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListLastIndexOfTester.java
5 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 39

              public class ListLastIndexOfTester<E> extends AbstractListIndexOfTester<E> {
  @Override
  protected int find(Object o) {
    return getList().lastIndexOf(o);
  }

  @Override
  protected String getMethodName() {
    return "lastIndexOf";

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 47

                  return "lastIndexOf";
  }

  @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testLastIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 52

                public void testLastIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "lastIndexOf(duplicate) should return index of last occurrence",
        getNumElements() / 2,
        getList().lastIndexOf(e0()));
  }

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 56

                  assertEquals(
        "lastIndexOf(duplicate) should return index of last occurrence",
        getNumElements() / 2,
        getList().lastIndexOf(e0()));
  }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '50'-'51').
Error

Line: 50

                @CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
  @CollectionSize.Require(absent = {ZERO, ONE})
  public void testLastIndexOf_duplicate() {
    E[] array = createSamplesArray();
    array[getNumElements() / 2] = e0();
    collection = getSubjectGenerator().create(array);
    assertEquals(
        "lastIndexOf(duplicate) should return index of last occurrence",
        getNumElements() / 2,

            

Reported by PMD.