The following issues were found

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

Line: 46

               * @author Robert KonigsbergSortedMapFeature
 */
public class ForwardingSortedMapTest extends TestCase {
  static class StandardImplForwardingSortedMap<K, V> extends ForwardingSortedMap<K, V> {
    private final SortedMap<K, V> backingSortedMap;

    StandardImplForwardingSortedMap(SortedMap<K, V> backingSortedMap) {
      this.backingSortedMap = backingSortedMap;
    }

            

Reported by PMD.

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

Line: 47

               */
public class ForwardingSortedMapTest extends TestCase {
  static class StandardImplForwardingSortedMap<K, V> extends ForwardingSortedMap<K, V> {
    private final SortedMap<K, V> backingSortedMap;

    StandardImplForwardingSortedMap(SortedMap<K, V> backingSortedMap) {
      this.backingSortedMap = backingSortedMap;
    }


            

Reported by PMD.

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

Line: 108

                    return new StandardEntrySet() {
        @Override
        public Iterator<Entry<K, V>> iterator() {
          return backingSortedMap.entrySet().iterator();
        }
      };
    }

    @Override

            

Reported by PMD.

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

Line: 129

                  }
  }

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

    suite.addTestSuite(ForwardingSortedMapTest.class);
    suite.addTest(
        SortedMapTestSuiteBuilder.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: 204

                  return suite;
  }

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

            

Reported by PMD.

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

Line: 205

                }

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

            

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: 217

                          });
  }

  public void testEquals() {
    SortedMap<Integer, String> map1 = ImmutableSortedMap.of(1, "one");
    SortedMap<Integer, String> map2 = ImmutableSortedMap.of(2, "two");
    new EqualsTester()
        .addEqualityGroup(map1, wrap(map1), wrap(map1))
        .addEqualityGroup(map2, wrap(map2))

            

Reported by PMD.

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

Line: 217

                          });
  }

  public void testEquals() {
    SortedMap<Integer, String> map1 = ImmutableSortedMap.of(1, "one");
    SortedMap<Integer, String> map2 = ImmutableSortedMap.of(2, "two");
    new EqualsTester()
        .addEqualityGroup(map1, wrap(map1), wrap(map1))
        .addEqualityGroup(map2, wrap(map2))

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/collect/MinMaxPriorityQueueBenchmark.java
8 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

               * @author Sverre Sundsdal
 */
public class MinMaxPriorityQueueBenchmark {
  @Param private ComparatorType comparator;

  // TODO(kevinb): add 1000000 back when we have the ability to throw
  // NotApplicableException in the expensive comparator case.
  @Param({"100", "10000"})
  private int size;

            

Reported by PMD.

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

Line: 40

                // TODO(kevinb): add 1000000 back when we have the ability to throw
  // NotApplicableException in the expensive comparator case.
  @Param({"100", "10000"})
  private int size;

  @Param private HeapType heap;

  private Queue<Integer> queue;


            

Reported by PMD.

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

Line: 42

                @Param({"100", "10000"})
  private int size;

  @Param private HeapType heap;

  private Queue<Integer> queue;

  private final Random random = new Random();


            

Reported by PMD.

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

Line: 44

              
  @Param private HeapType heap;

  private Queue<Integer> queue;

  private final Random random = new Random();

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 46

              
  private Queue<Integer> queue;

  private final Random random = new Random();

  @BeforeExperiment
  void setUp() {
    queue = heap.create(comparator.get());
    for (int i = 0; i < size; i++) {

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 48

              
  private final Random random = new Random();

  @BeforeExperiment
  void setUp() {
    queue = heap.create(comparator.get());
    for (int i = 0; i < size; i++) {
      queue.add(random.nextInt());
    }

            

Reported by PMD.

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

Line: 81

                 * pollMax using the same code that benchmarks poll.
   */
  static final class InvertedMinMaxPriorityQueue<T> extends ForwardingQueue<T> {
    MinMaxPriorityQueue<T> mmHeap;

    public InvertedMinMaxPriorityQueue(Comparator<T> comparator) {
      mmHeap = MinMaxPriorityQueue.orderedBy(comparator).create();
    }


            

Reported by PMD.

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

Line: 102

                  MIN_MAX {
      @Override
      public Queue<Integer> create(Comparator<Integer> comparator) {
        return MinMaxPriorityQueue.orderedBy(comparator).create();
      }
    },
    PRIORITY_QUEUE {
      @Override
      public Queue<Integer> create(Comparator<Integer> comparator) {

            

Reported by PMD.

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

Line: 58

                @Override
  protected List<Class<? extends AbstractTester>> getTesters() {
    List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
    testers.add(ListMultimapAsMapTester.class);
    testers.add(ListMultimapEqualsTester.class);
    testers.add(ListMultimapPutTester.class);
    testers.add(ListMultimapPutAllTester.class);
    testers.add(ListMultimapRemoveTester.class);
    testers.add(ListMultimapReplaceValuesTester.class);

            

Reported by PMD.

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

Line: 59

                protected List<Class<? extends AbstractTester>> getTesters() {
    List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
    testers.add(ListMultimapAsMapTester.class);
    testers.add(ListMultimapEqualsTester.class);
    testers.add(ListMultimapPutTester.class);
    testers.add(ListMultimapPutAllTester.class);
    testers.add(ListMultimapRemoveTester.class);
    testers.add(ListMultimapReplaceValuesTester.class);
    return testers;

            

Reported by PMD.

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

Line: 60

                  List<Class<? extends AbstractTester>> testers = Helpers.copyToList(super.getTesters());
    testers.add(ListMultimapAsMapTester.class);
    testers.add(ListMultimapEqualsTester.class);
    testers.add(ListMultimapPutTester.class);
    testers.add(ListMultimapPutAllTester.class);
    testers.add(ListMultimapRemoveTester.class);
    testers.add(ListMultimapReplaceValuesTester.class);
    return testers;
  }

            

Reported by PMD.

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

Line: 61

                  testers.add(ListMultimapAsMapTester.class);
    testers.add(ListMultimapEqualsTester.class);
    testers.add(ListMultimapPutTester.class);
    testers.add(ListMultimapPutAllTester.class);
    testers.add(ListMultimapRemoveTester.class);
    testers.add(ListMultimapReplaceValuesTester.class);
    return testers;
  }


            

Reported by PMD.

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

Line: 62

                  testers.add(ListMultimapEqualsTester.class);
    testers.add(ListMultimapPutTester.class);
    testers.add(ListMultimapPutAllTester.class);
    testers.add(ListMultimapRemoveTester.class);
    testers.add(ListMultimapReplaceValuesTester.class);
    return testers;
  }

  @Override

            

Reported by PMD.

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

Line: 63

                  testers.add(ListMultimapPutTester.class);
    testers.add(ListMultimapPutAllTester.class);
    testers.add(ListMultimapRemoveTester.class);
    testers.add(ListMultimapReplaceValuesTester.class);
    return testers;
  }

  @Override
  TestSuite computeMultimapGetTestSuite(

            

Reported by PMD.

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

Line: 101

                @Override
  Set<Feature<?>> computeMultimapGetFeatures(Set<Feature<?>> multimapFeatures) {
    Set<Feature<?>> derivedFeatures = super.computeMultimapGetFeatures(multimapFeatures);
    if (derivedFeatures.contains(CollectionFeature.SUPPORTS_ADD)) {
      derivedFeatures.add(ListFeature.SUPPORTS_ADD_WITH_INDEX);
    }
    if (derivedFeatures.contains(CollectionFeature.GENERAL_PURPOSE)) {
      derivedFeatures.add(ListFeature.GENERAL_PURPOSE);
    }

            

Reported by PMD.

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

Line: 104

                  if (derivedFeatures.contains(CollectionFeature.SUPPORTS_ADD)) {
      derivedFeatures.add(ListFeature.SUPPORTS_ADD_WITH_INDEX);
    }
    if (derivedFeatures.contains(CollectionFeature.GENERAL_PURPOSE)) {
      derivedFeatures.add(ListFeature.GENERAL_PURPOSE);
    }
    return derivedFeatures;
  }


            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/math/BigIntegerMathBenchmark.java
8 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 40

                private static final int[] binomials = new int[ARRAY_SIZE];

  @Param({"50", "1000", "10000"})
  int factorialBound;

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      factorials[i] = RANDOM_SOURCE.nextInt(factorialBound);

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 42

                @Param({"50", "1000", "10000"})
  int factorialBound;

  @BeforeExperiment
  void setUp() {
    for (int i = 0; i < ARRAY_SIZE; i++) {
      factorials[i] = RANDOM_SOURCE.nextInt(factorialBound);
      slowFactorials[i] = RANDOM_SOURCE.nextInt(factorialBound);
      binomials[i] = RANDOM_SOURCE.nextInt(factorials[i] + 1);

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 53

              
  /** Previous version of BigIntegerMath.factorial, kept for timing purposes. */
  private static BigInteger oldSlowFactorial(int n) {
    if (n <= 20) {
      return BigInteger.valueOf(LongMath.factorial(n));
    } else {
      int k = 20;
      return BigInteger.valueOf(LongMath.factorial(k)).multiply(oldSlowFactorial(k, n));
    }

            

Reported by PMD.

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

Line: 57

                    return BigInteger.valueOf(LongMath.factorial(n));
    } else {
      int k = 20;
      return BigInteger.valueOf(LongMath.factorial(k)).multiply(oldSlowFactorial(k, n));
    }
  }

  /** Returns the product of {@code n1} exclusive through {@code n2} inclusive. */
  private static BigInteger oldSlowFactorial(int n1, int n2) {

            

Reported by PMD.

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

Line: 78

                   * Currently, we just divide the range in half.
     */
    int mid = (n1 + n2) >>> 1;
    return oldSlowFactorial(n1, mid).multiply(oldSlowFactorial(mid, n2));
  }

  @Benchmark
  int slowFactorial(int reps) {
    int tmp = 0;

            

Reported by PMD.

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

Line: 86

                  int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      tmp += oldSlowFactorial(slowFactorials[j]).intValue();
    }
    return tmp;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 96

                  int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & ARRAY_MASK;
      tmp += BigIntegerMath.factorial(factorials[j]).intValue();
    }
    return tmp;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 106

                  int tmp = 0;
    for (int i = 0; i < reps; i++) {
      int j = i & 0xffff;
      tmp += BigIntegerMath.binomial(factorials[j], binomials[j]).intValue();
    }
    return tmp;
  }
}

            

Reported by PMD.

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

Line: 90

                    return new Ordering<Entry<String, Integer>>() {
        @Override
        public int compare(Entry<String, Integer> left, Entry<String, Integer> right) {
          return left.getKey().compareTo(right.getKey());
        }
      }.sortedCopy(insertionOrder);
    }

    @Override

            

Reported by PMD.

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

Line: 103

                      Entry<String, Integer> entry = (Entry<String, Integer>) o;
        builder.put(entry);
      }
      return builder.build().entrySet().asList();
    }
  }

  public static class ImmutableSortedMapKeyListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 103

                      Entry<String, Integer> entry = (Entry<String, Integer>) o;
        builder.put(entry);
      }
      return builder.build().entrySet().asList();
    }
  }

  public static class ImmutableSortedMapKeyListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 114

                    for (int i = 0; i < elements.length; i++) {
        builder.put(elements[i], i);
      }
      return builder.build().keySet().asList();
    }

    @Override
    public List<String> order(List<String> insertionOrder) {
      return Ordering.natural().sortedCopy(insertionOrder);

            

Reported by PMD.

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

Line: 114

                    for (int i = 0; i < elements.length; i++) {
        builder.put(elements[i], i);
      }
      return builder.build().keySet().asList();
    }

    @Override
    public List<String> order(List<String> insertionOrder) {
      return Ordering.natural().sortedCopy(insertionOrder);

            

Reported by PMD.

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

Line: 119

              
    @Override
    public List<String> order(List<String> insertionOrder) {
      return Ordering.natural().sortedCopy(insertionOrder);
    }
  }

  public static class ImmutableSortedMapValueListGenerator extends TestStringListGenerator {
    @Override

            

Reported by PMD.

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

Line: 130

                    for (int i = 0; i < elements.length; i++) {
        builder.put(i, elements[i]);
      }
      return builder.build().values().asList();
    }
  }
}

            

Reported by PMD.

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

Line: 130

                    for (int i = 0; i < elements.length; i++) {
        builder.put(i, elements[i]);
      }
      return builder.build().values().asList();
    }
  }
}

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/math/LessThanBenchmark.java
8 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 34

                static final int SAMPLE_MASK = 0x0FFF;

  @Param("1234")
  int randomSeed;

  int[] xInts;
  int[] yInts;

  long[] xLongs;

            

Reported by PMD.

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

Line: 36

                @Param("1234")
  int randomSeed;

  int[] xInts;
  int[] yInts;

  long[] xLongs;
  long[] yLongs;


            

Reported by PMD.

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

Line: 37

                int randomSeed;

  int[] xInts;
  int[] yInts;

  long[] xLongs;
  long[] yLongs;

  int[] constant;

            

Reported by PMD.

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

Line: 39

                int[] xInts;
  int[] yInts;

  long[] xLongs;
  long[] yLongs;

  int[] constant;

  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;

            

Reported by PMD.

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

Line: 40

                int[] yInts;

  long[] xLongs;
  long[] yLongs;

  int[] constant;

  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;


            

Reported by PMD.

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

Line: 42

                long[] xLongs;
  long[] yLongs;

  int[] constant;

  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 46

              
  private static final long NONNEGATIVE_LONG_MASK = 0x7FFFFFFFFFFFFFFFL;

  @BeforeExperiment
  void setUp() {
    Random random = new Random(randomSeed);
    xInts = new int[SAMPLE_SIZE];
    yInts = new int[SAMPLE_SIZE];
    xLongs = new long[SAMPLE_SIZE];

            

Reported by PMD.

Found 'DU'-anomaly for variable 'random' (lines '48'-'61').
Error

Line: 48

              
  @BeforeExperiment
  void setUp() {
    Random random = new Random(randomSeed);
    xInts = new int[SAMPLE_SIZE];
    yInts = new int[SAMPLE_SIZE];
    xLongs = new long[SAMPLE_SIZE];
    yLongs = new long[SAMPLE_SIZE];
    constant = new int[SAMPLE_SIZE];

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/math/QuantilesBenchmark.java
8 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

                    ContiguousSet.create(Range.closed(0, 10), DiscreteDomain.integers());

  @Param({"10", "100", "1000", "10000", "100000"})
  int datasetSize;

  @Param QuantilesAlgorithm algorithm;

  private double[][] datasets = new double[0x100][];


            

Reported by PMD.

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

Line: 37

                @Param({"10", "100", "1000", "10000", "100000"})
  int datasetSize;

  @Param QuantilesAlgorithm algorithm;

  private double[][] datasets = new double[0x100][];

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 39

              
  @Param QuantilesAlgorithm algorithm;

  private double[][] datasets = new double[0x100][];

  @BeforeExperiment
  void setUp() {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 41

              
  private double[][] datasets = new double[0x100][];

  @BeforeExperiment
  void setUp() {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      datasets[i] = new double[datasetSize];
      for (int j = 0; j < datasetSize; j++) {

            

Reported by PMD.

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

Line: 89

                double percentiles90And99(int reps) {
    double dummy = 0.0;
    for (int i = 0; i < reps; i++) {
      dummy += algorithm.multipleQuantiles(ImmutableSet.of(90, 99), 100, dataset(i)).get(90);
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 98

                double threePercentiles(int reps) {
    double dummy = 0.0;
    for (int i = 0; i < reps; i++) {
      dummy += algorithm.multipleQuantiles(ImmutableSet.of(90, 95, 99), 100, dataset(i)).get(90);
    }
    return dummy;
  }

  @Benchmark

            

Reported by PMD.

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

Line: 107

                double allDeciles(int reps) {
    double dummy = 0.0;
    for (int i = 0; i < reps; i++) {
      dummy += algorithm.multipleQuantiles(ALL_DECILE_INDEXES, 10, dataset(i)).get(9);
    }
    return dummy;
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'rng' (lines '43'-'50').
Error

Line: 43

              
  @BeforeExperiment
  void setUp() {
    Random rng = new Random();
    for (int i = 0; i < 0x100; i++) {
      datasets[i] = new double[datasetSize];
      for (int j = 0; j < datasetSize; j++) {
        datasets[i][j] = rng.nextDouble();
      }

            

Reported by PMD.

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

Line: 35

                  extends AbstractContainerTester<Collection<E>, E> {

  // TODO: replace this with an accessor.
  protected Collection<E> collection;

  @Override
  protected Collection<E> actualContents() {
    return collection;
  }

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 57

                /** @return an array of the proper size with {@code null} inserted into the middle element. */
  protected E[] createArrayWithNullElement() {
    E[] array = createSamplesArray();
    array[getNullLocation()] = null;
    return array;
  }

  protected void initCollectionWithNullElement() {
    E[] array = createArrayWithNullElement();

            

Reported by PMD.

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

Line: 63

              
  protected void initCollectionWithNullElement() {
    E[] array = createArrayWithNullElement();
    resetContainer(getSubjectGenerator().create(array));
  }

  /**
   * Equivalent to {@link #expectMissing(Object[]) expectMissing}{@code (null)} except that the call
   * to {@code contains(null)} is permitted to throw a {@code NullPointerException}.

            

Reported by PMD.

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

Line: 74

                 */
  protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 75

                protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 75

                protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 75

                protected void expectNullMissingWhenNullUnsupported(String message) {
    try {
      assertFalse(message, actualContents().contains(null));
    } catch (NullPointerException tolerated) {
      // Tolerated
    }
  }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'array' (lines '56'-'57').
Error

Line: 56

              
  /** @return an array of the proper size with {@code null} inserted into the middle element. */
  protected E[] createArrayWithNullElement() {
    E[] array = createSamplesArray();
    array[getNullLocation()] = null;
    return array;
  }

  protected void initCollectionWithNullElement() {

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/ListAddTester.java
8 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: 42

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddTester<E> extends AbstractListTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedPresent() {
    assertTrue("add(present) should return true", getList().add(e0()));
    expectAdded(e0());
  }

            

Reported by PMD.

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

Line: 45

                @CollectionFeature.Require(SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedPresent() {
    assertTrue("add(present) should return true", getList().add(e0()));
    expectAdded(e0());
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)

            

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: 49

                  expectAdded(e0());
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  /*
   * absent = ZERO isn't required, since unmodList.add() must
   * throw regardless, but it keeps the method name accurate.
   */

            

Reported by PMD.

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

Line: 57

                 */
  public void testAdd_unsupportedPresent() {
    try {
      getList().add(e0());
      fail("add(present) should throw");
    } catch (UnsupportedOperationException expected) {
    }
  }


            

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: 63

                  }
  }

  @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedNullPresent() {
    E[] array = createArrayWithNullElement();
    collection = getSubjectGenerator().create(array);
    assertTrue("add(nullPresent) should return true", getList().add(null));

            

Reported by PMD.

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

Line: 67

                @CollectionSize.Require(absent = ZERO)
  public void testAdd_supportedNullPresent() {
    E[] array = createArrayWithNullElement();
    collection = getSubjectGenerator().create(array);
    assertTrue("add(nullPresent) should return true", getList().add(null));

    List<E> expected = Helpers.copyToList(array);
    expected.add(null);
    expectContents(expected);

            

Reported by PMD.

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

Line: 68

                public void testAdd_supportedNullPresent() {
    E[] array = createArrayWithNullElement();
    collection = getSubjectGenerator().create(array);
    assertTrue("add(nullPresent) should return true", getList().add(null));

    List<E> expected = Helpers.copyToList(array);
    expected.add(null);
    expectContents(expected);
  }

            

Reported by PMD.

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

Line: 71

                  assertTrue("add(nullPresent) should return true", getList().add(null));

    List<E> expected = Helpers.copyToList(array);
    expected.add(null);
    expectContents(expected);
  }

  /**
   * Returns the {@link Method} instance for {@link #testAdd_supportedNullPresent()} so that tests

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/CollectionContainsTester.java
8 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: 40

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionContainsTester<E> extends AbstractCollectionTester<E> {
  @CollectionSize.Require(absent = ZERO)
  public void testContains_yes() {
    assertTrue("contains(present) should return true", collection.contains(e0()));
  }

  public void testContains_no() {

            

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: 45

                  assertTrue("contains(present) should return true", collection.contains(e0()));
  }

  public void testContains_no() {
    assertFalse("contains(notPresent) should return false", collection.contains(e3()));
  }

  @CollectionFeature.Require(ALLOWS_NULL_QUERIES)
  public void testContains_nullNotContainedButQueriesSupported() {

            

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: 49

                  assertFalse("contains(notPresent) should return false", collection.contains(e3()));
  }

  @CollectionFeature.Require(ALLOWS_NULL_QUERIES)
  public void testContains_nullNotContainedButQueriesSupported() {
    assertFalse("contains(null) should return false", collection.contains(null));
  }

  @CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)

            

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: 54

                  assertFalse("contains(null) should return false", collection.contains(null));
  }

  @CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
  public void testContains_nullNotContainedAndUnsupported() {
    expectNullMissingWhenNullUnsupported("contains(null) should return false or throw");
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)

            

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: 59

                  expectNullMissingWhenNullUnsupported("contains(null) should return false or throw");
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testContains_nonNullWhenNullContained() {
    initCollectionWithNullElement();
    assertFalse("contains(notPresent) should return false", collection.contains(e3()));
  }

            

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: 66

                  assertFalse("contains(notPresent) should return false", collection.contains(e3()));
  }

  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testContains_nullContained() {
    initCollectionWithNullElement();
    assertTrue("contains(null) should return true", collection.contains(null));
  }

            

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: 73

                  assertTrue("contains(null) should return true", collection.contains(null));
  }

  public void testContains_wrongType() {
    try {
      assertFalse(
          "contains(wrongType) should return false or throw", collection.contains(WrongType.VALUE));
    } catch (ClassCastException tolerated) {
    }

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 77

                  try {
      assertFalse(
          "contains(wrongType) should return false or throw", collection.contains(WrongType.VALUE));
    } catch (ClassCastException tolerated) {
    }
  }
}

            

Reported by PMD.