The following issues were found

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

Line: 26

              
/** @author Gregory Kick */
@GwtCompatible
public class RegularImmutableTableTest extends AbstractImmutableTableTest {
  private static final ImmutableSet<Cell<Character, Integer, String>> CELLS =
      ImmutableSet.of(
          Tables.immutableCell('a', 1, "foo"),
          Tables.immutableCell('b', 1, "bar"),
          Tables.immutableCell('a', 2, "baz"));

            

Reported by PMD.

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

Line: 29

              public class RegularImmutableTableTest extends AbstractImmutableTableTest {
  private static final ImmutableSet<Cell<Character, Integer, String>> CELLS =
      ImmutableSet.of(
          Tables.immutableCell('a', 1, "foo"),
          Tables.immutableCell('b', 1, "bar"),
          Tables.immutableCell('a', 2, "baz"));

  private static final ImmutableSet<Character> ROW_SPACE = ImmutableSet.of('a', 'b');


            

Reported by PMD.

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

Line: 30

                private static final ImmutableSet<Cell<Character, Integer, String>> CELLS =
      ImmutableSet.of(
          Tables.immutableCell('a', 1, "foo"),
          Tables.immutableCell('b', 1, "bar"),
          Tables.immutableCell('a', 2, "baz"));

  private static final ImmutableSet<Character> ROW_SPACE = ImmutableSet.of('a', 'b');

  private static final ImmutableSet<Integer> COLUMN_SPACE = ImmutableSet.of(1, 2);

            

Reported by PMD.

The String literal 'baz' appears 8 times in this file; the first occurrence is on line 31
Error

Line: 31

                    ImmutableSet.of(
          Tables.immutableCell('a', 1, "foo"),
          Tables.immutableCell('b', 1, "bar"),
          Tables.immutableCell('a', 2, "baz"));

  private static final ImmutableSet<Character> ROW_SPACE = ImmutableSet.of('a', 'b');

  private static final ImmutableSet<Integer> COLUMN_SPACE = ImmutableSet.of(1, 2);


            

Reported by PMD.

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

Line: 48

                  return ImmutableList.<ImmutableTable<Character, Integer, String>>of(SPARSE, DENSE);
  }

  public void testCellSet() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {
      assertEquals(CELLS, testInstance.cellSet());
    }
  }


            

Reported by PMD.

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

Line: 54

                  }
  }

  public void testValues() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {
      assertThat(testInstance.values()).containsExactly("foo", "bar", "baz").inOrder();
    }
  }


            

Reported by PMD.

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

Line: 56

              
  public void testValues() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {
      assertThat(testInstance.values()).containsExactly("foo", "bar", "baz").inOrder();
    }
  }

  public void testSize() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {

            

Reported by PMD.

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

Line: 56

              
  public void testValues() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {
      assertThat(testInstance.values()).containsExactly("foo", "bar", "baz").inOrder();
    }
  }

  public void testSize() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {

            

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

                  }
  }

  public void testSize() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {
      assertEquals(3, testInstance.size());
    }
  }


            

Reported by PMD.

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

Line: 66

                  }
  }

  public void testContainsValue() {
    for (ImmutableTable<Character, Integer, String> testInstance : getTestInstances()) {
      assertTrue(testInstance.containsValue("foo"));
      assertTrue(testInstance.containsValue("bar"));
      assertTrue(testInstance.containsValue("baz"));
      assertFalse(testInstance.containsValue("blah"));

            

Reported by PMD.

guava-tests/test/com/google/common/net/PercentEscaperTest.java
31 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: 38

              public class PercentEscaperTest extends TestCase {

  /** Tests that the simple escaper treats 0-9, a-z and A-Z as safe */
  public void testSimpleEscaper() {
    UnicodeEscaper e = new PercentEscaper("", false);
    for (char c = 0; c < 128; c++) {
      if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
        assertUnescaped(e, c);
      } else {

            

Reported by PMD.

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

Line: 38

              public class PercentEscaperTest extends TestCase {

  /** Tests that the simple escaper treats 0-9, a-z and A-Z as safe */
  public void testSimpleEscaper() {
    UnicodeEscaper e = new PercentEscaper("", false);
    for (char c = 0; c < 128; c++) {
      if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
        assertUnescaped(e, c);
      } else {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 59

                  assertUnicodeEscaping(e, "%F4%8F%BF%BF", '\uDBFF', '\uDFFF');

    // simple string tests
    assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

              
    // simple string tests
    assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }

  /** Tests the various ways that the space character can be handled */

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

                  // simple string tests
    assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }

  /** Tests the various ways that the space character can be handled */
  public void testPlusForSpace() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 62

                  assertEquals("", e.escape(""));
    assertEquals("safestring", e.escape("safestring"));
    assertEquals("embedded%00null", e.escape("embedded\0null"));
    assertEquals("max%EF%BF%BFchar", e.escape("max\uffffchar"));
  }

  /** Tests the various ways that the space character can be handled */
  public void testPlusForSpace() {
    UnicodeEscaper basicEscaper = new PercentEscaper("", false);

            

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

                }

  /** Tests the various ways that the space character can be handled */
  public void testPlusForSpace() {
    UnicodeEscaper basicEscaper = new PercentEscaper("", false);
    UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true);
    UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false);

    assertEquals("string%20with%20spaces", basicEscaper.escape("string with spaces"));

            

Reported by PMD.

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

Line: 66

                }

  /** Tests the various ways that the space character can be handled */
  public void testPlusForSpace() {
    UnicodeEscaper basicEscaper = new PercentEscaper("", false);
    UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true);
    UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false);

    assertEquals("string%20with%20spaces", basicEscaper.escape("string with spaces"));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 71

                  UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true);
    UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false);

    assertEquals("string%20with%20spaces", basicEscaper.escape("string with spaces"));
    assertEquals("string+with+spaces", plusForSpaceEscaper.escape("string with spaces"));
    assertEquals("string with spaces", spaceEscaper.escape("string with spaces"));
  }

  /** Tests that if we add extra 'safe' characters they remain unescaped */

            

Reported by PMD.

The String literal 'string with spaces' appears 4 times in this file; the first occurrence is on line 71
Error

Line: 71

                  UnicodeEscaper plusForSpaceEscaper = new PercentEscaper("", true);
    UnicodeEscaper spaceEscaper = new PercentEscaper(" ", false);

    assertEquals("string%20with%20spaces", basicEscaper.escape("string with spaces"));
    assertEquals("string+with+spaces", plusForSpaceEscaper.escape("string with spaces"));
    assertEquals("string with spaces", spaceEscaper.escape("string with spaces"));
  }

  /** Tests that if we add extra 'safe' characters they remain unescaped */

            

Reported by PMD.

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

Line: 37

                @Override
  protected Table<String, Integer, Character> create(Object... data) {
    Table<String, Integer, Character> table = HashBasedTable.create();
    table.put("foo", 4, 'a');
    table.put("cat", 1, 'b');
    table.clear();
    populate(table, data);
    return table;
  }

            

Reported by PMD.

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

Line: 37

                @Override
  protected Table<String, Integer, Character> create(Object... data) {
    Table<String, Integer, Character> table = HashBasedTable.create();
    table.put("foo", 4, 'a');
    table.put("cat", 1, 'b');
    table.clear();
    populate(table, data);
    return table;
  }

            

Reported by PMD.

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

Line: 38

                protected Table<String, Integer, Character> create(Object... data) {
    Table<String, Integer, Character> table = HashBasedTable.create();
    table.put("foo", 4, 'a');
    table.put("cat", 1, 'b');
    table.clear();
    populate(table, data);
    return table;
  }


            

Reported by PMD.

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

Line: 39

                  Table<String, Integer, Character> table = HashBasedTable.create();
    table.put("foo", 4, 'a');
    table.put("cat", 1, 'b');
    table.clear();
    populate(table, data);
    return table;
  }

  public void testIterationOrder() {

            

Reported by PMD.

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

Line: 44

                  return table;
  }

  public void testIterationOrder() {
    Table<String, String, String> table = HashBasedTable.create();
    for (int i = 0; i < 5; i++) {
      table.put("r" + i, "c" + i, "v" + i);
    }
    assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();

            

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

                  return table;
  }

  public void testIterationOrder() {
    Table<String, String, String> table = HashBasedTable.create();
    for (int i = 0; i < 5; i++) {
      table.put("r" + i, "c" + i, "v" + i);
    }
    assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();

            

Reported by PMD.

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

Line: 49

                  for (int i = 0; i < 5; i++) {
      table.put("r" + i, "c" + i, "v" + i);
    }
    assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();
    assertThat(table.columnKeySet()).containsExactly("c0", "c1", "c2", "c3", "c4").inOrder();
    assertThat(table.values()).containsExactly("v0", "v1", "v2", "v3", "v4").inOrder();
  }

  public void testCreateWithValidSizes() {

            

Reported by PMD.

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

Line: 49

                  for (int i = 0; i < 5; i++) {
      table.put("r" + i, "c" + i, "v" + i);
    }
    assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();
    assertThat(table.columnKeySet()).containsExactly("c0", "c1", "c2", "c3", "c4").inOrder();
    assertThat(table.values()).containsExactly("v0", "v1", "v2", "v3", "v4").inOrder();
  }

  public void testCreateWithValidSizes() {

            

Reported by PMD.

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

Line: 49

                  for (int i = 0; i < 5; i++) {
      table.put("r" + i, "c" + i, "v" + i);
    }
    assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();
    assertThat(table.columnKeySet()).containsExactly("c0", "c1", "c2", "c3", "c4").inOrder();
    assertThat(table.values()).containsExactly("v0", "v1", "v2", "v3", "v4").inOrder();
  }

  public void testCreateWithValidSizes() {

            

Reported by PMD.

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

Line: 50

                    table.put("r" + i, "c" + i, "v" + i);
    }
    assertThat(table.rowKeySet()).containsExactly("r0", "r1", "r2", "r3", "r4").inOrder();
    assertThat(table.columnKeySet()).containsExactly("c0", "c1", "c2", "c3", "c4").inOrder();
    assertThat(table.values()).containsExactly("v0", "v1", "v2", "v3", "v4").inOrder();
  }

  public void testCreateWithValidSizes() {
    Table<String, Integer, Character> table1 = HashBasedTable.create(100, 20);

            

Reported by PMD.

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

Line: 30

                private static final int TEST_CASES = 0x100;

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

  @Param Impl impl;

  private static final Object[][] tables = new Object[TEST_CASES][];


            

Reported by PMD.

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

Line: 32

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

  @Param Impl impl;

  private static final Object[][] tables = new Object[TEST_CASES][];

  @BeforeExperiment
  public void setUp() {

            

Reported by PMD.

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

Line: 36

              
  private static final Object[][] tables = new Object[TEST_CASES][];

  @BeforeExperiment
  public void setUp() {
    int tableSize = ImmutableSet.chooseTableSize(size);
    int mask = tableSize - 1;
    for (int i = 0; i < TEST_CASES; i++) {
      tables[i] = new Object[tableSize];

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 43

                  for (int i = 0; i < TEST_CASES; i++) {
      tables[i] = new Object[tableSize];
      for (int j = 0; j < size; j++) {
        Object o = new Object();
        for (int k = o.hashCode(); ; k++) {
          int index = k & mask;
          if (tables[i][index] == null) {
            tables[i][index] = o;
            break;

            

Reported by PMD.

The class 'Impl' has a Standard Cyclomatic Complexity of 5(Highest = 11).
Design

Line: 55

                  }
  }

  enum Impl {
    EXHAUSTIVE {
      int maxRunBeforeFallback(int tableSize) {
        return 12 * IntMath.log2(tableSize, RoundingMode.UNNECESSARY);
      }


            

Reported by PMD.

The class 'Impl' has a Modified Cyclomatic Complexity of 5(Highest = 11).
Design

Line: 55

                  }
  }

  enum Impl {
    EXHAUSTIVE {
      int maxRunBeforeFallback(int tableSize) {
        return 12 * IntMath.log2(tableSize, RoundingMode.UNNECESSARY);
      }


            

Reported by PMD.

The method 'hashFloodingDetected' has a Standard Cyclomatic Complexity of 10.
Design

Line: 62

                    }

      @Override
      boolean hashFloodingDetected(Object[] hashTable) {
        int maxRunBeforeFallback = maxRunBeforeFallback(hashTable.length);

        // Test for a run wrapping around the end of the table, then check for runs in the middle.
        int endOfStartRun;
        for (endOfStartRun = 0; endOfStartRun < hashTable.length; ) {

            

Reported by PMD.

The method 'hashFloodingDetected' has a Modified Cyclomatic Complexity of 10.
Design

Line: 62

                    }

      @Override
      boolean hashFloodingDetected(Object[] hashTable) {
        int maxRunBeforeFallback = maxRunBeforeFallback(hashTable.length);

        // Test for a run wrapping around the end of the table, then check for runs in the middle.
        int endOfStartRun;
        for (endOfStartRun = 0; endOfStartRun < hashTable.length; ) {

            

Reported by PMD.

The method 'hashFloodingDetected(Object)' has a cyclomatic complexity of 11.
Design

Line: 62

                    }

      @Override
      boolean hashFloodingDetected(Object[] hashTable) {
        int maxRunBeforeFallback = maxRunBeforeFallback(hashTable.length);

        // Test for a run wrapping around the end of the table, then check for runs in the middle.
        int endOfStartRun;
        for (endOfStartRun = 0; endOfStartRun < hashTable.length; ) {

            

Reported by PMD.

Avoid reassigning the loop control variable 'i'
Design

Line: 86

                        }
        }
        for (int i = endOfStartRun + 1; i < startOfEndRun; i++) {
          for (int runLength = 0; i < startOfEndRun && hashTable[i] != null; i++) {
            runLength++;
            if (runLength > maxRunBeforeFallback) {
              return true;
            }
          }

            

Reported by PMD.

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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetElementSetTester<E> extends AbstractMultisetTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testElementSetReflectsAddAbsent() {
    Set<E> elementSet = getMultiset().elementSet();
    assertFalse(elementSet.contains(e3()));
    getMultiset().add(e3(), 4);
    assertTrue(elementSet.contains(e3()));

            

Reported by PMD.

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

Line: 46

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetElementSetTester<E> extends AbstractMultisetTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testElementSetReflectsAddAbsent() {
    Set<E> elementSet = getMultiset().elementSet();
    assertFalse(elementSet.contains(e3()));
    getMultiset().add(e3(), 4);
    assertTrue(elementSet.contains(e3()));
  }

            

Reported by PMD.

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

Line: 47

              public class MultisetElementSetTester<E> extends AbstractMultisetTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testElementSetReflectsAddAbsent() {
    Set<E> elementSet = getMultiset().elementSet();
    assertFalse(elementSet.contains(e3()));
    getMultiset().add(e3(), 4);
    assertTrue(elementSet.contains(e3()));
  }


            

Reported by PMD.

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

Line: 48

                @CollectionFeature.Require(SUPPORTS_ADD)
  public void testElementSetReflectsAddAbsent() {
    Set<E> elementSet = getMultiset().elementSet();
    assertFalse(elementSet.contains(e3()));
    getMultiset().add(e3(), 4);
    assertTrue(elementSet.contains(e3()));
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 49

                public void testElementSetReflectsAddAbsent() {
    Set<E> elementSet = getMultiset().elementSet();
    assertFalse(elementSet.contains(e3()));
    getMultiset().add(e3(), 4);
    assertTrue(elementSet.contains(e3()));
  }

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

            

Reported by PMD.

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

Line: 50

                  Set<E> elementSet = getMultiset().elementSet();
    assertFalse(elementSet.contains(e3()));
    getMultiset().add(e3(), 4);
    assertTrue(elementSet.contains(e3()));
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testElementSetReflectsRemove() {

            

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

                  assertTrue(elementSet.contains(e3()));
  }

  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testElementSetReflectsRemove() {
    Set<E> elementSet = getMultiset().elementSet();
    assertTrue(elementSet.contains(e0()));
    getMultiset().removeAll(Collections.singleton(e0()));

            

Reported by PMD.

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

Line: 55

              
  @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testElementSetReflectsRemove() {
    Set<E> elementSet = getMultiset().elementSet();
    assertTrue(elementSet.contains(e0()));
    getMultiset().removeAll(Collections.singleton(e0()));
    assertFalse(elementSet.contains(e0()));
  }

            

Reported by PMD.

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

Line: 56

                @CollectionSize.Require(absent = ZERO)
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testElementSetReflectsRemove() {
    Set<E> elementSet = getMultiset().elementSet();
    assertTrue(elementSet.contains(e0()));
    getMultiset().removeAll(Collections.singleton(e0()));
    assertFalse(elementSet.contains(e0()));
  }


            

Reported by PMD.

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

Line: 57

                @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testElementSetReflectsRemove() {
    Set<E> elementSet = getMultiset().elementSet();
    assertTrue(elementSet.contains(e0()));
    getMultiset().removeAll(Collections.singleton(e0()));
    assertFalse(elementSet.contains(e0()));
  }

  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

guava-tests/test/com/google/common/collect/ForwardingConcurrentMapTest.java
31 issues
Field delegate has the same name as a method
Error

Line: 31

              public class ForwardingConcurrentMapTest extends TestCase {

  private static class TestMap extends ForwardingConcurrentMap<String, Integer> {
    final ConcurrentMap<String, Integer> delegate = new ConcurrentHashMap<>();

    @Override
    protected ConcurrentMap<String, Integer> delegate() {
      return delegate;
    }

            

Reported by PMD.

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

Line: 31

              public class ForwardingConcurrentMapTest extends TestCase {

  private static class TestMap extends ForwardingConcurrentMap<String, Integer> {
    final ConcurrentMap<String, Integer> delegate = new ConcurrentHashMap<>();

    @Override
    protected ConcurrentMap<String, Integer> delegate() {
      return delegate;
    }

            

Reported by PMD.

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

Line: 39

                  }
  }

  public void testPutIfAbsent() {
    TestMap map = new TestMap();
    map.put("foo", 1);
    assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 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: 39

                  }
  }

  public void testPutIfAbsent() {
    TestMap map = new TestMap();
    map.put("foo", 1);
    assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 3));

            

Reported by PMD.

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

Line: 41

              
  public void testPutIfAbsent() {
    TestMap map = new TestMap();
    map.put("foo", 1);
    assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 3));
    assertEquals(Integer.valueOf(3), map.get("bar"));
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

                public void testPutIfAbsent() {
    TestMap map = new TestMap();
    map.put("foo", 1);
    assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 3));
    assertEquals(Integer.valueOf(3), map.get("bar"));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 43

                  TestMap map = new TestMap();
    map.put("foo", 1);
    assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 3));
    assertEquals(Integer.valueOf(3), map.get("bar"));
  }

  public void testRemove() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 44

                  map.put("foo", 1);
    assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 3));
    assertEquals(Integer.valueOf(3), map.get("bar"));
  }

  public void testRemove() {
    TestMap map = new TestMap();

            

Reported by PMD.

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

Line: 44

                  map.put("foo", 1);
    assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 3));
    assertEquals(Integer.valueOf(3), map.get("bar"));
  }

  public void testRemove() {
    TestMap map = new TestMap();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 45

                  assertEquals(Integer.valueOf(1), map.putIfAbsent("foo", 2));
    assertEquals(Integer.valueOf(1), map.get("foo"));
    assertNull(map.putIfAbsent("bar", 3));
    assertEquals(Integer.valueOf(3), map.get("bar"));
  }

  public void testRemove() {
    TestMap map = new TestMap();
    map.put("foo", 1);

            

Reported by PMD.

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

Line: 33

                protected Table<String, Integer, Character> create(Object... data) {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> table = Tables.transpose(original);
    table.clear();
    populate(table, data);
    return table;
  }

  public void testTransposeTransposed() {

            

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

                  return table;
  }

  public void testTransposeTransposed() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    assertSame(original, Tables.transpose(Tables.transpose(original)));
  }

  public void testPutOriginalModifiesTranspose() {

            

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

                  assertSame(original, Tables.transpose(Tables.transpose(original)));
  }

  public void testPutOriginalModifiesTranspose() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    original.put(1, "foo", 'a');
    assertEquals((Character) 'a', transpose.get("foo", 1));
  }

            

Reported by PMD.

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

Line: 46

                public void testPutOriginalModifiesTranspose() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    original.put(1, "foo", 'a');
    assertEquals((Character) 'a', transpose.get("foo", 1));
  }

  public void testPutTransposeModifiesOriginal() {
    Table<Integer, String, Character> original = HashBasedTable.create();

            

Reported by PMD.

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

Line: 46

                public void testPutOriginalModifiesTranspose() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    original.put(1, "foo", 'a');
    assertEquals((Character) 'a', transpose.get("foo", 1));
  }

  public void testPutTransposeModifiesOriginal() {
    Table<Integer, String, Character> original = HashBasedTable.create();

            

Reported by PMD.

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

Line: 47

                  Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    original.put(1, "foo", 'a');
    assertEquals((Character) 'a', transpose.get("foo", 1));
  }

  public void testPutTransposeModifiesOriginal() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);

            

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

                  assertEquals((Character) 'a', transpose.get("foo", 1));
  }

  public void testPutTransposeModifiesOriginal() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    transpose.put("foo", 1, 'a');
    assertEquals((Character) 'a', original.get(1, "foo"));
  }

            

Reported by PMD.

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

Line: 53

                public void testPutTransposeModifiesOriginal() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    transpose.put("foo", 1, 'a');
    assertEquals((Character) 'a', original.get(1, "foo"));
  }

  public void testTransposedViews() {
    Table<Integer, String, Character> original = HashBasedTable.create();

            

Reported by PMD.

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

Line: 54

                  Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    transpose.put("foo", 1, 'a');
    assertEquals((Character) 'a', original.get(1, "foo"));
  }

  public void testTransposedViews() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);

            

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

                  assertEquals((Character) 'a', original.get(1, "foo"));
  }

  public void testTransposedViews() {
    Table<Integer, String, Character> original = HashBasedTable.create();
    Table<String, Integer, Character> transpose = Tables.transpose(original);
    original.put(1, "foo", 'a');
    assertSame(original.columnKeySet(), transpose.rowKeySet());
    assertSame(original.rowKeySet(), transpose.columnKeySet());

            

Reported by PMD.

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

Line: 32

               * @author Gregory Kick
 */
@GwtCompatible(emulated = true)
public class SingletonImmutableTableTest extends AbstractImmutableTableTest {
  private final ImmutableTable<Character, Integer, String> testTable =
      new SingletonImmutableTable<>('a', 1, "blah");

  public void testHashCode() {
    assertEquals(Objects.hashCode('a', 1, "blah"), testTable.hashCode());

            

Reported by PMD.

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

Line: 33

               */
@GwtCompatible(emulated = true)
public class SingletonImmutableTableTest extends AbstractImmutableTableTest {
  private final ImmutableTable<Character, Integer, String> testTable =
      new SingletonImmutableTable<>('a', 1, "blah");

  public void testHashCode() {
    assertEquals(Objects.hashCode('a', 1, "blah"), testTable.hashCode());
  }

            

Reported by PMD.

The String literal 'blah' appears 10 times in this file; the first occurrence is on line 34
Error

Line: 34

              @GwtCompatible(emulated = true)
public class SingletonImmutableTableTest extends AbstractImmutableTableTest {
  private final ImmutableTable<Character, Integer, String> testTable =
      new SingletonImmutableTable<>('a', 1, "blah");

  public void testHashCode() {
    assertEquals(Objects.hashCode('a', 1, "blah"), testTable.hashCode());
  }


            

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

                private final ImmutableTable<Character, Integer, String> testTable =
      new SingletonImmutableTable<>('a', 1, "blah");

  public void testHashCode() {
    assertEquals(Objects.hashCode('a', 1, "blah"), testTable.hashCode());
  }

  public void testCellSet() {
    assertEquals(ImmutableSet.of(Tables.immutableCell('a', 1, "blah")), testTable.cellSet());

            

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

                  assertEquals(Objects.hashCode('a', 1, "blah"), testTable.hashCode());
  }

  public void testCellSet() {
    assertEquals(ImmutableSet.of(Tables.immutableCell('a', 1, "blah")), testTable.cellSet());
  }

  public void testColumn() {
    assertEquals(ImmutableMap.of(), testTable.column(0));

            

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

                  assertEquals(ImmutableSet.of(Tables.immutableCell('a', 1, "blah")), testTable.cellSet());
  }

  public void testColumn() {
    assertEquals(ImmutableMap.of(), testTable.column(0));
    assertEquals(ImmutableMap.of('a', "blah"), testTable.column(1));
  }

  public void testColumnKeySet() {

            

Reported by PMD.

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

Line: 44

                  assertEquals(ImmutableSet.of(Tables.immutableCell('a', 1, "blah")), testTable.cellSet());
  }

  public void testColumn() {
    assertEquals(ImmutableMap.of(), testTable.column(0));
    assertEquals(ImmutableMap.of('a', "blah"), testTable.column(1));
  }

  public void testColumnKeySet() {

            

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

                  assertEquals(ImmutableMap.of('a', "blah"), testTable.column(1));
  }

  public void testColumnKeySet() {
    assertEquals(ImmutableSet.of(1), testTable.columnKeySet());
  }

  public void testColumnMap() {
    assertEquals(ImmutableMap.of(1, ImmutableMap.of('a', "blah")), testTable.columnMap());

            

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(ImmutableSet.of(1), testTable.columnKeySet());
  }

  public void testColumnMap() {
    assertEquals(ImmutableMap.of(1, ImmutableMap.of('a', "blah")), testTable.columnMap());
  }

  public void testRow() {
    assertEquals(ImmutableMap.of(), testTable.row('A'));

            

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

                  assertEquals(ImmutableMap.of(1, ImmutableMap.of('a', "blah")), testTable.columnMap());
  }

  public void testRow() {
    assertEquals(ImmutableMap.of(), testTable.row('A'));
    assertEquals(ImmutableMap.of(1, "blah"), testTable.row('a'));
  }

  public void testRowKeySet() {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java
30 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 34

              public class ForwardingSortedMapImplementsMapTest extends SortedMapInterfaceTest<String, Integer> {

  private static class SimpleForwardingSortedMap<K, V> extends ForwardingSortedMap<K, V> {
    final SortedMap<K, V> delegate;

    SimpleForwardingSortedMap(SortedMap<K, V> delegate) {
      this.delegate = delegate;
    }


            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 34

              public class ForwardingSortedMapImplementsMapTest extends SortedMapInterfaceTest<String, Integer> {

  private static class SimpleForwardingSortedMap<K, V> extends ForwardingSortedMap<K, V> {
    final SortedMap<K, V> delegate;

    SimpleForwardingSortedMap(SortedMap<K, V> delegate) {
      this.delegate = delegate;
    }


            

Reported by PMD.

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

Line: 53

                @Override
  protected SortedMap<String, Integer> makeEmptyMap() {
    return new SimpleForwardingSortedMap<>(
        new TreeMap<String, Integer>(Ordering.natural().nullsFirst()));
  }

  @Override
  protected SortedMap<String, Integer> makePopulatedMap() {
    final SortedMap<String, Integer> sortedMap = makeEmptyMap();

            

Reported by PMD.

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

Line: 59

                @Override
  protected SortedMap<String, Integer> makePopulatedMap() {
    final SortedMap<String, Integer> sortedMap = makeEmptyMap();
    sortedMap.put("one", 1);
    sortedMap.put("two", 2);
    sortedMap.put("three", 3);
    return sortedMap;
  }


            

Reported by PMD.

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

Line: 60

                protected SortedMap<String, Integer> makePopulatedMap() {
    final SortedMap<String, Integer> sortedMap = makeEmptyMap();
    sortedMap.put("one", 1);
    sortedMap.put("two", 2);
    sortedMap.put("three", 3);
    return sortedMap;
  }

  @Override

            

Reported by PMD.

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

Line: 61

                  final SortedMap<String, Integer> sortedMap = makeEmptyMap();
    sortedMap.put("one", 1);
    sortedMap.put("two", 2);
    sortedMap.put("three", 3);
    return sortedMap;
  }

  @Override
  protected String getKeyNotInPopulatedMap() throws UnsupportedOperationException {

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 66

                }

  @Override
  protected String getKeyNotInPopulatedMap() throws UnsupportedOperationException {
    return "minus one";
  }

  @Override
  protected Integer getValueNotInPopulatedMap() throws UnsupportedOperationException {

            

Reported by PMD.

A method or constructor should not explicitly declare unchecked exceptions in its 'throws' clause
Design

Line: 71

                }

  @Override
  protected Integer getValueNotInPopulatedMap() throws UnsupportedOperationException {
    return -1;
  }

  @Override
  public void testContainsKey() {

            

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 -1;
  }

  @Override
  public void testContainsKey() {
    try {
      super.testContainsKey();
    } catch (ClassCastException tolerated) {
    }

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 79

                public void testContainsKey() {
    try {
      super.testContainsKey();
    } catch (ClassCastException tolerated) {
    }
  }

  @Override
  public void testEntrySetContainsEntryIncompatibleKey() {

            

Reported by PMD.

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

Line: 42

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapComputeIfAbsentTester<K, V> extends AbstractMapTester<K, V> {

  @MapFeature.Require(SUPPORTS_PUT)
  public void testComputeIfAbsent_supportedAbsent() {
    assertEquals(
        "computeIfAbsent(notPresent, function) should return new value",
        v3(),
        getMap()

            

Reported by PMD.

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

Line: 43

              public class MapComputeIfAbsentTester<K, V> extends AbstractMapTester<K, V> {

  @MapFeature.Require(SUPPORTS_PUT)
  public void testComputeIfAbsent_supportedAbsent() {
    assertEquals(
        "computeIfAbsent(notPresent, function) should return new value",
        v3(),
        getMap()
            .computeIfAbsent(

            

Reported by PMD.

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

Line: 47

                  assertEquals(
        "computeIfAbsent(notPresent, function) should return new value",
        v3(),
        getMap()
            .computeIfAbsent(
                k3(),
                k -> {
                  assertEquals(k3(), k);
                  return v3();

            

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

                  expectAdded(e3());
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfAbsent_supportedPresent() {
    assertEquals(
        "computeIfAbsent(present, function) should return existing value",
        v0(),

            

Reported by PMD.

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

Line: 63

                  assertEquals(
        "computeIfAbsent(present, function) should return existing value",
        v0(),
        getMap()
            .computeIfAbsent(
                k0(),
                k -> {
                  throw new AssertionFailedError();
                }));

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_PUT)
  public void testComputeIfAbsent_functionReturnsNullNotInserted() {
    assertNull(
        "computeIfAbsent(absent, returnsNull) should return null",
        getMap()
            .computeIfAbsent(

            

Reported by PMD.

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

Line: 73

                }

  @MapFeature.Require(SUPPORTS_PUT)
  public void testComputeIfAbsent_functionReturnsNullNotInserted() {
    assertNull(
        "computeIfAbsent(absent, returnsNull) should return null",
        getMap()
            .computeIfAbsent(
                k3(),

            

Reported by PMD.

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

Line: 76

                public void testComputeIfAbsent_functionReturnsNullNotInserted() {
    assertNull(
        "computeIfAbsent(absent, returnsNull) should return null",
        getMap()
            .computeIfAbsent(
                k3(),
                k -> {
                  assertEquals(k3(), k);
                  return 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: 86

                  expectUnchanged();
  }

  @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfAbsent_nullTreatedAsAbsent() {
    initMapWithNullValue();
    assertEquals(
        "computeIfAbsent(presentAssignedToNull, function) should return newValue",

            

Reported by PMD.

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

Line: 88

              
  @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testComputeIfAbsent_nullTreatedAsAbsent() {
    initMapWithNullValue();
    assertEquals(
        "computeIfAbsent(presentAssignedToNull, function) should return newValue",
        getValueForNullKey(),
        getMap()

            

Reported by PMD.