The following issues were found

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

Line: 49

              @SuppressWarnings("unchecked") // too many "unchecked generic array creations"
@GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddAll_supportedNothing() {
    assertFalse("addAll(nothing) should return false", collection.addAll(emptyCollection()));
    expectUnchanged();
  }

            

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

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class CollectionAddAllTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddAll_supportedNothing() {
    assertFalse("addAll(nothing) should return false", collection.addAll(emptyCollection()));
    expectUnchanged();
  }


            

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

                  expectUnchanged();
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  public void testAddAll_unsupportedNothing() {
    try {
      assertFalse(
          "addAll(nothing) should return false or throw", collection.addAll(emptyCollection()));
    } catch (UnsupportedOperationException tolerated) {

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 61

                  try {
      assertFalse(
          "addAll(nothing) should return false or throw", collection.addAll(emptyCollection()));
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
  }

  @CollectionFeature.Require(SUPPORTS_ADD)

            

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

                  expectUnchanged();
  }

  @CollectionFeature.Require(SUPPORTS_ADD)
  public void testAddAll_supportedNonePresent() {
    assertTrue(
        "addAll(nonePresent) should return true", collection.addAll(createDisjointCollection()));
    expectAdded(e3(), e4());
  }

            

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

                  expectAdded(e3(), e4());
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  public void testAddAll_unsupportedNonePresent() {
    try {
      collection.addAll(createDisjointCollection());
      fail("addAll(nonePresent) should throw");
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.

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

Line: 84

                  expectMissing(e3(), e4());
  }

  @CollectionFeature.Require(SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAll_supportedSomePresent() {
    assertTrue(
        "addAll(somePresent) should return true",
        collection.addAll(MinimalCollection.of(e3(), e0())));

            

Reported by PMD.

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

Line: 86

              
  @CollectionFeature.Require(SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAll_supportedSomePresent() {
    assertTrue(
        "addAll(somePresent) should return true",
        collection.addAll(MinimalCollection.of(e3(), e0())));
    assertTrue("should contain " + e3(), collection.contains(e3()));
    assertTrue("should contain " + e0(), collection.contains(e0()));

            

Reported by PMD.

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

Line: 94

                  assertTrue("should contain " + e0(), collection.contains(e0()));
  }

  @CollectionFeature.Require(absent = SUPPORTS_ADD)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAll_unsupportedSomePresent() {
    try {
      collection.addAll(MinimalCollection.of(e3(), e0()));
      fail("addAll(somePresent) should throw");

            

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

                  expectUnchanged();
  }

  @CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
  @CollectionSize.Require(absent = ZERO)
  public void testAddAllConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      assertTrue(collection.addAll(MinimalCollection.of(e3(), e0())));

            

Reported by PMD.

guava-tests/test/com/google/common/collect/ForwardingMultisetTest.java
19 issues
This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import com.google.common.base.Function;
import com.google.common.collect.Multiset.Entry;
import com.google.common.collect.testing.SetTestSuiteBuilder;
import com.google.common.collect.testing.TestStringSetGenerator;

            

Reported by PMD.

The class 'ForwardingMultisetTest' has a Standard Cyclomatic Complexity of 8 (Highest = 28).
Design

Line: 43

               * @author Hayward Chan
 * @author Louis Wasserman
 */
public class ForwardingMultisetTest extends TestCase {

  static final class StandardImplForwardingMultiset<T> extends ForwardingMultiset<T> {
    private final Multiset<T> backingCollection;

    StandardImplForwardingMultiset(Multiset<T> backingMultiset) {

            

Reported by PMD.

The class 'ForwardingMultisetTest' has a Modified Cyclomatic Complexity of 8 (Highest = 28).
Design

Line: 43

               * @author Hayward Chan
 * @author Louis Wasserman
 */
public class ForwardingMultisetTest extends TestCase {

  static final class StandardImplForwardingMultiset<T> extends ForwardingMultiset<T> {
    private final Multiset<T> backingCollection;

    StandardImplForwardingMultiset(Multiset<T> backingMultiset) {

            

Reported by PMD.

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

Line: 45

               */
public class ForwardingMultisetTest extends TestCase {

  static final class StandardImplForwardingMultiset<T> extends ForwardingMultiset<T> {
    private final Multiset<T> backingCollection;

    StandardImplForwardingMultiset(Multiset<T> backingMultiset) {
      this.backingCollection = backingMultiset;
    }

            

Reported by PMD.

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

Line: 46

              public class ForwardingMultisetTest extends TestCase {

  static final class StandardImplForwardingMultiset<T> extends ForwardingMultiset<T> {
    private final Multiset<T> backingCollection;

    StandardImplForwardingMultiset(Multiset<T> backingMultiset) {
      this.backingCollection = backingMultiset;
    }


            

Reported by PMD.

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

Line: 158

                  }
  }

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

    suite.addTestSuite(ForwardingMultisetTest.class);
    suite.addTest(
        MultisetTestSuiteBuilder.using(

            

Reported by PMD.

Avoid really long methods.
Design

Line: 158

                  }
  }

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

    suite.addTestSuite(ForwardingMultisetTest.class);
    suite.addTest(
        MultisetTestSuiteBuilder.using(

            

Reported by PMD.

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

Line: 158

                  }
  }

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

    suite.addTestSuite(ForwardingMultisetTest.class);
    suite.addTest(
        MultisetTestSuiteBuilder.using(

            

Reported by PMD.

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

Line: 158

                  }
  }

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

    suite.addTestSuite(ForwardingMultisetTest.class);
    suite.addTest(
        MultisetTestSuiteBuilder.using(

            

Reported by PMD.

The method 'create' has a Standard Cyclomatic Complexity of 25.
Design

Line: 199

                                 * specifically authorized by the elementSet() or hashCode() docs.
                   */
                  @Override
                  protected Set<String> create(String[] elements) {
                    final Multiset<String> inner =
                        LinkedHashMultiset.create(Arrays.asList(elements));
                    return new ForwardingMultiset<String>() {
                      @Override
                      protected Multiset<String> delegate() {

            

Reported by PMD.

guava-tests/benchmark/com/google/common/util/concurrent/FuturesGetCheckedBenchmark.java
19 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 102

                        TooManyListenersException.class,
          URISyntaxException.class);

  @Param Validator validator;
  @Param Result result;
  @Param ExceptionType exceptionType;
  /**
   * The number of other exception types in the cache of known-good exceptions and the number of
   * other {@code ClassValue} entries for the exception type to be tested. This lets us evaluate

            

Reported by PMD.

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

Line: 103

                        URISyntaxException.class);

  @Param Validator validator;
  @Param Result result;
  @Param ExceptionType exceptionType;
  /**
   * The number of other exception types in the cache of known-good exceptions and the number of
   * other {@code ClassValue} entries for the exception type to be tested. This lets us evaluate
   * whether our solution scales to use with multiple exception types and to whether it is affected

            

Reported by PMD.

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

Line: 104

              
  @Param Validator validator;
  @Param Result result;
  @Param ExceptionType exceptionType;
  /**
   * The number of other exception types in the cache of known-good exceptions and the number of
   * other {@code ClassValue} entries for the exception type to be tested. This lets us evaluate
   * whether our solution scales to use with multiple exception types and to whether it is affected
   * by other {@code ClassValue} users. Some of the benchmarked implementations don't use one or

            

Reported by PMD.

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

Line: 113

                 * both of these mechanisms, so they will be unaffected.
   */
  @Param({"0", "1", "12"})
  int otherEntriesInDataStructure;

  final List<ClassValue<?>> retainedReferencesToOtherClassValues = newArrayList();

  @BeforeExperiment
  void addOtherEntries() throws Exception {

            

Reported by PMD.

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

Line: 115

                @Param({"0", "1", "12"})
  int otherEntriesInDataStructure;

  final List<ClassValue<?>> retainedReferencesToOtherClassValues = newArrayList();

  @BeforeExperiment
  void addOtherEntries() throws Exception {
    GetCheckedTypeValidator validator = this.validator.validator;
    Class<? extends Exception> exceptionType = this.exceptionType.exceptionType;

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 118

                final List<ClassValue<?>> retainedReferencesToOtherClassValues = newArrayList();

  @BeforeExperiment
  void addOtherEntries() throws Exception {
    GetCheckedTypeValidator validator = this.validator.validator;
    Class<? extends Exception> exceptionType = this.exceptionType.exceptionType;

    for (Class<? extends Exception> exceptionClass :
        OTHER_EXCEPTION_TYPES.asList().subList(0, otherEntriesInDataStructure)) {

            

Reported by PMD.

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

Line: 123

                  Class<? extends Exception> exceptionType = this.exceptionType.exceptionType;

    for (Class<? extends Exception> exceptionClass :
        OTHER_EXCEPTION_TYPES.asList().subList(0, otherEntriesInDataStructure)) {
      getChecked(validator, immediateFuture(""), exceptionClass);
    }

    for (int i = 0; i < otherEntriesInDataStructure; i++) {
      ClassValue<Boolean> classValue =

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 129

              
    for (int i = 0; i < otherEntriesInDataStructure; i++) {
      ClassValue<Boolean> classValue =
          new ClassValue<Boolean>() {
            @Override
            protected Boolean computeValue(Class<?> type) {
              return true;
            }
          };

            

Reported by PMD.

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

Line: 148

                  Class<? extends Exception> exceptionType = this.exceptionType.exceptionType;
    for (int i = 0; i < reps; ++i) {
      try {
        tmp += getChecked(validator, future, exceptionType).hashCode();
      } catch (Exception e) {
        tmp += e.hashCode();
      }
    }
    return tmp;

            

Reported by PMD.

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

Line: 149

                  for (int i = 0; i < reps; ++i) {
      try {
        tmp += getChecked(validator, future, exceptionType).hashCode();
      } catch (Exception e) {
        tmp += e.hashCode();
      }
    }
    return tmp;
  }

            

Reported by PMD.

guava-tests/test/com/google/common/graph/MapCacheTest.java
19 issues
Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 84

              
  @Test
  public void testRemoveEqualKeyWithDifferentReference() {
    String fooReference1 = new String("foo");
    String fooReference2 = new String("foo");
    assertThat(fooReference1).isNotSameInstanceAs(fooReference2);

    assertThat(mapCache.put(fooReference1, "bar")).isNull();
    assertThat(mapCache.get(fooReference1)).isEqualTo("bar"); // ensure first reference is cached

            

Reported by PMD.

Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 85

                @Test
  public void testRemoveEqualKeyWithDifferentReference() {
    String fooReference1 = new String("foo");
    String fooReference2 = new String("foo");
    assertThat(fooReference1).isNotSameInstanceAs(fooReference2);

    assertThat(mapCache.put(fooReference1, "bar")).isNull();
    assertThat(mapCache.get(fooReference1)).isEqualTo("bar"); // ensure first reference is cached
    assertThat(mapCache.remove(fooReference2)).isEqualTo("bar");

            

Reported by PMD.

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

Line: 38

              // TODO(cpovirk): Figure out Android JUnit 4 support. Does it work with Gingerbread? @RunWith?
@RunWith(Parameterized.class)
public final class MapCacheTest {
  private final MapIteratorCache<String, String> mapCache;

  public MapCacheTest(MapIteratorCache<String, String> mapCache) {
    this.mapCache = mapCache;
  }


            

Reported by PMD.

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

Line: 46

              
  @Parameters
  public static Collection<Object[]> parameters() {
    Comparator<String> nullsLast = Ordering.natural().nullsLast();

    return Arrays.asList(
        new Object[][] {
          {new MapIteratorCache<String, String>(new HashMap<String, String>())},
          {new MapIteratorCache<String, String>(new TreeMap<String, String>(nullsLast))},

            

Reported by PMD.

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

Line: 63

                }

  @Test
  public void testKeySetIterator() {
    mapCache.put("A", "A_value");
    mapCache.put("B", "B_value");
    mapCache.put("C", "C_value");

    assertThat(mapCache.unmodifiableKeySet()).hasSize(3);

            

Reported by PMD.

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

Line: 68

                  mapCache.put("B", "B_value");
    mapCache.put("C", "C_value");

    assertThat(mapCache.unmodifiableKeySet()).hasSize(3);
    for (String key : mapCache.unmodifiableKeySet()) {
      assertThat(mapCache.get(key)).isEqualTo(key + "_value");
    }
  }


            

Reported by PMD.

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

Line: 70

              
    assertThat(mapCache.unmodifiableKeySet()).hasSize(3);
    for (String key : mapCache.unmodifiableKeySet()) {
      assertThat(mapCache.get(key)).isEqualTo(key + "_value");
    }
  }

  @Test
  public void testPutNewValue() {

            

Reported by PMD.

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

Line: 75

                }

  @Test
  public void testPutNewValue() {
    assertThat(mapCache.put("key", "value")).isNull();
    assertThat(mapCache.get("key")).isEqualTo("value"); // ensure key/value is cached
    assertThat(mapCache.put("key", "new value")).isEqualTo("value");
    assertThat(mapCache.get("key")).isEqualTo("new value");
  }

            

Reported by PMD.

The String literal 'key' appears 4 times in this file; the first occurrence is on line 76
Error

Line: 76

              
  @Test
  public void testPutNewValue() {
    assertThat(mapCache.put("key", "value")).isNull();
    assertThat(mapCache.get("key")).isEqualTo("value"); // ensure key/value is cached
    assertThat(mapCache.put("key", "new value")).isEqualTo("value");
    assertThat(mapCache.get("key")).isEqualTo("new value");
  }


            

Reported by PMD.

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

Line: 76

              
  @Test
  public void testPutNewValue() {
    assertThat(mapCache.put("key", "value")).isNull();
    assertThat(mapCache.get("key")).isEqualTo("value"); // ensure key/value is cached
    assertThat(mapCache.put("key", "new value")).isEqualTo("value");
    assertThat(mapCache.get("key")).isEqualTo("new value");
  }


            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/CollectionRemoveTester.java
18 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 CollectionRemoveTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_present() {
    int initialSize = collection.size();
    assertTrue("remove(present) should return true", collection.remove(e0()));
    assertEquals(

            

Reported by PMD.

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

Line: 47

              public class CollectionRemoveTester<E> extends AbstractCollectionTester<E> {
  @CollectionFeature.Require(SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_present() {
    int initialSize = collection.size();
    assertTrue("remove(present) should return true", collection.remove(e0()));
    assertEquals(
        "remove(present) should decrease a collection's size by one.",
        initialSize - 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: 57

                  expectMissing(e0());
  }

  @CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
  @CollectionSize.Require(SEVERAL)
  public void testRemovePresentConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      assertTrue(collection.remove(e0()));

            

Reported by PMD.

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

Line: 70

                  }
  }

  @CollectionFeature.Require(SUPPORTS_REMOVE)
  public void testRemove_notPresent() {
    assertFalse("remove(notPresent) should return false", collection.remove(e3()));
    expectUnchanged();
  }


            

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

                  expectUnchanged();
  }

  @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_nullPresent() {
    collection = getSubjectGenerator().create(createArrayWithNullElement());

    int initialSize = collection.size();

            

Reported by PMD.

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

Line: 78

              
  @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_nullPresent() {
    collection = getSubjectGenerator().create(createArrayWithNullElement());

    int initialSize = collection.size();
    assertTrue("remove(null) should return true", collection.remove(null));
    assertEquals(

            

Reported by PMD.

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

Line: 79

                @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_nullPresent() {
    collection = getSubjectGenerator().create(createArrayWithNullElement());

    int initialSize = collection.size();
    assertTrue("remove(null) should return true", collection.remove(null));
    assertEquals(
        "remove(present) should decrease a collection's size by one.",

            

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

                  expectMissing((E) null);
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  @CollectionSize.Require(absent = ZERO)
  public void testRemove_unsupported() {
    try {
      collection.remove(e0());
      fail("remove(present) should throw UnsupportedOperationException");

            

Reported by PMD.

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

Line: 102

                  assertTrue("remove(present) should not remove the element", collection.contains(e0()));
  }

  @CollectionFeature.Require(absent = SUPPORTS_REMOVE)
  public void testRemove_unsupportedNotPresent() {
    try {
      assertFalse(
          "remove(notPresent) should return false or throw UnsupportedOperationException",
          collection.remove(e3()));

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 108

                    assertFalse(
          "remove(notPresent) should return false or throw UnsupportedOperationException",
          collection.remove(e3()));
    } catch (UnsupportedOperationException tolerated) {
    }
    expectUnchanged();
    expectMissing(e3());
  }


            

Reported by PMD.

guava-testlib/test/com/google/common/testing/SerializableTesterTest.java
18 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

               * @author Nick Kralevich
 */
public class SerializableTesterTest extends TestCase {
  public void testStringAssertions() {
    String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

            

Reported by PMD.

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

Line: 29

               * @author Nick Kralevich
 */
public class SerializableTesterTest extends TestCase {
  public void testStringAssertions() {
    String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 32

                public void testStringAssertions() {
    String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                  String original = "hello world";
    String copy = SerializableTester.reserializeAndAssert(original);
    assertEquals(original, copy);
    assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();
    boolean errorNotThrown = false;

            

Reported by PMD.

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

Line: 36

                  assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);
      errorNotThrown = true;

            

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

                  assertNotSame(original, copy);
  }

  public void testClassWhichDoesNotImplementEquals() {
    ClassWhichDoesNotImplementEquals orig = new ClassWhichDoesNotImplementEquals();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);
      errorNotThrown = true;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 46

                    // expected
      assertContains("must be Object#equals to", error.getMessage());
    }
    assertFalse(errorNotThrown);
  }

  public void testClassWhichIsAlwaysEqualButHasDifferentHashcodes() {
    ClassWhichIsAlwaysEqualButHasDifferentHashcodes orig =
        new ClassWhichIsAlwaysEqualButHasDifferentHashcodes();

            

Reported by PMD.

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

Line: 49

                  assertFalse(errorNotThrown);
  }

  public void testClassWhichIsAlwaysEqualButHasDifferentHashcodes() {
    ClassWhichIsAlwaysEqualButHasDifferentHashcodes orig =
        new ClassWhichIsAlwaysEqualButHasDifferentHashcodes();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);

            

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

                  assertFalse(errorNotThrown);
  }

  public void testClassWhichIsAlwaysEqualButHasDifferentHashcodes() {
    ClassWhichIsAlwaysEqualButHasDifferentHashcodes orig =
        new ClassWhichIsAlwaysEqualButHasDifferentHashcodes();
    boolean errorNotThrown = false;
    try {
      SerializableTester.reserializeAndAssert(orig);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 60

                    // expected
      assertContains("must be equal to the Object#hashCode", error.getMessage());
    }
    assertFalse(errorNotThrown);
  }

  public void testObjectWhichIsEqualButChangesClass() {
    ObjectWhichIsEqualButChangesClass orig = new ObjectWhichIsEqualButChangesClass();
    boolean errorNotThrown = false;

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/testers/MapReplaceAllTester.java
18 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: 52

                  return new SampleElements<V>(v0(), v1(), v2(), v3(), v4());
  }

  @MapFeature.Require(SUPPORTS_PUT)
  public void testReplaceAllRotate() {
    getMap()
        .replaceAll(
            (K k, V v) -> {
              int index = keys().asList().indexOf(k);

            

Reported by PMD.

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

Line: 54

              
  @MapFeature.Require(SUPPORTS_PUT)
  public void testReplaceAllRotate() {
    getMap()
        .replaceAll(
            (K k, V v) -> {
              int index = keys().asList().indexOf(k);
              return values().asList().get(index + 1);
            });

            

Reported by PMD.

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

Line: 62

                          });
    List<Entry<K, V>> expectedEntries = new ArrayList<>();
    for (Entry<K, V> entry : getSampleEntries()) {
      int index = keys().asList().indexOf(entry.getKey());
      expectedEntries.add(Helpers.mapEntry(entry.getKey(), values().asList().get(index + 1)));
    }
    expectContents(expectedEntries);
  }


            

Reported by PMD.

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

Line: 62

                          });
    List<Entry<K, V>> expectedEntries = new ArrayList<>();
    for (Entry<K, V> entry : getSampleEntries()) {
      int index = keys().asList().indexOf(entry.getKey());
      expectedEntries.add(Helpers.mapEntry(entry.getKey(), values().asList().get(index + 1)));
    }
    expectContents(expectedEntries);
  }


            

Reported by PMD.

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

Line: 63

                  List<Entry<K, V>> expectedEntries = new ArrayList<>();
    for (Entry<K, V> entry : getSampleEntries()) {
      int index = keys().asList().indexOf(entry.getKey());
      expectedEntries.add(Helpers.mapEntry(entry.getKey(), values().asList().get(index + 1)));
    }
    expectContents(expectedEntries);
  }

  @MapFeature.Require(SUPPORTS_PUT)

            

Reported by PMD.

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

Line: 63

                  List<Entry<K, V>> expectedEntries = new ArrayList<>();
    for (Entry<K, V> entry : getSampleEntries()) {
      int index = keys().asList().indexOf(entry.getKey());
      expectedEntries.add(Helpers.mapEntry(entry.getKey(), values().asList().get(index + 1)));
    }
    expectContents(expectedEntries);
  }

  @MapFeature.Require(SUPPORTS_PUT)

            

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

                  expectContents(expectedEntries);
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionFeature.Require(KNOWN_ORDER)
  public void testReplaceAllPreservesOrder() {
    getMap()
        .replaceAll(
            (K k, V v) -> {

            

Reported by PMD.

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

Line: 71

                @MapFeature.Require(SUPPORTS_PUT)
  @CollectionFeature.Require(KNOWN_ORDER)
  public void testReplaceAllPreservesOrder() {
    getMap()
        .replaceAll(
            (K k, V v) -> {
              int index = keys().asList().indexOf(k);
              return values().asList().get(index + 1);
            });

            

Reported by PMD.

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

Line: 79

                          });
    List<Entry<K, V>> orderedEntries = getOrderedElements();
    int index = 0;
    for (K key : getMap().keySet()) {
      assertEquals(orderedEntries.get(index).getKey(), key);
      index++;
    }
  }


            

Reported by PMD.

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

Line: 80

                  List<Entry<K, V>> orderedEntries = getOrderedElements();
    int index = 0;
    for (K key : getMap().keySet()) {
      assertEquals(orderedEntries.get(index).getKey(), key);
      index++;
    }
  }

  @MapFeature.Require(absent = SUPPORTS_PUT)

            

Reported by PMD.

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

Line: 39

               * @author Michael Lancaster
 */
public class CloseablesTest extends TestCase {
  private Closeable mockCloseable;

  public void testClose_closeableClean() throws IOException {
    // make sure that no exception is thrown regardless of value of
    // 'swallowException' when the mock does not throw an exception.
    setupCloseable(false);

            

Reported by PMD.

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

Line: 41

              public class CloseablesTest extends TestCase {
  private Closeable mockCloseable;

  public void testClose_closeableClean() throws IOException {
    // make sure that no exception is thrown regardless of value of
    // 'swallowException' when the mock does not throw an exception.
    setupCloseable(false);
    doClose(mockCloseable, false, 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: 41

              public class CloseablesTest extends TestCase {
  private Closeable mockCloseable;

  public void testClose_closeableClean() throws IOException {
    // make sure that no exception is thrown regardless of value of
    // 'swallowException' when the mock does not throw an exception.
    setupCloseable(false);
    doClose(mockCloseable, false, false);


            

Reported by PMD.

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

Line: 51

                  doClose(mockCloseable, true, false);
  }

  public void testClose_closeableWithEatenException() throws IOException {
    // make sure that no exception is thrown if 'swallowException' is true
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, true);
  }

            

Reported by PMD.

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

Line: 51

                  doClose(mockCloseable, true, false);
  }

  public void testClose_closeableWithEatenException() throws IOException {
    // make sure that no exception is thrown if 'swallowException' is true
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, true);
  }

            

Reported by PMD.

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

Line: 58

                  doClose(mockCloseable, true);
  }

  public void testClose_closeableWithThrownException() throws IOException {
    // make sure that the exception is thrown if 'swallowException' is false
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, false);
  }

            

Reported by PMD.

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

Line: 58

                  doClose(mockCloseable, true);
  }

  public void testClose_closeableWithThrownException() throws IOException {
    // make sure that the exception is thrown if 'swallowException' is false
    // when the mock does throw an exception.
    setupCloseable(true);
    doClose(mockCloseable, 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: 65

                  doClose(mockCloseable, false);
  }

  public void testCloseQuietly_inputStreamWithEatenException() throws IOException {
    TestInputStream in =
        new TestInputStream(new ByteArrayInputStream(new byte[1]), TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);
    assertTrue(in.closed());
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 69

                  TestInputStream in =
        new TestInputStream(new ByteArrayInputStream(new byte[1]), TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);
    assertTrue(in.closed());
  }

  public void testCloseQuietly_readerWithEatenException() throws IOException {
    TestReader in = new TestReader(TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);

            

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

                  assertTrue(in.closed());
  }

  public void testCloseQuietly_readerWithEatenException() throws IOException {
    TestReader in = new TestReader(TestOption.CLOSE_THROWS);
    Closeables.closeQuietly(in);
    assertTrue(in.closed());
  }


            

Reported by PMD.

guava-tests/test/com/google/common/io/IoTestCase.java
18 issues
Avoid throwing raw exception types.
Design

Line: 72

              
    URL testFileUrl = IoTestCase.class.getResource("testdata/i18n.txt");
    if (testFileUrl == null) {
      throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());

            

Reported by PMD.

Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 159

                private static void copy(URL url, File file) throws IOException {
    InputStream in = url.openStream();
    try {
      OutputStream out = new FileOutputStream(file);
      try {
        byte[] buf = new byte[4096];
        for (int read = in.read(buf); read != -1; read = in.read(buf)) {
          out.write(buf, 0, read);
        }

            

Reported by PMD.

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

Line: 50

                    " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
          + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

  private File testDir;
  private File tempDir;

  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override

            

Reported by PMD.

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

Line: 51

                        + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

  private File testDir;
  private File tempDir;

  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override
  protected void tearDown() {

            

Reported by PMD.

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

Line: 53

                private File testDir;
  private File tempDir;

  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override
  protected void tearDown() {
    for (File file : filesToDelete) {
      if (file.exists()) {

            

Reported by PMD.

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

Line: 55

              
  private final Set<File> filesToDelete = Sets.newHashSet();

  @Override
  protected void tearDown() {
    for (File file : filesToDelete) {
      if (file.exists()) {
        delete(file);
      }

            

Reported by PMD.

Position literals first in String comparisons
Design

Line: 75

                    throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException

            

Reported by PMD.

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

Line: 75

                    throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException

            

Reported by PMD.

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

Line: 75

                    throw new RuntimeException("unable to locate testdata directory");
    }

    if (testFileUrl.getProtocol().equals("file")) {
      try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException

            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 79

                    try {
        File testFile = new File(testFileUrl.toURI());
        testDir = testFile.getParentFile(); // the testdata directory
      } catch (Exception ignore) {
        // probably URISyntaxException or IllegalArgumentException
        // fall back to copying URLs to files in the testDir == null block below
      }
    }


            

Reported by PMD.

android/guava/src/com/google/common/collect/TreeBasedTable.java
18 issues
Overridable method 'compare' called during object construction
Error

Line: 190

                    this.lowerBound = lowerBound;
      this.upperBound = upperBound;
      checkArgument(
          lowerBound == null || upperBound == null || compare(lowerBound, upperBound) <= 0);
    }

    @Override
    public SortedSet<C> keySet() {
      return new Maps.SortedKeySet<>(this);

            

Reported by PMD.

Field columnComparator has the same name as a method
Error

Line: 72

              @GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
public class TreeBasedTable<R, C, V> extends StandardRowSortedTable<R, C, V> {
  private final Comparator<? super C> columnComparator;

  private static class Factory<C, V> implements Supplier<TreeMap<C, V>>, Serializable {
    final Comparator<? super C> comparator;

    Factory(Comparator<? super C> comparator) {

            

Reported by PMD.

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

Line: 72

              @GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
public class TreeBasedTable<R, C, V> extends StandardRowSortedTable<R, C, V> {
  private final Comparator<? super C> columnComparator;

  private static class Factory<C, V> implements Supplier<TreeMap<C, V>>, Serializable {
    final Comparator<? super C> comparator;

    Factory(Comparator<? super C> comparator) {

            

Reported by PMD.

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

Line: 75

                private final Comparator<? super C> columnComparator;

  private static class Factory<C, V> implements Supplier<TreeMap<C, V>>, Serializable {
    final Comparator<? super C> comparator;

    Factory(Comparator<? super C> comparator) {
      this.comparator = comparator;
    }


            

Reported by PMD.

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

Line: 144

                   * requireNonNull is safe because the factories require non-null Comparators, which they pass on
     * to the backing collections.
     */
    return requireNonNull(rowKeySet().comparator());
  }

  /**
   * Returns the comparator that orders the columns. With natural ordering, {@link
   * Ordering#natural()} is returned.

            

Reported by PMD.

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

Line: 177

                  return new TreeRow(rowKey);
  }

  private class TreeRow extends Row implements SortedMap<C, V> {
    @CheckForNull final C lowerBound;
    @CheckForNull final C upperBound;

    TreeRow(R rowKey) {
      this(rowKey, null, null);

            

Reported by PMD.

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

Line: 178

                }

  private class TreeRow extends Row implements SortedMap<C, V> {
    @CheckForNull final C lowerBound;
    @CheckForNull final C upperBound;

    TreeRow(R rowKey) {
      this(rowKey, null, null);
    }

            

Reported by PMD.

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

Line: 179

              
  private class TreeRow extends Row implements SortedMap<C, V> {
    @CheckForNull final C lowerBound;
    @CheckForNull final C upperBound;

    TreeRow(R rowKey) {
      this(rowKey, null, null);
    }


            

Reported by PMD.

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

Line: 207

                    // pretend we can compare anything
      @SuppressWarnings("unchecked")
      Comparator<Object> cmp = (Comparator<Object>) comparator();
      return cmp.compare(a, b);
    }

    boolean rangeContains(@CheckForNull Object o) {
      return o != null
          && (lowerBound == null || compare(lowerBound, o) <= 0)

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 283

                    updateWholeRowField();
      if (wholeRow != null && wholeRow.isEmpty()) {
        backingMap.remove(rowKey);
        wholeRow = null;
        backingRowMap = null;
      }
    }

    @Override

            

Reported by PMD.