The following issues were found

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

Line: 35

               *
 * @author Colin Decker
 */
public class CharSinkTest extends IoTestCase {

  private static final String STRING = ASCII + I18N;

  private TestCharSink sink;


            

Reported by PMD.

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

Line: 39

              
  private static final String STRING = ASCII + I18N;

  private TestCharSink sink;

  @Override
  public void setUp() {
    sink = new TestCharSink();
  }

            

Reported by PMD.

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

Line: 41

              
  private TestCharSink sink;

  @Override
  public void setUp() {
    sink = new TestCharSink();
  }

  public void testOpenBufferedStream() 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: 46

                  sink = new TestCharSink();
  }

  public void testOpenBufferedStream() throws IOException {
    Writer writer = sink.openBufferedStream();
    assertTrue(sink.wasStreamOpened());
    assertFalse(sink.wasStreamClosed());

    writer.write(STRING);

            

Reported by PMD.

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

Line: 46

                  sink = new TestCharSink();
  }

  public void testOpenBufferedStream() throws IOException {
    Writer writer = sink.openBufferedStream();
    assertTrue(sink.wasStreamOpened());
    assertFalse(sink.wasStreamClosed());

    writer.write(STRING);

            

Reported by PMD.

Ensure that resources like this Writer object are closed after use
Error

Line: 47

                }

  public void testOpenBufferedStream() throws IOException {
    Writer writer = sink.openBufferedStream();
    assertTrue(sink.wasStreamOpened());
    assertFalse(sink.wasStreamClosed());

    writer.write(STRING);
    writer.close();

            

Reported by PMD.

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

Line: 51

                  assertTrue(sink.wasStreamOpened());
    assertFalse(sink.wasStreamClosed());

    writer.write(STRING);
    writer.close();

    assertTrue(sink.wasStreamClosed());
    assertEquals(STRING, sink.getString());
  }

            

Reported by PMD.

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

Line: 52

                  assertFalse(sink.wasStreamClosed());

    writer.write(STRING);
    writer.close();

    assertTrue(sink.wasStreamClosed());
    assertEquals(STRING, sink.getString());
  }


            

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

                  assertEquals(STRING, sink.getString());
  }

  public void testWrite_string() throws IOException {
    assertEquals("", sink.getString());
    sink.write(STRING);

    assertTrue(sink.wasStreamOpened() && sink.wasStreamClosed());
    assertEquals(STRING, sink.getString());

            

Reported by PMD.

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

Line: 58

                  assertEquals(STRING, sink.getString());
  }

  public void testWrite_string() throws IOException {
    assertEquals("", sink.getString());
    sink.write(STRING);

    assertTrue(sink.wasStreamOpened() && sink.wasStreamClosed());
    assertEquals(STRING, sink.getString());

            

Reported by PMD.

guava-tests/test/com/google/common/collect/AbstractSequentialIteratorTest.java
29 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 {@link AbstractSequentialIterator}. */
@GwtCompatible(emulated = true)
public class AbstractSequentialIteratorTest extends TestCase {
  @GwtIncompatible // Too slow
  public void testDoublerExhaustive() {
    new IteratorTester<Integer>(
        3, UNMODIFIABLE, ImmutableList.of(1, 2), IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<Integer> newTargetIterator() {

            

Reported by PMD.

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

Line: 34

              @GwtCompatible(emulated = true)
public class AbstractSequentialIteratorTest extends TestCase {
  @GwtIncompatible // Too slow
  public void testDoublerExhaustive() {
    new IteratorTester<Integer>(
        3, UNMODIFIABLE, ImmutableList.of(1, 2), IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<Integer> newTargetIterator() {
        return newDoubler(1, 2);

            

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

                  }.test();
  }

  public void testDoubler() {
    Iterable<Integer> doubled =
        new Iterable<Integer>() {
          @Override
          public Iterator<Integer> iterator() {
            return newDoubler(2, 32);

            

Reported by PMD.

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

Line: 52

                          return newDoubler(2, 32);
          }
        };
    assertThat(doubled).containsExactly(2, 4, 8, 16, 32).inOrder();
  }

  public void testSampleCode() {
    Iterable<Integer> actual =
        new Iterable<Integer>() {

            

Reported by PMD.

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

Line: 52

                          return newDoubler(2, 32);
          }
        };
    assertThat(doubled).containsExactly(2, 4, 8, 16, 32).inOrder();
  }

  public void testSampleCode() {
    Iterable<Integer> actual =
        new Iterable<Integer>() {

            

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

                  assertThat(doubled).containsExactly(2, 4, 8, 16, 32).inOrder();
  }

  public void testSampleCode() {
    Iterable<Integer> actual =
        new Iterable<Integer>() {
          @Override
          public Iterator<Integer> iterator() {
            Iterator<Integer> powersOfTwo =

            

Reported by PMD.

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

Line: 70

                          return powersOfTwo;
          }
        };
    assertThat(actual)
        .containsExactly(
            1,
            2,
            4,
            8,

            

Reported by PMD.

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

Line: 70

                          return powersOfTwo;
          }
        };
    assertThat(actual)
        .containsExactly(
            1,
            2,
            4,
            8,

            

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

                      .inOrder();
  }

  public void testEmpty() {
    Iterator<Object> empty = newEmpty();
    assertFalse(empty.hasNext());
    try {
      empty.next();
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 108

              
  public void testEmpty() {
    Iterator<Object> empty = newEmpty();
    assertFalse(empty.hasNext());
    try {
      empty.next();
      fail();
    } catch (NoSuchElementException expected) {
    }

            

Reported by PMD.

guava-tests/test/com/google/common/base/ObjectsTest.java
29 issues
Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 38

              
    // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));

            

Reported by PMD.

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

Line: 49

              
  public void testHashCode() throws Exception {
    int h1 = Objects.hashCode(1, "two", 3.0);
    int h2 = Objects.hashCode(new Integer(1), new String("two"), new Double(3.0));
    // repeatable
    assertEquals(h1, h2);

    // These don't strictly need to be true, but they're nice properties.
    assertTrue(Objects.hashCode(1, 2, null) != Objects.hashCode(1, 2));

            

Reported by PMD.

Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 49

              
  public void testHashCode() throws Exception {
    int h1 = Objects.hashCode(1, "two", 3.0);
    int h2 = Objects.hashCode(new Integer(1), new String("two"), new Double(3.0));
    // repeatable
    assertEquals(h1, h2);

    // These don't strictly need to be true, but they're nice properties.
    assertTrue(Objects.hashCode(1, 2, null) != Objects.hashCode(1, 2));

            

Reported by PMD.

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

Line: 32

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

  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";

            

Reported by PMD.

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

Line: 32

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

  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

              public class ObjectsTest extends TestCase {

  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

              
  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));
    assertFalse(Objects.equal("1", 1));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 41

                  String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));
    assertFalse(Objects.equal("1", 1));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

                  assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));
    assertFalse(Objects.equal("1", 1));
  }

  public void testHashCode() throws Exception {

            

Reported by PMD.

guava-tests/test/com/google/common/collect/UnmodifiableListIteratorTest.java
29 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: 32

               */
@GwtCompatible
public class UnmodifiableListIteratorTest extends TestCase {
  public void testRemove() {
    Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {

            

Reported by PMD.

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

Line: 32

               */
@GwtCompatible
public class UnmodifiableListIteratorTest extends TestCase {
  public void testRemove() {
    Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 35

                public void testRemove() {
    Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 36

                  Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {
    }
  }

  public void testAdd() {

            

Reported by PMD.

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

Line: 39

                  assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {
    }
  }

  public void testAdd() {

            

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 testAdd() {
    ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());

            

Reported by PMD.

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

Line: 44

                  }
  }

  public void testAdd() {
    ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

                public void testAdd() {
    ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());
    assertEquals("b", iterator.previous());
    try {
      iterator.add("c");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 48

                  ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());
    assertEquals("b", iterator.previous());
    try {
      iterator.add("c");
      fail();

            

Reported by PMD.

guava-tests/test/com/google/common/collect/AbstractTableTest.java
29 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: 48

                  return false;
  }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));

            

Reported by PMD.

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

Line: 48

                  return false;
  }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));

            

Reported by PMD.

The String literal 'bar' appears 16 times in this file; the first occurrence is on line 49
Error

Line: 49

                }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));
    } else {

            

Reported by PMD.

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

Line: 49

                }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));
    } else {

            

Reported by PMD.

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

Line: 63

                  }
  }

  public void testPut() {
    assertNull(table.put("foo", 1, 'a'));
    assertNull(table.put("bar", 1, 'b'));
    assertNull(table.put("foo", 3, 'c'));
    assertEquals((Character) 'a', table.put("foo", 1, 'd'));
    assertEquals((Character) 'd', table.get("foo", 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: 63

                  }
  }

  public void testPut() {
    assertNull(table.put("foo", 1, 'a'));
    assertNull(table.put("bar", 1, 'b'));
    assertNull(table.put("foo", 3, 'c'));
    assertEquals((Character) 'a', table.put("foo", 1, 'd'));
    assertEquals((Character) 'd', table.get("foo", 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: 77

                }

  // This test assumes that the implementation does not support nulls.
  public void testPutNull() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    assertSize(3);
    try {
      table.put(null, 2, 'd');
      fail();

            

Reported by PMD.

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

Line: 77

                }

  // This test assumes that the implementation does not support nulls.
  public void testPutNull() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    assertSize(3);
    try {
      table.put(null, 2, 'd');
      fail();

            

Reported by PMD.

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

Line: 83

                  try {
      table.put(null, 2, 'd');
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      table.put("cat", null, 'd');
      fail();
    } catch (NullPointerException expected) {

            

Reported by PMD.

Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 83

                  try {
      table.put(null, 2, 'd');
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      table.put("cat", null, 'd');
      fail();
    } catch (NullPointerException expected) {

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/UnmodifiableListIteratorTest.java
29 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: 32

               */
@GwtCompatible
public class UnmodifiableListIteratorTest extends TestCase {
  public void testRemove() {
    Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {

            

Reported by PMD.

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

Line: 32

               */
@GwtCompatible
public class UnmodifiableListIteratorTest extends TestCase {
  public void testRemove() {
    Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 35

                public void testRemove() {
    Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 36

                  Iterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {
    }

            

Reported by PMD.

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

Line: 39

                  assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {
    }
  }

  public void testAdd() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  assertEquals("a", iterator.next());
    try {
      iterator.remove();
      fail();
    } catch (UnsupportedOperationException expected) {
    }
  }

  public void testAdd() {

            

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 testAdd() {
    ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());

            

Reported by PMD.

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

Line: 44

                  }
  }

  public void testAdd() {
    ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 47

                public void testAdd() {
    ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());
    assertEquals("b", iterator.previous());
    try {
      iterator.add("c");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 48

                  ListIterator<String> iterator = create();

    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next());
    assertEquals("b", iterator.next());
    assertEquals("b", iterator.previous());
    try {
      iterator.add("c");
      fail();

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/AbstractSequentialIteratorTest.java
29 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 {@link AbstractSequentialIterator}. */
@GwtCompatible(emulated = true)
public class AbstractSequentialIteratorTest extends TestCase {
  @GwtIncompatible // Too slow
  public void testDoublerExhaustive() {
    new IteratorTester<Integer>(
        3, UNMODIFIABLE, ImmutableList.of(1, 2), IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<Integer> newTargetIterator() {

            

Reported by PMD.

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

Line: 34

              @GwtCompatible(emulated = true)
public class AbstractSequentialIteratorTest extends TestCase {
  @GwtIncompatible // Too slow
  public void testDoublerExhaustive() {
    new IteratorTester<Integer>(
        3, UNMODIFIABLE, ImmutableList.of(1, 2), IteratorTester.KnownOrder.KNOWN_ORDER) {
      @Override
      protected Iterator<Integer> newTargetIterator() {
        return newDoubler(1, 2);

            

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

                  }.test();
  }

  public void testDoubler() {
    Iterable<Integer> doubled =
        new Iterable<Integer>() {
          @Override
          public Iterator<Integer> iterator() {
            return newDoubler(2, 32);

            

Reported by PMD.

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

Line: 52

                          return newDoubler(2, 32);
          }
        };
    assertThat(doubled).containsExactly(2, 4, 8, 16, 32).inOrder();
  }

  public void testSampleCode() {
    Iterable<Integer> actual =
        new Iterable<Integer>() {

            

Reported by PMD.

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

Line: 52

                          return newDoubler(2, 32);
          }
        };
    assertThat(doubled).containsExactly(2, 4, 8, 16, 32).inOrder();
  }

  public void testSampleCode() {
    Iterable<Integer> actual =
        new Iterable<Integer>() {

            

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

                  assertThat(doubled).containsExactly(2, 4, 8, 16, 32).inOrder();
  }

  public void testSampleCode() {
    Iterable<Integer> actual =
        new Iterable<Integer>() {
          @Override
          public Iterator<Integer> iterator() {
            Iterator<Integer> powersOfTwo =

            

Reported by PMD.

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

Line: 69

                          return powersOfTwo;
          }
        };
    assertThat(actual)
        .containsExactly(
            1,
            2,
            4,
            8,

            

Reported by PMD.

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

Line: 69

                          return powersOfTwo;
          }
        };
    assertThat(actual)
        .containsExactly(
            1,
            2,
            4,
            8,

            

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

                      .inOrder();
  }

  public void testEmpty() {
    Iterator<Object> empty = newEmpty();
    assertFalse(empty.hasNext());
    try {
      empty.next();
      fail();

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 107

              
  public void testEmpty() {
    Iterator<Object> empty = newEmpty();
    assertFalse(empty.hasNext());
    try {
      empty.next();
      fail();
    } catch (NoSuchElementException expected) {
    }

            

Reported by PMD.

android/guava-tests/test/com/google/common/collect/AbstractTableTest.java
29 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: 48

                  return false;
  }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));

            

Reported by PMD.

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

Line: 48

                  return false;
  }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));

            

Reported by PMD.

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

Line: 49

                }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));
    } else {

            

Reported by PMD.

The String literal 'bar' appears 16 times in this file; the first occurrence is on line 49
Error

Line: 49

                }

  public void testClear() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    if (supportsRemove()) {
      table.clear();
      assertEquals(0, table.size());
      assertFalse(table.containsRow("foo"));
    } else {

            

Reported by PMD.

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

Line: 63

                  }
  }

  public void testPut() {
    assertNull(table.put("foo", 1, 'a'));
    assertNull(table.put("bar", 1, 'b'));
    assertNull(table.put("foo", 3, 'c'));
    assertEquals((Character) 'a', table.put("foo", 1, 'd'));
    assertEquals((Character) 'd', table.get("foo", 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: 63

                  }
  }

  public void testPut() {
    assertNull(table.put("foo", 1, 'a'));
    assertNull(table.put("bar", 1, 'b'));
    assertNull(table.put("foo", 3, 'c'));
    assertEquals((Character) 'a', table.put("foo", 1, 'd'));
    assertEquals((Character) 'd', table.get("foo", 1));

            

Reported by PMD.

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

Line: 77

                }

  // This test assumes that the implementation does not support nulls.
  public void testPutNull() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    assertSize(3);
    try {
      table.put(null, 2, 'd');
      fail();

            

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

                }

  // This test assumes that the implementation does not support nulls.
  public void testPutNull() {
    table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
    assertSize(3);
    try {
      table.put(null, 2, 'd');
      fail();

            

Reported by PMD.

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

Line: 83

                  try {
      table.put(null, 2, 'd');
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      table.put("cat", null, 'd');
      fail();
    } catch (NullPointerException expected) {

            

Reported by PMD.

Avoid catching NullPointerException; consider removing the cause of the NPE.
Error

Line: 83

                  try {
      table.put(null, 2, 'd');
      fail();
    } catch (NullPointerException expected) {
    }
    try {
      table.put("cat", null, 'd');
      fail();
    } catch (NullPointerException expected) {

            

Reported by PMD.

android/guava-tests/test/com/google/common/base/ObjectsTest.java
29 issues
Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 38

              
    // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));

            

Reported by PMD.

Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 49

              
  public void testHashCode() throws Exception {
    int h1 = Objects.hashCode(1, "two", 3.0);
    int h2 = Objects.hashCode(new Integer(1), new String("two"), new Double(3.0));
    // repeatable
    assertEquals(h1, h2);

    // These don't strictly need to be true, but they're nice properties.
    assertTrue(Objects.hashCode(1, 2, null) != Objects.hashCode(1, 2));

            

Reported by PMD.

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

Line: 49

              
  public void testHashCode() throws Exception {
    int h1 = Objects.hashCode(1, "two", 3.0);
    int h2 = Objects.hashCode(new Integer(1), new String("two"), new Double(3.0));
    // repeatable
    assertEquals(h1, h2);

    // These don't strictly need to be true, but they're nice properties.
    assertTrue(Objects.hashCode(1, 2, null) != Objects.hashCode(1, 2));

            

Reported by PMD.

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

Line: 32

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

  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";

            

Reported by PMD.

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

Line: 32

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

  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

              public class ObjectsTest extends TestCase {

  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

              
  public void testEqual() throws Exception {
    assertTrue(Objects.equal(1, 1));
    assertTrue(Objects.equal(null, null));

    // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 39

                  // test distinct string objects
    String s1 = "foobar";
    String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));
    assertFalse(Objects.equal("1", 1));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 41

                  String s2 = new String(s1);
    assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));
    assertFalse(Objects.equal("1", 1));
  }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 42

                  assertTrue(Objects.equal(s1, s2));

    assertFalse(Objects.equal(s1, null));
    assertFalse(Objects.equal(null, s1));
    assertFalse(Objects.equal("foo", "bar"));
    assertFalse(Objects.equal("1", 1));
  }

  public void testHashCode() throws Exception {

            

Reported by PMD.

android/guava-testlib/src/com/google/common/collect/testing/testers/MapEqualsTester.java
29 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: 42

              @GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MapEqualsTester<K, V> extends AbstractMapTester<K, V> {
  public void testEquals_otherMapWithSameEntries() {
    assertTrue(
        "A Map should equal any other Map containing the same entries.",
        getMap().equals(newHashMap(getSampleEntries())));
  }


            

Reported by PMD.

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

Line: 45

                public void testEquals_otherMapWithSameEntries() {
    assertTrue(
        "A Map should equal any other Map containing the same entries.",
        getMap().equals(newHashMap(getSampleEntries())));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherMapWithDifferentEntries() {
    Map<K, V> other = newHashMap(getSampleEntries(getNumEntries() - 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: 48

                      getMap().equals(newHashMap(getSampleEntries())));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherMapWithDifferentEntries() {
    Map<K, V> other = newHashMap(getSampleEntries(getNumEntries() - 1));
    other.put(k3(), v3());
    assertFalse(
        "A Map should not equal another Map containing different entries.", getMap().equals(other));

            

Reported by PMD.

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

Line: 51

                @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherMapWithDifferentEntries() {
    Map<K, V> other = newHashMap(getSampleEntries(getNumEntries() - 1));
    other.put(k3(), v3());
    assertFalse(
        "A Map should not equal another Map containing different entries.", getMap().equals(other));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)

            

Reported by PMD.

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

Line: 53

                  Map<K, V> other = newHashMap(getSampleEntries(getNumEntries() - 1));
    other.put(k3(), v3());
    assertFalse(
        "A Map should not equal another Map containing different entries.", getMap().equals(other));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testEquals_containingNullKey() {

            

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

                      "A Map should not equal another Map containing different entries.", getMap().equals(other));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testEquals_containingNullKey() {
    Collection<Entry<K, V>> entries = getSampleEntries(getNumEntries() - 1);
    entries.add(entry(null, v3()));


            

Reported by PMD.

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

Line: 60

                @MapFeature.Require(ALLOWS_NULL_KEYS)
  public void testEquals_containingNullKey() {
    Collection<Entry<K, V>> entries = getSampleEntries(getNumEntries() - 1);
    entries.add(entry(null, v3()));

    resetContainer(getSubjectGenerator().create(entries.toArray()));
    assertTrue(
        "A Map should equal any other Map containing the same entries,"
            + " even if some keys are null.",

            

Reported by PMD.

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

Line: 62

                  Collection<Entry<K, V>> entries = getSampleEntries(getNumEntries() - 1);
    entries.add(entry(null, v3()));

    resetContainer(getSubjectGenerator().create(entries.toArray()));
    assertTrue(
        "A Map should equal any other Map containing the same entries,"
            + " even if some keys are null.",
        getMap().equals(newHashMap(entries)));
  }

            

Reported by PMD.

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

Line: 62

                  Collection<Entry<K, V>> entries = getSampleEntries(getNumEntries() - 1);
    entries.add(entry(null, v3()));

    resetContainer(getSubjectGenerator().create(entries.toArray()));
    assertTrue(
        "A Map should equal any other Map containing the same entries,"
            + " even if some keys are null.",
        getMap().equals(newHashMap(entries)));
  }

            

Reported by PMD.

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

Line: 66

                  assertTrue(
        "A Map should equal any other Map containing the same entries,"
            + " even if some keys are null.",
        getMap().equals(newHashMap(entries)));
  }

  @CollectionSize.Require(absent = CollectionSize.ZERO)
  public void testEquals_otherContainsNullKey() {
    Collection<Entry<K, V>> entries = getSampleEntries(getNumEntries() - 1);

            

Reported by PMD.