The following issues were found

guava-tests/test/com/google/common/graph/EndpointPairTest.java
140 issues
This class has too many methods, consider refactoring it.
Design

Line: 33

              
/** Tests for {@link EndpointPair} and {@link Graph#edges()}. */
@RunWith(JUnit4.class)
public final class EndpointPairTest {
  private static final Integer N0 = 0;
  private static final Integer N1 = 1;
  private static final Integer N2 = 2;
  private static final Integer N3 = 3;
  private static final Integer N4 = 4;

            

Reported by PMD.

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

Line: 48

                // Test for EndpointPair class

  @Test
  public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");

            

Reported by PMD.

The String literal 'source' appears 6 times in this file; the first occurrence is on line 49
Error

Line: 49

              
  @Test
  public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");

            

Reported by PMD.

The String literal 'target' appears 6 times in this file; the first occurrence is on line 49
Error

Line: 49

              
  @Test
  public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");

            

Reported by PMD.

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

Line: 50

                @Test
  public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");
    assertThat(ordered.nodeV()).isEqualTo("target");

            

Reported by PMD.

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

Line: 50

                @Test
  public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");
    assertThat(ordered.nodeV()).isEqualTo("target");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 51

                public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");
    assertThat(ordered.nodeV()).isEqualTo("target");
    assertThat(ordered.adjacentNode("source")).isEqualTo("target");

            

Reported by PMD.

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

Line: 51

                public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");
    assertThat(ordered.nodeV()).isEqualTo("target");
    assertThat(ordered.adjacentNode("source")).isEqualTo("target");

            

Reported by PMD.

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

Line: 51

                public void testOrderedEndpointPair() {
    EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");
    assertThat(ordered.nodeV()).isEqualTo("target");
    assertThat(ordered.adjacentNode("source")).isEqualTo("target");

            

Reported by PMD.

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

Line: 52

                  EndpointPair<String> ordered = EndpointPair.ordered("source", "target");
    assertThat(ordered.isOrdered()).isTrue();
    assertThat(ordered).containsExactly("source", "target").inOrder();
    assertThat(ordered.source()).isEqualTo("source");
    assertThat(ordered.target()).isEqualTo("target");
    assertThat(ordered.nodeU()).isEqualTo("source");
    assertThat(ordered.nodeV()).isEqualTo("target");
    assertThat(ordered.adjacentNode("source")).isEqualTo("target");
    assertThat(ordered.adjacentNode("target")).isEqualTo("source");

            

Reported by PMD.

android/guava/src/com/google/common/collect/AbstractMapBasedMultimap.java
139 issues
This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT;

            

Reported by PMD.

Avoid really long classes.
Design

Line: 88

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class AbstractMapBasedMultimap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMultimap<K, V> implements Serializable {
  /*
   * Here's an outline of the overall design.
   *
   * The map variable contains the collection of values associated with each

            

Reported by PMD.

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

Line: 89

              @GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class AbstractMapBasedMultimap<K extends @Nullable Object, V extends @Nullable Object>
    extends AbstractMultimap<K, V> implements Serializable {
  /*
   * Here's an outline of the overall design.
   *
   * The map variable contains the collection of values associated with each
   * key. When a key-value pair is added to a multimap that didn't previously

            

Reported by PMD.

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

Line: 196

                    } else {
        throw new AssertionError("New Collection violated the Collection spec");
      }
    } else if (collection.add(value)) {
      totalSize++;
      return true;
    } else {
      return false;
    }

            

Reported by PMD.

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

Line: 230

                  // TODO(lowasser): investigate atomic failure?
    Collection<V> collection = getOrCreateCollection(key);
    Collection<V> oldValues = createCollection();
    oldValues.addAll(collection);

    totalSize -= collection.size();
    collection.clear();

    while (iterator.hasNext()) {

            

Reported by PMD.

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

Line: 232

                  Collection<V> oldValues = createCollection();
    oldValues.addAll(collection);

    totalSize -= collection.size();
    collection.clear();

    while (iterator.hasNext()) {
      if (collection.add(iterator.next())) {
        totalSize++;

            

Reported by PMD.

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

Line: 233

                  oldValues.addAll(collection);

    totalSize -= collection.size();
    collection.clear();

    while (iterator.hasNext()) {
      if (collection.add(iterator.next())) {
        totalSize++;
      }

            

Reported by PMD.

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

Line: 258

                  }

    Collection<V> output = createCollection();
    output.addAll(collection);
    totalSize -= collection.size();
    collection.clear();

    return unmodifiableCollectionSubclass(output);
  }

            

Reported by PMD.

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

Line: 259

              
    Collection<V> output = createCollection();
    output.addAll(collection);
    totalSize -= collection.size();
    collection.clear();

    return unmodifiableCollectionSubclass(output);
  }


            

Reported by PMD.

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

Line: 260

                  Collection<V> output = createCollection();
    output.addAll(collection);
    totalSize -= collection.size();
    collection.clear();

    return unmodifiableCollectionSubclass(output);
  }

  <E extends @Nullable Object> Collection<E> unmodifiableCollectionSubclass(

            

Reported by PMD.

guava-tests/test/com/google/common/graph/ElementOrderTest.java
137 issues
This class has too many methods, consider refactoring it.
Design

Line: 32

              
/** Tests for ordering the elements of graphs. */
@RunWith(JUnit4.class)
public final class ElementOrderTest {
  // Node order tests

  @Test
  public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

            

Reported by PMD.

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

Line: 37

              
  @Test
  public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test

            

Reported by PMD.

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

Line: 37

              
  @Test
  public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test

            

Reported by PMD.

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

Line: 39

                public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

            

Reported by PMD.

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

Line: 39

                public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

            

Reported by PMD.

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

Line: 43

                }

  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());

            

Reported by PMD.

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

Line: 44

              
  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();

            

Reported by PMD.

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

Line: 44

              
  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();

            

Reported by PMD.

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

Line: 48

              
    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();
  }

  // The default ordering is INSERTION unless otherwise specified.
  @Test

            

Reported by PMD.

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

Line: 48

              
    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();
  }

  // The default ordering is INSERTION unless otherwise specified.
  @Test

            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/ElementOrderTest.java
137 issues
This class has too many methods, consider refactoring it.
Design

Line: 32

              
/** Tests for ordering the elements of graphs. */
@RunWith(JUnit4.class)
public final class ElementOrderTest {
  // Node order tests

  @Test
  public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

            

Reported by PMD.

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

Line: 37

              
  @Test
  public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test

            

Reported by PMD.

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

Line: 37

              
  @Test
  public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test

            

Reported by PMD.

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

Line: 39

                public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

            

Reported by PMD.

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

Line: 39

                public void nodeOrder_none() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(unordered()).build();

    assertThat(graph.nodeOrder()).isEqualTo(unordered());
  }

  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

            

Reported by PMD.

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

Line: 43

                }

  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());

            

Reported by PMD.

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

Line: 44

              
  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();

            

Reported by PMD.

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

Line: 44

              
  @Test
  public void nodeOrder_insertion() {
    MutableGraph<Integer> graph = GraphBuilder.directed().nodeOrder(insertion()).build();

    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();

            

Reported by PMD.

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

Line: 48

              
    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();
  }

  // The default ordering is INSERTION unless otherwise specified.
  @Test

            

Reported by PMD.

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

Line: 48

              
    addNodes(graph);

    assertThat(graph.nodeOrder()).isEqualTo(insertion());
    assertThat(graph.nodes()).containsExactly(3, 1, 4).inOrder();
  }

  // The default ordering is INSERTION unless otherwise specified.
  @Test

            

Reported by PMD.

guava-tests/test/com/google/common/io/BaseEncodingTest.java
136 issues
Possible God Class (WMC=58, ATFD=6, TCC=0.000%)
Design

Line: 47

               * @author Louis Wasserman
 */
@GwtCompatible(emulated = true)
public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");

            

Reported by PMD.

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

Line: 47

               * @author Louis Wasserman
 */
@GwtCompatible(emulated = true)
public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");

            

Reported by PMD.

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

Line: 49

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

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }


            

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

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

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }


            

Reported by PMD.

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

Line: 50

              public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {

            

Reported by PMD.

The String literal 'foobar' appears 30 times in this file; the first occurrence is on line 50
Error

Line: 50

              public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {

            

Reported by PMD.

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

Line: 51

              
  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {
    try {

            

Reported by PMD.

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

Line: 52

                public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {
    try {
      base64().withSeparator("=", 3);

            

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

                  testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {
    try {
      base64().withSeparator("=", 3);
      fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }

            

Reported by PMD.

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

Line: 57

              
  public void testSeparatorSameAsPadChar() {
    try {
      base64().withSeparator("=", 3);
      fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }

    try {

            

Reported by PMD.

guava-tests/test/com/google/common/hash/HashTestUtils.java
136 issues
Do not use the short type
Performance

Line: 116

                  PUT_SHORT() {
      @Override
      void performAction(Random random, Iterable<? extends PrimitiveSink> sinks) {
        short value = (short) random.nextInt();
        for (PrimitiveSink sink : sinks) {
          sink.putShort(value);
        }
      }
    },

            

Reported by PMD.

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

Line: 41

               * @author Dimitris Andreou
 * @author Kurt Alfred Kluever
 */
final class HashTestUtils {
  private HashTestUtils() {}

  /** Converts a string, which should contain only ascii-representable characters, to a byte[]. */
  static byte[] ascii(String string) {
    byte[] bytes = new byte[string.length()];

            

Reported by PMD.

Possible God Class (WMC=61, ATFD=17, TCC=0.000%)
Design

Line: 41

               * @author Dimitris Andreou
 * @author Kurt Alfred Kluever
 */
final class HashTestUtils {
  private HashTestUtils() {}

  /** Converts a string, which should contain only ascii-representable characters, to a byte[]. */
  static byte[] ascii(String string) {
    byte[] bytes = new byte[string.length()];

            

Reported by PMD.

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

Line: 198

                      int limit = pos + random.nextInt(value.length - pos + 1);
        for (PrimitiveSink sink : sinks) {
          ByteBuffer buffer = ByteBuffer.wrap(value);
          buffer.position(pos);
          buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }

            

Reported by PMD.

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

Line: 199

                      for (PrimitiveSink sink : sinks) {
          ByteBuffer buffer = ByteBuffer.wrap(value);
          buffer.position(pos);
          buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }
      }

            

Reported by PMD.

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

Line: 201

                        buffer.position(pos);
          buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }
      }
    },
    PUT_STRING() {

            

Reported by PMD.

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

Line: 202

                        buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }
      }
    },
    PUT_STRING() {
      @Override

            

Reported by PMD.

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

Line: 296

                      // flip input bit for key2
        int key2 = key1 ^ (1 << i);
        // get hashes
        int hash1 = function.hashInt(key1).asInt();
        int hash2 = function.hashInt(key2).asInt();
        // test whether the hash values have same output bits
        same |= ~(hash1 ^ hash2);
        // test whether the hash values have different output bits
        diff |= (hash1 ^ hash2);

            

Reported by PMD.

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

Line: 297

                      int key2 = key1 ^ (1 << i);
        // get hashes
        int hash1 = function.hashInt(key1).asInt();
        int hash2 = function.hashInt(key2).asInt();
        // test whether the hash values have same output bits
        same |= ~(hash1 ^ hash2);
        // test whether the hash values have different output bits
        diff |= (hash1 ^ hash2);


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 335

                  int keyBits = 32;
    int hashBits = function.bits();
    for (int i = 0; i < keyBits; i++) {
      int[] same = new int[hashBits];
      int[] diff = new int[hashBits];
      // go through trials to compute probability
      for (int j = 0; j < trials; j++) {
        int key1 = rand.nextInt();
        // flip input bit for key2

            

Reported by PMD.

android/guava-tests/test/com/google/common/io/BaseEncodingTest.java
136 issues
Possible God Class (WMC=58, ATFD=6, TCC=0.000%)
Design

Line: 47

               * @author Louis Wasserman
 */
@GwtCompatible(emulated = true)
public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");

            

Reported by PMD.

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

Line: 47

               * @author Louis Wasserman
 */
@GwtCompatible(emulated = true)
public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");

            

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

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

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }


            

Reported by PMD.

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

Line: 49

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

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }


            

Reported by PMD.

The String literal 'foobar' appears 30 times in this file; the first occurrence is on line 50
Error

Line: 50

              public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {

            

Reported by PMD.

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

Line: 50

              public class BaseEncodingTest extends TestCase {

  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {

            

Reported by PMD.

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

Line: 51

              
  public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {
    try {

            

Reported by PMD.

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

Line: 52

                public void testSeparatorsExplicitly() {
    testEncodes(base64().withSeparator("\n", 3), "foobar", "Zm9\nvYm\nFy");
    testEncodes(base64().withSeparator("$", 4), "foobar", "Zm9v$YmFy");
    testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {
    try {
      base64().withSeparator("=", 3);

            

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

                  testEncodes(base32().withSeparator("*", 4), "foobar", "MZXW*6YTB*OI==*====");
  }

  public void testSeparatorSameAsPadChar() {
    try {
      base64().withSeparator("=", 3);
      fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }

            

Reported by PMD.

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

Line: 57

              
  public void testSeparatorSameAsPadChar() {
    try {
      base64().withSeparator("=", 3);
      fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }

    try {

            

Reported by PMD.

android/guava-tests/test/com/google/common/hash/HashTestUtils.java
136 issues
Do not use the short type
Performance

Line: 116

                  PUT_SHORT() {
      @Override
      void performAction(Random random, Iterable<? extends PrimitiveSink> sinks) {
        short value = (short) random.nextInt();
        for (PrimitiveSink sink : sinks) {
          sink.putShort(value);
        }
      }
    },

            

Reported by PMD.

Possible God Class (WMC=61, ATFD=17, TCC=0.000%)
Design

Line: 41

               * @author Dimitris Andreou
 * @author Kurt Alfred Kluever
 */
final class HashTestUtils {
  private HashTestUtils() {}

  /** Converts a string, which should contain only ascii-representable characters, to a byte[]. */
  static byte[] ascii(String string) {
    byte[] bytes = new byte[string.length()];

            

Reported by PMD.

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

Line: 41

               * @author Dimitris Andreou
 * @author Kurt Alfred Kluever
 */
final class HashTestUtils {
  private HashTestUtils() {}

  /** Converts a string, which should contain only ascii-representable characters, to a byte[]. */
  static byte[] ascii(String string) {
    byte[] bytes = new byte[string.length()];

            

Reported by PMD.

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

Line: 198

                      int limit = pos + random.nextInt(value.length - pos + 1);
        for (PrimitiveSink sink : sinks) {
          ByteBuffer buffer = ByteBuffer.wrap(value);
          buffer.position(pos);
          buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }

            

Reported by PMD.

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

Line: 199

                      for (PrimitiveSink sink : sinks) {
          ByteBuffer buffer = ByteBuffer.wrap(value);
          buffer.position(pos);
          buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }
      }

            

Reported by PMD.

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

Line: 201

                        buffer.position(pos);
          buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }
      }
    },
    PUT_STRING() {

            

Reported by PMD.

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

Line: 202

                        buffer.limit(limit);
          sink.putBytes(buffer);
          assertEquals(limit, buffer.limit());
          assertEquals(limit, buffer.position());
        }
      }
    },
    PUT_STRING() {
      @Override

            

Reported by PMD.

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

Line: 296

                      // flip input bit for key2
        int key2 = key1 ^ (1 << i);
        // get hashes
        int hash1 = function.hashInt(key1).asInt();
        int hash2 = function.hashInt(key2).asInt();
        // test whether the hash values have same output bits
        same |= ~(hash1 ^ hash2);
        // test whether the hash values have different output bits
        diff |= (hash1 ^ hash2);

            

Reported by PMD.

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

Line: 297

                      int key2 = key1 ^ (1 << i);
        // get hashes
        int hash1 = function.hashInt(key1).asInt();
        int hash2 = function.hashInt(key2).asInt();
        // test whether the hash values have same output bits
        same |= ~(hash1 ^ hash2);
        // test whether the hash values have different output bits
        diff |= (hash1 ^ hash2);


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 335

                  int keyBits = 32;
    int hashBits = function.bits();
    for (int i = 0; i < keyBits; i++) {
      int[] same = new int[hashBits];
      int[] diff = new int[hashBits];
      // go through trials to compute probability
      for (int j = 0; j < trials; j++) {
        int key1 = rand.nextInt();
        // flip input bit for key2

            

Reported by PMD.

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

Line: 42

               * @author Mike Bostock
 */
@GwtCompatible(emulated = true)
public class HashBiMapTest extends TestCase {

  public static final class HashBiMapGenerator extends TestStringBiMapGenerator {
    @Override
    protected BiMap<String, String> create(Entry<String, String>[] entries) {
      BiMap<String, String> result = HashBiMap.create();

            

Reported by PMD.

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

Line: 55

                  }
  }

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

            

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

                  return suite;
  }

  public void testMapConstructor() {
    /* Test with non-empty Map. */
    Map<String, String> map =
        ImmutableMap.of(
            "canada", "dollar",
            "chile", "peso",

            

Reported by PMD.

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

Line: 75

                  return suite;
  }

  public void testMapConstructor() {
    /* Test with non-empty Map. */
    Map<String, String> map =
        ImmutableMap.of(
            "canada", "dollar",
            "chile", "peso",

            

Reported by PMD.

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

Line: 83

                          "chile", "peso",
            "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 83

                          "chile", "peso",
            "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;


            

Reported by PMD.

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

Line: 84

                          "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;

  public void testBashIt() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 84

                          "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;

  public void testBashIt() throws Exception {

            

Reported by PMD.

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

Line: 84

                          "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;

  public void testBashIt() throws Exception {

            

Reported by PMD.

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

Line: 89

              
  private static final int N = 1000;

  public void testBashIt() throws Exception {
    BiMap<Integer, Integer> bimap = HashBiMap.create(N);
    BiMap<Integer, Integer> inverse = bimap.inverse();

    for (int i = 0; i < N; i++) {
      assertNull(bimap.put(2 * i, 2 * i + 1));

            

Reported by PMD.

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

Line: 42

               * @author Mike Bostock
 */
@GwtCompatible(emulated = true)
public class HashBiMapTest extends TestCase {

  public static final class HashBiMapGenerator extends TestStringBiMapGenerator {
    @Override
    protected BiMap<String, String> create(Entry<String, String>[] entries) {
      BiMap<String, String> result = HashBiMap.create();

            

Reported by PMD.

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

Line: 55

                  }
  }

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

            

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

                  return suite;
  }

  public void testMapConstructor() {
    /* Test with non-empty Map. */
    Map<String, String> map =
        ImmutableMap.of(
            "canada", "dollar",
            "chile", "peso",

            

Reported by PMD.

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

Line: 75

                  return suite;
  }

  public void testMapConstructor() {
    /* Test with non-empty Map. */
    Map<String, String> map =
        ImmutableMap.of(
            "canada", "dollar",
            "chile", "peso",

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 83

                          "chile", "peso",
            "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;


            

Reported by PMD.

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

Line: 83

                          "chile", "peso",
            "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;


            

Reported by PMD.

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

Line: 84

                          "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;

  public void testBashIt() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 84

                          "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;

  public void testBashIt() throws Exception {

            

Reported by PMD.

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

Line: 84

                          "switzerland", "franc");
    HashBiMap<String, String> bimap = HashBiMap.create(map);
    assertEquals("dollar", bimap.get("canada"));
    assertEquals("canada", bimap.inverse().get("dollar"));
  }

  private static final int N = 1000;

  public void testBashIt() throws Exception {

            

Reported by PMD.

The method 'testBashIt()' has an NPath complexity of 256, current threshold is 200
Design

Line: 89

              
  private static final int N = 1000;

  public void testBashIt() throws Exception {
    BiMap<Integer, Integer> bimap = HashBiMap.create(N);
    BiMap<Integer, Integer> inverse = bimap.inverse();

    for (int i = 0; i < N; i++) {
      assertNull(bimap.put(2 * i, 2 * i + 1));

            

Reported by PMD.