The following issues were found

guava-tests/test/com/google/common/util/concurrent/AtomicDoubleTest.java
48 issues
This class has too many methods, consider refactoring it.
Design

Line: 18

              

/** Unit test for {@link AtomicDouble}. */
public class AtomicDoubleTest extends JSR166TestCase {

  private static final double[] VALUES = {
    Double.NEGATIVE_INFINITY,
    -Double.MAX_VALUE,
    (double) Long.MIN_VALUE,

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 43

              
  /** The notion of equality used by AtomicDouble */
  static boolean bitEquals(double x, double y) {
    return Double.doubleToRawLongBits(x) == Double.doubleToRawLongBits(y);
  }

  static void assertBitEquals(double x, double y) {
    assertEquals(Double.doubleToRawLongBits(x), Double.doubleToRawLongBits(y));
  }

            

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

                }

  /** constructor initializes to given value */
  public void testConstructor() {
    for (double x : VALUES) {
      AtomicDouble a = new AtomicDouble(x);
      assertBitEquals(x, a.get());
    }
  }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 53

                /** constructor initializes to given value */
  public void testConstructor() {
    for (double x : VALUES) {
      AtomicDouble a = new AtomicDouble(x);
      assertBitEquals(x, a.get());
    }
  }

  /** default constructed initializes to zero */

            

Reported by PMD.

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

Line: 59

                }

  /** default constructed initializes to zero */
  public void testConstructor2() {
    AtomicDouble a = new AtomicDouble();
    assertBitEquals(0.0, a.get());
  }

  /** get returns the last value set */

            

Reported by PMD.

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

Line: 65

                }

  /** get returns the last value set */
  public void testGetSet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.set(x);
      assertBitEquals(x, at.get());

            

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

                }

  /** get returns the last value set */
  public void testGetSet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.set(x);
      assertBitEquals(x, at.get());

            

Reported by PMD.

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

Line: 75

                }

  /** get returns the last value lazySet in same thread */
  public void testGetLazySet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.lazySet(x);
      assertBitEquals(x, at.get());

            

Reported by PMD.

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

Line: 75

                }

  /** get returns the last value lazySet in same thread */
  public void testGetLazySet() {
    AtomicDouble at = new AtomicDouble(1.0);
    assertBitEquals(1.0, at.get());
    for (double x : VALUES) {
      at.lazySet(x);
      assertBitEquals(x, at.get());

            

Reported by PMD.

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

Line: 85

                }

  /** compareAndSet succeeds in changing value if equal to expected else fails */
  public void testCompareAndSet() {
    double prev = Math.E;
    double unused = Math.E + Math.PI;
    AtomicDouble at = new AtomicDouble(prev);
    for (double x : VALUES) {
      assertBitEquals(prev, at.get());

            

Reported by PMD.

android/guava-tests/test/com/google/common/cache/AbstractLoadingCacheTest.java
48 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: 34

               */
public class AbstractLoadingCacheTest extends TestCase {

  public void testGetUnchecked_checked() {
    final Exception cause = new Exception();
    final AtomicReference<Object> valueRef = new AtomicReference<>();
    LoadingCache<Object, Object> cache =
        new AbstractLoadingCache<Object, Object>() {
          @Override

            

Reported by PMD.

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

Line: 34

               */
public class AbstractLoadingCacheTest extends TestCase {

  public void testGetUnchecked_checked() {
    final Exception cause = new Exception();
    final AtomicReference<Object> valueRef = new AtomicReference<>();
    LoadingCache<Object, Object> cache =
        new AbstractLoadingCache<Object, Object>() {
          @Override

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 56

              
    try {
      cache.getUnchecked(new Object());
      fail();
    } catch (UncheckedExecutionException expected) {
      assertThat(expected).hasCauseThat().isEqualTo(cause);
    }

    Object newValue = new Object();

            

Reported by PMD.

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

Line: 58

                    cache.getUnchecked(new Object());
      fail();
    } catch (UncheckedExecutionException expected) {
      assertThat(expected).hasCauseThat().isEqualTo(cause);
    }

    Object newValue = new Object();
    valueRef.set(newValue);
    assertSame(newValue, cache.getUnchecked(new Object()));

            

Reported by PMD.

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

Line: 58

                    cache.getUnchecked(new Object());
      fail();
    } catch (UncheckedExecutionException expected) {
      assertThat(expected).hasCauseThat().isEqualTo(cause);
    }

    Object newValue = new Object();
    valueRef.set(newValue);
    assertSame(newValue, cache.getUnchecked(new Object()));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 63

              
    Object newValue = new Object();
    valueRef.set(newValue);
    assertSame(newValue, cache.getUnchecked(new Object()));
  }

  public void testGetUnchecked_unchecked() {
    final RuntimeException cause = new RuntimeException();
    final AtomicReference<Object> valueRef = new AtomicReference<>();

            

Reported by PMD.

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

Line: 66

                  assertSame(newValue, cache.getUnchecked(new Object()));
  }

  public void testGetUnchecked_unchecked() {
    final RuntimeException cause = new RuntimeException();
    final AtomicReference<Object> valueRef = new AtomicReference<>();
    LoadingCache<Object, Object> cache =
        new AbstractLoadingCache<Object, Object>() {
          @Override

            

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

                  assertSame(newValue, cache.getUnchecked(new Object()));
  }

  public void testGetUnchecked_unchecked() {
    final RuntimeException cause = new RuntimeException();
    final AtomicReference<Object> valueRef = new AtomicReference<>();
    LoadingCache<Object, Object> cache =
        new AbstractLoadingCache<Object, Object>() {
          @Override

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 88

              
    try {
      cache.getUnchecked(new Object());
      fail();
    } catch (UncheckedExecutionException expected) {
      assertThat(expected).hasCauseThat().isEqualTo(cause);
    }

    Object newValue = new Object();

            

Reported by PMD.

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

Line: 90

                    cache.getUnchecked(new Object());
      fail();
    } catch (UncheckedExecutionException expected) {
      assertThat(expected).hasCauseThat().isEqualTo(cause);
    }

    Object newValue = new Object();
    valueRef.set(newValue);
    assertSame(newValue, cache.getUnchecked(new Object()));

            

Reported by PMD.

android/guava/src/com/google/common/math/IntMath.java
48 issues
Using multiple unary operators may be a bug, and/or is confusing.
Error

Line: 107

                static int lessThanBranchFree(int x, int y) {
    // The double negation is optimized away by normal Java, but is necessary for GWT
    // to make sure bit twiddling works as expected.
    return ~~(x - y) >>> (Integer.SIZE - 1);
  }

  /**
   * Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode.
   *

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 228

                 * @throws IllegalArgumentException if {@code k < 0}
   */
  @GwtIncompatible // failing tests
  public static int pow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

Avoid reassigning parameters such as 'k'
Design

Line: 228

                 * @throws IllegalArgumentException if {@code k < 0}
   */
  @GwtIncompatible // failing tests
  public static int pow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

Avoid reassigning parameters such as 'a'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'a'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'a'
Design

Line: 405

                 *
   * @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
   */
  public static int gcd(int a, int b) {
    /*
     * The reason we require both arguments to be >= 0 is because otherwise, what do you return on
     * gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31 isn't
     * an int.
     */

            

Reported by PMD.

Avoid reassigning parameters such as 'k'
Design

Line: 491

                 * @throws ArithmeticException if {@code b} to the {@code k}th power overflows in signed {@code
   *     int} arithmetic
   */
  public static int checkedPow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

Avoid reassigning parameters such as 'b'
Design

Line: 491

                 * @throws ArithmeticException if {@code b} to the {@code k}th power overflows in signed {@code
   *     int} arithmetic
   */
  public static int checkedPow(int b, int k) {
    checkNonNegative("exponent", k);
    switch (b) {
      case 0:
        return (k == 0) ? 1 : 0;
      case 1:

            

Reported by PMD.

guava/src/com/google/common/collect/LinkedHashMultimap.java
48 issues
This class has too many methods, consider refactoring it.
Design

Line: 89

              @GwtCompatible(serializable = true, emulated = true)
@ElementTypesAreNonnullByDefault
public final class LinkedHashMultimap<K extends @Nullable Object, V extends @Nullable Object>
    extends LinkedHashMultimapGwtSerializationDependencies<K, V> {

  /** Creates a new, empty {@code LinkedHashMultimap} with the default initial capacities. */
  public static <K extends @Nullable Object, V extends @Nullable Object>
      LinkedHashMultimap<K, V> create() {
    return new LinkedHashMultimap<>(DEFAULT_KEY_CAPACITY, DEFAULT_VALUE_SET_CAPACITY);

            

Reported by PMD.

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

Line: 122

                 */
  public static <K extends @Nullable Object, V extends @Nullable Object>
      LinkedHashMultimap<K, V> create(Multimap<? extends K, ? extends V> multimap) {
    LinkedHashMultimap<K, V> result = create(multimap.keySet().size(), DEFAULT_VALUE_SET_CAPACITY);
    result.putAll(multimap);
    return result;
  }

  private interface ValueSetLink<K extends @Nullable Object, V extends @Nullable Object> {

            

Reported by PMD.

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

Line: 123

                public static <K extends @Nullable Object, V extends @Nullable Object>
      LinkedHashMultimap<K, V> create(Multimap<? extends K, ? extends V> multimap) {
    LinkedHashMultimap<K, V> result = create(multimap.keySet().size(), DEFAULT_VALUE_SET_CAPACITY);
    result.putAll(multimap);
    return result;
  }

  private interface ValueSetLink<K extends @Nullable Object, V extends @Nullable Object> {
    ValueSetLink<K, V> getPredecessorInValueSet();

            

Reported by PMD.

The class 'ValueEntry' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=8, WMC=11)
Design

Line: 166

                 * whole.
   */
  @VisibleForTesting
  static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Object>
      extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 166

                 * whole.
   */
  @VisibleForTesting
  static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Object>
      extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*

            

Reported by PMD.

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

Line: 168

                @VisibleForTesting
  static final class ValueEntry<K extends @Nullable Object, V extends @Nullable Object>
      extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*
     * The *InValueSet and *InMultimap fields below are null after construction, but we almost
     * always call succeedsIn*() to initialize them immediately thereafter.

            

Reported by PMD.

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

Line: 170

                    extends ImmutableEntry<K, V> implements ValueSetLink<K, V> {
    final int smearedValueHash;

    @CheckForNull ValueEntry<K, V> nextInValueBucket;
    /*
     * The *InValueSet and *InMultimap fields below are null after construction, but we almost
     * always call succeedsIn*() to initialize them immediately thereafter.
     *
     * The exception is the *InValueSet fields of multimapHeaderEntry, which are never set. (That

            

Reported by PMD.

The field initializer for 'valueSetCapacity' is never used (overwritten on line 269)
Design

Line: 262

                private static final int DEFAULT_VALUE_SET_CAPACITY = 2;
  @VisibleForTesting static final double VALUE_SET_LOAD_FACTOR = 1.0;

  @VisibleForTesting transient int valueSetCapacity = DEFAULT_VALUE_SET_CAPACITY;
  private transient ValueEntry<K, V> multimapHeaderEntry;

  private LinkedHashMultimap(int keyCapacity, int valueSetCapacity) {
    super(Platform.<K, Collection<V>>newLinkedHashMapWithExpectedSize(keyCapacity));
    checkNonnegative(valueSetCapacity, "expectedValuesPerKey");

            

Reported by PMD.

Overriding method merely calls super
Design

Line: 325

                 * time the entry is returned by a method call to the collection or its iterator.
   */
  @Override
  public Set<Entry<K, V>> entries() {
    return super.entries();
  }

  /**
   * Returns a view collection of all <i>distinct</i> keys contained in this multimap. Note that the

            

Reported by PMD.

Overriding method merely calls super
Design

Line: 340

                 * <i>adding</i> to the returned set is not possible.
   */
  @Override
  public Set<K> keySet() {
    return super.keySet();
  }

  /**
   * Returns a collection of all values in the multimap. Changes to the returned collection will

            

Reported by PMD.

guava-tests/test/com/google/common/io/ResourcesTest.java
47 issues
This class has too many methods, consider refactoring it.
Design

Line: 43

               * @author Chris Nokleberg
 */

public class ResourcesTest extends IoTestCase {

  public static TestSuite suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        ByteSourceTester.tests(

            

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

                  return suite;
  }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }


            

Reported by PMD.

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

Line: 59

                  return suite;
  }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }


            

Reported by PMD.

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

Line: 60

                }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {

            

Reported by PMD.

The String literal 'testdata/i18n.txt' appears 4 times in this file; the first occurrence is on line 60
Error

Line: 60

                }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {

            

Reported by PMD.

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

Line: 62

                public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {
    byte[] data = Resources.toByteArray(classfile(Resources.class));
    assertEquals(0xCAFEBABE, new DataInputStream(new ByteArrayInputStream(data)).readInt());

            

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

                  assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {
    byte[] data = Resources.toByteArray(classfile(Resources.class));
    assertEquals(0xCAFEBABE, new DataInputStream(new ByteArrayInputStream(data)).readInt());
  }

  public void testReadLines() throws IOException {

            

Reported by PMD.

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

Line: 70

                  assertEquals(0xCAFEBABE, new DataInputStream(new ByteArrayInputStream(data)).readInt());
  }

  public void testReadLines() throws IOException {
    // TODO(chrisn): Check in a better resource
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
  }


            

Reported by PMD.

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

Line: 72

              
  public void testReadLines() throws IOException {
    // TODO(chrisn): Check in a better resource
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
  }

  public void testReadLines_withLineProcessor() throws IOException {
    URL resource = getClass().getResource("testdata/alice_in_wonderland.txt");

            

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

                  assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
  }

  public void testReadLines_withLineProcessor() throws IOException {
    URL resource = getClass().getResource("testdata/alice_in_wonderland.txt");
    LineProcessor<List<String>> collectAndLowercaseAndTrim =
        new LineProcessor<List<String>>() {
          List<String> collector = new ArrayList<>();


            

Reported by PMD.

android/guava-tests/test/com/google/common/io/ResourcesTest.java
47 issues
This class has too many methods, consider refactoring it.
Design

Line: 43

               * @author Chris Nokleberg
 */

public class ResourcesTest extends IoTestCase {

  public static TestSuite suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(
        ByteSourceTester.tests(

            

Reported by PMD.

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

Line: 59

                  return suite;
  }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }


            

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

                  return suite;
  }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }


            

Reported by PMD.

The String literal 'testdata/i18n.txt' appears 4 times in this file; the first occurrence is on line 60
Error

Line: 60

                }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {

            

Reported by PMD.

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

Line: 60

                }

  public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {

            

Reported by PMD.

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

Line: 62

                public void testToString() throws IOException {
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(I18N, Resources.toString(resource, Charsets.UTF_8));
    assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {
    byte[] data = Resources.toByteArray(classfile(Resources.class));
    assertEquals(0xCAFEBABE, new DataInputStream(new ByteArrayInputStream(data)).readInt());

            

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

                  assertThat(Resources.toString(resource, Charsets.US_ASCII)).isNotEqualTo(I18N);
  }

  public void testToToByteArray() throws IOException {
    byte[] data = Resources.toByteArray(classfile(Resources.class));
    assertEquals(0xCAFEBABE, new DataInputStream(new ByteArrayInputStream(data)).readInt());
  }

  public void testReadLines() throws IOException {

            

Reported by PMD.

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

Line: 70

                  assertEquals(0xCAFEBABE, new DataInputStream(new ByteArrayInputStream(data)).readInt());
  }

  public void testReadLines() throws IOException {
    // TODO(chrisn): Check in a better resource
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
  }


            

Reported by PMD.

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

Line: 72

              
  public void testReadLines() throws IOException {
    // TODO(chrisn): Check in a better resource
    URL resource = getClass().getResource("testdata/i18n.txt");
    assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
  }

  public void testReadLines_withLineProcessor() throws IOException {
    URL resource = getClass().getResource("testdata/alice_in_wonderland.txt");

            

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

                  assertEquals(ImmutableList.of(I18N), Resources.readLines(resource, Charsets.UTF_8));
  }

  public void testReadLines_withLineProcessor() throws IOException {
    URL resource = getClass().getResource("testdata/alice_in_wonderland.txt");
    LineProcessor<List<String>> collectAndLowercaseAndTrim =
        new LineProcessor<List<String>>() {
          List<String> collector = new ArrayList<>();


            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/DiscreteDomainTest.java
47 issues
JUnit tests should include assert() or fail()
Design

Line: 32

               */
@GwtIncompatible // SerializableTester
public class DiscreteDomainTest extends TestCase {
  public void testSerialization() {
    reserializeAndAssert(DiscreteDomain.integers());
    reserializeAndAssert(DiscreteDomain.longs());
    reserializeAndAssert(DiscreteDomain.bigIntegers());
  }


            

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

               */
@GwtIncompatible // SerializableTester
public class DiscreteDomainTest extends TestCase {
  public void testSerialization() {
    reserializeAndAssert(DiscreteDomain.integers());
    reserializeAndAssert(DiscreteDomain.longs());
    reserializeAndAssert(DiscreteDomain.bigIntegers());
  }


            

Reported by PMD.

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

Line: 38

                  reserializeAndAssert(DiscreteDomain.bigIntegers());
  }

  public void testIntegersOffset() {
    assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }

            

Reported by PMD.

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

Line: 38

                  reserializeAndAssert(DiscreteDomain.bigIntegers());
  }

  public void testIntegersOffset() {
    assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                }

  public void testIntegersOffset() {
    assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }


            

Reported by PMD.

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

Line: 39

                }

  public void testIntegersOffset() {
    assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }


            

Reported by PMD.

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

Line: 39

                }

  public void testIntegersOffset() {
    assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

              
  public void testIntegersOffset() {
    assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }

  public void testIntegersOffsetExceptions() {

            

Reported by PMD.

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

Line: 42

                  assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }

  public void testIntegersOffsetExceptions() {
    try {
      DiscreteDomain.integers().offset(0, -1);

            

Reported by PMD.

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

Line: 42

                  assertEquals(1, DiscreteDomain.integers().offset(0, 1).intValue());
    assertEquals(
        Integer.MAX_VALUE,
        DiscreteDomain.integers().offset(Integer.MIN_VALUE, (1L << 32) - 1).intValue());
  }

  public void testIntegersOffsetExceptions() {
    try {
      DiscreteDomain.integers().offset(0, -1);

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/google/MultimapAsMapTester.java
47 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: 51

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapAsMapTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testAsMapGet() {
    for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());

            

Reported by PMD.

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

Line: 51

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapAsMapTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testAsMapGet() {
    for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 53

              public class MultimapAsMapTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testAsMapGet() {
    for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());
        }
      }

            

Reported by PMD.

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

Line: 55

                  for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());
        }
      }

      Collection<V> collection = multimap().asMap().get(key);

            

Reported by PMD.

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

Line: 60

                      }
      }

      Collection<V> collection = multimap().asMap().get(key);
      if (expectedValues.isEmpty()) {
        assertNull(collection);
      } else {
        assertEqualIgnoringOrder(expectedValues, collection);
      }

            

Reported by PMD.

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

Line: 60

                      }
      }

      Collection<V> collection = multimap().asMap().get(key);
      if (expectedValues.isEmpty()) {
        assertNull(collection);
      } else {
        assertEqualIgnoringOrder(expectedValues, collection);
      }

            

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

                  }
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testAsMapGetNullKeyPresent() {
    initMultimapWithNullKey();
    assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

            

Reported by PMD.

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

Line: 73

                @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testAsMapGetNullKeyPresent() {
    initMultimapWithNullKey();
    assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testAsMapGetNullKeyAbsent() {
    assertNull(multimap().asMap().get(null));

            

Reported by PMD.

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

Line: 73

                @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testAsMapGetNullKeyPresent() {
    initMultimapWithNullKey();
    assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testAsMapGetNullKeyAbsent() {
    assertNull(multimap().asMap().get(null));

            

Reported by PMD.

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

Line: 76

                  assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testAsMapGetNullKeyAbsent() {
    assertNull(multimap().asMap().get(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/google/MultimapAsMapTester.java
47 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 51

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapAsMapTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testAsMapGet() {
    for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());

            

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

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultimapAsMapTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testAsMapGet() {
    for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 53

              public class MultimapAsMapTester<K, V> extends AbstractMultimapTester<K, V, Multimap<K, V>> {
  public void testAsMapGet() {
    for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());
        }
      }

            

Reported by PMD.

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

Line: 55

                  for (K key : sampleKeys()) {
      List<V> expectedValues = new ArrayList<>();
      for (Entry<K, V> entry : getSampleElements()) {
        if (entry.getKey().equals(key)) {
          expectedValues.add(entry.getValue());
        }
      }

      Collection<V> collection = multimap().asMap().get(key);

            

Reported by PMD.

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

Line: 60

                      }
      }

      Collection<V> collection = multimap().asMap().get(key);
      if (expectedValues.isEmpty()) {
        assertNull(collection);
      } else {
        assertEqualIgnoringOrder(expectedValues, collection);
      }

            

Reported by PMD.

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

Line: 60

                      }
      }

      Collection<V> collection = multimap().asMap().get(key);
      if (expectedValues.isEmpty()) {
        assertNull(collection);
      } else {
        assertEqualIgnoringOrder(expectedValues, collection);
      }

            

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

                  }
  }

  @CollectionSize.Require(absent = ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testAsMapGetNullKeyPresent() {
    initMultimapWithNullKey();
    assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

            

Reported by PMD.

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

Line: 73

                @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testAsMapGetNullKeyPresent() {
    initMultimapWithNullKey();
    assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testAsMapGetNullKeyAbsent() {
    assertNull(multimap().asMap().get(null));

            

Reported by PMD.

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

Line: 73

                @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testAsMapGetNullKeyPresent() {
    initMultimapWithNullKey();
    assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testAsMapGetNullKeyAbsent() {
    assertNull(multimap().asMap().get(null));

            

Reported by PMD.

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

Line: 76

                  assertContentsAnyOrder(multimap().asMap().get(null), getValueForNullKey());
  }

  @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
  public void testAsMapGetNullKeyAbsent() {
    assertNull(multimap().asMap().get(null));
  }

  @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)

            

Reported by PMD.

guava-testlib/src/com/google/common/collect/testing/AbstractIteratorTester.java
47 issues
Avoid throwing raw exception types.
Design

Line: 319

                  try {
      recurse(0);
    } catch (RuntimeException e) {
      throw new RuntimeException(Arrays.toString(stimuli), e);
    }
  }

  public void testForEachRemaining() {
    for (int i = 0; i < expectedElements.size() - 1; i++) {

            

Reported by PMD.

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

Line: 44

               * @author Chris Povirk
 */
@GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;

            

Reported by PMD.

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

Line: 45

               */
@GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

            

Reported by PMD.

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

Line: 46

              @GwtCompatible
abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;


            

Reported by PMD.

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

Line: 47

              abstract class AbstractIteratorTester<E, I extends Iterator<E>> {
  private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**

            

Reported by PMD.

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

Line: 48

                private Stimulus<E, ? super I>[] stimuli;
  private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of

            

Reported by PMD.

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

Line: 49

                private final Iterator<E> elementsToInsert;
  private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of
   * throwing any particular exception type.

            

Reported by PMD.

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

Line: 50

                private final Set<IteratorFeature> features;
  private final List<E> expectedElements;
  private final int startIndex;
  private final KnownOrder knownOrder;

  /**
   * Meta-exception thrown by {@link AbstractIteratorTester.MultiExceptionListIterator} instead of
   * throwing any particular exception type.
   */

            

Reported by PMD.

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

Line: 97

                    if (!isPermitted(exception)) {
        String message =
            "Exception "
                + exception.getClass().getSimpleName()
                + " was thrown; expected "
                + getMessage();
        Helpers.fail(exception, message);
      }
    }

            

Reported by PMD.

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

Line: 129

                 * <p>This class is accessible but not supported in GWT as it references {@link
   * PermittedMetaException}.
   */
  protected final class MultiExceptionListIterator implements ListIterator<E> {
    // TODO: track seen elements when order isn't guaranteed
    // TODO: verify contents afterward
    // TODO: something shiny and new instead of Stack
    // TODO: test whether null is supported (create a Feature)
    /**

            

Reported by PMD.