The following issues were found

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.

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.

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.

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.

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.

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 Modified Cyclomatic Complexity of 3 (Highest = 13).
Design

Line: 176

               */
@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 Standard Cyclomatic Complexity of 3 (Highest = 13).
Design

Line: 176

               */
@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: 182

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

                 * 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: 193

                 */
  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: 194

                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 Modified Cyclomatic Complexity of 13.
Design

Line: 349

                 * Returns an arbitrary instance for {@code type}, or {@code null} if no arbitrary instance can be
   * determined.
   */
  public static <T> @Nullable 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' has a Standard Cyclomatic Complexity of 13.
Design

Line: 349

                 * Returns an arbitrary instance for {@code type}, or {@code null} if no arbitrary instance can be
   * determined.
   */
  public static <T> @Nullable T get(Class<T> type) {
    T defaultValue = DEFAULTS.getInstance(type);
    if (defaultValue != null) {
      return defaultValue;
    }
    Class<? extends T> implementation = getImplementation(type);

            

Reported by PMD.

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.

guava-testlib/src/com/google/common/collect/testing/testers/MapMergeTester.java
26 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 45

              @GwtCompatible(emulated = true)
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapMergeTester<K, V> extends AbstractMapTester<K, V> {
  @MapFeature.Require(SUPPORTS_PUT)
  public void testAbsent() {
    assertEquals(
        "Map.merge(absent, value, function) should return value",
        v3(),
        getMap()

            

Reported by PMD.

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

Line: 50

                  assertEquals(
        "Map.merge(absent, value, function) should return value",
        v3(),
        getMap()
            .merge(
                k3(),
                v3(),
                (oldV, newV) -> {
                  throw new AssertionFailedError(

            

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

                  expectAdded(e3());
  }

  @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
  @CollectionSize.Require(absent = ZERO)
  public void testMappedToNull() {
    initMapWithNullValue();
    assertEquals(
        "Map.merge(keyMappedToNull, value, function) should return value",

            

Reported by PMD.

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

Line: 68

                  assertEquals(
        "Map.merge(keyMappedToNull, value, function) should return value",
        v3(),
        getMap()
            .merge(
                getKeyForNullValue(),
                v3(),
                (oldV, newV) -> {
                  throw new AssertionFailedError(

            

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

                  expectReplacement(entry(getKeyForNullValue(), v3()));
  }

  @MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS})
  public void testMergeAbsentNullKey() {
    assertEquals(
        "Map.merge(null, value, function) should return value",
        v3(),
        getMap()

            

Reported by PMD.

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

Line: 84

                  assertEquals(
        "Map.merge(null, value, function) should return value",
        v3(),
        getMap()
            .merge(
                null,
                v3(),
                (oldV, newV) -> {
                  throw new AssertionFailedError(

            

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

                  expectAdded(entry(null, v3()));
  }

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testMergePresent() {
    assertEquals(
        "Map.merge(present, value, function) should return function result",
        v4(),

            

Reported by PMD.

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

Line: 97

              
  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testMergePresent() {
    assertEquals(
        "Map.merge(present, value, function) should return function result",
        v4(),
        getMap()
            .merge(

            

Reported by PMD.

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

Line: 101

                  assertEquals(
        "Map.merge(present, value, function) should return function result",
        v4(),
        getMap()
            .merge(
                k0(),
                v3(),
                (oldV, newV) -> {
                  assertEquals(v0(), oldV);

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 113

                  expectReplacement(entry(k0(), v4()));
  }

  private static class ExpectedException extends RuntimeException {}

  @MapFeature.Require(SUPPORTS_PUT)
  @CollectionSize.Require(absent = ZERO)
  public void testMergeFunctionThrows() {
    try {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/CollectSpliteratorsTest.java
26 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

              /** Tests for {@code CollectSpliterators}. */
@GwtCompatible
public class CollectSpliteratorsTest extends TestCase {
  public void testMap() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.map(
                    Arrays.spliterator(new String[] {"a", "b", "c", "d", "e"}), Ascii::toUpperCase))
        .expect("A", "B", "C", "D", "E");

            

Reported by PMD.

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

Line: 33

              /** Tests for {@code CollectSpliterators}. */
@GwtCompatible
public class CollectSpliteratorsTest extends TestCase {
  public void testMap() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.map(
                    Arrays.spliterator(new String[] {"a", "b", "c", "d", "e"}), Ascii::toUpperCase))
        .expect("A", "B", "C", "D", "E");

            

Reported by PMD.

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

Line: 34

              @GwtCompatible
public class CollectSpliteratorsTest extends TestCase {
  public void testMap() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.map(
                    Arrays.spliterator(new String[] {"a", "b", "c", "d", "e"}), Ascii::toUpperCase))
        .expect("A", "B", "C", "D", "E");
  }

            

Reported by PMD.

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

Line: 41

                      .expect("A", "B", "C", "D", "E");
  }

  public void testFlatMap() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.flatMap(
                    Arrays.spliterator(new String[] {"abc", "", "de", "f", "g", ""}),
                    (String str) -> Lists.charactersOf(str).spliterator(),

            

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

                      .expect("A", "B", "C", "D", "E");
  }

  public void testFlatMap() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.flatMap(
                    Arrays.spliterator(new String[] {"abc", "", "de", "f", "g", ""}),
                    (String str) -> Lists.charactersOf(str).spliterator(),

            

Reported by PMD.

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

Line: 42

                }

  public void testFlatMap() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.flatMap(
                    Arrays.spliterator(new String[] {"abc", "", "de", "f", "g", ""}),
                    (String str) -> Lists.charactersOf(str).spliterator(),
                    Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.NONNULL,

            

Reported by PMD.

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

Line: 52

                      .expect('a', 'b', 'c', 'd', 'e', 'f', 'g');
  }

  public void testFlatMap_nullStream() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.flatMap(
                    Arrays.spliterator(new String[] {"abc", "", "de", "f", "g", ""}),
                    (String str) -> str.isEmpty() ? null : Lists.charactersOf(str).spliterator(),

            

Reported by PMD.

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

Line: 52

                      .expect('a', 'b', 'c', 'd', 'e', 'f', 'g');
  }

  public void testFlatMap_nullStream() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.flatMap(
                    Arrays.spliterator(new String[] {"abc", "", "de", "f", "g", ""}),
                    (String str) -> str.isEmpty() ? null : Lists.charactersOf(str).spliterator(),

            

Reported by PMD.

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

Line: 53

                }

  public void testFlatMap_nullStream() {
    SpliteratorTester.of(
            () ->
                CollectSpliterators.flatMap(
                    Arrays.spliterator(new String[] {"abc", "", "de", "f", "g", ""}),
                    (String str) -> str.isEmpty() ? null : Lists.charactersOf(str).spliterator(),
                    Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.NONNULL,

            

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

                      .expect('a', 'b', 'c', 'd', 'e', 'f', 'g');
  }

  public void testFlatMapToInt_nullStream() {
    SpliteratorTester.ofInt(
            () ->
                CollectSpliterators.flatMapToInt(
                    Arrays.spliterator(new Integer[] {1, 0, 1, 2, 3}),
                    (Integer i) -> i == 0 ? null : IntStream.of(i).spliterator(),

            

Reported by PMD.

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

Line: 45

              
public class ConcurrentHashMultisetBasherTest extends TestCase {

  public void testAddAndRemove_ConcurrentHashMap() throws Exception {
    testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
    testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());

            

Reported by PMD.

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

Line: 45

              
public class ConcurrentHashMultisetBasherTest extends TestCase {

  public void testAddAndRemove_ConcurrentHashMap() throws Exception {
    testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
    testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());

            

Reported by PMD.

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

Line: 49

                  testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
    testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_MapMakerMap() throws Exception {
    MapMaker mapMaker = new MapMaker();

            

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

                  testAddAndRemove(new ConcurrentHashMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_ConcurrentSkipListMap() throws Exception {
    testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_MapMakerMap() throws Exception {
    MapMaker mapMaker = new MapMaker();

            

Reported by PMD.

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

Line: 53

                  testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_MapMakerMap() throws Exception {
    MapMaker mapMaker = new MapMaker();
    // force MapMaker to use its own MapMakerInternalMap
    mapMaker.useCustomMap = true;
    testAddAndRemove(mapMaker.<String, AtomicInteger>makeMap());
  }

            

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

                  testAddAndRemove(new ConcurrentSkipListMap<String, AtomicInteger>());
  }

  public void testAddAndRemove_MapMakerMap() throws Exception {
    MapMaker mapMaker = new MapMaker();
    // force MapMaker to use its own MapMakerInternalMap
    mapMaker.useCustomMap = true;
    testAddAndRemove(mapMaker.<String, AtomicInteger>makeMap());
  }

            

Reported by PMD.

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

Line: 60

                  testAddAndRemove(mapMaker.<String, AtomicInteger>makeMap());
  }

  private void testAddAndRemove(ConcurrentMap<String, AtomicInteger> map)
      throws ExecutionException, InterruptedException {

    final ConcurrentHashMultiset<String> multiset = new ConcurrentHashMultiset<>(map);
    int nThreads = 20;
    int tasksPerThread = 10;

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 72

                  try {
      List<Future<int[]>> futures = Lists.newArrayListWithExpectedSize(nTasks);
      for (int i = 0; i < nTasks; i++) {
        futures.add(pool.submit(new MutateTask(multiset, keys)));
      }

      int[] deltas = new int[3];
      for (Future<int[]> future : futures) {
        int[] taskDeltas = future.get();

            

Reported by PMD.

Use assertSame(x, y) instead of assertTrue(x==y), or assertNotSame(x,y) vs assertFalse(x==y)
Design

Line: 99

              
    // Since we have access to the backing map, verify that there are no zeroes in the map
    for (AtomicInteger value : map.values()) {
      assertTrue("map should not contain a zero", value.get() != 0);
    }
  }

  private static class MutateTask implements Callable<int[]> {
    private final ConcurrentHashMultiset<String> multiset;

            

Reported by PMD.

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

Line: 104

                }

  private static class MutateTask implements Callable<int[]> {
    private final ConcurrentHashMultiset<String> multiset;
    private final ImmutableList<String> keys;
    private final Random random = new Random();

    private MutateTask(ConcurrentHashMultiset<String> multiset, ImmutableList<String> keys) {
      this.multiset = multiset;

            

Reported by PMD.

android/guava-tests/test/com/google/common/escape/ArrayBasedUnicodeEscaperTest.java
26 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 36

                        '&', "<and>");
  private static final char[] NO_CHARS = new char[0];

  public void testReplacements() throws IOException {
    // In reality this is not a very sensible escaper to have (if you are only
    // escaping elements from a map you would use a ArrayBasedCharEscaper).
    UnicodeEscaper escaper =
        new ArrayBasedUnicodeEscaper(
            SIMPLE_REPLACEMENTS, Character.MIN_VALUE, Character.MAX_CODE_POINT, 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: 36

                        '&', "<and>");
  private static final char[] NO_CHARS = new char[0];

  public void testReplacements() throws IOException {
    // In reality this is not a very sensible escaper to have (if you are only
    // escaping elements from a map you would use a ArrayBasedCharEscaper).
    UnicodeEscaper escaper =
        new ArrayBasedUnicodeEscaper(
            SIMPLE_REPLACEMENTS, Character.MIN_VALUE, Character.MAX_CODE_POINT, null) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 48

                        }
        };
    EscaperAsserts.assertBasic(escaper);
    assertEquals("<tab>Fish <and> Chips<newline>", escaper.escape("\tFish & Chips\n"));

    // Verify that everything else is left unescaped.
    String safeChars = "\0\u0100\uD800\uDC00\uFFFF";
    assertEquals(safeChars, escaper.escape(safeChars));


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 52

              
    // Verify that everything else is left unescaped.
    String safeChars = "\0\u0100\uD800\uDC00\uFFFF";
    assertEquals(safeChars, escaper.escape(safeChars));

    // Ensure that Unicode escapers behave correctly wrt badly formed input.
    String badUnicode = "\uDC00\uD800";
    try {
      escaper.escape(badUnicode);

            

Reported by PMD.

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

Line: 58

                  String badUnicode = "\uDC00\uD800";
    try {
      escaper.escape(badUnicode);
      fail("should fail for bad Unicode");
    } catch (IllegalArgumentException e) {
      // Pass
    }
  }


            

Reported by PMD.

Avoid empty catch blocks
Error

Line: 59

                  try {
      escaper.escape(badUnicode);
      fail("should fail for bad Unicode");
    } catch (IllegalArgumentException e) {
      // Pass
    }
  }

  public void testSafeRange() 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: 64

                  }
  }

  public void testSafeRange() throws IOException {
    // Basic escaping of unsafe chars (wrap them in {,}'s)
    UnicodeEscaper wrappingEscaper =
        new ArrayBasedUnicodeEscaper(NO_REPLACEMENTS, 'A', 'Z', null) {
          @Override
          protected char[] escapeUnsafe(int c) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 75

                      };
    EscaperAsserts.assertBasic(wrappingEscaper);
    // '[' and '@' lie either side of [A-Z].
    assertEquals("{[}FOO{@}BAR{]}", wrappingEscaper.escape("[FOO@BAR]"));
  }

  public void testDeleteUnsafeChars() throws IOException {
    UnicodeEscaper deletingEscaper =
        new ArrayBasedUnicodeEscaper(NO_REPLACEMENTS, ' ', '~', 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: 78

                  assertEquals("{[}FOO{@}BAR{]}", wrappingEscaper.escape("[FOO@BAR]"));
  }

  public void testDeleteUnsafeChars() throws IOException {
    UnicodeEscaper deletingEscaper =
        new ArrayBasedUnicodeEscaper(NO_REPLACEMENTS, ' ', '~', null) {
          @Override
          protected char[] escapeUnsafe(int c) {
            return NO_CHARS;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 87

                        }
        };
    EscaperAsserts.assertBasic(deletingEscaper);
    assertEquals(
        "Everything outside the printable ASCII range is deleted.",
        deletingEscaper.escape(
            "\tEverything\0 outside the\uD800\uDC00 "
                + "printable ASCII \uFFFFrange is \u007Fdeleted.\n"));
  }

            

Reported by PMD.

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

Line: 37

              
public class DispatcherTest extends TestCase {

  private final EventBus bus = new EventBus();

  private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
  private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
  private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
  private final ImmutableList<Subscriber> integerSubscribers =

            

Reported by PMD.

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

Line: 39

              
  private final EventBus bus = new EventBus();

  private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
  private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
  private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
  private final ImmutableList<Subscriber> integerSubscribers =
      ImmutableList.of(
          subscriber(bus, i1, "handleInteger", Integer.class),

            

Reported by PMD.

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

Line: 40

                private final EventBus bus = new EventBus();

  private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
  private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
  private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
  private final ImmutableList<Subscriber> integerSubscribers =
      ImmutableList.of(
          subscriber(bus, i1, "handleInteger", Integer.class),
          subscriber(bus, i2, "handleInteger", Integer.class),

            

Reported by PMD.

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

Line: 41

              
  private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
  private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
  private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
  private final ImmutableList<Subscriber> integerSubscribers =
      ImmutableList.of(
          subscriber(bus, i1, "handleInteger", Integer.class),
          subscriber(bus, i2, "handleInteger", Integer.class),
          subscriber(bus, i3, "handleInteger", Integer.class));

            

Reported by PMD.

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

Line: 42

                private final IntegerSubscriber i1 = new IntegerSubscriber("i1");
  private final IntegerSubscriber i2 = new IntegerSubscriber("i2");
  private final IntegerSubscriber i3 = new IntegerSubscriber("i3");
  private final ImmutableList<Subscriber> integerSubscribers =
      ImmutableList.of(
          subscriber(bus, i1, "handleInteger", Integer.class),
          subscriber(bus, i2, "handleInteger", Integer.class),
          subscriber(bus, i3, "handleInteger", Integer.class));


            

Reported by PMD.

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

Line: 48

                        subscriber(bus, i2, "handleInteger", Integer.class),
          subscriber(bus, i3, "handleInteger", Integer.class));

  private final StringSubscriber s1 = new StringSubscriber("s1");
  private final StringSubscriber s2 = new StringSubscriber("s2");
  private final ImmutableList<Subscriber> stringSubscribers =
      ImmutableList.of(
          subscriber(bus, s1, "handleString", String.class),
          subscriber(bus, s2, "handleString", String.class));

            

Reported by PMD.

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

Line: 49

                        subscriber(bus, i3, "handleInteger", Integer.class));

  private final StringSubscriber s1 = new StringSubscriber("s1");
  private final StringSubscriber s2 = new StringSubscriber("s2");
  private final ImmutableList<Subscriber> stringSubscribers =
      ImmutableList.of(
          subscriber(bus, s1, "handleString", String.class),
          subscriber(bus, s2, "handleString", String.class));


            

Reported by PMD.

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

Line: 50

              
  private final StringSubscriber s1 = new StringSubscriber("s1");
  private final StringSubscriber s2 = new StringSubscriber("s2");
  private final ImmutableList<Subscriber> stringSubscribers =
      ImmutableList.of(
          subscriber(bus, s1, "handleString", String.class),
          subscriber(bus, s2, "handleString", String.class));

  private final ConcurrentLinkedQueue<Object> dispatchedSubscribers =

            

Reported by PMD.

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

Line: 55

                        subscriber(bus, s1, "handleString", String.class),
          subscriber(bus, s2, "handleString", String.class));

  private final ConcurrentLinkedQueue<Object> dispatchedSubscribers =
      Queues.newConcurrentLinkedQueue();

  private Dispatcher dispatcher;

  public void testPerThreadQueuedDispatcher() {

            

Reported by PMD.

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

Line: 58

                private final ConcurrentLinkedQueue<Object> dispatchedSubscribers =
      Queues.newConcurrentLinkedQueue();

  private Dispatcher dispatcher;

  public void testPerThreadQueuedDispatcher() {
    dispatcher = Dispatcher.perThreadDispatchQueue();
    dispatcher.dispatch(1, integerSubscribers.iterator());


            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/FeatureSpecificTestSuiteBuilder.java
26 issues
Avoid throwing raw exception types.
Design

Line: 229

                  try {
      requirements = FeatureUtil.getTesterRequirements(method);
    } catch (ConflictingRequirementsException e) {
      throw new RuntimeException(e);
    }
    if (!features.containsAll(requirements.getPresentFeatures())) {
      if (logger.isLoggable(FINER)) {
        Set<Feature<?>> missingFeatures = Helpers.copyToSet(requirements.getPresentFeatures());
        missingFeatures.removeAll(features);

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 176

                public TestSuite createTestSuite() {
    checkCanCreate();

    logger.fine(" Testing: " + name);
    logger.fine("Features: " + formatFeatureSet(features));

    FeatureUtil.addImpliedFeatures(features);

    logger.fine("Expanded: " + formatFeatureSet(features));

            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 177

                  checkCanCreate();

    logger.fine(" Testing: " + name);
    logger.fine("Features: " + formatFeatureSet(features));

    FeatureUtil.addImpliedFeatures(features);

    logger.fine("Expanded: " + formatFeatureSet(features));


            

Reported by PMD.

Logger calls should be surrounded by log level guards.
Design

Line: 181

              
    FeatureUtil.addImpliedFeatures(features);

    logger.fine("Expanded: " + formatFeatureSet(features));

    // Class parameters must be raw.
    List<Class<? extends AbstractTester>> testers = getTesters();

    TestSuite suite = new TestSuite(name);

            

Reported by PMD.

Possible God Class (WMC=51, ATFD=22, TCC=17.391%)
Design

Line: 55

               * @author George van den Driessche
 */
@GwtIncompatible
public abstract class FeatureSpecificTestSuiteBuilder<
    B extends FeatureSpecificTestSuiteBuilder<B, G>, G> {
  @SuppressWarnings("unchecked")
  protected B self() {
    return (B) this;
  }

            

Reported by PMD.

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

Line: 56

               */
@GwtIncompatible
public abstract class FeatureSpecificTestSuiteBuilder<
    B extends FeatureSpecificTestSuiteBuilder<B, G>, G> {
  @SuppressWarnings("unchecked")
  protected B self() {
    return (B) this;
  }


            

Reported by PMD.

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

Line: 64

              
  // Test Data

  private G subjectGenerator;
  // Gets run before every test.
  private Runnable setUp;
  // Gets run at the conclusion of every test.
  private Runnable tearDown;


            

Reported by PMD.

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

Line: 66

              
  private G subjectGenerator;
  // Gets run before every test.
  private Runnable setUp;
  // Gets run at the conclusion of every test.
  private Runnable tearDown;

  protected B usingGenerator(G subjectGenerator) {
    this.subjectGenerator = subjectGenerator;

            

Reported by PMD.

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

Line: 68

                // Gets run before every test.
  private Runnable setUp;
  // Gets run at the conclusion of every test.
  private Runnable tearDown;

  protected B usingGenerator(G subjectGenerator) {
    this.subjectGenerator = subjectGenerator;
    return self();
  }

            

Reported by PMD.

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

Line: 122

              
  // Name

  private String name;

  /** Configures this builder produce a TestSuite with the given name. */
  public B named(String name) {
    if (name.contains("(")) {
      throw new IllegalArgumentException(

            

Reported by PMD.