The following issues were found

android/guava/src/com/google/common/graph/Graphs.java
73 issues
Possible God Class (WMC=71, ATFD=13, TCC=0.000%)
Design

Line: 47

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class Graphs {

  private Graphs() {}

  // Graph query methods


            

Reported by PMD.

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

Line: 47

               */
@Beta
@ElementTypesAreNonnullByDefault
public final class Graphs {

  private Graphs() {}

  // Graph query methods


            

Reported by PMD.

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

Line: 61

                 * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
   */
  public static <N> boolean hasCycle(Graph<N> graph) {
    int numEdges = graph.edges().size();
    if (numEdges == 0) {
      return false; // An edge-free graph is acyclic by definition.
    }
    if (!graph.isDirected() && numEdges >= graph.nodes().size()) {
      return true; // Optimization for the undirected case: at least one cycle must exist.

            

Reported by PMD.

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

Line: 65

                  if (numEdges == 0) {
      return false; // An edge-free graph is acyclic by definition.
    }
    if (!graph.isDirected() && numEdges >= graph.nodes().size()) {
      return true; // Optimization for the undirected case: at least one cycle must exist.
    }

    Map<Object, NodeVisitState> visitedNodes =
        Maps.newHashMapWithExpectedSize(graph.nodes().size());

            

Reported by PMD.

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

Line: 70

                  }

    Map<Object, NodeVisitState> visitedNodes =
        Maps.newHashMapWithExpectedSize(graph.nodes().size());
    for (N node : graph.nodes()) {
      if (subgraphHasCycle(graph, visitedNodes, node, null)) {
        return true;
      }
    }

            

Reported by PMD.

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

Line: 91

                  // However, in an undirected graph, any parallel edge induces a cycle in the graph.
    if (!network.isDirected()
        && network.allowsParallelEdges()
        && network.edges().size() > network.asGraph().edges().size()) {
      return true;
    }
    return hasCycle(network.asGraph());
  }


            

Reported by PMD.

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

Line: 91

                  // However, in an undirected graph, any parallel edge induces a cycle in the graph.
    if (!network.isDirected()
        && network.allowsParallelEdges()
        && network.edges().size() > network.asGraph().edges().size()) {
      return true;
    }
    return hasCycle(network.asGraph());
  }


            

Reported by PMD.

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

Line: 91

                  // However, in an undirected graph, any parallel edge induces a cycle in the graph.
    if (!network.isDirected()
        && network.allowsParallelEdges()
        && network.edges().size() > network.asGraph().edges().size()) {
      return true;
    }
    return hasCycle(network.asGraph());
  }


            

Reported by PMD.

Avoid unnecessary if..then..else statements when returning booleans
Design

Line: 134

                 */
  private static boolean canTraverseWithoutReusingEdge(
      Graph<?> graph, Object nextNode, @CheckForNull Object previousNode) {
    if (graph.isDirected() || !Objects.equal(previousNode, nextNode)) {
      return true;
    }
    // This falls into the undirected A->B->A case. The Graph interface does not support parallel
    // edges, so this traversal would require reusing the undirected AB edge.
    return false;

            

Reported by PMD.

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

Line: 153

                 */
  // TODO(b/31438252): Consider potential optimizations for this algorithm.
  public static <N> Graph<N> transitiveClosure(Graph<N> graph) {
    MutableGraph<N> transitiveClosure = GraphBuilder.from(graph).allowsSelfLoops(true).build();
    // Every node is, at a minimum, reachable from itself. Since the resulting transitive closure
    // will have no isolated nodes, we can skip adding nodes explicitly and let putEdge() do it.

    if (graph.isDirected()) {
      // Note: works for both directed and undirected graphs, but we only use in the directed case.

            

Reported by PMD.

android/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java
73 issues
This class has too many methods, consider refactoring it.
Design

Line: 27

              import junit.framework.TestCase;

/** Tests for {@link Murmur3_32HashFunction}. */
public class Murmur3Hash32Test extends TestCase {
  public void testKnownIntegerInputs() {
    assertHash(593689054, murmur3_32().hashInt(0));
    assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));

            

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

              
/** Tests for {@link Murmur3_32HashFunction}. */
public class Murmur3Hash32Test extends TestCase {
  public void testKnownIntegerInputs() {
    assertHash(593689054, murmur3_32().hashInt(0));
    assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));
    assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));

            

Reported by PMD.

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

Line: 28

              
/** Tests for {@link Murmur3_32HashFunction}. */
public class Murmur3Hash32Test extends TestCase {
  public void testKnownIntegerInputs() {
    assertHash(593689054, murmur3_32().hashInt(0));
    assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));
    assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));

            

Reported by PMD.

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

Line: 29

              /** Tests for {@link Murmur3_32HashFunction}. */
public class Murmur3Hash32Test extends TestCase {
  public void testKnownIntegerInputs() {
    assertHash(593689054, murmur3_32().hashInt(0));
    assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));
    assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));
  }

            

Reported by PMD.

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

Line: 30

              public class Murmur3Hash32Test extends TestCase {
  public void testKnownIntegerInputs() {
    assertHash(593689054, murmur3_32().hashInt(0));
    assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));
    assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));
  }


            

Reported by PMD.

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

Line: 31

                public void testKnownIntegerInputs() {
    assertHash(593689054, murmur3_32().hashInt(0));
    assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));
    assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));
  }

  public void testKnownLongInputs() {

            

Reported by PMD.

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

Line: 32

                  assertHash(593689054, murmur3_32().hashInt(0));
    assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));
    assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));
  }

  public void testKnownLongInputs() {
    assertHash(1669671676, murmur3_32().hashLong(0L));

            

Reported by PMD.

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

Line: 33

                  assertHash(-189366624, murmur3_32().hashInt(-42));
    assertHash(-1134849565, murmur3_32().hashInt(42));
    assertHash(-1718298732, murmur3_32().hashInt(Integer.MIN_VALUE));
    assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));
  }

  public void testKnownLongInputs() {
    assertHash(1669671676, murmur3_32().hashLong(0L));
    assertHash(-846261623, murmur3_32().hashLong(-42L));

            

Reported by PMD.

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

Line: 36

                  assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));
  }

  public void testKnownLongInputs() {
    assertHash(1669671676, murmur3_32().hashLong(0L));
    assertHash(-846261623, murmur3_32().hashLong(-42L));
    assertHash(1871679806, murmur3_32().hashLong(42L));
    assertHash(1366273829, murmur3_32().hashLong(Long.MIN_VALUE));
    assertHash(-2106506049, murmur3_32().hashLong(Long.MAX_VALUE));

            

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

                  assertHash(-1653689534, murmur3_32().hashInt(Integer.MAX_VALUE));
  }

  public void testKnownLongInputs() {
    assertHash(1669671676, murmur3_32().hashLong(0L));
    assertHash(-846261623, murmur3_32().hashLong(-42L));
    assertHash(1871679806, murmur3_32().hashLong(42L));
    assertHash(1366273829, murmur3_32().hashLong(Long.MIN_VALUE));
    assertHash(-2106506049, murmur3_32().hashLong(Long.MAX_VALUE));

            

Reported by PMD.

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

Line: 68

                    BiMap<Country, String> result = EnumHashBiMap.create(Country.class);
      for (Object o : entries) {
        Entry<Country, String> entry = (Entry<Country, String>) o;
        result.put(entry.getKey(), entry.getValue());
      }
      return result;
    }

    @Override

            

Reported by PMD.

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

Line: 68

                    BiMap<Country, String> result = EnumHashBiMap.create(Country.class);
      for (Object o : entries) {
        Entry<Country, String> entry = (Entry<Country, String>) o;
        result.put(entry.getKey(), entry.getValue());
      }
      return result;
    }

    @Override

            

Reported by PMD.

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

Line: 105

                  }
  }

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        BiMapTestSuiteBuilder.using(new EnumHashBiMapGenerator())
            .named("EnumHashBiMap")

            

Reported by PMD.

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

Line: 123

                  return suite;
  }

  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");

            

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

                  return suite;
  }

  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 125

              
  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));

            

Reported by PMD.

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

Line: 125

              
  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 126

                public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));
  }

            

Reported by PMD.

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

Line: 126

                public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 127

                  EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));
  }


            

Reported by PMD.

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

Line: 68

                    BiMap<Country, String> result = EnumHashBiMap.create(Country.class);
      for (Object o : entries) {
        Entry<Country, String> entry = (Entry<Country, String>) o;
        result.put(entry.getKey(), entry.getValue());
      }
      return result;
    }

    @Override

            

Reported by PMD.

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

Line: 68

                    BiMap<Country, String> result = EnumHashBiMap.create(Country.class);
      for (Object o : entries) {
        Entry<Country, String> entry = (Entry<Country, String>) o;
        result.put(entry.getKey(), entry.getValue());
      }
      return result;
    }

    @Override

            

Reported by PMD.

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

Line: 105

                  }
  }

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        BiMapTestSuiteBuilder.using(new EnumHashBiMapGenerator())
            .named("EnumHashBiMap")

            

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

                  return suite;
  }

  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");

            

Reported by PMD.

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

Line: 123

                  return suite;
  }

  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 125

              
  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));

            

Reported by PMD.

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

Line: 125

              
  public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 126

                public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));
  }

            

Reported by PMD.

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

Line: 126

                public void testCreate() {
    EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 127

                  EnumHashBiMap<Currency, String> bimap = EnumHashBiMap.create(Currency.class);
    assertTrue(bimap.isEmpty());
    assertEquals("{}", bimap.toString());
    assertEquals(HashBiMap.create(), bimap);
    bimap.put(Currency.DOLLAR, "dollar");
    assertEquals("dollar", bimap.get(Currency.DOLLAR));
    assertEquals(Currency.DOLLAR, bimap.inverse().get("dollar"));
  }


            

Reported by PMD.

guava-tests/test/com/google/common/io/CharSourceTest.java
71 issues
The class 'CharSourceTest' has a Modified Cyclomatic Complexity of 2 (Highest = 12).
Design

Line: 46

               *
 * @author Colin Decker
 */
public class CharSourceTest extends IoTestCase {

  @AndroidIncompatible // Android doesn't understand suites whose tests lack default constructors.
  public static TestSuite suite() {
    TestSuite suite = new TestSuite();
    for (boolean asByteSource : new boolean[] {false, true}) {

            

Reported by PMD.

The class 'CharSourceTest' has a Standard Cyclomatic Complexity of 2 (Highest = 12).
Design

Line: 46

               *
 * @author Colin Decker
 */
public class CharSourceTest extends IoTestCase {

  @AndroidIncompatible // Android doesn't understand suites whose tests lack default constructors.
  public static TestSuite suite() {
    TestSuite suite = new TestSuite();
    for (boolean asByteSource : new boolean[] {false, true}) {

            

Reported by PMD.

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

Line: 46

               *
 * @author Colin Decker
 */
public class CharSourceTest extends IoTestCase {

  @AndroidIncompatible // Android doesn't understand suites whose tests lack default constructors.
  public static TestSuite suite() {
    TestSuite suite = new TestSuite();
    for (boolean asByteSource : new boolean[] {false, true}) {

            

Reported by PMD.

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

Line: 68

                private static final String STRING = ASCII + I18N;
  private static final String LINES = "foo\nbar\r\nbaz\rsomething";
  private static final ImmutableList<String> SPLIT_LINES =
      ImmutableList.of("foo", "bar", "baz", "something");

  private TestCharSource source;

  @Override
  public void setUp() {

            

Reported by PMD.

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

Line: 70

                private static final ImmutableList<String> SPLIT_LINES =
      ImmutableList.of("foo", "bar", "baz", "something");

  private TestCharSource source;

  @Override
  public void setUp() {
    source = new TestCharSource(STRING);
  }

            

Reported by PMD.

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

Line: 72

              
  private TestCharSource source;

  @Override
  public void setUp() {
    source = new TestCharSource(STRING);
  }

  public void testOpenBufferedStream() throws IOException {

            

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

                  source = new TestCharSource(STRING);
  }

  public void testOpenBufferedStream() throws IOException {
    BufferedReader reader = source.openBufferedStream();
    assertTrue(source.wasStreamOpened());
    assertFalse(source.wasStreamClosed());

    StringWriter writer = new StringWriter();

            

Reported by PMD.

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

Line: 77

                  source = new TestCharSource(STRING);
  }

  public void testOpenBufferedStream() throws IOException {
    BufferedReader reader = source.openBufferedStream();
    assertTrue(source.wasStreamOpened());
    assertFalse(source.wasStreamClosed());

    StringWriter writer = new StringWriter();

            

Reported by PMD.

Ensure that resources like this BufferedReader object are closed after use
Error

Line: 78

                }

  public void testOpenBufferedStream() throws IOException {
    BufferedReader reader = source.openBufferedStream();
    assertTrue(source.wasStreamOpened());
    assertFalse(source.wasStreamClosed());

    StringWriter writer = new StringWriter();
    char[] buf = new char[64];

            

Reported by PMD.

Avoid assignments in operands
Error

Line: 85

                  StringWriter writer = new StringWriter();
    char[] buf = new char[64];
    int read;
    while ((read = reader.read(buf)) != -1) {
      writer.write(buf, 0, read);
    }
    reader.close();
    writer.close();


            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/AbstractIteratorTest.java
71 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 36

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

  public void testDefaultBehaviorOfNextAndHasNext() {

    // This sample AbstractIterator returns 0 on the first call, 1 on the
    // second, then signals that it's reached the end of the data
    Iterator<Integer> iter =
        new AbstractIterator<Integer>() {

            

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

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

  public void testDefaultBehaviorOfNextAndHasNext() {

    // This sample AbstractIterator returns 0 on the first call, 1 on the
    // second, then signals that it's reached the end of the data
    Iterator<Integer> iter =
        new AbstractIterator<Integer>() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

                        }
        };

    assertTrue(iter.hasNext());
    assertEquals(0, (int) iter.next());

    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

                      };

    assertTrue(iter.hasNext());
    assertEquals(0, (int) iter.next());

    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

                  assertEquals(0, (int) iter.next());

    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 65

              
    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 66

                  // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 67

                  assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again
    assertFalse(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                  assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again
    assertFalse(iter.hasNext());

    try {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 72

                  assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again
    assertFalse(iter.hasNext());

    try {
      iter.next();
      fail("no exception thrown");
    } catch (NoSuchElementException expected) {

            

Reported by PMD.

guava-tests/test/com/google/common/util/concurrent/GeneratedMonitorTest.java
71 issues
The class 'GeneratedMonitorTest' has a Modified Cyclomatic Complexity of 3 (Highest = 16).
Design

Line: 50

               * @author Justin T. Sampson
 */

public class GeneratedMonitorTest extends TestCase {

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

    Method[] methods = Monitor.class.getMethods();

            

Reported by PMD.

This class name ends with Test but contains no test cases
Error

Line: 50

               * @author Justin T. Sampson
 */

public class GeneratedMonitorTest extends TestCase {

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

    Method[] methods = Monitor.class.getMethods();

            

Reported by PMD.

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

Line: 50

               * @author Justin T. Sampson
 */

public class GeneratedMonitorTest extends TestCase {

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

    Method[] methods = Monitor.class.getMethods();

            

Reported by PMD.

The class 'GeneratedMonitorTest' has a total cyclomatic complexity of 98 (highest 17).
Design

Line: 50

               * @author Justin T. Sampson
 */

public class GeneratedMonitorTest extends TestCase {

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

    Method[] methods = Monitor.class.getMethods();

            

Reported by PMD.

The class 'GeneratedMonitorTest' has a Standard Cyclomatic Complexity of 3 (Highest = 16).
Design

Line: 50

               * @author Justin T. Sampson
 */

public class GeneratedMonitorTest extends TestCase {

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

    Method[] methods = Monitor.class.getMethods();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

                    }
    }

    assertEquals(980, suite.testCount());

    return suite;
  }

  /** A typical timeout value we'll use in the tests. */

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 99

              
    @Override
    public String toString() {
      return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
    }
  }

  /** Timeout values to combine with each {@link Scenario}. */
  private enum Timeout {

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 159

              
    @Override
    public String toString() {
      return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
    }
  }

  /** Identifies all enterXxx and tryEnterXxx methods. */
  private static boolean isAnyEnter(Method method) {

            

Reported by PMD.

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

Line: 165

              
  /** Identifies all enterXxx and tryEnterXxx methods. */
  private static boolean isAnyEnter(Method method) {
    return method.getName().startsWith("enter") || method.getName().startsWith("tryEnter");
  }

  /** Identifies just tryEnterXxx methods (a subset of {@link #isAnyEnter}), which never block. */
  private static boolean isTryEnter(Method method) {
    return method.getName().startsWith("tryEnter");

            

Reported by PMD.

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

Line: 165

              
  /** Identifies all enterXxx and tryEnterXxx methods. */
  private static boolean isAnyEnter(Method method) {
    return method.getName().startsWith("enter") || method.getName().startsWith("tryEnter");
  }

  /** Identifies just tryEnterXxx methods (a subset of {@link #isAnyEnter}), which never block. */
  private static boolean isTryEnter(Method method) {
    return method.getName().startsWith("tryEnter");

            

Reported by PMD.

guava-tests/test/com/google/common/collect/AbstractIteratorTest.java
71 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 36

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

  public void testDefaultBehaviorOfNextAndHasNext() {

    // This sample AbstractIterator returns 0 on the first call, 1 on the
    // second, then signals that it's reached the end of the data
    Iterator<Integer> iter =
        new AbstractIterator<Integer>() {

            

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

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

  public void testDefaultBehaviorOfNextAndHasNext() {

    // This sample AbstractIterator returns 0 on the first call, 1 on the
    // second, then signals that it's reached the end of the data
    Iterator<Integer> iter =
        new AbstractIterator<Integer>() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

                        }
        };

    assertTrue(iter.hasNext());
    assertEquals(0, (int) iter.next());

    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

                      };

    assertTrue(iter.hasNext());
    assertEquals(0, (int) iter.next());

    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 64

                  assertEquals(0, (int) iter.next());

    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 65

              
    // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 66

                  // verify idempotence of hasNext()
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 67

                  assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again
    assertFalse(iter.hasNext());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                  assertTrue(iter.hasNext());
    assertEquals(1, (int) iter.next());

    assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again
    assertFalse(iter.hasNext());

    try {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 72

                  assertFalse(iter.hasNext());

    // Make sure computeNext() doesn't get invoked again
    assertFalse(iter.hasNext());

    try {
      iter.next();
      fail("no exception thrown");
    } catch (NoSuchElementException expected) {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/SetOperationsTest.java
70 issues
The class 'SetOperationsTest' has a Standard Cyclomatic Complexity of 20 (Highest = 19).
Design

Line: 40

               * @author Kevin Bourrillion
 */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(

            

Reported by PMD.

The class 'SetOperationsTest' has a Modified Cyclomatic Complexity of 20 (Highest = 19).
Design

Line: 40

               * @author Kevin Bourrillion
 */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(

            

Reported by PMD.

This class name ends with Test but contains no test cases
Error

Line: 40

               * @author Kevin Bourrillion
 */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(

            

Reported by PMD.

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

Line: 41

               */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(

            

Reported by PMD.

The method 'suite' has a Standard Cyclomatic Complexity of 19.
Design

Line: 42

              @GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(
                new TestStringSetGenerator() {

            

Reported by PMD.

Avoid really long methods.
Design

Line: 42

              @GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(
                new TestStringSetGenerator() {

            

Reported by PMD.

The method 'suite' has a Modified Cyclomatic Complexity of 19.
Design

Line: 42

              @GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(
                new TestStringSetGenerator() {

            

Reported by PMD.

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

Line: 256

                                protected Set<String> create(String[] elements) {
                    Set<String> set = Sets.newHashSet(elements);
                    Set<String> other = Sets.newHashSet("wz", "xq");
                    set.addAll(other);
                    other.add("pq");
                    return Sets.difference(set, other);
                  }
                })
            .named("set - set")

            

Reported by PMD.

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

Line: 257

                                  Set<String> set = Sets.newHashSet(elements);
                    Set<String> other = Sets.newHashSet("wz", "xq");
                    set.addAll(other);
                    other.add("pq");
                    return Sets.difference(set, other);
                  }
                })
            .named("set - set")
            .withFeatures(

            

Reported by PMD.

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

Line: 299

                }

  public static class MoreTests extends TestCase {
    Set<String> friends;
    Set<String> enemies;

    @Override
    public void setUp() {
      friends = Sets.newHashSet("Tom", "Joe", "Dave");

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/SetOperationsTest.java
70 issues
The class 'SetOperationsTest' has a Standard Cyclomatic Complexity of 20 (Highest = 19).
Design

Line: 40

               * @author Kevin Bourrillion
 */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(

            

Reported by PMD.

This class name ends with Test but contains no test cases
Error

Line: 40

               * @author Kevin Bourrillion
 */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(

            

Reported by PMD.

The class 'SetOperationsTest' has a Modified Cyclomatic Complexity of 20 (Highest = 19).
Design

Line: 40

               * @author Kevin Bourrillion
 */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(

            

Reported by PMD.

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

Line: 41

               */
@GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(

            

Reported by PMD.

Avoid really long methods.
Design

Line: 42

              @GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(
                new TestStringSetGenerator() {

            

Reported by PMD.

The method 'suite' has a Modified Cyclomatic Complexity of 19.
Design

Line: 42

              @GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(
                new TestStringSetGenerator() {

            

Reported by PMD.

The method 'suite' has a Standard Cyclomatic Complexity of 19.
Design

Line: 42

              @GwtCompatible(emulated = true)
public class SetOperationsTest extends TestCase {
  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();

    suite.addTest(
        SetTestSuiteBuilder.using(
                new TestStringSetGenerator() {

            

Reported by PMD.

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

Line: 256

                                protected Set<String> create(String[] elements) {
                    Set<String> set = Sets.newHashSet(elements);
                    Set<String> other = Sets.newHashSet("wz", "xq");
                    set.addAll(other);
                    other.add("pq");
                    return Sets.difference(set, other);
                  }
                })
            .named("set - set")

            

Reported by PMD.

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

Line: 257

                                  Set<String> set = Sets.newHashSet(elements);
                    Set<String> other = Sets.newHashSet("wz", "xq");
                    set.addAll(other);
                    other.add("pq");
                    return Sets.difference(set, other);
                  }
                })
            .named("set - set")
            .withFeatures(

            

Reported by PMD.

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

Line: 299

                }

  public static class MoreTests extends TestCase {
    Set<String> friends;
    Set<String> enemies;

    @Override
    public void setUp() {
      friends = Sets.newHashSet("Tom", "Joe", "Dave");

            

Reported by PMD.