The following issues were found

android/guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java
45 issues
Avoid throwing raw exception types.
Design

Line: 319

                  try {
      recurse(0);
    } catch (RuntimeException e) {
      throw new RuntimeException(Arrays.toString(stimuli), e);
    }
  }

  private void recurse(int level) {
    // We're going to reuse the stimuli array 3^steps times by overwriting it

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 44

               * @author Chris Povirk
 */
@GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;

            

Reported by PMD.

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

Line: 45

               */
@GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

            

Reported by PMD.

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

Line: 46

              @GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;


            

Reported by PMD.

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

Line: 47

              abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**

            

Reported by PMD.

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

Line: 48

                private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of

            

Reported by PMD.

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

Line: 49

                private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of
   * throwing any particular exception type.

            

Reported by PMD.

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

Line: 50

                private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of
   * throwing any particular exception type.
   */

            

Reported by PMD.

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

Line: 97

                    if (!isPermitted(exception)) {
        String message =
            "Exception "
                + exception.getClass().getSimpleName()
                + " was thrown; expected "
                + getMessage();
        Helpers.fail(exception, message);
      }
    }

            

Reported by PMD.

This class has too many methods, consider refactoring it.
Design

Line: 129

                 * <p>This class is accessible but not supported in GWT as it references {@link
   * PermittedMetaException}.
   */
  protected final class MultiExceptionListIterator implements ListIterator<E> {
    // TODO: track seen elements when order isn't guaranteed
    // TODO: verify contents afterward
    // TODO: something shiny and new instead of Stack
    // TODO: test whether null is supported (create a Feature)
    /**

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/HashMultisetTest.java
45 issues
JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 44

              @GwtCompatible(emulated = true)
public class HashMultisetTest extends TestCase {

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(

            

Reported by PMD.

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

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

Reported by PMD.

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

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

Reported by PMD.

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

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

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

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

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

Line: 71

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

The String literal 'foo' appears 7 times in this file; the first occurrence is on line 73
Error

Line: 73

              
  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }


            

Reported by PMD.

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

Line: 73

              
  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }


            

Reported by PMD.

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

Line: 74

                public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }

  public void testCreateWithSize() {

            

Reported by PMD.

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

Line: 75

                  Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }

  public void testCreateWithSize() {
    Multiset<String> multiset = HashMultiset.create(50);

            

Reported by PMD.

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

Line: 43

              @GwtIncompatible
public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {


            

Reported by PMD.

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

Line: 44

              public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.

            

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

                protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.
    latch = new CountDownLatch(1);
    future = createListenableFuture(Boolean.TRUE, null, latch);

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 54

                  future = createListenableFuture(Boolean.TRUE, null, latch);
  }

  @Override
  protected void tearDown() throws Exception {

    // Make sure we have no waiting threads.
    latch.countDown();
  }

            

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

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

Reported by PMD.

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

Line: 66

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 68

                /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];

    // Wait on the future in a separate thread.

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 80

                            @Override
              public void run() {
                try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 82

                              try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }
              }
            })

            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/NetworkMutationTest.java
45 issues
JUnit tests should include assert() or fail()
Design

Line: 40

                private static final int NODE_POOL_SIZE = 1000; // must be >> NUM_NODES

  @Test
  public void directedNetwork() {
    testNetworkMutation(NetworkBuilder.directed());
  }

  @Test
  public void undirectedNetwork() {

            

Reported by PMD.

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

Line: 45

                }

  @Test
  public void undirectedNetwork() {
    testNetworkMutation(NetworkBuilder.undirected());
  }

  private static void testNetworkMutation(NetworkBuilder<? super Integer, Object> networkBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

            

Reported by PMD.

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

Line: 49

                  testNetworkMutation(NetworkBuilder.undirected());
  }

  private static void testNetworkMutation(NetworkBuilder<? super Integer, Object> networkBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

            

Reported by PMD.

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

Line: 54

              
    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);


            

Reported by PMD.

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

Line: 54

              
    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);


            

Reported by PMD.

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

Line: 56

                    MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 56

                    MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 57

                        networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 57

                        networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 60

                    assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }
      ArrayList<Integer> nodeList = new ArrayList<>(network.nodes());
      for (int i = 0; i < NUM_EDGES; ++i) {
        // Parallel edges are allowed, so this should always succeed.

            

Reported by PMD.

android/guava-testlib/test/com/google/common/testing/FakeTickerTest.java
45 issues
This class has too many methods, consider refactoring it.
Design

Line: 36

               * @author Jige Yu
 */
@GwtCompatible(emulated = true)
public class FakeTickerTest extends TestCase {

  @GwtIncompatible // NullPointerTester
  public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicInstanceMethods(new FakeTicker());

            

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

              @GwtCompatible(emulated = true)
public class FakeTickerTest extends TestCase {

  @GwtIncompatible // NullPointerTester
  public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicInstanceMethods(new FakeTicker());
  }


            

Reported by PMD.

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

Line: 39

              public class FakeTickerTest extends TestCase {

  @GwtIncompatible // NullPointerTester
  public void testNullPointerExceptions() {
    NullPointerTester tester = new NullPointerTester();
    tester.testAllPublicInstanceMethods(new FakeTicker());
  }

  public void testAdvance() {

            

Reported by PMD.

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

Line: 44

                  tester.testAllPublicInstanceMethods(new FakeTicker());
  }

  public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);

            

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

                  tester.testAllPublicInstanceMethods(new FakeTicker());
  }

  public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

              
  public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

                public void testAdvance() {
    FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 48

                  FakeTicker ticker = new FakeTicker();
    assertEquals(0, ticker.read());
    assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }

  public void testAutoIncrementStep_returnsSameInstance() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 50

                  assertSame(ticker, ticker.advance(10));
    assertEquals(10, ticker.read());
    ticker.advance(1, TimeUnit.MILLISECONDS);
    assertEquals(1000010L, ticker.read());
  }

  public void testAutoIncrementStep_returnsSameInstance() {
    FakeTicker ticker = new FakeTicker();
    assertSame(ticker, ticker.setAutoIncrementStep(10, TimeUnit.NANOSECONDS));

            

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

                  assertEquals(1000010L, ticker.read());
  }

  public void testAutoIncrementStep_returnsSameInstance() {
    FakeTicker ticker = new FakeTicker();
    assertSame(ticker, ticker.setAutoIncrementStep(10, TimeUnit.NANOSECONDS));
  }

  public void testAutoIncrementStep_nanos() {

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultimapEntriesTester.java
45 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: 47

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapEntriesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testEntries() {
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)

            

Reported by PMD.

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

Line: 48

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapEntriesTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testEntries() {
    assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testContainsEntryWithNullKeyPresent() {

            

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

                  assertEqualIgnoringOrder(getSampleElements(), multimap().entries());
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testContainsEntryWithNullKeyPresent() {
    initMultimapWithNullKey();
    assertContains(multimap().entries(), Helpers.mapEntry((K) null, getValueForNullKey()));
  }

            

Reported by PMD.

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

Line: 55

                @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testContainsEntryWithNullKeyPresent() {
    initMultimapWithNullKey();
    assertContains(multimap().entries(), Helpers.mapEntry((K) null, getValueForNullKey()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));

            

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

                  assertContains(multimap().entries(), Helpers.mapEntry((K) null, getValueForNullKey()));
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 60

              
  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {

            

Reported by PMD.

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

Line: 60

              
  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testContainsEntryWithNullKeyAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {

            

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

                  assertFalse(multimap().entries().contains(Helpers.mapEntry(null, v0())));
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {
    initMultimapWithNullValue();
    assertContains(multimap().entries(), Helpers.mapEntry(getKeyForNullValue(), (V) null));
  }

            

Reported by PMD.

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

Line: 67

                @MapFeature.Require(ALLOWS_NULL_VALUES)
  public void testContainsEntryWithNullValuePresent() {
    initMultimapWithNullValue();
    assertContains(multimap().entries(), Helpers.mapEntry(getKeyForNullValue(), (V) null));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsEntryWithNullValueAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(k0(), 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: 70

                  assertContains(multimap().entries(), Helpers.mapEntry(getKeyForNullValue(), (V) null));
  }

  @MapFeature.Require(ALLOWS_NULL_VALUE_QUERIES)
  public void testContainsEntryWithNullValueAbsent() {
    assertFalse(multimap().entries().contains(Helpers.mapEntry(k0(), null)));
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultisetAddTester.java
45 issues
This class has too many methods, consider refactoring it.
Design

Line: 34

               */
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetAddTester<E> extends AbstractMultisetTester<E> {
  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  public void testAddUnsupported() {
    try {
      getMultiset().add(e0());
      fail("Expected UnsupportedOperationException");

            

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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetAddTester<E> extends AbstractMultisetTester<E> {
  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  public void testAddUnsupported() {
    try {
      getMultiset().add(e0());
      fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.

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

Line: 38

                @CollectionFeature.Require(absent = SUPPORTS_ADD)
  public void testAddUnsupported() {
    try {
      getMultiset().add(e0());
      fail("Expected UnsupportedOperationException");
    } 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: 44

                  }
  }

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddMeansAddOne() {
    int originalCount = getMultiset().count(e0());
    assertTrue(getMultiset().add(e0()));
    assertEquals(originalCount + 1, getMultiset().count(e0()));
  }

            

Reported by PMD.

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

Line: 45

                }

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddMeansAddOne() {
    int originalCount = getMultiset().count(e0());
    assertTrue(getMultiset().add(e0()));
    assertEquals(originalCount + 1, getMultiset().count(e0()));
  }


            

Reported by PMD.

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

Line: 46

              
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddMeansAddOne() {
    int originalCount = getMultiset().count(e0());
    assertTrue(getMultiset().add(e0()));
    assertEquals(originalCount + 1, getMultiset().count(e0()));
  }

  @CollectionFeature.Require(SUPPORTS_ADD)

            

Reported by PMD.

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

Line: 47

                @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddMeansAddOne() {
    int originalCount = getMultiset().count(e0());
    assertTrue(getMultiset().add(e0()));
    assertEquals(originalCount + 1, getMultiset().count(e0()));
  }

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddOccurrencesZero() {

            

Reported by PMD.

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

Line: 48

                public void testAddMeansAddOne() {
    int originalCount = getMultiset().count(e0());
    assertTrue(getMultiset().add(e0()));
    assertEquals(originalCount + 1, getMultiset().count(e0()));
  }

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddOccurrencesZero() {
    int originalCount = getMultiset().count(e0());

            

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

                  assertEquals(originalCount + 1, getMultiset().count(e0()));
  }

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddOccurrencesZero() {
    int originalCount = getMultiset().count(e0());
    assertEquals("old count", originalCount, getMultiset().add(e0(), 0));
    expectUnchanged();
  }

            

Reported by PMD.

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

Line: 53

              
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddOccurrencesZero() {
    int originalCount = getMultiset().count(e0());
    assertEquals("old count", originalCount, getMultiset().add(e0(), 0));
    expectUnchanged();
  }

  @CollectionFeature.Require(SUPPORTS_ADD)

            

Reported by PMD.

guava-tests/test/com/google/common/collect/HashMultisetTest.java
45 issues
JUnit 4 indicates test suites via annotations, not the suite method.
Design

Line: 44

              @GwtCompatible(emulated = true)
public class HashMultisetTest extends TestCase {

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(

            

Reported by PMD.

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

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

Reported by PMD.

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

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

Reported by PMD.

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

Line: 48

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(hashMultisetGenerator())
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                CollectionFeature.ALLOWS_NULL_VALUES,
                CollectionFeature.SERIALIZABLE,

            

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

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

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

Line: 71

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

The String literal 'foo' appears 7 times in this file; the first occurrence is on line 73
Error

Line: 73

              
  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }


            

Reported by PMD.

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

Line: 73

              
  public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }


            

Reported by PMD.

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

Line: 74

                public void testCreate() {
    Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }

  public void testCreateWithSize() {

            

Reported by PMD.

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

Line: 75

                  Multiset<String> multiset = HashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
  }

  public void testCreateWithSize() {
    Multiset<String> multiset = HashMultiset.create(50);

            

Reported by PMD.

guava-testlib/src/com/google/common/util/concurrent/testing/AbstractListenableFutureTest.java
45 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 43

              @GwtIncompatible
public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {


            

Reported by PMD.

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

Line: 44

              public abstract class AbstractListenableFutureTest extends TestCase {

  protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.

            

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

                protected CountDownLatch latch;
  protected ListenableFuture<Boolean> future;

  @Override
  protected void setUp() throws Exception {

    // Create a latch and a future that waits on the latch.
    latch = new CountDownLatch(1);
    future = createListenableFuture(Boolean.TRUE, null, latch);

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 54

                  future = createListenableFuture(Boolean.TRUE, null, latch);
  }

  @Override
  protected void tearDown() throws Exception {

    // Make sure we have no waiting threads.
    latch.countDown();
  }

            

Reported by PMD.

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

Line: 66

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

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

                    V value, Exception except, CountDownLatch waitOn);

  /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 68

                /** Tests that the {@link Future#get()} method blocks until a value is available. */
  public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                public void testGetBlocksUntilValueAvailable() throws Throwable {

    assertFalse(future.isDone());
    assertFalse(future.isCancelled());

    final CountDownLatch successLatch = new CountDownLatch(1);
    final Throwable[] badness = new Throwable[1];

    // Wait on the future in a separate thread.

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 80

                            @Override
              public void run() {
                try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 82

                              try {
                  assertSame(Boolean.TRUE, future.get());
                  successLatch.countDown();
                } catch (Throwable t) {
                  t.printStackTrace();
                  badness[0] = t;
                }
              }
            })

            

Reported by PMD.

guava-tests/test/com/google/common/graph/NetworkMutationTest.java
45 issues
JUnit tests should include assert() or fail()
Design

Line: 40

                private static final int NODE_POOL_SIZE = 1000; // must be >> NUM_NODES

  @Test
  public void directedNetwork() {
    testNetworkMutation(NetworkBuilder.directed());
  }

  @Test
  public void undirectedNetwork() {

            

Reported by PMD.

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

Line: 45

                }

  @Test
  public void undirectedNetwork() {
    testNetworkMutation(NetworkBuilder.undirected());
  }

  private static void testNetworkMutation(NetworkBuilder<? super Integer, Object> networkBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

            

Reported by PMD.

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

Line: 49

                  testNetworkMutation(NetworkBuilder.undirected());
  }

  private static void testNetworkMutation(NetworkBuilder<? super Integer, Object> networkBuilder) {
    Random gen = new Random(42); // Fixed seed so test results are deterministic.

    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

            

Reported by PMD.

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

Line: 54

              
    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);


            

Reported by PMD.

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

Line: 54

              
    for (int trial = 0; trial < NUM_TRIALS; ++trial) {
      MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);


            

Reported by PMD.

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

Line: 56

                    MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 56

                    MutableNetwork<Integer, Object> network =
          networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));

            

Reported by PMD.

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

Line: 57

                        networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 57

                        networkBuilder.allowsParallelEdges(true).allowsSelfLoops(true).build();

      assertThat(network.nodes()).isEmpty();
      assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }

            

Reported by PMD.

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

Line: 60

                    assertThat(network.edges()).isEmpty();
      AbstractNetworkTest.validateNetwork(network);

      while (network.nodes().size() < NUM_NODES) {
        network.addNode(gen.nextInt(NODE_POOL_SIZE));
      }
      ArrayList<Integer> nodeList = new ArrayList<>(network.nodes());
      for (int i = 0; i < NUM_EDGES; ++i) {
        // Parallel edges are allowed, so this should always succeed.

            

Reported by PMD.