The following issues were found
guava-tests/test/com/google/common/io/CharSinkTester.java
16 issues
Line: 35
* @author Colin Decker
*/
@AndroidIncompatible // Android doesn't understand tests that lack default constructors.
public class CharSinkTester extends SourceSinkTester<CharSink, String, CharSinkFactory> {
private static final ImmutableList<Method> testMethods = getTestMethods(CharSinkTester.class);
static TestSuite tests(String name, CharSinkFactory factory) {
TestSuite suite = new TestSuite(name);
Reported by PMD.
Line: 53
String name, CharSinkFactory factory, String string, String desc) {
TestSuite stringSuite = new TestSuite(name + " [" + desc + "]");
for (final Method method : testMethods) {
stringSuite.addTest(new CharSinkTester(factory, string, name, desc, method));
}
return stringSuite;
}
private final ImmutableList<String> lines;
Reported by PMD.
Line: 58
return stringSuite;
}
private final ImmutableList<String> lines;
private final ImmutableList<String> expectedLines;
private CharSink sink;
public CharSinkTester(
Reported by PMD.
Line: 59
}
private final ImmutableList<String> lines;
private final ImmutableList<String> expectedLines;
private CharSink sink;
public CharSinkTester(
CharSinkFactory factory, String string, String suiteName, String caseDesc, Method method) {
Reported by PMD.
Line: 61
private final ImmutableList<String> lines;
private final ImmutableList<String> expectedLines;
private CharSink sink;
public CharSinkTester(
CharSinkFactory factory, String string, String suiteName, String caseDesc, Method method) {
super(factory, string, suiteName, caseDesc, method);
this.lines = getLines(string);
Reported by PMD.
Line: 70
this.expectedLines = getLines(expected);
}
@Override
protected void setUp() throws Exception {
this.sink = factory.createSink();
}
public void testOpenStream() throws IOException {
Reported by PMD.
Line: 75
this.sink = factory.createSink();
}
public void testOpenStream() throws IOException {
Writer writer = sink.openStream();
try {
writer.write(data);
} finally {
writer.close();
Reported by PMD.
Line: 77
public void testOpenStream() throws IOException {
Writer writer = sink.openStream();
try {
writer.write(data);
} finally {
writer.close();
}
Reported by PMD.
Line: 86
assertContainsExpectedString();
}
public void testOpenBufferedStream() throws IOException {
Writer writer = sink.openBufferedStream();
try {
writer.write(data);
} finally {
writer.close();
Reported by PMD.
Line: 88
public void testOpenBufferedStream() throws IOException {
Writer writer = sink.openBufferedStream();
try {
writer.write(data);
} finally {
writer.close();
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/google/MultisetCountTester.java
16 issues
Line: 44
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class MultisetCountTester<E> extends AbstractMultisetTester<E> {
public void testCount_0() {
assertEquals("multiset.count(missing) didn't return 0", 0, getMultiset().count(e3()));
}
@CollectionSize.Require(absent = ZERO)
public void testCount_1() {
Reported by PMD.
Line: 45
public class MultisetCountTester<E> extends AbstractMultisetTester<E> {
public void testCount_0() {
assertEquals("multiset.count(missing) didn't return 0", 0, getMultiset().count(e3()));
}
@CollectionSize.Require(absent = ZERO)
public void testCount_1() {
assertEquals("multiset.count(present) didn't return 1", 1, getMultiset().count(e0()));
Reported by PMD.
Line: 48
assertEquals("multiset.count(missing) didn't return 0", 0, getMultiset().count(e3()));
}
@CollectionSize.Require(absent = ZERO)
public void testCount_1() {
assertEquals("multiset.count(present) didn't return 1", 1, getMultiset().count(e0()));
}
@CollectionSize.Require(SEVERAL)
Reported by PMD.
Line: 50
@CollectionSize.Require(absent = ZERO)
public void testCount_1() {
assertEquals("multiset.count(present) didn't return 1", 1, getMultiset().count(e0()));
}
@CollectionSize.Require(SEVERAL)
public void testCount_3() {
initThreeCopies();
Reported by PMD.
Line: 53
assertEquals("multiset.count(present) didn't return 1", 1, getMultiset().count(e0()));
}
@CollectionSize.Require(SEVERAL)
public void testCount_3() {
initThreeCopies();
assertEquals("multiset.count(thriceContained) didn't return 3", 3, getMultiset().count(e0()));
}
Reported by PMD.
Line: 56
@CollectionSize.Require(SEVERAL)
public void testCount_3() {
initThreeCopies();
assertEquals("multiset.count(thriceContained) didn't return 3", 3, getMultiset().count(e0()));
}
@CollectionFeature.Require(ALLOWS_NULL_QUERIES)
public void testCount_nullAbsent() {
assertEquals("multiset.count(null) didn't return 0", 0, getMultiset().count(null));
Reported by PMD.
Line: 59
assertEquals("multiset.count(thriceContained) didn't return 3", 3, getMultiset().count(e0()));
}
@CollectionFeature.Require(ALLOWS_NULL_QUERIES)
public void testCount_nullAbsent() {
assertEquals("multiset.count(null) didn't return 0", 0, getMultiset().count(null));
}
@CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
Reported by PMD.
Line: 61
@CollectionFeature.Require(ALLOWS_NULL_QUERIES)
public void testCount_nullAbsent() {
assertEquals("multiset.count(null) didn't return 0", 0, getMultiset().count(null));
}
@CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
public void testCount_null_forbidden() {
try {
Reported by PMD.
Line: 64
assertEquals("multiset.count(null) didn't return 0", 0, getMultiset().count(null));
}
@CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
public void testCount_null_forbidden() {
try {
getMultiset().count(null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
Reported by PMD.
Line: 67
@CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
public void testCount_null_forbidden() {
try {
getMultiset().count(null);
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
}
}
Reported by PMD.
guava-testlib/src/com/google/common/collect/testing/testers/SetCreationTester.java
16 issues
Line: 41
@GwtCompatible
@Ignore // Affects only Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
public class SetCreationTester<E> extends AbstractSetTester<E> {
@CollectionFeature.Require(value = ALLOWS_NULL_VALUES, absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testCreateWithDuplicates_nullDuplicatesNotRejected() {
E[] array = createArrayWithNullElement();
array[0] = null;
collection = getSubjectGenerator().create(array);
Reported by PMD.
Line: 45
@CollectionSize.Require(absent = {ZERO, ONE})
public void testCreateWithDuplicates_nullDuplicatesNotRejected() {
E[] array = createArrayWithNullElement();
array[0] = null;
collection = getSubjectGenerator().create(array);
List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1, getNumElements());
expectContents(expectedWithDuplicateRemoved);
}
Reported by PMD.
Line: 46
public void testCreateWithDuplicates_nullDuplicatesNotRejected() {
E[] array = createArrayWithNullElement();
array[0] = null;
collection = getSubjectGenerator().create(array);
List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1, getNumElements());
expectContents(expectedWithDuplicateRemoved);
}
Reported by PMD.
Line: 48
array[0] = null;
collection = getSubjectGenerator().create(array);
List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1, getNumElements());
expectContents(expectedWithDuplicateRemoved);
}
@CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO, ONE})
Reported by PMD.
Line: 52
expectContents(expectedWithDuplicateRemoved);
}
@CollectionFeature.Require(absent = REJECTS_DUPLICATES_AT_CREATION)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testCreateWithDuplicates_nonNullDuplicatesNotRejected() {
E[] array = createSamplesArray();
array[1] = e0();
collection = getSubjectGenerator().create(array);
Reported by PMD.
Line: 57
public void testCreateWithDuplicates_nonNullDuplicatesNotRejected() {
E[] array = createSamplesArray();
array[1] = e0();
collection = getSubjectGenerator().create(array);
List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1, getNumElements());
expectContents(expectedWithDuplicateRemoved);
}
Reported by PMD.
Line: 59
array[1] = e0();
collection = getSubjectGenerator().create(array);
List<E> expectedWithDuplicateRemoved = Arrays.asList(array).subList(1, getNumElements());
expectContents(expectedWithDuplicateRemoved);
}
@CollectionFeature.Require({ALLOWS_NULL_VALUES, REJECTS_DUPLICATES_AT_CREATION})
@CollectionSize.Require(absent = {ZERO, ONE})
Reported by PMD.
Line: 63
expectContents(expectedWithDuplicateRemoved);
}
@CollectionFeature.Require({ALLOWS_NULL_VALUES, REJECTS_DUPLICATES_AT_CREATION})
@CollectionSize.Require(absent = {ZERO, ONE})
public void testCreateWithDuplicates_nullDuplicatesRejected() {
E[] array = createArrayWithNullElement();
array[0] = null;
try {
Reported by PMD.
Line: 67
@CollectionSize.Require(absent = {ZERO, ONE})
public void testCreateWithDuplicates_nullDuplicatesRejected() {
E[] array = createArrayWithNullElement();
array[0] = null;
try {
collection = getSubjectGenerator().create(array);
fail("Should reject duplicate null elements at creation");
} catch (IllegalArgumentException expected) {
}
Reported by PMD.
Line: 69
E[] array = createArrayWithNullElement();
array[0] = null;
try {
collection = getSubjectGenerator().create(array);
fail("Should reject duplicate null elements at creation");
} catch (IllegalArgumentException expected) {
}
}
Reported by PMD.
guava-testlib/src/com/google/common/testing/GcFinalization.java
16 issues
Line: 155
} catch (CancellationException | ExecutionException ok) {
return;
} catch (InterruptedException ie) {
throw new RuntimeException("Unexpected interrupt while waiting for future", ie);
} catch (TimeoutException tryHarder) {
/* OK */
}
} while (System.nanoTime() - deadline < 0);
throw formatRuntimeException("Future not done within %d second timeout", timeoutSeconds);
Reported by PMD.
Line: 214
return;
}
} catch (InterruptedException ie) {
throw new RuntimeException("Unexpected interrupt while waiting for latch", ie);
}
} while (System.nanoTime() - deadline < 0);
throw formatRuntimeException(
"Latch failed to count down within %d second timeout", timeoutSeconds);
}
Reported by PMD.
Line: 144
final long timeoutSeconds = timeoutSeconds();
final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
do {
System.runFinalization();
if (future.isDone()) {
return;
}
System.gc();
try {
Reported by PMD.
Line: 148
if (future.isDone()) {
return;
}
System.gc();
try {
future.get(1L, SECONDS);
return;
} catch (CancellationException | ExecutionException ok) {
return;
Reported by PMD.
Line: 176
final long timeoutSeconds = timeoutSeconds();
final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
do {
System.runFinalization();
if (predicate.isDone()) {
return;
}
CountDownLatch done = new CountDownLatch(1);
createUnreachableLatchFinalizer(done);
Reported by PMD.
Line: 204
final long timeoutSeconds = timeoutSeconds();
final long deadline = System.nanoTime() + SECONDS.toNanos(timeoutSeconds);
do {
System.runFinalization();
if (latch.getCount() == 0) {
return;
}
System.gc();
try {
Reported by PMD.
Line: 208
if (latch.getCount() == 0) {
return;
}
System.gc();
try {
if (latch.await(1L, SECONDS)) {
return;
}
} catch (InterruptedException ie) {
Reported by PMD.
Line: 313
awaitClear(ref);
// Hope to catch some stragglers queued up behind our finalizable object
System.runFinalization();
}
private static RuntimeException formatRuntimeException(String format, Object... args) {
return new RuntimeException(String.format(Locale.ROOT, format, args));
}
Reported by PMD.
Line: 128
//
// TODO(user): Consider scaling by number of mutator threads,
// e.g. using Thread#activeCount()
return Math.max(10L, Runtime.getRuntime().totalMemory() / (32L * 1024L * 1024L));
}
/**
* Waits until the given future {@linkplain Future#isDone is done}, invoking the garbage collector
* as necessary to try to ensure that this will happen.
Reported by PMD.
Line: 156
return;
} catch (InterruptedException ie) {
throw new RuntimeException("Unexpected interrupt while waiting for future", ie);
} catch (TimeoutException tryHarder) {
/* OK */
}
} while (System.nanoTime() - deadline < 0);
throw formatRuntimeException("Future not done within %d second timeout", timeoutSeconds);
}
Reported by PMD.
guava-tests/benchmark/com/google/common/util/concurrent/StripedBenchmark.java
16 issues
Line: 49
};
@Param({"2", "8", "64", "1024", "65536"})
int numStripes;
@Param Impl impl;
enum Impl {
EAGER {
Reported by PMD.
Line: 51
@Param({"2", "8", "64", "1024", "65536"})
int numStripes;
@Param Impl impl;
enum Impl {
EAGER {
@Override
Striped<Lock> get(int stripes) {
Reported by PMD.
Line: 76
abstract Striped<Lock> get(int stripes);
}
private Striped<Lock> striped;
private int[] stripes;
private List<Integer> bulkGetSet;
@BeforeExperiment
void setUp() {
Reported by PMD.
Line: 77
}
private Striped<Lock> striped;
private int[] stripes;
private List<Integer> bulkGetSet;
@BeforeExperiment
void setUp() {
this.striped = impl.get(numStripes);
Reported by PMD.
Line: 78
private Striped<Lock> striped;
private int[] stripes;
private List<Integer> bulkGetSet;
@BeforeExperiment
void setUp() {
this.striped = impl.get(numStripes);
stripes = new int[numStripes];
Reported by PMD.
Line: 80
private int[] stripes;
private List<Integer> bulkGetSet;
@BeforeExperiment
void setUp() {
this.striped = impl.get(numStripes);
stripes = new int[numStripes];
for (int i = 0; i < numStripes; i++) {
stripes[i] = i;
Reported by PMD.
Line: 100
}
// a place to put the locks in sizeOfPopulatedStriped so they don't get GC'd before we measure
final List<Lock> locks = new ArrayList<>(numStripes);
@Footprint
Object sizeOfPopulatedStriped() {
locks.clear();
Striped<Lock> striped = impl.get(numStripes);
Reported by PMD.
Line: 118
int numStripesLocal = numStripes;
Impl implLocal = impl;
for (long i = 0; i < reps; i++) {
rvalue += implLocal.get(numStripesLocal).hashCode();
}
return rvalue;
}
@Benchmark
Reported by PMD.
Line: 141
List<Integer> bulkGetSetLocal = bulkGetSet;
Striped<Lock> stripedLocal = striped;
for (long i = 0; i < reps; i++) {
rvalue += stripedLocal.bulkGet(bulkGetSetLocal).hashCode();
}
return rvalue;
}
}
Reported by PMD.
Line: 115
@Benchmark
long timeConstruct(long reps) {
long rvalue = 0;
int numStripesLocal = numStripes;
Impl implLocal = impl;
for (long i = 0; i < reps; i++) {
rvalue += implLocal.get(numStripesLocal).hashCode();
}
return rvalue;
Reported by PMD.
guava-tests/test/com/google/common/cache/CacheBuilderFactory.java
16 issues
Line: 37
*
* @author mike nonemacher
*/
class CacheBuilderFactory {
// Default values contain only 'null', which means don't call the CacheBuilder method (just give
// the CacheBuilder default).
private Set<Integer> concurrencyLevels = Sets.newHashSet((Integer) null);
private Set<Integer> initialCapacities = Sets.newHashSet((Integer) null);
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
Reported by PMD.
Line: 40
class CacheBuilderFactory {
// Default values contain only 'null', which means don't call the CacheBuilder method (just give
// the CacheBuilder default).
private Set<Integer> concurrencyLevels = Sets.newHashSet((Integer) null);
private Set<Integer> initialCapacities = Sets.newHashSet((Integer) null);
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
Reported by PMD.
Line: 41
// Default values contain only 'null', which means don't call the CacheBuilder method (just give
// the CacheBuilder default).
private Set<Integer> concurrencyLevels = Sets.newHashSet((Integer) null);
private Set<Integer> initialCapacities = Sets.newHashSet((Integer) null);
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
Reported by PMD.
Line: 42
// the CacheBuilder default).
private Set<Integer> concurrencyLevels = Sets.newHashSet((Integer) null);
private Set<Integer> initialCapacities = Sets.newHashSet((Integer) null);
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
private Set<Strength> valueStrengths = Sets.newHashSet((Strength) null);
Reported by PMD.
Line: 43
private Set<Integer> concurrencyLevels = Sets.newHashSet((Integer) null);
private Set<Integer> initialCapacities = Sets.newHashSet((Integer) null);
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
private Set<Strength> valueStrengths = Sets.newHashSet((Strength) null);
Reported by PMD.
Line: 44
private Set<Integer> initialCapacities = Sets.newHashSet((Integer) null);
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
private Set<Strength> valueStrengths = Sets.newHashSet((Strength) null);
CacheBuilderFactory withConcurrencyLevels(Set<Integer> concurrencyLevels) {
Reported by PMD.
Line: 45
private Set<Integer> maximumSizes = Sets.newHashSet((Integer) null);
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
private Set<Strength> valueStrengths = Sets.newHashSet((Strength) null);
CacheBuilderFactory withConcurrencyLevels(Set<Integer> concurrencyLevels) {
this.concurrencyLevels = Sets.newLinkedHashSet(concurrencyLevels);
Reported by PMD.
Line: 46
private Set<DurationSpec> expireAfterWrites = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
private Set<Strength> valueStrengths = Sets.newHashSet((Strength) null);
CacheBuilderFactory withConcurrencyLevels(Set<Integer> concurrencyLevels) {
this.concurrencyLevels = Sets.newLinkedHashSet(concurrencyLevels);
return this;
Reported by PMD.
Line: 47
private Set<DurationSpec> expireAfterAccesses = Sets.newHashSet((DurationSpec) null);
private Set<DurationSpec> refreshes = Sets.newHashSet((DurationSpec) null);
private Set<Strength> keyStrengths = Sets.newHashSet((Strength) null);
private Set<Strength> valueStrengths = Sets.newHashSet((Strength) null);
CacheBuilderFactory withConcurrencyLevels(Set<Integer> concurrencyLevels) {
this.concurrencyLevels = Sets.newLinkedHashSet(concurrencyLevels);
return this;
}
Reported by PMD.
Line: 160
});
}
private CacheBuilder<Object, Object> createCacheBuilder(
Integer concurrencyLevel,
Integer initialCapacity,
Integer maximumSize,
DurationSpec expireAfterWrite,
DurationSpec expireAfterAccess,
Reported by PMD.
guava-tests/test/com/google/common/collect/ForwardingNavigableMapTest.java
16 issues
Line: 50
* @author Louis Wasserman
*/
public class ForwardingNavigableMapTest extends TestCase {
static class StandardImplForwardingNavigableMap<K, V> extends ForwardingNavigableMap<K, V> {
private final NavigableMap<K, V> backingMap;
StandardImplForwardingNavigableMap(NavigableMap<K, V> backingMap) {
this.backingMap = backingMap;
}
Reported by PMD.
Line: 51
*/
public class ForwardingNavigableMapTest extends TestCase {
static class StandardImplForwardingNavigableMap<K, V> extends ForwardingNavigableMap<K, V> {
private final NavigableMap<K, V> backingMap;
StandardImplForwardingNavigableMap(NavigableMap<K, V> backingMap) {
this.backingMap = backingMap;
}
Reported by PMD.
Line: 116
return new StandardEntrySet() {
@Override
public Iterator<Entry<K, V>> iterator() {
return backingMap.entrySet().iterator();
}
};
}
@Override
Reported by PMD.
Line: 233
}
static class StandardLastEntryForwardingNavigableMap<K, V> extends ForwardingNavigableMap<K, V> {
private final NavigableMap<K, V> backingMap;
StandardLastEntryForwardingNavigableMap(NavigableMap<K, V> backingMap) {
this.backingMap = backingMap;
}
Reported by PMD.
Line: 250
}
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(ForwardingNavigableMapTest.class);
suite.addTest(
NavigableMapTestSuiteBuilder.using(
Reported by PMD.
Line: 291
return suite;
}
public void testStandardLastEntry() {
NavigableMap<String, Integer> forwarding =
new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
assertNull(forwarding.lastEntry());
forwarding.put("b", 2);
assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
Reported by PMD.
Line: 291
return suite;
}
public void testStandardLastEntry() {
NavigableMap<String, Integer> forwarding =
new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
assertNull(forwarding.lastEntry());
forwarding.put("b", 2);
assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
Reported by PMD.
Line: 294
public void testStandardLastEntry() {
NavigableMap<String, Integer> forwarding =
new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
assertNull(forwarding.lastEntry());
forwarding.put("b", 2);
assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
forwarding.put("c", 3);
assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
forwarding.put("a", 1);
Reported by PMD.
Line: 296
new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>());
assertNull(forwarding.lastEntry());
forwarding.put("b", 2);
assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
forwarding.put("c", 3);
assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
forwarding.put("a", 1);
assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
forwarding.remove("c");
Reported by PMD.
Line: 298
forwarding.put("b", 2);
assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
forwarding.put("c", 3);
assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
forwarding.put("a", 1);
assertEquals(immutableEntry("c", 3), forwarding.lastEntry());
forwarding.remove("c");
assertEquals(immutableEntry("b", 2), forwarding.lastEntry());
}
Reported by PMD.
guava-tests/test/com/google/common/escape/ArrayBasedCharEscaperTest.java
16 issues
Line: 35
'\t', "<tab>",
'&', "<and>");
public void testSafeRange() throws IOException {
// Basic escaping of unsafe chars (wrap them in {,}'s)
CharEscaper wrappingEscaper =
new ArrayBasedCharEscaper(NO_REPLACEMENTS, 'A', 'Z') {
@Override
protected char[] escapeUnsafe(char c) {
Reported by PMD.
Line: 46
};
EscaperAsserts.assertBasic(wrappingEscaper);
// '[' and '@' lie either side of [A-Z].
assertEquals("{[}FOO{@}BAR{]}", wrappingEscaper.escape("[FOO@BAR]"));
}
public void testSafeRange_maxLessThanMin() throws IOException {
// Basic escaping of unsafe chars (wrap them in {,}'s)
CharEscaper wrappingEscaper =
Reported by PMD.
Line: 49
assertEquals("{[}FOO{@}BAR{]}", wrappingEscaper.escape("[FOO@BAR]"));
}
public void testSafeRange_maxLessThanMin() throws IOException {
// Basic escaping of unsafe chars (wrap them in {,}'s)
CharEscaper wrappingEscaper =
new ArrayBasedCharEscaper(NO_REPLACEMENTS, 'Z', 'A') {
@Override
protected char[] escapeUnsafe(char c) {
Reported by PMD.
Line: 60
};
EscaperAsserts.assertBasic(wrappingEscaper);
// escape everything.
assertEquals("{[}{F}{O}{O}{]}", wrappingEscaper.escape("[FOO]"));
}
public void testDeleteUnsafeChars() throws IOException {
CharEscaper deletingEscaper =
new ArrayBasedCharEscaper(NO_REPLACEMENTS, ' ', '~') {
Reported by PMD.
Line: 63
assertEquals("{[}{F}{O}{O}{]}", wrappingEscaper.escape("[FOO]"));
}
public void testDeleteUnsafeChars() throws IOException {
CharEscaper deletingEscaper =
new ArrayBasedCharEscaper(NO_REPLACEMENTS, ' ', '~') {
private final char[] noChars = new char[0];
@Override
Reported by PMD.
Line: 74
}
};
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.
Line: 81
+ "printable ASCII \uFFFFrange is \u007Fdeleted.\n"));
}
public void testReplacementPriority() throws IOException {
CharEscaper replacingEscaper =
new ArrayBasedCharEscaper(SIMPLE_REPLACEMENTS, ' ', '~') {
private final char[] unknown = new char[] {'?'};
@Override
Reported by PMD.
Line: 95
// Replacements are applied first regardless of whether the character is in
// the safe range or not ('&' is a safe char while '\t' and '\n' are not).
assertEquals(
"<tab>Fish <and>? Chips?<newline>", replacingEscaper.escape("\tFish &\0 Chips\r\n"));
}
}
Reported by PMD.
Line: 37
public void testSafeRange() throws IOException {
// Basic escaping of unsafe chars (wrap them in {,}'s)
CharEscaper wrappingEscaper =
new ArrayBasedCharEscaper(NO_REPLACEMENTS, 'A', 'Z') {
@Override
protected char[] escapeUnsafe(char c) {
return ("{" + c + "}").toCharArray();
}
Reported by PMD.
Line: 37
public void testSafeRange() throws IOException {
// Basic escaping of unsafe chars (wrap them in {,}'s)
CharEscaper wrappingEscaper =
new ArrayBasedCharEscaper(NO_REPLACEMENTS, 'A', 'Z') {
@Override
protected char[] escapeUnsafe(char c) {
return ("{" + c + "}").toCharArray();
}
Reported by PMD.
guava-tests/test/com/google/common/hash/ChecksumHashFunctionTest.java
16 issues
Line: 30
*/
public class ChecksumHashFunctionTest extends TestCase {
public void testCrc32_equalsChecksumValue() throws Exception {
assertChecksum(CRC_32, "");
assertChecksum(CRC_32, "Z");
assertChecksum(CRC_32, "foobar");
}
Reported by PMD.
Line: 30
*/
public class ChecksumHashFunctionTest extends TestCase {
public void testCrc32_equalsChecksumValue() throws Exception {
assertChecksum(CRC_32, "");
assertChecksum(CRC_32, "Z");
assertChecksum(CRC_32, "foobar");
}
Reported by PMD.
Line: 36
assertChecksum(CRC_32, "foobar");
}
public void testAdler32_equalsChecksumValue() throws Exception {
assertChecksum(ADLER_32, "");
assertChecksum(ADLER_32, "Z");
assertChecksum(ADLER_32, "foobar");
}
Reported by PMD.
Line: 36
assertChecksum(CRC_32, "foobar");
}
public void testAdler32_equalsChecksumValue() throws Exception {
assertChecksum(ADLER_32, "");
assertChecksum(ADLER_32, "Z");
assertChecksum(ADLER_32, "foobar");
}
Reported by PMD.
Line: 42
assertChecksum(ADLER_32, "foobar");
}
public void testCrc32_knownValues() throws Exception {
assertHash32(0x1C8600E3, CRC_32, "hell");
assertHash32(0x3610A686, CRC_32, "hello");
assertHash32(0xED81F9F6, CRC_32, "hello ");
assertHash32(0x4850DDC2, CRC_32, "hello w");
assertHash32(0x7A2D6005, CRC_32, "hello wo");
Reported by PMD.
Line: 42
assertChecksum(ADLER_32, "foobar");
}
public void testCrc32_knownValues() throws Exception {
assertHash32(0x1C8600E3, CRC_32, "hell");
assertHash32(0x3610A686, CRC_32, "hello");
assertHash32(0xED81F9F6, CRC_32, "hello ");
assertHash32(0x4850DDC2, CRC_32, "hello w");
assertHash32(0x7A2D6005, CRC_32, "hello wo");
Reported by PMD.
Line: 53
assertHash32(0x4400B5BC, CRC_32, "The quick brown fox jumps over the lazy cog");
}
public void testAdler32_knownValues() throws Exception {
assertHash32(0x041701A6, ADLER_32, "hell");
assertHash32(0x062C0215, ADLER_32, "hello");
assertHash32(0x08610235, ADLER_32, "hello ");
assertHash32(0x0B0D02AC, ADLER_32, "hello w");
assertHash32(0x0E28031B, ADLER_32, "hello wo");
Reported by PMD.
Line: 53
assertHash32(0x4400B5BC, CRC_32, "The quick brown fox jumps over the lazy cog");
}
public void testAdler32_knownValues() throws Exception {
assertHash32(0x041701A6, ADLER_32, "hell");
assertHash32(0x062C0215, ADLER_32, "hello");
assertHash32(0x08610235, ADLER_32, "hello ");
assertHash32(0x0B0D02AC, ADLER_32, "hello w");
assertHash32(0x0E28031B, ADLER_32, "hello wo");
Reported by PMD.
Line: 68
byte[] bytes = HashTestUtils.ascii(input);
Checksum checksum = supplier.get();
checksum.update(bytes, 0, bytes.length);
long value = checksum.getValue();
String toString = "name";
HashFunction func = new ChecksumHashFunction(supplier, 32, toString);
assertEquals(toString, func.toString());
Reported by PMD.
Line: 69
Checksum checksum = supplier.get();
checksum.update(bytes, 0, bytes.length);
long value = checksum.getValue();
String toString = "name";
HashFunction func = new ChecksumHashFunction(supplier, 32, toString);
assertEquals(toString, func.toString());
assertEquals(value, func.hashBytes(bytes).padToLong());
Reported by PMD.
guava-tests/benchmark/com/google/common/collect/BinaryTreeTraverserBenchmark.java
15 issues
Line: 32
*/
public class BinaryTreeTraverserBenchmark {
private static class BinaryNode {
final int x;
final Optional<BinaryNode> left;
final Optional<BinaryNode> right;
BinaryNode(int x, Optional<BinaryNode> left, Optional<BinaryNode> right) {
this.x = x;
Reported by PMD.
Line: 33
public class BinaryTreeTraverserBenchmark {
private static class BinaryNode {
final int x;
final Optional<BinaryNode> left;
final Optional<BinaryNode> right;
BinaryNode(int x, Optional<BinaryNode> left, Optional<BinaryNode> right) {
this.x = x;
this.left = left;
Reported by PMD.
Line: 34
private static class BinaryNode {
final int x;
final Optional<BinaryNode> left;
final Optional<BinaryNode> right;
BinaryNode(int x, Optional<BinaryNode> left, Optional<BinaryNode> right) {
this.x = x;
this.left = left;
this.right = right;
Reported by PMD.
Line: 63
Optional<BinaryNode> createTree(int size, Random rng) {
Optional<BinaryNode> root = Optional.absent();
for (int i = 0; i < size; i++) {
root = Optional.of(new BinaryNode(rng.nextInt(), root, Optional.<BinaryNode>absent()));
}
return root;
}
},
ALL_RIGHT {
Reported by PMD.
Line: 73
Optional<BinaryNode> createTree(int size, Random rng) {
Optional<BinaryNode> root = Optional.absent();
for (int i = 0; i < size; i++) {
root = Optional.of(new BinaryNode(rng.nextInt(), Optional.<BinaryNode>absent(), root));
}
return root;
}
},
RANDOM {
Reported by PMD.
Line: 143
abstract <T> Iterable<T> view(T root, TreeTraverser<T> viewer);
}
private Iterable<BinaryNode> view;
@Param Topology topology;
@Param({"1", "100", "10000", "1000000"})
int size;
Reported by PMD.
Line: 145
private Iterable<BinaryNode> view;
@Param Topology topology;
@Param({"1", "100", "10000", "1000000"})
int size;
@Param Traversal traversal;
Reported by PMD.
Line: 148
@Param Topology topology;
@Param({"1", "100", "10000", "1000000"})
int size;
@Param Traversal traversal;
@Param({"1234"})
SpecialRandom rng;
Reported by PMD.
Line: 150
@Param({"1", "100", "10000", "1000000"})
int size;
@Param Traversal traversal;
@Param({"1234"})
SpecialRandom rng;
@BeforeExperiment
Reported by PMD.
Line: 150
@Param({"1", "100", "10000", "1000000"})
int size;
@Param Traversal traversal;
@Param({"1234"})
SpecialRandom rng;
@BeforeExperiment
Reported by PMD.