The following issues were found

android/guava-tests/test/com/google/common/collect/InternersTest.java
61 issues
Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 36

              
  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

            

Reported by PMD.

Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 62

              
  public void testWeak_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newWeakInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 89

              

  public void testWeak_afterGC() throws InterruptedException {
    Integer canonical = new Integer(5);
    Integer not = new Integer(5);

    Interner<Integer> pool = Interners.newWeakInterner();
    assertSame(canonical, pool.intern(canonical));


            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 90

              
  public void testWeak_afterGC() throws InterruptedException {
    Integer canonical = new Integer(5);
    Integer not = new Integer(5);

    Interner<Integer> pool = Interners.newWeakInterner();
    assertSame(canonical, pool.intern(canonical));

    WeakReference<Integer> signal = new WeakReference<>(canonical);

            

Reported by PMD.

Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 104

              
  public void testAsFunction_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Function<String, String> internerFunction =
        Interners.asFunction(Interners.<String>newStrongInterner());

    assertSame(canonical, internerFunction.apply(canonical));

            

Reported by PMD.

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

Line: 32

               *
 * @author Kevin Bourrillion
 */
public class InternersTest extends TestCase {

  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");


            

Reported by PMD.

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

Line: 34

               */
public class InternersTest extends TestCase {

  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));

            

Reported by PMD.

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

Line: 34

               */
public class InternersTest extends TestCase {

  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));

            

Reported by PMD.

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

Line: 39

                  String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

  public void testStrong_null() {
    Interner<String> pool = Interners.newStrongInterner();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

  public void testStrong_null() {
    Interner<String> pool = Interners.newStrongInterner();

            

Reported by PMD.

guava/src/com/google/common/collect/Multimaps.java
61 issues
A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static com.google.common.collect.CollectPreconditions.checkRemove;
import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT;

            

Reported by PMD.

This class has a bunch of public methods and attributes
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static com.google.common.collect.CollectPreconditions.checkRemove;
import static com.google.common.collect.NullnessCasts.uncheckedCastNullableTToT;

            

Reported by PMD.

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

Line: 77

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Multimaps {
  private Multimaps() {}

  /**
   * Returns a {@code Collector} accumulating entries into a {@code Multimap} generated from the
   * specified supplier. The keys and values of the entries are the result of applying the provided

            

Reported by PMD.

Avoid really long classes.
Design

Line: 77

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Multimaps {
  private Multimaps() {}

  /**
   * Returns a {@code Collector} accumulating entries into a {@code Multimap} generated from the
   * specified supplier. The keys and values of the entries are the result of applying the provided

            

Reported by PMD.

Possible God Class (WMC=67, ATFD=7, TCC=0.000%)
Design

Line: 77

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Multimaps {
  private Multimaps() {}

  /**
   * Returns a {@code Collector} accumulating entries into a {@code Multimap} generated from the
   * specified supplier. The keys and values of the entries are the result of applying the provided

            

Reported by PMD.

The String literal 'unchecked' appears 11 times in this file; the first occurrence is on line 282
Error

Line: 282

                  }

    @GwtIncompatible // java.io.ObjectInputStream
    @SuppressWarnings("unchecked") // reading data stored by writeObject
    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
      stream.defaultReadObject();
      factory = (Supplier<? extends Collection<V>>) stream.readObject();
      Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject();
      setMap(map);

            

Reported by PMD.

Field valueComparator has the same name as a method
Error

Line: 517

                        K extends @Nullable Object, V extends @Nullable Object>
      extends AbstractSortedSetMultimap<K, V> {
    transient Supplier<? extends SortedSet<V>> factory;
    @CheckForNull transient Comparator<? super V> valueComparator;

    CustomSortedSetMultimap(Map<K, Collection<V>> map, Supplier<? extends SortedSet<V>> factory) {
      super(map);
      this.factory = checkNotNull(factory);
      valueComparator = factory.get().comparator();

            

Reported by PMD.

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

Line: 559

                  private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
      stream.defaultReadObject();
      factory = (Supplier<? extends SortedSet<V>>) stream.readObject();
      valueComparator = factory.get().comparator();
      Map<K, Collection<V>> map = (Map<K, Collection<V>>) stream.readObject();
      setMap(map);
    }

    @GwtIncompatible // not needed in emulated source

            

Reported by PMD.

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

Line: 657

                }

  private static class UnmodifiableMultimap<K extends @Nullable Object, V extends @Nullable Object>
      extends ForwardingMultimap<K, V> implements Serializable {
    final Multimap<K, V> delegate;
    @LazyInit @CheckForNull transient Collection<Entry<K, V>> entries;
    @LazyInit @CheckForNull transient Multiset<K> keys;
    @LazyInit @CheckForNull transient Set<K> keySet;
    @LazyInit @CheckForNull transient Collection<V> values;

            

Reported by PMD.

Field delegate has the same name as a method
Error

Line: 658

              
  private static class UnmodifiableMultimap<K extends @Nullable Object, V extends @Nullable Object>
      extends ForwardingMultimap<K, V> implements Serializable {
    final Multimap<K, V> delegate;
    @LazyInit @CheckForNull transient Collection<Entry<K, V>> entries;
    @LazyInit @CheckForNull transient Multiset<K> keys;
    @LazyInit @CheckForNull transient Set<K> keySet;
    @LazyInit @CheckForNull transient Collection<V> values;
    @LazyInit @CheckForNull transient Map<K, Collection<V>> map;

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java
61 issues
No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 310

                  }
  }

  public abstract static class TestUnhashableSetGenerator
      extends TestUnhashableCollectionGenerator<Set<UnhashableObject>>
      implements TestSetGenerator<UnhashableObject> {}

  private static Ordering<String> createExplicitComparator(String[] elements) {
    // Collapse equal elements, which Ordering.explicit() doesn't support, while

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect.testing.google;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newTreeSet;
import static com.google.common.collect.testing.SampleElements.Strings.AFTER_LAST;

            

Reported by PMD.

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

Line: 86

                  @Override
    protected Set<String> create(String[] elements) {
      ImmutableSet.Builder<String> builder =
          ImmutableSet.builderWithExpectedSize(Sets.newHashSet(elements).size());
      for (String e : elements) {
        builder.add(e);
      }
      return builder.build();
    }

            

Reported by PMD.

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

Line: 98

                  @Override
    protected Set<String> create(String[] elements) {
      ImmutableSet.Builder<String> builder =
          ImmutableSet.builderWithExpectedSize(Sets.newHashSet(elements).size() + 1);
      for (String e : elements) {
        builder.add(e);
      }
      return builder.build();
    }

            

Reported by PMD.

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

Line: 110

                  @Override
    protected Set<String> create(String[] elements) {
      ImmutableSet.Builder<String> builder =
          ImmutableSet.builderWithExpectedSize(Math.max(0, Sets.newHashSet(elements).size() - 1));
      for (String e : elements) {
        builder.add(e);
      }
      return builder.build();
    }

            

Reported by PMD.

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

Line: 150

                  @Override
    protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("zzz");
      return ImmutableSortedSet.copyOf(list).headSet("zzy");
    }
  }

  public static class ImmutableSortedSetTailsetGenerator extends TestStringSortedSetGenerator {

            

Reported by PMD.

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

Line: 151

                  protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("zzz");
      return ImmutableSortedSet.copyOf(list).headSet("zzy");
    }
  }

  public static class ImmutableSortedSetTailsetGenerator extends TestStringSortedSetGenerator {
    @Override

            

Reported by PMD.

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

Line: 159

                  @Override
    protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("\0");
      return ImmutableSortedSet.copyOf(list).tailSet("\0\0");
    }
  }

  public static class ImmutableSortedSetSubsetGenerator extends TestStringSortedSetGenerator {

            

Reported by PMD.

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

Line: 160

                  protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("\0");
      return ImmutableSortedSet.copyOf(list).tailSet("\0\0");
    }
  }

  public static class ImmutableSortedSetSubsetGenerator extends TestStringSortedSetGenerator {
    @Override

            

Reported by PMD.

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

Line: 168

                  @Override
    protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("\0");
      list.add("zzz");
      return ImmutableSortedSet.copyOf(list).subSet("\0\0", "zzy");
    }
  }


            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/SetGenerators.java
61 issues
No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 310

                  }
  }

  public abstract static class TestUnhashableSetGenerator
      extends TestUnhashableCollectionGenerator<Set<UnhashableObject>>
      implements TestSetGenerator<UnhashableObject> {}

  private static Ordering<String> createExplicitComparator(String[] elements) {
    // Collapse equal elements, which Ordering.explicit() doesn't support, while

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.collect.testing.google;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newTreeSet;
import static com.google.common.collect.testing.SampleElements.Strings.AFTER_LAST;

            

Reported by PMD.

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

Line: 86

                  @Override
    protected Set<String> create(String[] elements) {
      ImmutableSet.Builder<String> builder =
          ImmutableSet.builderWithExpectedSize(Sets.newHashSet(elements).size());
      for (String e : elements) {
        builder.add(e);
      }
      return builder.build();
    }

            

Reported by PMD.

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

Line: 98

                  @Override
    protected Set<String> create(String[] elements) {
      ImmutableSet.Builder<String> builder =
          ImmutableSet.builderWithExpectedSize(Sets.newHashSet(elements).size() + 1);
      for (String e : elements) {
        builder.add(e);
      }
      return builder.build();
    }

            

Reported by PMD.

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

Line: 110

                  @Override
    protected Set<String> create(String[] elements) {
      ImmutableSet.Builder<String> builder =
          ImmutableSet.builderWithExpectedSize(Math.max(0, Sets.newHashSet(elements).size() - 1));
      for (String e : elements) {
        builder.add(e);
      }
      return builder.build();
    }

            

Reported by PMD.

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

Line: 150

                  @Override
    protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("zzz");
      return ImmutableSortedSet.copyOf(list).headSet("zzy");
    }
  }

  public static class ImmutableSortedSetTailsetGenerator extends TestStringSortedSetGenerator {

            

Reported by PMD.

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

Line: 151

                  protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("zzz");
      return ImmutableSortedSet.copyOf(list).headSet("zzy");
    }
  }

  public static class ImmutableSortedSetTailsetGenerator extends TestStringSortedSetGenerator {
    @Override

            

Reported by PMD.

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

Line: 159

                  @Override
    protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("\0");
      return ImmutableSortedSet.copyOf(list).tailSet("\0\0");
    }
  }

  public static class ImmutableSortedSetSubsetGenerator extends TestStringSortedSetGenerator {

            

Reported by PMD.

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

Line: 160

                  protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("\0");
      return ImmutableSortedSet.copyOf(list).tailSet("\0\0");
    }
  }

  public static class ImmutableSortedSetSubsetGenerator extends TestStringSortedSetGenerator {
    @Override

            

Reported by PMD.

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

Line: 168

                  @Override
    protected SortedSet<String> create(String[] elements) {
      List<String> list = Lists.newArrayList(elements);
      list.add("\0");
      list.add("zzz");
      return ImmutableSortedSet.copyOf(list).subSet("\0\0", "zzy");
    }
  }


            

Reported by PMD.

guava-tests/test/com/google/common/collect/InternersTest.java
61 issues
Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 36

              
  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

            

Reported by PMD.

Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 62

              
  public void testWeak_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newWeakInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 89

              

  public void testWeak_afterGC() throws InterruptedException {
    Integer canonical = new Integer(5);
    Integer not = new Integer(5);

    Interner<Integer> pool = Interners.newWeakInterner();
    assertSame(canonical, pool.intern(canonical));


            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 90

              
  public void testWeak_afterGC() throws InterruptedException {
    Integer canonical = new Integer(5);
    Integer not = new Integer(5);

    Interner<Integer> pool = Interners.newWeakInterner();
    assertSame(canonical, pool.intern(canonical));

    WeakReference<Integer> signal = new WeakReference<>(canonical);

            

Reported by PMD.

Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 104

              
  public void testAsFunction_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Function<String, String> internerFunction =
        Interners.asFunction(Interners.<String>newStrongInterner());

    assertSame(canonical, internerFunction.apply(canonical));

            

Reported by PMD.

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

Line: 32

               *
 * @author Kevin Bourrillion
 */
public class InternersTest extends TestCase {

  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");


            

Reported by PMD.

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

Line: 34

               */
public class InternersTest extends TestCase {

  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));

            

Reported by PMD.

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

Line: 34

               */
public class InternersTest extends TestCase {

  public void testStrong_simplistic() {
    String canonical = "a";
    String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));

            

Reported by PMD.

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

Line: 39

                  String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

  public void testStrong_null() {
    Interner<String> pool = Interners.newStrongInterner();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  String not = new String("a");

    Interner<String> pool = Interners.newStrongInterner();
    assertSame(canonical, pool.intern(canonical));
    assertSame(canonical, pool.intern(not));
  }

  public void testStrong_null() {
    Interner<String> pool = Interners.newStrongInterner();

            

Reported by PMD.

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

Line: 43

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

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")

            

Reported by PMD.

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

Line: 47

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.KNOWN_ORDER,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

Reported by PMD.

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

Line: 47

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.KNOWN_ORDER,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

Reported by PMD.

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

Line: 47

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.KNOWN_ORDER,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

Reported by PMD.

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

Line: 85

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

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

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

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

Line: 87

              
  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }

            

Reported by PMD.

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

Line: 87

              
  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }

            

Reported by PMD.

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

Line: 88

                public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 89

                  Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }

  public void testCreateWithSize() {

            

Reported by PMD.

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

Line: 43

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

  @GwtIncompatible // suite
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")

            

Reported by PMD.

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

Line: 47

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.KNOWN_ORDER,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

Reported by PMD.

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

Line: 47

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.KNOWN_ORDER,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

Reported by PMD.

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

Line: 47

                public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        MultisetTestSuiteBuilder.using(linkedHashMultisetGenerator())
            .named("LinkedHashMultiset")
            .withFeatures(
                CollectionSize.ANY,
                CollectionFeature.KNOWN_ORDER,
                CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,

            

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

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

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

Line: 85

                  };
  }

  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));

            

Reported by PMD.

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

Line: 87

              
  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }

            

Reported by PMD.

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

Line: 87

              
  public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }

            

Reported by PMD.

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

Line: 88

                public void testCreate() {
    Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 89

                  Multiset<String> multiset = LinkedHashMultiset.create();
    multiset.add("foo", 2);
    multiset.add("bar");
    assertEquals(3, multiset.size());
    assertEquals(2, multiset.count("foo"));
    assertEquals("[foo x 2, bar]", multiset.toString());
  }

  public void testCreateWithSize() {

            

Reported by PMD.

guava-testlib/src/com/google/common/testing/NullPointerTester.java
60 issues
Avoid throwing raw exception types.
Design

Line: 370

                    error.initCause(cause);
      throw error;
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }

  private Object[] buildParamList(Invokable<?, ?> invokable, int indexOfParamToSetToNull) {
    ImmutableList<Parameter> params = invokable.getParameters();

            

Reported by PMD.

A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.testing;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.Beta;

            

Reported by PMD.

Possible God Class (WMC=66, ATFD=72, TCC=0.758%)
Design

Line: 73

               */
@Beta
@GwtIncompatible
public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

            

Reported by PMD.

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

Line: 73

               */
@Beta
@GwtIncompatible
public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

            

Reported by PMD.

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

Line: 75

              @GwtIncompatible
public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**

            

Reported by PMD.

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

Line: 76

              public final class NullPointerTester {

  private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**
   * Sets a default value that can be used for any parameter of type {@code type}. Returns this

            

Reported by PMD.

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

Line: 78

                private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**
   * Sets a default value that can be used for any parameter of type {@code type}. Returns this
   * object.
   */

            

Reported by PMD.

Private field 'policy' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 78

                private final ClassToInstanceMap<Object> defaults = MutableClassToInstanceMap.create();
  private final List<Member> ignoredMembers = Lists.newArrayList();

  private ExceptionTypePolicy policy = ExceptionTypePolicy.NPE_OR_UOE;

  /**
   * Sets a default value that can be used for any parameter of type {@code type}. Returns this
   * object.
   */

            

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

                 * Runs {@link #testConstructor} on every constructor in class {@code c} that has at least {@code
   * minimalVisibility}.
   */
  public void testConstructors(Class<?> c, Visibility minimalVisibility) {
    for (Constructor<?> constructor : c.getDeclaredConstructors()) {
      if (minimalVisibility.isVisible(constructor) && !isIgnored(constructor)) {
        testConstructor(constructor);
      }
    }

            

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

                }

  /** Runs {@link #testConstructor} on every public constructor in class {@code c}. */
  public void testAllPublicConstructors(Class<?> c) {
    testConstructors(c, Visibility.PUBLIC);
  }

  /**
   * Runs {@link #testMethod} on every static method of class {@code c} that has at least {@code

            

Reported by PMD.

guava-tests/test/com/google/common/collect/AbstractMapEntryTest.java
60 issues
Avoid using equals() to compare against null
Error

Line: 70

                  assertFalse(control("foo", 1).equals(entry("foo", 2)));
    assertFalse(foo1.equals(control("bar", 1)));
    assertFalse(foo1.equals(new Object()));
    assertFalse(foo1.equals(null));
  }

  public void testEqualsNull() {
    assertEquals(control(NK, 1), entry(NK, 1));
    assertEquals(control("bar", NV), entry("bar", NV));

            

Reported by PMD.

Avoid using equals() to compare against null
Error

Line: 79

                  assertFalse(control(NK, 1).equals(entry(NK, 2)));
    assertFalse(entry(NK, 1).equals(control("bar", 1)));
    assertFalse(entry(NK, 1).equals(new Object()));
    assertFalse(entry(NK, 1).equals(null));
  }

  public void testHashCode() {
    assertEquals(control("foo", 1).hashCode(), entry("foo", 1).hashCode());
    assertEquals(control("bar", 2).hashCode(), entry("bar", 2).hashCode());

            

Reported by PMD.

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

Line: 49

                }

  private static <K, V> Entry<K, V> control(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

            

Reported by PMD.

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

Line: 49

                }

  private static <K, V> Entry<K, V> control(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

            

Reported by PMD.

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

Line: 49

                }

  private static <K, V> Entry<K, V> control(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

            

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

                  return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 53

                }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());

            

Reported by PMD.

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

Line: 53

                }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());

            

Reported by PMD.

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

Line: 53

                }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());

            

Reported by PMD.

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

Line: 56

                  assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());
    assertEquals("null=null", entry(NK, NV).toString());
  }


            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/AbstractMapEntryTest.java
60 issues
Avoid using equals() to compare against null
Error

Line: 70

                  assertFalse(control("foo", 1).equals(entry("foo", 2)));
    assertFalse(foo1.equals(control("bar", 1)));
    assertFalse(foo1.equals(new Object()));
    assertFalse(foo1.equals(null));
  }

  public void testEqualsNull() {
    assertEquals(control(NK, 1), entry(NK, 1));
    assertEquals(control("bar", NV), entry("bar", NV));

            

Reported by PMD.

Avoid using equals() to compare against null
Error

Line: 79

                  assertFalse(control(NK, 1).equals(entry(NK, 2)));
    assertFalse(entry(NK, 1).equals(control("bar", 1)));
    assertFalse(entry(NK, 1).equals(new Object()));
    assertFalse(entry(NK, 1).equals(null));
  }

  public void testHashCode() {
    assertEquals(control("foo", 1).hashCode(), entry("foo", 1).hashCode());
    assertEquals(control("bar", 2).hashCode(), entry("bar", 2).hashCode());

            

Reported by PMD.

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

Line: 49

                }

  private static <K, V> Entry<K, V> control(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

            

Reported by PMD.

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

Line: 49

                }

  private static <K, V> Entry<K, V> control(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

            

Reported by PMD.

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

Line: 49

                }

  private static <K, V> Entry<K, V> control(K key, V value) {
    return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

            

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

                  return Collections.singletonMap(key, value).entrySet().iterator().next();
  }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());

            

Reported by PMD.

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

Line: 53

                }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());

            

Reported by PMD.

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

Line: 53

                }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 53

                }

  public void testToString() {
    assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());

            

Reported by PMD.

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

Line: 56

                  assertEquals("foo=1", entry("foo", 1).toString());
  }

  public void testToStringNull() {
    assertEquals("null=1", entry(NK, 1).toString());
    assertEquals("foo=null", entry("foo", NV).toString());
    assertEquals("null=null", entry(NK, NV).toString());
  }


            

Reported by PMD.