Use final.

This commit is contained in:
Gary Gregory 2018-06-12 15:33:17 -06:00
parent 56706c8203
commit 274c9c1d37
4 changed files with 30 additions and 29 deletions

View File

@ -761,7 +761,7 @@ public class IteratorUtilsTest {
@Test @Test
public void testFirstFromIterator() throws Exception { public void testFirstFromIterator() throws Exception {
// Iterator, entry exists // Iterator, entry exists
Iterator<Integer> iterator = iterableA.iterator(); final Iterator<Integer> iterator = iterableA.iterator();
assertEquals(1, (int) IteratorUtils.first(iterator)); assertEquals(1, (int) IteratorUtils.first(iterator));
} }

View File

@ -47,12 +47,12 @@ public class MultiSetUtilsTest {
*/ */
@Test @Test
public void testEmptyMultiSet() { public void testEmptyMultiSet() {
MultiSet<Integer> empty = MultiSetUtils.emptyMultiSet(); final MultiSet<Integer> empty = MultiSetUtils.emptyMultiSet();
assertEquals(0, empty.size()); assertEquals(0, empty.size());
try { try {
empty.add(55); empty.add(55);
fail("Empty multi set must be read-only"); fail("Empty multi set must be read-only");
} catch (UnsupportedOperationException e) { } catch (final UnsupportedOperationException e) {
} }
} }
@ -61,19 +61,19 @@ public class MultiSetUtilsTest {
*/ */
@Test @Test
public void testUnmodifiableMultiSet() { public void testUnmodifiableMultiSet() {
MultiSet<String> unmodifiable = MultiSetUtils.unmodifiableMultiSet(multiSet); final MultiSet<String> unmodifiable = MultiSetUtils.unmodifiableMultiSet(multiSet);
assertEquals(multiSet, unmodifiable); assertEquals(multiSet, unmodifiable);
try { try {
unmodifiable.add("a"); unmodifiable.add("a");
fail("Empty multi set must be read-only"); fail("Empty multi set must be read-only");
} catch (UnsupportedOperationException e) { } catch (final UnsupportedOperationException e) {
} }
try { try {
MultiSetUtils.unmodifiableMultiSet(null); MultiSetUtils.unmodifiableMultiSet(null);
fail("Expecting NPE"); fail("Expecting NPE");
} catch (NullPointerException e) { } catch (final NullPointerException e) {
} }
} }
@ -82,7 +82,7 @@ public class MultiSetUtilsTest {
*/ */
@Test @Test
public void testSynchronizedMultiSet() { public void testSynchronizedMultiSet() {
MultiSet<String> synced = MultiSetUtils.synchronizedMultiSet(multiSet); final MultiSet<String> synced = MultiSetUtils.synchronizedMultiSet(multiSet);
assertEquals(multiSet, synced); assertEquals(multiSet, synced);
synced.add("a"); // ensure adding works synced.add("a"); // ensure adding works
} }
@ -92,38 +92,38 @@ public class MultiSetUtilsTest {
*/ */
@Test @Test
public void testPredicatedMultiSet() { public void testPredicatedMultiSet() {
Predicate<String> predicate = new Predicate<String>() { final Predicate<String> predicate = new Predicate<String>() {
@Override @Override
public boolean evaluate(String object) { public boolean evaluate(final String object) {
return object.length() == 1; return object.length() == 1;
}; };
}; };
MultiSet<String> predicated = MultiSetUtils.predicatedMultiSet(multiSet, predicate); final MultiSet<String> predicated = MultiSetUtils.predicatedMultiSet(multiSet, predicate);
assertEquals(multiSet.size(), predicated.size()); assertEquals(multiSet.size(), predicated.size());
assertEquals(multiSet.getCount("a"), predicated.getCount("a")); assertEquals(multiSet.getCount("a"), predicated.getCount("a"));
try { try {
MultiSetUtils.predicatedMultiSet(null, predicate); MultiSetUtils.predicatedMultiSet(null, predicate);
fail("Expecting NPE"); fail("Expecting NPE");
} catch (NullPointerException e) { } catch (final NullPointerException e) {
} }
try { try {
MultiSetUtils.predicatedMultiSet(multiSet, null); MultiSetUtils.predicatedMultiSet(multiSet, null);
fail("Expecting NPE"); fail("Expecting NPE");
} catch (NullPointerException e) { } catch (final NullPointerException e) {
} }
try { try {
MultiSetUtils.predicatedMultiSet(multiSet, new Predicate<String>() { MultiSetUtils.predicatedMultiSet(multiSet, new Predicate<String>() {
@Override @Override
public boolean evaluate(String object) { public boolean evaluate(final String object) {
return object.equals("a"); return object.equals("a");
}; };
}); });
fail("Predicate is violated for all elements not being 'a'"); fail("Predicate is violated for all elements not being 'a'");
} }
catch (IllegalArgumentException iae) { catch (final IllegalArgumentException iae) {
} }
} }
} }

View File

@ -698,7 +698,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(TWO, TWO); m.put(TWO, TWO);
m.put(null, THREE); m.put(null, THREE);
boolean contains = m.containsKey(null); final boolean contains = m.containsKey(null);
assertEquals(true, contains); assertEquals(true, contains);
} }
@ -707,7 +707,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(null, TWO); m.put(null, TWO);
boolean contains = m.containsKey(null); final boolean contains = m.containsKey(null);
assertEquals(true, contains); assertEquals(true, contains);
} }
@ -715,7 +715,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
final Flat3Map<Integer, Integer> m = new Flat3Map<>(); final Flat3Map<Integer, Integer> m = new Flat3Map<>();
m.put(null, ONE); m.put(null, ONE);
boolean contains = m.containsKey(null); final boolean contains = m.containsKey(null);
assertEquals(true, contains); assertEquals(true, contains);
} }
@ -725,7 +725,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(TWO, TWO); m.put(TWO, TWO);
m.put(THREE, null); m.put(THREE, null);
boolean contains = m.containsValue(null); final boolean contains = m.containsValue(null);
assertEquals(true, contains); assertEquals(true, contains);
} }
@ -734,7 +734,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(TWO, null); m.put(TWO, null);
boolean contains = m.containsValue(null); final boolean contains = m.containsValue(null);
assertEquals(true, contains); assertEquals(true, contains);
} }
@ -742,7 +742,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
final Flat3Map<Integer, Integer> m = new Flat3Map<>(); final Flat3Map<Integer, Integer> m = new Flat3Map<>();
m.put(ONE, null); m.put(ONE, null);
boolean contains = m.containsValue(null); final boolean contains = m.containsValue(null);
assertEquals(true, contains); assertEquals(true, contains);
} }
@ -752,7 +752,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(TWO, TWO); m.put(TWO, TWO);
m.put(null, THREE); m.put(null, THREE);
Object old = m.put(null, ONE); final Object old = m.put(null, ONE);
assertEquals(THREE, old); assertEquals(THREE, old);
assertEquals(ONE, m.get(null)); assertEquals(ONE, m.get(null));
} }
@ -762,7 +762,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(null, THREE); m.put(null, THREE);
Object old = m.put(null, ONE); final Object old = m.put(null, ONE);
assertEquals(THREE, old); assertEquals(THREE, old);
assertEquals(ONE, m.get(null)); assertEquals(ONE, m.get(null));
} }
@ -771,7 +771,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
final Flat3Map<Integer, Integer> m = new Flat3Map<>(); final Flat3Map<Integer, Integer> m = new Flat3Map<>();
m.put(null, THREE); m.put(null, THREE);
Object old = m.put(null, ONE); final Object old = m.put(null, ONE);
assertEquals(THREE, old); assertEquals(THREE, old);
assertEquals(null, m.get(ONE)); assertEquals(null, m.get(ONE));
} }
@ -782,7 +782,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(TWO, TWO); m.put(TWO, TWO);
m.put(THREE, THREE); m.put(THREE, THREE);
Object old = m.put(THREE, ONE); final Object old = m.put(THREE, ONE);
assertEquals(THREE, old); assertEquals(THREE, old);
assertEquals(ONE, m.get(THREE)); assertEquals(ONE, m.get(THREE));
} }
@ -792,7 +792,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
m.put(ONE, ONE); m.put(ONE, ONE);
m.put(TWO, THREE); m.put(TWO, THREE);
Object old = m.put(TWO, ONE); final Object old = m.put(TWO, ONE);
assertEquals(THREE, old); assertEquals(THREE, old);
assertEquals(ONE, m.get(TWO)); assertEquals(ONE, m.get(TWO));
} }
@ -801,7 +801,7 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
final Flat3Map<Integer, Integer> m = new Flat3Map<>(); final Flat3Map<Integer, Integer> m = new Flat3Map<>();
m.put(ONE, THREE); m.put(ONE, THREE);
Object old = m.put(ONE, ONE); final Object old = m.put(ONE, ONE);
assertEquals(THREE, old); assertEquals(THREE, old);
assertEquals(ONE, m.get(ONE)); assertEquals(ONE, m.get(ONE));
} }

View File

@ -262,17 +262,18 @@ public class ReferenceMapTest<K, V> extends AbstractIterableMapTest<K, V> {
*/ */
public void testDataSizeAfterSerialization() throws IOException, ClassNotFoundException { public void testDataSizeAfterSerialization() throws IOException, ClassNotFoundException {
ReferenceMap<String,String> serialiseMap = new ReferenceMap<>(ReferenceStrength.WEAK, ReferenceStrength.WEAK, true); final ReferenceMap<String,String> serialiseMap = new ReferenceMap<>(ReferenceStrength.WEAK, ReferenceStrength.WEAK, true);
serialiseMap.put("KEY", "VALUE"); serialiseMap.put("KEY", "VALUE");
ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(baos)) { try (ObjectOutputStream out = new ObjectOutputStream(baos)) {
out.writeObject(serialiseMap); out.writeObject(serialiseMap);
} }
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
try (ObjectInputStream in = new ObjectInputStream(bais)) { try (ObjectInputStream in = new ObjectInputStream(bais)) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final
ReferenceMap<String,String> deserialisedMap = (ReferenceMap<String,String>) in.readObject(); ReferenceMap<String,String> deserialisedMap = (ReferenceMap<String,String>) in.readObject();
assertEquals(1, deserialisedMap.size()); assertEquals(1, deserialisedMap.size());
assertEquals(serialiseMap.data.length, deserialisedMap.data.length); assertEquals(serialiseMap.data.length, deserialisedMap.data.length);