The following issues were found

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

Line: 43

              @Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SortedSetNavigationTester<E> extends AbstractSetTester<E> {

  private SortedSet<E> sortedSet;
  private List<E> values;
  private E a;
  private E b;
  private E c;


            

Reported by PMD.

Perhaps 'values' could be replaced by a local variable.
Design

Line: 44

              public class SortedSetNavigationTester<E> extends AbstractSetTester<E> {

  private SortedSet<E> sortedSet;
  private List<E> values;
  private E a;
  private E b;
  private E c;

  @Override

            

Reported by PMD.

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

Line: 44

              public class SortedSetNavigationTester<E> extends AbstractSetTester<E> {

  private SortedSet<E> sortedSet;
  private List<E> values;
  private E a;
  private E b;
  private E c;

  @Override

            

Reported by PMD.

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

Line: 45

              
  private SortedSet<E> sortedSet;
  private List<E> values;
  private E a;
  private E b;
  private E c;

  @Override
  public void setUp() throws Exception {

            

Reported by PMD.

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

Line: 46

                private SortedSet<E> sortedSet;
  private List<E> values;
  private E a;
  private E b;
  private E c;

  @Override
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

Avoid unused private fields such as 'b'.
Design

Line: 46

                private SortedSet<E> sortedSet;
  private List<E> values;
  private E a;
  private E b;
  private E c;

  @Override
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

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

Line: 47

                private List<E> values;
  private E a;
  private E b;
  private E c;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    sortedSet = (SortedSet<E>) getSet();

            

Reported by PMD.

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

Line: 49

                private E b;
  private E c;

  @Override
  public void setUp() throws Exception {
    super.setUp();
    sortedSet = (SortedSet<E>) getSet();
    values =
        Helpers.copyToList(

            

Reported by PMD.

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

Line: 55

                  sortedSet = (SortedSet<E>) getSet();
    values =
        Helpers.copyToList(
            getSubjectGenerator()
                .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
    Collections.sort(values, sortedSet.comparator());

    // some tests assume SEVERAL == 3
    if (values.size() >= 1) {

            

Reported by PMD.

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

Line: 56

                  values =
        Helpers.copyToList(
            getSubjectGenerator()
                .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
    Collections.sort(values, sortedSet.comparator());

    // some tests assume SEVERAL == 3
    if (values.size() >= 1) {
      a = values.get(0);

            

Reported by PMD.

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

Line: 31

               * @author Chris Nokleberg
 */
public class CountingInputStreamTest extends IoTestCase {
  private CountingInputStream counter;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));

            

Reported by PMD.

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

Line: 33

              public class CountingInputStreamTest extends IoTestCase {
  private CountingInputStream counter;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));
  }


            

Reported by PMD.

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

Line: 39

                  counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));
  }

  public void testReadSingleByte() throws IOException {
    assertEquals(0, counter.getCount());
    assertEquals(0, counter.read());
    assertEquals(1, counter.getCount());
  }


            

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

                  counter = new CountingInputStream(new ByteArrayInputStream(new byte[20]));
  }

  public void testReadSingleByte() throws IOException {
    assertEquals(0, counter.getCount());
    assertEquals(0, counter.read());
    assertEquals(1, counter.getCount());
  }


            

Reported by PMD.

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

Line: 45

                  assertEquals(1, counter.getCount());
  }

  public void testReadArray() throws IOException {
    assertEquals(10, counter.read(new byte[10]));
    assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() throws IOException {

            

Reported by PMD.

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

Line: 45

                  assertEquals(1, counter.getCount());
  }

  public void testReadArray() throws IOException {
    assertEquals(10, counter.read(new byte[10]));
    assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() throws IOException {

            

Reported by PMD.

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

Line: 50

                  assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() throws IOException {
    assertEquals(3, counter.read(new byte[10], 1, 3));
    assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {

            

Reported by PMD.

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

Line: 50

                  assertEquals(10, counter.getCount());
  }

  public void testReadArrayRange() throws IOException {
    assertEquals(3, counter.read(new byte[10], 1, 3));
    assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {

            

Reported by PMD.

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

Line: 55

                  assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {
    assertEquals(10, counter.skip(10));
    assertEquals(10, counter.getCount());
  }

  public void testSkipEOF() throws IOException {

            

Reported by PMD.

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

Line: 55

                  assertEquals(3, counter.getCount());
  }

  public void testSkip() throws IOException {
    assertEquals(10, counter.skip(10));
    assertEquals(10, counter.getCount());
  }

  public void testSkipEOF() throws IOException {

            

Reported by PMD.

guava-tests/test/com/google/common/graph/TestUtil.java
22 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 42

                private TestUtil() {}

  static void assertNodeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(NODE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);

            

Reported by PMD.

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

Line: 42

                private TestUtil() {}

  static void assertNodeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(NODE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);

            

Reported by PMD.

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

Line: 43

              
  static void assertNodeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(NODE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);

            

Reported by PMD.

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

Line: 43

              
  static void assertNodeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(NODE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);

            

Reported by PMD.

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

Line: 47

                }

  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) {
    // Properties not covered by equals()

            

Reported by PMD.

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

Line: 47

                }

  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) {
    // Properties not covered by equals()

            

Reported by PMD.

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

Line: 48

              
  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) {
    // Properties not covered by equals()
    assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops());

            

Reported by PMD.

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

Line: 48

              
  static void assertEdgeNotInGraphErrorMessage(Throwable throwable) {
    assertThat(throwable).hasMessageThat().startsWith(EDGE_STRING);
    assertThat(throwable).hasMessageThat().contains(ERROR_ELEMENT_NOT_IN_GRAPH);
  }

  static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) {
    // Properties not covered by equals()
    assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops());

            

Reported by PMD.

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

Line: 53

              
  static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) {
    // Properties not covered by equals()
    assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops());
    assertThat(graphA.nodeOrder()).isEqualTo(graphB.nodeOrder());

    assertThat(graphA).isEqualTo(graphB);
  }


            

Reported by PMD.

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

Line: 54

                static void assertStronglyEquivalent(Graph<?> graphA, Graph<?> graphB) {
    // Properties not covered by equals()
    assertThat(graphA.allowsSelfLoops()).isEqualTo(graphB.allowsSelfLoops());
    assertThat(graphA.nodeOrder()).isEqualTo(graphB.nodeOrder());

    assertThat(graphA).isEqualTo(graphB);
  }

  static void assertStronglyEquivalent(ValueGraph<?, ?> graphA, ValueGraph<?, ?> graphB) {

            

Reported by PMD.

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

Line: 47

                  return (ConcurrentMap<K, V>) super.getMap();
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testReplace_supportedPresent() {
    assertEquals(v0(), getMap().replace(k0(), v3()));
    expectReplacement(entry(k0(), v3()));
  }

            

Reported by PMD.

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

Line: 50

                @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testReplace_supportedPresent() {
    assertEquals(v0(), getMap().replace(k0(), v3()));
    expectReplacement(entry(k0(), v3()));
  }

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

            

Reported by PMD.

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

Line: 54

                  expectReplacement(entry(k0(), v3()));
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testReplace_supportedPresentNoChange() {
    assertEquals(v0(), getMap().replace(k0(), v0()));
    expectUnchanged();
  }

            

Reported by PMD.

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

Line: 57

                @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testReplace_supportedPresentNoChange() {
    assertEquals(v0(), getMap().replace(k0(), v0()));
    expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_PUT)
  public void testReplace_supportedAbsent() {

            

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

                  expectUnchanged();
  }

  @MapFeature.Require(SUPPORTS_PUT)
  public void testReplace_supportedAbsent() {
    assertNull(getMap().replace(k3(), v3()));
    expectUnchanged();
  }


            

Reported by PMD.

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

Line: 63

              
  @MapFeature.Require(SUPPORTS_PUT)
  public void testReplace_supportedAbsent() {
    assertNull(getMap().replace(k3(), v3()));
    expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 67

                  expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
  @CollectionSize.Require(absent = ZERO)
  public void testReplace_presentNullValueUnsupported() {
    try {
      getMap().replace(k0(), null);
      fail("Expected NullPointerException");

            

Reported by PMD.

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

Line: 71

                @CollectionSize.Require(absent = ZERO)
  public void testReplace_presentNullValueUnsupported() {
    try {
      getMap().replace(k0(), null);
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {
    }
    expectUnchanged();
  }

            

Reported by PMD.

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

Line: 73

                  try {
      getMap().replace(k0(), null);
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {
    }
    expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)

            

Reported by PMD.

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

Line: 73

                  try {
      getMap().replace(k0(), null);
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {
    }
    expectUnchanged();
  }

  @MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)

            

Reported by PMD.

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

Line: 42

               */
@GwtIncompatible // java.util.Arrays#copyOf(Object[], int), java.lang.reflect.Array
public class CompactHashSetTest extends TestCase {
  public static Test suite() {
    List<Feature<?>> allFeatures =
        Arrays.<Feature<?>>asList(
            CollectionSize.ANY,
            CollectionFeature.ALLOWS_NULL_VALUES,
            CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

Reported by PMD.

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

Line: 74

                                @Override
                  protected Set<String> create(String[] elements) {
                    CompactHashSet<String> set = CompactHashSet.create();
                    set.convertToHashFloodingResistantImplementation();
                    Collections.addAll(set, elements);
                    return set;
                  }
                })
            .named("CompactHashSet with flooding protection")

            

Reported by PMD.

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

Line: 94

                                  for (int i = 0; i < 100; i++) {
                      set.remove(i);
                    }
                    set.trimToSize();
                    return set;
                  }
                })
            .named("CompactHashSet#TrimToSize")
            .withFeatures(allFeatures)

            

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

                  return suite;
  }

  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);

            

Reported by PMD.

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

Line: 104

                  return suite;
  }

  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);

            

Reported by PMD.

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

Line: 106

              
  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);

            

Reported by PMD.

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

Line: 106

              
  public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);

            

Reported by PMD.

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

Line: 107

                public void testAllocArraysDefault() {
    CompactHashSet<Integer> set = CompactHashSet.create();
    assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);
  }

            

Reported by PMD.

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

Line: 109

                  assertThat(set.needsAllocArrays()).isTrue();
    assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);
  }

  public void testAllocArraysExpectedSize() {

            

Reported by PMD.

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

Line: 110

                  assertThat(set.elements).isNull();

    set.add(1);
    assertThat(set.needsAllocArrays()).isFalse();
    assertThat(set.elements).hasLength(CompactHashing.DEFAULT_SIZE);
  }

  public void testAllocArraysExpectedSize() {
    for (int i = 0; i <= CompactHashing.DEFAULT_SIZE; i++) {

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/SetEqualsTester.java
21 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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetEqualsTester<E> extends AbstractSetTester<E> {
  public void testEquals_otherSetWithSameElements() {
    assertTrue(
        "A Set should equal any other Set containing the same elements.",
        getSet().equals(MinimalSet.from(getSampleElements())));
  }


            

Reported by PMD.

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

Line: 41

                public void testEquals_otherSetWithSameElements() {
    assertTrue(
        "A Set should equal any other Set containing the same elements.",
        getSet().equals(MinimalSet.from(getSampleElements())));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherSetWithDifferentElements() {
    Collection<E> elements = getSampleElements(getNumElements() - 1);

            

Reported by PMD.

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

Line: 44

                      getSet().equals(MinimalSet.from(getSampleElements())));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherSetWithDifferentElements() {
    Collection<E> elements = getSampleElements(getNumElements() - 1);
    elements.add(getSubjectGenerator().samples().e3());

    assertFalse(

            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherSetWithDifferentElements() {
    Collection<E> elements = getSampleElements(getNumElements() - 1);
    elements.add(getSubjectGenerator().samples().e3());

    assertFalse(
        "A Set should not equal another Set containing different elements.",
        getSet().equals(MinimalSet.from(elements)));
  }

            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherSetWithDifferentElements() {
    Collection<E> elements = getSampleElements(getNumElements() - 1);
    elements.add(getSubjectGenerator().samples().e3());

    assertFalse(
        "A Set should not equal another Set containing different elements.",
        getSet().equals(MinimalSet.from(elements)));
  }

            

Reported by PMD.

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

Line: 47

                @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherSetWithDifferentElements() {
    Collection<E> elements = getSampleElements(getNumElements() - 1);
    elements.add(getSubjectGenerator().samples().e3());

    assertFalse(
        "A Set should not equal another Set containing different elements.",
        getSet().equals(MinimalSet.from(elements)));
  }

            

Reported by PMD.

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

Line: 51

              
    assertFalse(
        "A Set should not equal another Set containing different elements.",
        getSet().equals(MinimalSet.from(elements)));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEquals_containingNull() {

            

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

                      getSet().equals(MinimalSet.from(elements)));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEquals_containingNull() {
    Collection<E> elements = getSampleElements(getNumElements() - 1);
    elements.add(null);


            

Reported by PMD.

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

Line: 58

                @CollectionFeature.Require(ALLOWS_NULL_VALUES)
  public void testEquals_containingNull() {
    Collection<E> elements = getSampleElements(getNumElements() - 1);
    elements.add(null);

    collection = getSubjectGenerator().create(elements.toArray());
    assertTrue(
        "A Set should equal any other Set containing the same elements,"
            + " even if some elements are null.",

            

Reported by PMD.

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

Line: 60

                  Collection<E> elements = getSampleElements(getNumElements() - 1);
    elements.add(null);

    collection = getSubjectGenerator().create(elements.toArray());
    assertTrue(
        "A Set should equal any other Set containing the same elements,"
            + " even if some elements are null.",
        getSet().equals(MinimalSet.from(elements)));
  }

            

Reported by PMD.

guava-tests/test/com/google/common/escape/ArrayBasedEscaperMapTest.java
21 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: 27

              /** @author David Beaumont */
@GwtCompatible
public class ArrayBasedEscaperMapTest extends TestCase {
  public void testNullMap() {
    try {
      ArrayBasedEscaperMap.create(null);
      fail("expected exception did not occur");
    } catch (NullPointerException e) {
      // pass

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 30

                public void testNullMap() {
    try {
      ArrayBasedEscaperMap.create(null);
      fail("expected exception did not occur");
    } catch (NullPointerException e) {
      // pass
    }
  }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 31

                  try {
      ArrayBasedEscaperMap.create(null);
      fail("expected exception did not occur");
    } catch (NullPointerException e) {
      // pass
    }
  }

  public void testEmptyMap() {

            

Reported by PMD.

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

Line: 31

                  try {
      ArrayBasedEscaperMap.create(null);
      fail("expected exception did not occur");
    } catch (NullPointerException e) {
      // pass
    }
  }

  public void testEmptyMap() {

            

Reported by PMD.

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

Line: 31

                  try {
      ArrayBasedEscaperMap.create(null);
      fail("expected exception did not occur");
    } catch (NullPointerException e) {
      // pass
    }
  }

  public void testEmptyMap() {

            

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

                  }
  }

  public void testEmptyMap() {
    Map<Character, String> map = ImmutableMap.of();
    ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);
    // Non-null array of zero length.
    assertEquals(0, fem.getReplacementArray().length);
  }

            

Reported by PMD.

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

Line: 40

                  Map<Character, String> map = ImmutableMap.of();
    ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);
    // Non-null array of zero length.
    assertEquals(0, fem.getReplacementArray().length);
  }

  public void testMapLength() {
    Map<Character, String> map =
        ImmutableMap.of(

            

Reported by PMD.

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

Line: 40

                  Map<Character, String> map = ImmutableMap.of();
    ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);
    // Non-null array of zero length.
    assertEquals(0, fem.getReplacementArray().length);
  }

  public void testMapLength() {
    Map<Character, String> map =
        ImmutableMap.of(

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

                  Map<Character, String> map = ImmutableMap.of();
    ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);
    // Non-null array of zero length.
    assertEquals(0, fem.getReplacementArray().length);
  }

  public void testMapLength() {
    Map<Character, String> map =
        ImmutableMap.of(

            

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

                  assertEquals(0, fem.getReplacementArray().length);
  }

  public void testMapLength() {
    Map<Character, String> map =
        ImmutableMap.of(
            'a', "first",
            'z', "last");
    ArrayBasedEscaperMap fem = ArrayBasedEscaperMap.create(map);

            

Reported by PMD.

guava-tests/test/com/google/common/base/DefaultsTest.java
21 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: 27

               * @author Jige Yu
 */
public class DefaultsTest extends TestCase {
  public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());

            

Reported by PMD.

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

Line: 27

               * @author Jige Yu
 */
public class DefaultsTest extends TestCase {
  public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());

            

Reported by PMD.

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

Line: 28

               */
public class DefaultsTest extends TestCase {
  public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());

            

Reported by PMD.

Use assertTrue(x)/assertFalse(x) instead of assertEquals(true, x)/assertEquals(false, x) or assertEquals(Boolean.TRUE, x)/assertEquals(Boolean.FALSE, x).
Design

Line: 28

               */
public class DefaultsTest extends TestCase {
  public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 28

               */
public class DefaultsTest extends TestCase {
  public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

              public class DefaultsTest extends TestCase {
  public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());
    assertEquals(0.0f, Defaults.defaultValue(float.class).floatValue());

            

Reported by PMD.

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

Line: 29

              public class DefaultsTest extends TestCase {
  public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());
    assertEquals(0.0f, Defaults.defaultValue(float.class).floatValue());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 30

                public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());
    assertEquals(0.0f, Defaults.defaultValue(float.class).floatValue());
    assertEquals(0.0d, Defaults.defaultValue(double.class).doubleValue());

            

Reported by PMD.

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

Line: 30

                public void testGetDefaultValue() {
    assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());
    assertEquals(0.0f, Defaults.defaultValue(float.class).floatValue());
    assertEquals(0.0d, Defaults.defaultValue(double.class).doubleValue());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

                  assertEquals(false, Defaults.defaultValue(boolean.class).booleanValue());
    assertEquals('\0', Defaults.defaultValue(char.class).charValue());
    assertEquals(0, Defaults.defaultValue(byte.class).byteValue());
    assertEquals(0, Defaults.defaultValue(short.class).shortValue());
    assertEquals(0, Defaults.defaultValue(int.class).intValue());
    assertEquals(0, Defaults.defaultValue(long.class).longValue());
    assertEquals(0.0f, Defaults.defaultValue(float.class).floatValue());
    assertEquals(0.0d, Defaults.defaultValue(double.class).doubleValue());
    assertNull(Defaults.defaultValue(void.class));

            

Reported by PMD.

guava-tests/test/com/google/common/hash/Murmur3Hash128Test.java
21 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: 29

              
/** Tests for {@link Murmur3_128HashFunction}. */
public class Murmur3Hash128Test extends TestCase {
  public void testKnownValues() {
    assertHash(0, 0x629942693e10f867L, 0x92db0b82baeb5347L, "hell");
    assertHash(1, 0xa78ddff5adae8d10L, 0x128900ef20900135L, "hello");
    assertHash(2, 0x8a486b23f422e826L, 0xf962a2c58947765fL, "hello ");
    assertHash(3, 0x2ea59f466f6bed8cL, 0xc610990acc428a17L, "hello w");
    assertHash(4, 0x79f6305a386c572cL, 0x46305aed3483b94eL, "hello wo");

            

Reported by PMD.

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

Line: 29

              
/** Tests for {@link Murmur3_128HashFunction}. */
public class Murmur3Hash128Test extends TestCase {
  public void testKnownValues() {
    assertHash(0, 0x629942693e10f867L, 0x92db0b82baeb5347L, "hell");
    assertHash(1, 0xa78ddff5adae8d10L, 0x128900ef20900135L, "hello");
    assertHash(2, 0x8a486b23f422e826L, 0xf962a2c58947765fL, "hello ");
    assertHash(3, 0x2ea59f466f6bed8cL, 0xc610990acc428a17L, "hello w");
    assertHash(4, 0x79f6305a386c572cL, 0x46305aed3483b94eL, "hello wo");

            

Reported by PMD.

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

Line: 43

              
    // Known output from Python smhasher
    HashCode foxHash =
        murmur3_128(0).hashString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8);
    assertEquals("6c1b07bc7bbc4be347939ac4a93c437a", foxHash.toString());
  }

  private static void assertHash(int seed, long expected1, long expected2, String stringInput) {
    HashCode expected = toHashCode(expected1, expected2);

            

Reported by PMD.

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

Line: 44

                  // Known output from Python smhasher
    HashCode foxHash =
        murmur3_128(0).hashString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8);
    assertEquals("6c1b07bc7bbc4be347939ac4a93c437a", foxHash.toString());
  }

  private static void assertHash(int seed, long expected1, long expected2, String stringInput) {
    HashCode expected = toHashCode(expected1, expected2);
    byte[] input = HashTestUtils.ascii(stringInput);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 44

                  // Known output from Python smhasher
    HashCode foxHash =
        murmur3_128(0).hashString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8);
    assertEquals("6c1b07bc7bbc4be347939ac4a93c437a", foxHash.toString());
  }

  private static void assertHash(int seed, long expected1, long expected2, String stringInput) {
    HashCode expected = toHashCode(expected1, expected2);
    byte[] input = HashTestUtils.ascii(stringInput);

            

Reported by PMD.

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

Line: 50

                private static void assertHash(int seed, long expected1, long expected2, String stringInput) {
    HashCode expected = toHashCode(expected1, expected2);
    byte[] input = HashTestUtils.ascii(stringInput);
    assertEquals(expected, murmur3_128(seed).hashBytes(input));
    assertEquals(expected, murmur3_128(seed).newHasher().putBytes(input).hash());
  }

  /** Returns a {@link HashCode} for a sequence of longs, in big-endian order. */
  private static HashCode toHashCode(long... longs) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 50

                private static void assertHash(int seed, long expected1, long expected2, String stringInput) {
    HashCode expected = toHashCode(expected1, expected2);
    byte[] input = HashTestUtils.ascii(stringInput);
    assertEquals(expected, murmur3_128(seed).hashBytes(input));
    assertEquals(expected, murmur3_128(seed).newHasher().putBytes(input).hash());
  }

  /** Returns a {@link HashCode} for a sequence of longs, in big-endian order. */
  private static HashCode toHashCode(long... longs) {

            

Reported by PMD.

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

Line: 51

                  HashCode expected = toHashCode(expected1, expected2);
    byte[] input = HashTestUtils.ascii(stringInput);
    assertEquals(expected, murmur3_128(seed).hashBytes(input));
    assertEquals(expected, murmur3_128(seed).newHasher().putBytes(input).hash());
  }

  /** Returns a {@link HashCode} for a sequence of longs, in big-endian order. */
  private static HashCode toHashCode(long... longs) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[longs.length * 8]).order(ByteOrder.LITTLE_ENDIAN);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 51

                  HashCode expected = toHashCode(expected1, expected2);
    byte[] input = HashTestUtils.ascii(stringInput);
    assertEquals(expected, murmur3_128(seed).hashBytes(input));
    assertEquals(expected, murmur3_128(seed).newHasher().putBytes(input).hash());
  }

  /** Returns a {@link HashCode} for a sequence of longs, in big-endian order. */
  private static HashCode toHashCode(long... longs) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[longs.length * 8]).order(ByteOrder.LITTLE_ENDIAN);

            

Reported by PMD.

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

Line: 51

                  HashCode expected = toHashCode(expected1, expected2);
    byte[] input = HashTestUtils.ascii(stringInput);
    assertEquals(expected, murmur3_128(seed).hashBytes(input));
    assertEquals(expected, murmur3_128(seed).newHasher().putBytes(input).hash());
  }

  /** Returns a {@link HashCode} for a sequence of longs, in big-endian order. */
  private static HashCode toHashCode(long... longs) {
    ByteBuffer bb = ByteBuffer.wrap(new byte[longs.length * 8]).order(ByteOrder.LITTLE_ENDIAN);

            

Reported by PMD.

android/guava/src/com/google/common/cache/CacheStats.java
21 issues
This class has too many methods, consider refactoring it.
Design

Line: 61

               */
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class CacheStats {
  private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;


            

Reported by PMD.

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

Line: 62

              @GwtCompatible
@ElementTypesAreNonnullByDefault
public final class CacheStats {
  private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration

            

Reported by PMD.

Field hitCount has the same name as a method
Error

Line: 62

              @GwtCompatible
@ElementTypesAreNonnullByDefault
public final class CacheStats {
  private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration

            

Reported by PMD.

Field missCount has the same name as a method
Error

Line: 63

              @ElementTypesAreNonnullByDefault
public final class CacheStats {
  private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private final long totalLoadTime;

            

Reported by PMD.

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

Line: 63

              @ElementTypesAreNonnullByDefault
public final class CacheStats {
  private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private final long totalLoadTime;

            

Reported by PMD.

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

Line: 64

              public final class CacheStats {
  private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private final long totalLoadTime;


            

Reported by PMD.

Field loadSuccessCount has the same name as a method
Error

Line: 64

              public final class CacheStats {
  private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private final long totalLoadTime;


            

Reported by PMD.

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

Line: 65

                private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private final long totalLoadTime;

  private final long evictionCount;

            

Reported by PMD.

Field loadExceptionCount has the same name as a method
Error

Line: 65

                private final long hitCount;
  private final long missCount;
  private final long loadSuccessCount;
  private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private final long totalLoadTime;

  private final long evictionCount;

            

Reported by PMD.

Field totalLoadTime has the same name as a method
Error

Line: 68

                private final long loadExceptionCount;

  @SuppressWarnings("GoodTime") // should be a java.time.Duration
  private final long totalLoadTime;

  private final long evictionCount;

  /**
   * Constructs a new {@code CacheStats} instance.

            

Reported by PMD.