The following issues were found

android/guava-tests/test/com/google/common/base/VerifyTest.java
26 issues
This class has too many methods, consider refactoring it.
Design

Line: 28

              
/** Unit test for {@link com.google.common.base.Verify}. */
@GwtCompatible(emulated = true)
public class VerifyTest extends TestCase {
  public void testVerify_simple_success() {
    verify(true);
  }

  public void testVerify_simple_failure() {

            

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

              /** Unit test for {@link com.google.common.base.Verify}. */
@GwtCompatible(emulated = true)
public class VerifyTest extends TestCase {
  public void testVerify_simple_success() {
    verify(true);
  }

  public void testVerify_simple_failure() {
    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: 33

                  verify(true);
  }

  public void testVerify_simple_failure() {
    try {
      verify(false);
      fail();
    } catch (VerifyException expected) {
    }

            

Reported by PMD.

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

Line: 36

                public void testVerify_simple_failure() {
    try {
      verify(false);
      fail();
    } catch (VerifyException expected) {
    }
  }

  public void testVerify_simpleMessage_success() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 36

                public void testVerify_simple_failure() {
    try {
      verify(false);
      fail();
    } catch (VerifyException expected) {
    }
  }

  public void testVerify_simpleMessage_success() {

            

Reported by PMD.

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

Line: 41

                  }
  }

  public void testVerify_simpleMessage_success() {
    verify(true, "message");
  }

  public void testVerify_simpleMessage_failure() {
    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: 45

                  verify(true, "message");
  }

  public void testVerify_simpleMessage_failure() {
    try {
      verify(false, "message");
      fail();
    } catch (VerifyException expected) {
      assertThat(expected).hasMessageThat().isEqualTo("message");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 48

                public void testVerify_simpleMessage_failure() {
    try {
      verify(false, "message");
      fail();
    } catch (VerifyException expected) {
      assertThat(expected).hasMessageThat().isEqualTo("message");
    }
  }


            

Reported by PMD.

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

Line: 50

                    verify(false, "message");
      fail();
    } catch (VerifyException expected) {
      assertThat(expected).hasMessageThat().isEqualTo("message");
    }
  }

  public void testVerify_complexMessage_success() {
    verify(true, "%s", IGNORE_ME);

            

Reported by PMD.

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

Line: 50

                    verify(false, "message");
      fail();
    } catch (VerifyException expected) {
      assertThat(expected).hasMessageThat().isEqualTo("message");
    }
  }

  public void testVerify_complexMessage_success() {
    verify(true, "%s", IGNORE_ME);

            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/DefaultNetworkImplementationsTest.java
26 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 46

              // TODO(cpovirk): Figure out Android JUnit 4 support. Does it work with Gingerbread? @RunWith?
@RunWith(Parameterized.class)
public final class DefaultNetworkImplementationsTest {
  private MutableNetwork<Integer, String> network;
  private NetworkForTest<Integer, String> networkForTest;
  private static final Integer N1 = 1;
  private static final Integer N2 = 2;
  private static final Integer NODE_NOT_IN_GRAPH = 1000;
  private static final String E11 = "1-1";

            

Reported by PMD.

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

Line: 47

              @RunWith(Parameterized.class)
public final class DefaultNetworkImplementationsTest {
  private MutableNetwork<Integer, String> network;
  private NetworkForTest<Integer, String> networkForTest;
  private static final Integer N1 = 1;
  private static final Integer N2 = 2;
  private static final Integer NODE_NOT_IN_GRAPH = 1000;
  private static final String E11 = "1-1";
  private static final String E11_A = "1-1a";

            

Reported by PMD.

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

Line: 66

                      });
  }

  private final EdgeType edgeType;

  public DefaultNetworkImplementationsTest(EdgeType edgeType) {
    this.edgeType = edgeType;
  }


            

Reported by PMD.

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

Line: 77

                  NetworkBuilder<Object, Object> builder =
        (edgeType == EdgeType.DIRECTED) ? NetworkBuilder.directed() : NetworkBuilder.undirected();

    network = builder.allowsSelfLoops(true).allowsParallelEdges(true).build();
    networkForTest = NetworkForTest.from(network);
  }

  @Test
  public void edgesConnecting_disconnectedNodes() {

            

Reported by PMD.

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

Line: 77

                  NetworkBuilder<Object, Object> builder =
        (edgeType == EdgeType.DIRECTED) ? NetworkBuilder.directed() : NetworkBuilder.undirected();

    network = builder.allowsSelfLoops(true).allowsParallelEdges(true).build();
    networkForTest = NetworkForTest.from(network);
  }

  @Test
  public void edgesConnecting_disconnectedNodes() {

            

Reported by PMD.

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

Line: 85

                public void edgesConnecting_disconnectedNodes() {
    network.addNode(N1);
    network.addNode(N2);
    assertThat(networkForTest.edgesConnecting(N1, N2)).isEmpty();
  }

  @Test
  public void edgesConnecting_nodesNotInGraph() {
    network.addNode(N1);

            

Reported by PMD.

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

Line: 89

                }

  @Test
  public void edgesConnecting_nodesNotInGraph() {
    network.addNode(N1);
    network.addNode(N2);
    try {
      networkForTest.edgesConnecting(N1, NODE_NOT_IN_GRAPH);
      fail(ERROR_NODE_NOT_IN_GRAPH);

            

Reported by PMD.

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

Line: 122

                    fail(ERROR_MODIFIABLE_COLLECTION);
    } catch (UnsupportedOperationException e) {
      network.addEdge(N1, N2, E12);
      assertThat(networkForTest.edgesConnecting(N1, N2)).containsExactlyElementsIn(edgesConnecting);
    }
  }

  @Test
  public void edgesConnecting_oneEdge() {

            

Reported by PMD.

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

Line: 127

                }

  @Test
  public void edgesConnecting_oneEdge() {
    network.addEdge(N1, N2, E12);
    assertThat(networkForTest.edgesConnecting(N1, N2)).containsExactly(E12);
    if (edgeType == EdgeType.DIRECTED) {
      assertThat(networkForTest.edgesConnecting(N2, N1)).isEmpty();
    } else {

            

Reported by PMD.

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

Line: 129

                @Test
  public void edgesConnecting_oneEdge() {
    network.addEdge(N1, N2, E12);
    assertThat(networkForTest.edgesConnecting(N1, N2)).containsExactly(E12);
    if (edgeType == EdgeType.DIRECTED) {
      assertThat(networkForTest.edgesConnecting(N2, N1)).isEmpty();
    } else {
      assertThat(networkForTest.edgesConnecting(N2, N1)).containsExactly(E12);
    }

            

Reported by PMD.

android/guava-testlib/src/com/google/common/testing/ArbitraryInstances.java
26 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.testing;

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

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtIncompatible;

            

Reported by PMD.

High amount of different objects as members denotes a high coupling
Design

Line: 17

               * limitations under the License.
 */

package com.google.common.testing;

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

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtIncompatible;

            

Reported by PMD.

The class 'ArbitraryInstances' has a Standard Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 171

               */
@Beta
@GwtIncompatible
public final class ArbitraryInstances {

  private static final Ordering<Field> BY_FIELD_NAME =
      new Ordering<Field>() {
        @Override
        public int compare(Field left, Field right) {

            

Reported by PMD.

The class 'ArbitraryInstances' has a Modified Cyclomatic Complexity of 3 (Highest = 12).
Design

Line: 171

               */
@Beta
@GwtIncompatible
public final class ArbitraryInstances {

  private static final Ordering<Field> BY_FIELD_NAME =
      new Ordering<Field>() {
        @Override
        public int compare(Field left, Field right) {

            

Reported by PMD.

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

Line: 177

                    new Ordering<Field>() {
        @Override
        public int compare(Field left, Field right) {
          return left.getName().compareTo(right.getName());
        }
      };

  /**
   * Returns a new {@code MatchResult} that corresponds to a successful match. Apache Harmony (used

            

Reported by PMD.

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

Line: 187

                 * http://goo.gl/5VQFmC
   */
  private static MatchResult newMatchResult() {
    Matcher matcher = Pattern.compile(".").matcher("X");
    matcher.find();
    return matcher.toMatchResult();
  }

  private static final ClassToInstanceMap<Object> DEFAULTS =

            

Reported by PMD.

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

Line: 188

                 */
  private static MatchResult newMatchResult() {
    Matcher matcher = Pattern.compile(".").matcher("X");
    matcher.find();
    return matcher.toMatchResult();
  }

  private static final ClassToInstanceMap<Object> DEFAULTS =
      ImmutableClassToInstanceMap.builder()

            

Reported by PMD.

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

Line: 189

                private static MatchResult newMatchResult() {
    Matcher matcher = Pattern.compile(".").matcher("X");
    matcher.find();
    return matcher.toMatchResult();
  }

  private static final ClassToInstanceMap<Object> DEFAULTS =
      ImmutableClassToInstanceMap.builder()
          // primitives

            

Reported by PMD.

The method 'get' has a Standard Cyclomatic Complexity of 12.
Design

Line: 342

                 * determined.
   */
  @NullableDecl
  public static <T> T get(Class<T> type) {
    T defaultValue = DEFAULTS.getInstance(type);
    if (defaultValue != null) {
      return defaultValue;
    }
    Class<? extends T> implementation = getImplementation(type);

            

Reported by PMD.

The method 'get(Class)' has a cyclomatic complexity of 15.
Design

Line: 342

                 * determined.
   */
  @NullableDecl
  public static <T> T get(Class<T> type) {
    T defaultValue = DEFAULTS.getInstance(type);
    if (defaultValue != null) {
      return defaultValue;
    }
    Class<? extends T> implementation = getImplementation(type);

            

Reported by PMD.

android/guava-testlib/test/com/google/common/testing/TestLogHandlerTest.java
26 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 31

               */
public class TestLogHandlerTest extends TestCase {

  private TestLogHandler handler;
  private TearDownStack stack = new TearDownStack();

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

            

Reported by PMD.

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

Line: 32

              public class TestLogHandlerTest extends TestCase {

  private TestLogHandler handler;
  private TearDownStack stack = new TearDownStack();

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


            

Reported by PMD.

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

Line: 32

              public class TestLogHandlerTest extends TestCase {

  private TestLogHandler handler;
  private TearDownStack stack = new TearDownStack();

  @Override
  protected 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: 34

                private TestLogHandler handler;
  private TearDownStack stack = new TearDownStack();

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

    handler = new TestLogHandler();


            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 41

                  handler = new TestLogHandler();

    // You could also apply it higher up the Logger hierarchy than this
    ExampleClassUnderTest.logger.addHandler(handler);

    ExampleClassUnderTest.logger.setUseParentHandlers(false); // optional

    stack.addTearDown(
        new TearDown() {

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 43

                  // You could also apply it higher up the Logger hierarchy than this
    ExampleClassUnderTest.logger.addHandler(handler);

    ExampleClassUnderTest.logger.setUseParentHandlers(false); // optional

    stack.addTearDown(
        new TearDown() {
          @Override
          public void tearDown() throws Exception {

            

Reported by PMD.

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

Line: 47

              
    stack.addTearDown(
        new TearDown() {
          @Override
          public void tearDown() throws Exception {
            ExampleClassUnderTest.logger.setUseParentHandlers(true);
            ExampleClassUnderTest.logger.removeHandler(handler);
          }
        });

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 49

                      new TearDown() {
          @Override
          public void tearDown() throws Exception {
            ExampleClassUnderTest.logger.setUseParentHandlers(true);
            ExampleClassUnderTest.logger.removeHandler(handler);
          }
        });
  }


            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 50

                        @Override
          public void tearDown() throws Exception {
            ExampleClassUnderTest.logger.setUseParentHandlers(true);
            ExampleClassUnderTest.logger.removeHandler(handler);
          }
        });
  }

  public void test() throws Exception {

            

Reported by PMD.

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

Line: 55

                      });
  }

  public void test() throws Exception {
    assertTrue(handler.getStoredLogRecords().isEmpty());
    ExampleClassUnderTest.foo();
    LogRecord record = handler.getStoredLogRecords().get(0);
    assertEquals(Level.INFO, record.getLevel());
    assertEquals("message", record.getMessage());

            

Reported by PMD.

android/guava-testlib/test/com/google/common/collect/testing/MapTestSuiteBuilderTests.java
26 issues
Avoid throwing null pointer exceptions.
Design

Line: 100

                        @Override
          Map<String, String> wrap(final HashMap<String, String> map) {
            if (map.containsKey(null)) {
              throw new NullPointerException();
            }
            return new AbstractMap<String, String>() {
              @Override
              public Set<Entry<String, String>> entrySet() {
                return map.entrySet();

            

Reported by PMD.

Avoid throwing null pointer exceptions.
Design

Line: 126

                        @Override
          Map<String, String> wrap(final HashMap<String, String> map) {
            if (map.containsValue(null)) {
              throw new NullPointerException();
            }

            return new AbstractMap<String, String>() {
              @Override
              public Set<Entry<String, String>> entrySet() {

            

Reported by PMD.

This class name ends with Test but contains no test cases
Error

Line: 54

               *
 * @author George van den Driessche
 */
public final class MapTestSuiteBuilderTests extends TestCase {
  private MapTestSuiteBuilderTests() {}

  public static Test suite() {
    TestSuite suite = new TestSuite(MapTestSuiteBuilderTests.class.getSimpleName());
    suite.addTest(testsForHashMapNullKeysForbidden());

            

Reported by PMD.

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

Line: 57

              public final class MapTestSuiteBuilderTests extends TestCase {
  private MapTestSuiteBuilderTests() {}

  public static Test suite() {
    TestSuite suite = new TestSuite(MapTestSuiteBuilderTests.class.getSimpleName());
    suite.addTest(testsForHashMapNullKeysForbidden());
    suite.addTest(testsForHashMapNullValuesForbidden());
    suite.addTest(testsForSetUpTearDown());
    return suite;

            

Reported by PMD.

Avoid using implementation types like 'HashMap'; use the interface instead
Design

Line: 75

                    return wrap(map);
    }

    abstract Map<String, String> wrap(HashMap<String, String> map);
  }

  private static TestSuite wrappedHashMapTests(
      WrappedHashMapGenerator generator, String name, Feature<?>... features) {
    List<Feature<?>> featuresList = Lists.newArrayList(features);

            

Reported by PMD.

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

Line: 86

                      MapFeature.GENERAL_PURPOSE,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
        CollectionSize.ANY);
    return MapTestSuiteBuilder.using(generator)
        .named(name)
        .withFeatures(featuresList)
        .createTestSuite();
  }


            

Reported by PMD.

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

Line: 86

                      MapFeature.GENERAL_PURPOSE,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
        CollectionSize.ANY);
    return MapTestSuiteBuilder.using(generator)
        .named(name)
        .withFeatures(featuresList)
        .createTestSuite();
  }


            

Reported by PMD.

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

Line: 86

                      MapFeature.GENERAL_PURPOSE,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
        CollectionSize.ANY);
    return MapTestSuiteBuilder.using(generator)
        .named(name)
        .withFeatures(featuresList)
        .createTestSuite();
  }


            

Reported by PMD.

Avoid really long methods.
Design

Line: 120

                      ALLOWS_NULL_VALUES);
  }

  private static Test testsForHashMapNullValuesForbidden() {
    return wrappedHashMapTests(
        new WrappedHashMapGenerator() {
          @Override
          Map<String, String> wrap(final HashMap<String, String> map) {
            if (map.containsValue(null)) {

            

Reported by PMD.

Avoid really long methods.
Design

Line: 124

                  return wrappedHashMapTests(
        new WrappedHashMapGenerator() {
          @Override
          Map<String, String> wrap(final HashMap<String, String> map) {
            if (map.containsValue(null)) {
              throw new NullPointerException();
            }

            return new AbstractMap<String, String>() {

            

Reported by PMD.

android/guava-tests/test/com/google/common/eventbus/SubscriberTest.java
26 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

              
  private static final Object FIXTURE_ARGUMENT = new Object();

  private EventBus bus;
  private boolean methodCalled;
  private Object methodArgument;

  @Override
  protected void setUp() throws Exception {

            

Reported by PMD.

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

Line: 37

                private static final Object FIXTURE_ARGUMENT = new Object();

  private EventBus bus;
  private boolean methodCalled;
  private Object methodArgument;

  @Override
  protected void setUp() throws Exception {
    bus = new EventBus();

            

Reported by PMD.

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

Line: 38

              
  private EventBus bus;
  private boolean methodCalled;
  private Object methodArgument;

  @Override
  protected void setUp() throws Exception {
    bus = new EventBus();
    methodCalled = false;

            

Reported by PMD.

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

Line: 40

                private boolean methodCalled;
  private Object methodArgument;

  @Override
  protected void setUp() throws Exception {
    bus = new EventBus();
    methodCalled = false;
    methodArgument = null;
  }

            

Reported by PMD.

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

Line: 44

                protected void setUp() throws Exception {
    bus = new EventBus();
    methodCalled = false;
    methodArgument = null;
  }

  public void testCreate() {
    Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
    assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);

            

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

                  methodArgument = null;
  }

  public void testCreate() {
    Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
    assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);

    // a thread-safe method should not create a synchronized subscriber
    Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));

            

Reported by PMD.

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

Line: 47

                  methodArgument = null;
  }

  public void testCreate() {
    Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
    assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);

    // a thread-safe method should not create a synchronized subscriber
    Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));

            

Reported by PMD.

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

Line: 49

              
  public void testCreate() {
    Subscriber s1 = Subscriber.create(bus, this, getTestSubscriberMethod("recordingMethod"));
    assertThat(s1).isInstanceOf(Subscriber.SynchronizedSubscriber.class);

    // a thread-safe method should not create a synchronized subscriber
    Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));
    assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class);
  }

            

Reported by PMD.

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

Line: 53

              
    // a thread-safe method should not create a synchronized subscriber
    Subscriber s2 = Subscriber.create(bus, this, getTestSubscriberMethod("threadSafeMethod"));
    assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class);
  }

  public void testInvokeSubscriberMethod_basicMethodCall() throws Throwable {
    Method method = getTestSubscriberMethod("recordingMethod");
    Subscriber subscriber = Subscriber.create(bus, this, method);

            

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

                  assertThat(s2).isNotInstanceOf(Subscriber.SynchronizedSubscriber.class);
  }

  public void testInvokeSubscriberMethod_basicMethodCall() throws Throwable {
    Method method = getTestSubscriberMethod("recordingMethod");
    Subscriber subscriber = Subscriber.create(bus, this, method);

    subscriber.invokeSubscriberMethod(FIXTURE_ARGUMENT);


            

Reported by PMD.

android/guava-tests/test/com/google/common/base/FinalizableReferenceQueueTest.java
25 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

               */
public class FinalizableReferenceQueueTest extends TestCase {

  private FinalizableReferenceQueue frq;

  @Override
  protected void tearDown() throws Exception {
    frq = null;
  }

            

Reported by PMD.

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

Line: 38

              
  private FinalizableReferenceQueue frq;

  @Override
  protected void tearDown() throws Exception {
    frq = null;
  }



            

Reported by PMD.

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

Line: 40

              
  @Override
  protected void tearDown() throws Exception {
    frq = null;
  }


  public void testFinalizeReferentCalled() {
    final MockReference reference = new MockReference(frq = new FinalizableReferenceQueue());

            

Reported by PMD.

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

Line: 44

                }


  public void testFinalizeReferentCalled() {
    final MockReference reference = new MockReference(frq = new FinalizableReferenceQueue());

    GcFinalization.awaitDone(
        new GcFinalization.FinalizationPredicate() {
          public boolean isDone() {

            

Reported by PMD.

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

Line: 44

                }


  public void testFinalizeReferentCalled() {
    final MockReference reference = new MockReference(frq = new FinalizableReferenceQueue());

    GcFinalization.awaitDone(
        new GcFinalization.FinalizationPredicate() {
          public boolean isDone() {

            

Reported by PMD.

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

Line: 57

              
  static class MockReference extends FinalizableWeakReference<Object> {

    volatile boolean finalizeReferentCalled;

    MockReference(FinalizableReferenceQueue frq) {
      super(new Object(), frq);
    }


            

Reported by PMD.

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

Line: 73

                 * Keeps a weak reference to the underlying reference queue. When this reference is cleared, we
   * know that the background thread has stopped and released its strong reference.
   */
  private WeakReference<ReferenceQueue<Object>> queueReference;


  public void testThatFinalizerStops() {
    weaklyReferenceQueue();
    GcFinalization.awaitClear(queueReference);

            

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

                private WeakReference<ReferenceQueue<Object>> queueReference;


  public void testThatFinalizerStops() {
    weaklyReferenceQueue();
    GcFinalization.awaitClear(queueReference);
  }

  /** If we don't keep a strong reference to the reference object, it won't be enqueued. */

            

Reported by PMD.

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

Line: 76

                private WeakReference<ReferenceQueue<Object>> queueReference;


  public void testThatFinalizerStops() {
    weaklyReferenceQueue();
    GcFinalization.awaitClear(queueReference);
  }

  /** If we don't keep a strong reference to the reference object, it won't be enqueued. */

            

Reported by PMD.

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

Line: 82

                }

  /** If we don't keep a strong reference to the reference object, it won't be enqueued. */
  FinalizableWeakReference<Object> reference;

  /** Create the FRQ in a method that goes out of scope so that we're sure it will be reclaimed. */
  private void weaklyReferenceQueue() {
    frq = new FinalizableReferenceQueue();
    queueReference = new WeakReference<>(frq.queue);

            

Reported by PMD.

android/guava-tests/benchmark/com/google/common/base/JoinerBenchmark.java
25 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                private static final Joiner JOINER_ON_CHARACTER = Joiner.on(DELIMITER_CHARACTER);

  @Param({"3", "30", "300"})
  int count;

  @Param({"0", "1", "16", "32", "100"})
  int componentLength;

  private Iterable<String> components;

            

Reported by PMD.

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

Line: 42

                int count;

  @Param({"0", "1", "16", "32", "100"})
  int componentLength;

  private Iterable<String> components;

  @BeforeExperiment
  void setUp() {

            

Reported by PMD.

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

Line: 44

                @Param({"0", "1", "16", "32", "100"})
  int componentLength;

  private Iterable<String> components;

  @BeforeExperiment
  void setUp() {
    String component = Strings.repeat("a", componentLength);
    String[] raw = new String[count];

            

Reported by PMD.

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

Line: 46

              
  private Iterable<String> components;

  @BeforeExperiment
  void setUp() {
    String component = Strings.repeat("a", componentLength);
    String[] raw = new String[count];
    Arrays.fill(raw, component);
    components = Arrays.asList(raw);

            

Reported by PMD.

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

Line: 59

                int joinerWithStringDelimiter(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      dummy ^= JOINER_ON_STRING.join(components).length();
    }
    return dummy;
  }

  /** {@link Joiner} with a character delimiter. */

            

Reported by PMD.

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

Line: 69

                int joinerWithCharacterDelimiter(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      dummy ^= JOINER_ON_CHARACTER.join(components).length();
    }
    return dummy;
  }

  /**

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 82

                int joinerInlined(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      StringBuilder sb = new StringBuilder();
      Iterator<String> iterator = components.iterator();
      if (iterator.hasNext()) {
        sb.append(iterator.next().toString());
        while (iterator.hasNext()) {
          sb.append(DELIMITER_STRING);

            

Reported by PMD.

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

Line: 85

                    StringBuilder sb = new StringBuilder();
      Iterator<String> iterator = components.iterator();
      if (iterator.hasNext()) {
        sb.append(iterator.next().toString());
        while (iterator.hasNext()) {
          sb.append(DELIMITER_STRING);
          sb.append(iterator.next());
        }
      }

            

Reported by PMD.

This is an inefficient use of StringBuffer.toString; call StringBuffer.length instead.
Performance

Line: 91

                        sb.append(iterator.next());
        }
      }
      dummy ^= sb.toString().length();
    }
    return dummy;
  }

  /**

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 104

                int stringBuilderIsEmpty(int reps) {
    int dummy = 0;
    for (int i = 0; i < reps; i++) {
      StringBuilder sb = new StringBuilder();
      for (String comp : components) {
        if (sb.length() > 0) {
          sb.append(DELIMITER_STRING);
        }
        sb.append(comp);

            

Reported by PMD.

android/guava-tests/test/com/google/common/graph/GraphEquivalenceTest.java
25 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                private static final Integer N2 = 2;
  private static final Integer N3 = 3;

  private final EdgeType edgeType;
  private final MutableGraph<Integer> graph;

  // add parameters: directed/undirected
  @Parameters
  public static Collection<Object[]> parameters() {

            

Reported by PMD.

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

Line: 40

                private static final Integer N3 = 3;

  private final EdgeType edgeType;
  private final MutableGraph<Integer> graph;

  // add parameters: directed/undirected
  @Parameters
  public static Collection<Object[]> parameters() {
    return Arrays.asList(new Object[][] {{EdgeType.UNDIRECTED}, {EdgeType.DIRECTED}});

            

Reported by PMD.

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

Line: 56

                private static MutableGraph<Integer> createGraph(EdgeType edgeType) {
    switch (edgeType) {
      case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }

            

Reported by PMD.

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

Line: 56

                private static MutableGraph<Integer> createGraph(EdgeType edgeType) {
    switch (edgeType) {
      case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }

            

Reported by PMD.

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

Line: 58

                    case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }
  }


            

Reported by PMD.

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

Line: 58

                    case UNDIRECTED:
        return GraphBuilder.undirected().allowsSelfLoops(true).build();
      case DIRECTED:
        return GraphBuilder.directed().allowsSelfLoops(true).build();
      default:
        throw new IllegalStateException("Unexpected edge type: " + edgeType);
    }
  }


            

Reported by PMD.

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

Line: 80

                  graph.addNode(N1);

    MutableGraph<Integer> g2 = createGraph(edgeType);
    g2.addNode(N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets are the same, but node/edge connections differ due to edge type.

            

Reported by PMD.

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

Line: 82

                  MutableGraph<Integer> g2 = createGraph(edgeType);
    g2.addNode(N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets are the same, but node/edge connections differ due to edge type.
  @Test
  public void equivalent_directedVsUndirected() {

            

Reported by PMD.

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

Line: 91

                  graph.putEdge(N1, N2);

    MutableGraph<Integer> g2 = createGraph(oppositeType(edgeType));
    g2.putEdge(N1, N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets and node/edge connections are the same, but directedness differs.

            

Reported by PMD.

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

Line: 93

                  MutableGraph<Integer> g2 = createGraph(oppositeType(edgeType));
    g2.putEdge(N1, N2);

    assertThat(graph).isNotEqualTo(g2);
  }

  // Node/edge sets and node/edge connections are the same, but directedness differs.
  @Test
  public void equivalent_selfLoop_directedVsUndirected() {

            

Reported by PMD.

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

Line: 45

              @SuppressWarnings("unchecked") // too many "unchecked generic array creations"
@GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAtIndex_supportedPresent() {
    getList().add(0, e0());
    expectAdded(0, e0());

            

Reported by PMD.

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

Line: 46

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class ListAddAtIndexTester<E> extends AbstractListTester<E> {
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAtIndex_supportedPresent() {
    getList().add(0, e0());
    expectAdded(0, e0());
  }

            

Reported by PMD.

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

Line: 49

                @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  public void testAddAtIndex_supportedPresent() {
    getList().add(0, e0());
    expectAdded(0, e0());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)

            

Reported by PMD.

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

Line: 53

                  expectAdded(0, e0());
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  @CollectionSize.Require(absent = ZERO)
  /*
   * absent = ZERO isn't required, since unmodList.add() must
   * throw regardless, but it keeps the method name accurate.
   */

            

Reported by PMD.

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

Line: 61

                 */
  public void testAddAtIndex_unsupportedPresent() {
    try {
      getList().add(0, e0());
      fail("add(n, present) should throw");
    } catch (UnsupportedOperationException expected) {
    }
    expectUnchanged();
  }

            

Reported by PMD.

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

Line: 68

                  expectUnchanged();
  }

  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndex_supportedNotPresent() {
    getList().add(0, e3());
    expectAdded(0, e3());
  }


            

Reported by PMD.

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

Line: 70

              
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndex_supportedNotPresent() {
    getList().add(0, e3());
    expectAdded(0, e3());
  }

  @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)

            

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

                  expectAdded(0, e3());
  }

  @CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
  @ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      getList().add(0, e3());

            

Reported by PMD.

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

Line: 79

                public void testAddAtIndexConcurrentWithIteration() {
    try {
      Iterator<E> iterator = collection.iterator();
      getList().add(0, e3());
      iterator.next();
      fail("Expected ConcurrentModificationException");
    } catch (ConcurrentModificationException expected) {
      // success
    }

            

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

                  }
  }

  @ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
  public void testAddAtIndex_unsupportedNotPresent() {
    try {
      getList().add(0, e3());
      fail("add(n, notPresent) should throw");
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.