The following issues were found

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

Line: 33

               * @author Louis Wasserman
 */
@GwtCompatible
public class MoreCollectorsTest extends TestCase {
  public void testToOptionalEmpty() {
    assertThat(Stream.empty().collect(MoreCollectors.toOptional())).isEmpty();
  }

  public void testToOptionalSingleton() {

            

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

               */
@GwtCompatible
public class MoreCollectorsTest extends TestCase {
  public void testToOptionalEmpty() {
    assertThat(Stream.empty().collect(MoreCollectors.toOptional())).isEmpty();
  }

  public void testToOptionalSingleton() {
    assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);

            

Reported by PMD.

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

Line: 35

              @GwtCompatible
public class MoreCollectorsTest extends TestCase {
  public void testToOptionalEmpty() {
    assertThat(Stream.empty().collect(MoreCollectors.toOptional())).isEmpty();
  }

  public void testToOptionalSingleton() {
    assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);
  }

            

Reported by PMD.

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

Line: 35

              @GwtCompatible
public class MoreCollectorsTest extends TestCase {
  public void testToOptionalEmpty() {
    assertThat(Stream.empty().collect(MoreCollectors.toOptional())).isEmpty();
  }

  public void testToOptionalSingleton() {
    assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);
  }

            

Reported by PMD.

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

Line: 38

                  assertThat(Stream.empty().collect(MoreCollectors.toOptional())).isEmpty();
  }

  public void testToOptionalSingleton() {
    assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);
  }

  public void testToOptionalNull() {
    Stream<Object> stream = Stream.of((Object) null);

            

Reported by PMD.

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

Line: 39

                }

  public void testToOptionalSingleton() {
    assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);
  }

  public void testToOptionalNull() {
    Stream<Object> stream = Stream.of((Object) null);
    try {

            

Reported by PMD.

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

Line: 39

                }

  public void testToOptionalSingleton() {
    assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);
  }

  public void testToOptionalNull() {
    Stream<Object> stream = Stream.of((Object) null);
    try {

            

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

                  assertThat(Stream.of(1).collect(MoreCollectors.toOptional())).hasValue(1);
  }

  public void testToOptionalNull() {
    Stream<Object> stream = Stream.of((Object) null);
    try {
      stream.collect(MoreCollectors.toOptional());
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {

            

Reported by PMD.

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

Line: 46

                  Stream<Object> stream = Stream.of((Object) null);
    try {
      stream.collect(MoreCollectors.toOptional());
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {
    }
  }

  public void testToOptionalMultiple() {

            

Reported by PMD.

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

Line: 47

                  try {
      stream.collect(MoreCollectors.toOptional());
      fail("Expected NullPointerException");
    } catch (NullPointerException expected) {
    }
  }

  public void testToOptionalMultiple() {
    try {

            

Reported by PMD.

guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java
36 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 52

                        .put("SHA-512", Hashing.sha512())
          .build();

  public void testHashing() {
    for (String stringToTest : INPUTS) {
      for (String algorithmToTest : ALGORITHMS.keySet()) {
        assertMessageDigestHashing(HashTestUtils.ascii(stringToTest), algorithmToTest);
      }
    }

            

Reported by PMD.

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

Line: 60

                  }
  }

  public void testPutAfterHash() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)

            

Reported by PMD.

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

Line: 61

                }

  public void testPutAfterHash() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 63

                public void testPutAfterHash() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {

            

Reported by PMD.

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

Line: 65

              
    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {
      sha1.putInt(42);
      fail();

            

Reported by PMD.

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

Line: 65

              
    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {
      sha1.putInt(42);
      fail();

            

Reported by PMD.

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

Line: 65

              
    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {
      sha1.putInt(42);
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 70

                          .toString());
    try {
      sha1.putInt(42);
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testHashTwice() {

            

Reported by PMD.

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

Line: 70

                          .toString());
    try {
      sha1.putInt(42);
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testHashTwice() {

            

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

                  }
  }

  public void testHashTwice() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/Uninterruptibles.java
36 issues
This class has too many methods, consider refactoring it.
Design

Line: 48

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Uninterruptibles {

  // Implementation Note: As of 3-7-11, the logic for each blocking/timeout
  // methods is identical, save for method being invoked.

  /** Invokes {@code latch.}{@link CountDownLatch#await() await()} uninterruptibly. */

            

Reported by PMD.

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

Line: 68

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

The String literal 'GoodTime' appears 9 times in this file; the first occurrence is on line 79
Error

Line: 79

                 */
  @CanIgnoreReturnValue // TODO(cpovirk): Consider being more strict.
  @GwtIncompatible // concurrency
  @SuppressWarnings("GoodTime") // should accept a java.time.Duration
  public static boolean awaitUninterruptibly(CountDownLatch latch, long timeout, TimeUnit unit) {
    boolean interrupted = false;
    try {
      long remainingNanos = unit.toNanos(timeout);
      long end = System.nanoTime() + remainingNanos;

            

Reported by PMD.

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

Line: 97

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 126

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /** Invokes {@code toJoin.}{@link Thread#join() join()} uninterruptibly. */

            

Reported by PMD.

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

Line: 146

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 175

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 212

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

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

Line: 257

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /** Invokes {@code queue.}{@link BlockingQueue#take() take()} uninterruptibly. */

            

Reported by PMD.

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

Line: 276

                    }
    } finally {
      if (interrupted) {
        Thread.currentThread().interrupt();
      }
    }
  }

  /**

            

Reported by PMD.

android/guava/src/com/google/common/util/concurrent/Futures.java
36 issues
A high number of imports can indicate a high degree of coupling within an object.
Design

Line: 15

               * the License.
 */

package com.google.common.util.concurrent;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static com.google.common.util.concurrent.Uninterruptibles.getUninterruptibly;

            

Reported by PMD.

Avoid really long classes.
Design

Line: 77

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Futures extends GwtFuturesCatchingSpecialization {

  // A note on memory visibility.
  // Many of the utilities in this class (transform, withFallback, withTimeout, asList, combine)
  // have two requirements that significantly complicate their design.
  // 1. Cancellation should propagate from the returned future to the input future(s).

            

Reported by PMD.

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

Line: 77

               */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Futures extends GwtFuturesCatchingSpecialization {

  // A note on memory visibility.
  // Many of the utilities in this class (transform, withFallback, withTimeout, asList, combine)
  // have two requirements that significantly complicate their design.
  // 1. Cancellation should propagate from the returned future to the input future(s).

            

Reported by PMD.

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

Line: 135

                    @ParametricNullness V value) {
    if (value == null) {
      // This cast is safe because null is assignable to V for all V (i.e. it is bivariant)
      @SuppressWarnings("unchecked")
      ListenableFuture<V> typedNull = (ListenableFuture<V>) ImmediateFuture.NULL;
      return typedNull;
    }
    return new ImmediateFuture<>(value);
  }

            

Reported by PMD.

A catch statement should never catch throwable since it includes errors.
Error

Line: 518

                    private O applyTransformation(I input) throws ExecutionException {
        try {
          return function.apply(input);
        } catch (Throwable t) {
          throw new ExecutionException(t);
        }
      }
    };
  }

            

Reported by PMD.

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

Line: 666

                @CanIgnoreReturnValue // TODO(cpovirk): Consider removing, especially if we provide run(Runnable)
  @GwtCompatible
  public static final class FutureCombiner<V extends @Nullable Object> {
    private final boolean allMustSucceed;
    private final ImmutableList<ListenableFuture<? extends V>> futures;

    private FutureCombiner(
        boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures) {
      this.allMustSucceed = allMustSucceed;

            

Reported by PMD.

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

Line: 667

                @GwtCompatible
  public static final class FutureCombiner<V extends @Nullable Object> {
    private final boolean allMustSucceed;
    private final ImmutableList<ListenableFuture<? extends V>> futures;

    private FutureCombiner(
        boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures) {
      this.allMustSucceed = allMustSucceed;
      this.futures = futures;

            

Reported by PMD.

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

Line: 760

                /** A wrapped future that does not propagate cancellation to its delegate. */
  private static final class NonCancellationPropagatingFuture<V extends @Nullable Object>
      extends AbstractFuture.TrustedFuture<V> implements Runnable {
    @CheckForNull private ListenableFuture<V> delegate;

    NonCancellationPropagatingFuture(final ListenableFuture<V> delegate) {
      this.delegate = delegate;
    }


            

Reported by PMD.

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

Line: 788

              
    @Override
    protected void afterDone() {
      delegate = null;
    }
  }

  /**
   * Creates a new {@code ListenableFuture} whose value is a list containing the values of all its

            

Reported by PMD.

This for loop can be replaced by a foreach loop
Design

Line: 881

                  final InCompletionOrderState<T> state = new InCompletionOrderState<>(copy);
    ImmutableList.Builder<AbstractFuture<T>> delegatesBuilder =
        ImmutableList.builderWithExpectedSize(copy.length);
    for (int i = 0; i < copy.length; i++) {
      delegatesBuilder.add(new InCompletionOrderFuture<T>(state));
    }

    final ImmutableList<AbstractFuture<T>> delegates = delegatesBuilder.build();
    for (int i = 0; i < copy.length; i++) {

            

Reported by PMD.

android/guava-tests/test/com/google/common/reflect/SubtypeTester.java
36 issues
Avoid using redundant field initializer for 'method'
Performance

Line: 81

                  boolean suppressGetSupertype() default false;
  }

  private Method method = null;

  /** Call this in a {@link TestSubtype} public method asserting subtype relationship. */
  final <T> T isSubtype(T sub) {
    Type returnType = method.getGenericReturnType();
    Type paramType = getOnlyParameterType();

            

Reported by PMD.

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

Line: 81

                  boolean suppressGetSupertype() default false;
  }

  private Method method = null;

  /** Call this in a {@link TestSubtype} public method asserting subtype relationship. */
  final <T> T isSubtype(T sub) {
    Type returnType = method.getGenericReturnType();
    Type paramType = getOnlyParameterType();

            

Reported by PMD.

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

Line: 88

                  Type returnType = method.getGenericReturnType();
    Type paramType = getOnlyParameterType();
    TestSubtype spec = method.getAnnotation(TestSubtype.class);
    assertWithMessage("%s is subtype of %s", paramType, returnType)
        .that(TypeToken.of(paramType).isSubtypeOf(returnType))
        .isTrue();
    assertWithMessage("%s is supertype of %s", returnType, paramType)
        .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();

            

Reported by PMD.

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

Line: 88

                  Type returnType = method.getGenericReturnType();
    Type paramType = getOnlyParameterType();
    TestSubtype spec = method.getAnnotation(TestSubtype.class);
    assertWithMessage("%s is subtype of %s", paramType, returnType)
        .that(TypeToken.of(paramType).isSubtypeOf(returnType))
        .isTrue();
    assertWithMessage("%s is supertype of %s", returnType, paramType)
        .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();

            

Reported by PMD.

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

Line: 89

                  Type paramType = getOnlyParameterType();
    TestSubtype spec = method.getAnnotation(TestSubtype.class);
    assertWithMessage("%s is subtype of %s", paramType, returnType)
        .that(TypeToken.of(paramType).isSubtypeOf(returnType))
        .isTrue();
    assertWithMessage("%s is supertype of %s", returnType, paramType)
        .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();
    if (!spec.suppressGetSubtype()) {

            

Reported by PMD.

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

Line: 91

                  assertWithMessage("%s is subtype of %s", paramType, returnType)
        .that(TypeToken.of(paramType).isSubtypeOf(returnType))
        .isTrue();
    assertWithMessage("%s is supertype of %s", returnType, paramType)
        .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();
    if (!spec.suppressGetSubtype()) {
      assertThat(getSubtype(returnType, TypeToken.of(paramType).getRawType())).isEqualTo(paramType);
    }

            

Reported by PMD.

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

Line: 91

                  assertWithMessage("%s is subtype of %s", paramType, returnType)
        .that(TypeToken.of(paramType).isSubtypeOf(returnType))
        .isTrue();
    assertWithMessage("%s is supertype of %s", returnType, paramType)
        .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();
    if (!spec.suppressGetSubtype()) {
      assertThat(getSubtype(returnType, TypeToken.of(paramType).getRawType())).isEqualTo(paramType);
    }

            

Reported by PMD.

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

Line: 92

                      .that(TypeToken.of(paramType).isSubtypeOf(returnType))
        .isTrue();
    assertWithMessage("%s is supertype of %s", returnType, paramType)
        .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();
    if (!spec.suppressGetSubtype()) {
      assertThat(getSubtype(returnType, TypeToken.of(paramType).getRawType())).isEqualTo(paramType);
    }
    if (!spec.suppressGetSupertype()) {

            

Reported by PMD.

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

Line: 94

                  assertWithMessage("%s is supertype of %s", returnType, paramType)
        .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();
    if (!spec.suppressGetSubtype()) {
      assertThat(getSubtype(returnType, TypeToken.of(paramType).getRawType())).isEqualTo(paramType);
    }
    if (!spec.suppressGetSupertype()) {
      assertThat(getSupertype(paramType, TypeToken.of(returnType).getRawType()))
          .isEqualTo(returnType);

            

Reported by PMD.

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

Line: 95

                      .that(TypeToken.of(returnType).isSupertypeOf(paramType))
        .isTrue();
    if (!spec.suppressGetSubtype()) {
      assertThat(getSubtype(returnType, TypeToken.of(paramType).getRawType())).isEqualTo(paramType);
    }
    if (!spec.suppressGetSupertype()) {
      assertThat(getSupertype(paramType, TypeToken.of(returnType).getRawType()))
          .isEqualTo(returnType);
    }

            

Reported by PMD.

android/guava-tests/test/com/google/common/hash/MessageDigestHashFunctionTest.java
36 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 52

                        .put("SHA-512", Hashing.sha512())
          .build();

  public void testHashing() {
    for (String stringToTest : INPUTS) {
      for (String algorithmToTest : ALGORITHMS.keySet()) {
        assertMessageDigestHashing(HashTestUtils.ascii(stringToTest), algorithmToTest);
      }
    }

            

Reported by PMD.

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

Line: 60

                  }
  }

  public void testPutAfterHash() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)

            

Reported by PMD.

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

Line: 61

                }

  public void testPutAfterHash() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 63

                public void testPutAfterHash() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {

            

Reported by PMD.

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

Line: 65

              
    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {
      sha1.putInt(42);
      fail();

            

Reported by PMD.

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

Line: 65

              
    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {
      sha1.putInt(42);
      fail();

            

Reported by PMD.

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

Line: 65

              
    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)
            .hash()
            .toString());
    try {
      sha1.putInt(42);
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 70

                          .toString());
    try {
      sha1.putInt(42);
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testHashTwice() {

            

Reported by PMD.

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

Line: 70

                          .toString());
    try {
      sha1.putInt(42);
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testHashTwice() {

            

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

                  }
  }

  public void testHashTwice() {
    Hasher sha1 = Hashing.sha1().newHasher();

    assertEquals(
        "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
        sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8)

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/FilteredMultimapTest.java
36 issues
The String literal 'badkey' appears 7 times in this file; the first occurrence is on line 37
Error

Line: 37

                    new Predicate<Entry<String, Integer>>() {
        @Override
        public boolean apply(Entry<String, Integer> entry) {
          return !"badkey".equals(entry.getKey()) && !((Integer) 55556).equals(entry.getValue());
        }
      };

  protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();

            

Reported by PMD.

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

Line: 43

              
  protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, ENTRY_PREDICATE);
  }

  private static final Predicate<String> KEY_PREDICATE =

            

Reported by PMD.

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

Line: 43

              
  protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, ENTRY_PREDICATE);
  }

  private static final Predicate<String> KEY_PREDICATE =

            

Reported by PMD.

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

Line: 44

                protected Multimap<String, Integer> create() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    return Multimaps.filterEntries(unfiltered, ENTRY_PREDICATE);
  }

  private static final Predicate<String> KEY_PREDICATE =
      new Predicate<String>() {

            

Reported by PMD.

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

Line: 56

                      }
      };

  public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());

            

Reported by PMD.

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

Line: 56

                      }
      };

  public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());

            

Reported by PMD.

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

Line: 58

              
  public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }

            

Reported by PMD.

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

Line: 59

                public void testFilterKeys() {
    Multimap<String, Integer> unfiltered = HashMultimap.create();
    unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 61

                  unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }

  private static final Predicate<Integer> VALUE_PREDICATE =
      new Predicate<Integer>() {

            

Reported by PMD.

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

Line: 61

                  unfiltered.put("foo", 55556);
    unfiltered.put("badkey", 1);
    Multimap<String, Integer> filtered = Multimaps.filterKeys(unfiltered, KEY_PREDICATE);
    assertEquals(1, filtered.size());
    assertTrue(filtered.containsEntry("foo", 55556));
  }

  private static final Predicate<Integer> VALUE_PREDICATE =
      new Predicate<Integer>() {

            

Reported by PMD.

android/guava-testlib/test/com/google/common/collect/testing/MinimalIterableTest.java
36 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: 33

              @GwtCompatible
public class MinimalIterableTest extends TestCase {

  public void testOf_empty() {
    Iterable<String> iterable = MinimalIterable.<String>of();
    Iterator<String> iterator = iterable.iterator();
    assertFalse(iterator.hasNext());
    try {
      iterator.next();

            

Reported by PMD.

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

Line: 35

              
  public void testOf_empty() {
    Iterable<String> iterable = MinimalIterable.<String>of();
    Iterator<String> iterator = iterable.iterator();
    assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 36

                public void testOf_empty() {
    Iterable<String> iterable = MinimalIterable.<String>of();
    Iterator<String> iterator = iterable.iterator();
    assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {
    }

            

Reported by PMD.

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

Line: 39

                  assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {
    }
    try {
      iterable.iterator();
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  assertFalse(iterator.hasNext());
    try {
      iterator.next();
      fail();
    } catch (NoSuchElementException expected) {
    }
    try {
      iterable.iterator();
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 44

                  }
    try {
      iterable.iterator();
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testOf_one() {

            

Reported by PMD.

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

Line: 44

                  }
    try {
      iterable.iterator();
      fail();
    } catch (IllegalStateException expected) {
    }
  }

  public void testOf_one() {

            

Reported by PMD.

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

Line: 49

                  }
  }

  public void testOf_one() {
    Iterable<String> iterable = MinimalIterable.of("a");
    Iterator<String> iterator = iterable.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertFalse(iterator.hasNext());

            

Reported by PMD.

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

Line: 49

                  }
  }

  public void testOf_one() {
    Iterable<String> iterable = MinimalIterable.of("a");
    Iterator<String> iterator = iterable.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertFalse(iterator.hasNext());

            

Reported by PMD.

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

Line: 51

              
  public void testOf_one() {
    Iterable<String> iterable = MinimalIterable.of("a");
    Iterator<String> iterator = iterable.iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertFalse(iterator.hasNext());
    try {
      iterator.next();

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/MapEntrySetTester.java
36 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: 55

                  INSTANCE;
  }

  @CollectionSize.Require(ONE)
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());

            

Reported by PMD.

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

Line: 57

              
  @CollectionSize.Require(ONE)
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());

            

Reported by PMD.

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

Line: 58

                @CollectionSize.Require(ONE)
  @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));

            

Reported by PMD.

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

Line: 59

                @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
  public void testEntrySetIteratorRemove() {
    Set<Entry<K, V>> entrySet = getMap().entrySet();
    Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));
  }

            

Reported by PMD.

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

Line: 62

                  Iterator<Entry<K, V>> entryItr = entrySet.iterator();
    assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));
  }

  public void testContainsEntryWithIncomparableKey() {
    try {

            

Reported by PMD.

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

Line: 63

                  assertEquals(e0(), entryItr.next());
    entryItr.remove();
    assertTrue(getMap().isEmpty());
    assertFalse(entrySet.contains(e0()));
  }

  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));

            

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

                  assertFalse(entrySet.contains(e0()));
  }

  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }

            

Reported by PMD.

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

Line: 68

              
  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }
  }


            

Reported by PMD.

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

Line: 68

              
  public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }
  }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 69

                public void testContainsEntryWithIncomparableKey() {
    try {
      assertFalse(getMap().entrySet().contains(Helpers.mapEntry(IncomparableType.INSTANCE, v0())));
    } catch (ClassCastException acceptable) {
      // allowed by the spec
    }
  }

  public void testContainsEntryWithIncomparableValue() {

            

Reported by PMD.

android/guava-tests/test/com/google/common/cache/ForwardingLoadingCacheTest.java
36 issues
This class has too many methods, consider refactoring it.
Design

Line: 33

               *
 * @author Charles Fry
 */
public class ForwardingLoadingCacheTest extends TestCase {
  private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override

            

Reported by PMD.

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

Line: 34

               * @author Charles Fry
 */
public class ForwardingLoadingCacheTest extends TestCase {
  private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override
  public void setUp() throws Exception {

            

Reported by PMD.

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

Line: 35

               */
public class ForwardingLoadingCacheTest extends TestCase {
  private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override
  public void setUp() throws Exception {
    super.setUp();

            

Reported by PMD.

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

Line: 37

                private LoadingCache<String, Boolean> forward;
  private LoadingCache<String, Boolean> mock;

  @SuppressWarnings({"unchecked", "DoNotMock"}) // mock
  @Override
  public void setUp() throws Exception {
    super.setUp();
    /*
     * Class parameters must be raw, so we can't create a proxy with generic

            

Reported by PMD.

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

Line: 56

                      };
  }

  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {

            

Reported by PMD.

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

Line: 57

                }

  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);

            

Reported by PMD.

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

Line: 57

                }

  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 58

              
  public void testGet() throws ExecutionException {
    when(mock.get("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.getUnchecked("key"));

            

Reported by PMD.

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

Line: 61

                  assertSame(Boolean.TRUE, forward.get("key"));
  }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.getUnchecked("key"));
  }

  public void testGetAll() throws ExecutionException {

            

Reported by PMD.

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

Line: 62

                }

  public void testGetUnchecked() {
    when(mock.getUnchecked("key")).thenReturn(Boolean.TRUE);
    assertSame(Boolean.TRUE, forward.getUnchecked("key"));
  }

  public void testGetAll() throws ExecutionException {
    when(mock.getAll(ImmutableList.of("key"))).thenReturn(ImmutableMap.of("key", Boolean.TRUE));

            

Reported by PMD.