Use local variable type inference and migrate to JUnit5.
Change-Id: If80b8eb6b5c5ae49c248bcf8c4710c96b1cbc51f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
private final MultiRegistry<Integer, P> parsers = new MultiRegistry<>();
public Registration registerParser(final int type, final P parser) {
- return this.parsers.register(type, parser);
+ return parsers.register(type, parser);
}
public P getParser(final int type) {
- return this.parsers.get(type);
+ return parsers.get(type);
}
public Registration registerSerializer(final Class<? extends C> clazz, final S serializer) {
- return this.serializers.register(clazz, serializer);
+ return serializers.register(clazz, serializer);
}
public S getSerializer(final Class<? extends C> clazz) {
- return this.serializers.get(clazz);
+ return serializers.get(clazz);
}
public Iterable<S> getAllSerializers() {
- return this.serializers.getAllValues();
+ return serializers.getAllValues();
}
}
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
-import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.checkerframework.checker.lock.qual.GuardedBy;
*/
public final class MultiRegistry<K, V> {
private static final Logger LOG = LoggerFactory.getLogger(MultiRegistry.class);
+
private final ConcurrentMap<K, V> current = new ConcurrentHashMap<>();
@GuardedBy("this")
@Holding("this")
private void updateCurrent(final K key) {
- final List<V> values = this.candidates.get(key);
+ final var values = candidates.get(key);
// Simple case: no candidates
if (values.isEmpty()) {
- this.current.remove(key);
+ current.remove(key);
return;
}
V best = values.get(0);
- for (V v : values) {
- final Class<?> vc = v.getClass();
- final Class<?> bc = best.getClass();
+ for (var v : values) {
+ final var vc = v.getClass();
+ final var bc = best.getClass();
if (bc.isAssignableFrom(vc)) {
LOG.debug("{} is superclass of {}, preferring the latter", bc, vc);
best = v;
}
LOG.debug("New best value {}", best);
- this.current.put(key, best);
+ current.put(key, best);
}
public synchronized Registration register(final K key, final V value) {
- this.candidates.put(key, value);
+ candidates.put(key, value);
updateCurrent(key);
return new AbstractRegistration() {
}
public V get(final K key) {
- return this.current.get(key);
+ return current.get(key);
}
public Iterable<V> getAllValues() {
- return Iterables.unmodifiableIterable(this.current.values());
+ return Iterables.unmodifiableIterable(current.values());
}
}
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import java.util.HashSet;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yangtools.yang.common.Uint32;
-public class ASNumberTest {
- private AsNumber asn1;
- private AsNumber asn3;
- private AsNumber asn4;
-
- @Before
- public void setUp() {
- asn1 = new AsNumber(Uint32.valueOf(4294967295L));
- asn3 = new AsNumber(Uint32.valueOf(200));
- asn4 = new AsNumber(Uint32.valueOf(429496335L));
- }
+class ASNumberTest {
+ private static final AsNumber ASN1 = new AsNumber(Uint32.valueOf(4294967295L));
+ private static final AsNumber ASN3 = new AsNumber(Uint32.valueOf(200));
+ private static final AsNumber ASN4 = new AsNumber(Uint32.valueOf(429496335L));
@Test
- public void testHashCode() {
- final Set<AsNumber> set = new HashSet<>();
+ void testHashCode() {
+ final var set = new HashSet<AsNumber>();
- set.add(asn1);
+ set.add(ASN1);
assertEquals(1, set.size());
- set.add(asn3);
+ set.add(ASN3);
assertEquals(2, set.size());
}
@Test
- public void testGetters() {
- assertEquals(4294967295L, asn1.getValue().longValue());
+ void testGetters() {
+ assertEquals(4294967295L, ASN1.getValue().longValue());
}
@Test
- public void testEquals() {
- assertThat(asn1, not(equalTo(asn3)));
- assertThat(asn1, not(equalTo(asn4)));
- assertThat(asn1, not(equalTo(new Object())));
- assertNotEquals(asn1, new Object());
+ void testEquals() {
+ assertThat(ASN1, not(equalTo(ASN3)));
+ assertThat(ASN1, not(equalTo(ASN4)));
+ assertThat(ASN1, not(equalTo(new Object())));
+ assertNotEquals(ASN1, new Object());
}
@Test
- public void testToString() {
- assertEquals("AsNumber{value=4294967295}", asn1.toString());
- assertEquals("AsNumber{value=200}", asn3.toString());
+ void testToString() {
+ assertEquals("AsNumber{value=4294967295}", ASN1.toString());
+ assertEquals("AsNumber{value=200}", ASN3.toString());
}
}
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import io.netty.buffer.Unpooled;
import java.util.HashSet;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
-public class BandwidthTest {
- private Bandwidth b1;
- private Bandwidth b2;
- private Bandwidth b3;
- private Bandwidth b4;
-
- @Before
- public void setUp() {
- this.b1 = new Bandwidth(Unpooled.copyInt(1000).array());
- this.b2 = new Bandwidth(Unpooled.copyInt(2000).array());
- this.b3 = new Bandwidth(Unpooled.copyInt(2000).array());
- this.b4 = new Bandwidth(Unpooled.copyInt(100).array());
- }
+class BandwidthTest {
+ private static final Bandwidth B1 = new Bandwidth(Unpooled.copyInt(1000).array());
+ private static final Bandwidth B2 = new Bandwidth(Unpooled.copyInt(2000).array());
+ private static final Bandwidth B3 = new Bandwidth(Unpooled.copyInt(2000).array());
+ private static final Bandwidth B4 = new Bandwidth(Unpooled.copyInt(100).array());
@Test
- public void testBitsBytes() {
- assertEquals(1000.0, Unpooled.wrappedBuffer(this.b1.getValue()).readInt(), 0.1);
+ void testBitsBytes() {
+ assertEquals(1000.0, Unpooled.wrappedBuffer(B1.getValue()).readInt(), 0.1);
}
@Test
- public void testEquals() {
- assertFalse(this.b1.equals(null));
- assertThat(this.b1, not(equalTo(new Object())));
- assertThat(this.b1, equalTo(this.b1));
- assertThat(this.b1, not(equalTo(this.b2)));
- assertEquals(this.b2, this.b3);
- assertNotEquals(this.b1, new Object());
+ void testEquals() {
+ assertFalse(B1.equals(null));
+ assertThat(B1, not(equalTo(new Object())));
+ assertThat(B1, equalTo(B1));
+ assertThat(B1, not(equalTo(B2)));
+ assertEquals(B2, B3);
+ assertNotEquals(B1, new Object());
}
@Test
- public void testHashCode() {
- final Set<Bandwidth> set = new HashSet<>();
+ void testHashCode() {
+ final var set = new HashSet<Bandwidth>();
- set.add(this.b1);
+ set.add(B1);
assertEquals(1, set.size());
- set.add(this.b2);
+ set.add(B2);
assertEquals(2, set.size());
- set.add(this.b3);
+ set.add(B3);
assertEquals(2, set.size());
- set.add(this.b4);
+ set.add(B4);
assertEquals(3, set.size());
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.concepts;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-public class DefaultInstanceReferenceTest {
-
- private static final InstanceIdentifier<NetworkTopology> IID
- = InstanceIdentifier.builder(NetworkTopology.class).build();
+class DefaultInstanceReferenceTest {
+ private static final InstanceIdentifier<NetworkTopology> IID = InstanceIdentifier.create(NetworkTopology.class);
@Test
- public void testDefaultInstanceReference() {
- final DefaultInstanceReference<NetworkTopology> defaultIID = new DefaultInstanceReference<>(IID);
- Assert.assertEquals(IID, defaultIID.getInstanceIdentifier());
+ void testDefaultInstanceReference() {
+ final var defaultIID = new DefaultInstanceReference<>(IID);
+ assertEquals(IID, defaultIID.getInstanceIdentifier());
}
- @Test(expected = NullPointerException.class)
- public void testNullReference() {
- new DefaultInstanceReference<>(null);
+ @Test
+ void testNullReference() {
+ assertThrows(NullPointerException.class, () -> new DefaultInstanceReference<>(null));
}
-
}
*/
package org.opendaylight.protocol.concepts;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
-import org.junit.Test;
-import org.opendaylight.yangtools.concepts.Registration;
+import org.junit.jupiter.api.Test;
-public class HandlerRegistryTest {
+class HandlerRegistryTest {
private static final String PARSER = "parser";
private static final String SERIALIZER = "serializer";
private static final int TYPE = 1;
@Test
- public void testHandlerRegistry() {
- final HandlerRegistry<Object, String, String> registry = new HandlerRegistry<>();
- final Registration parserReg = registry.registerParser(TYPE, PARSER);
- final Registration serializerReg = registry.registerSerializer(Object.class, SERIALIZER);
+ void testHandlerRegistry() {
+ final var registry = new HandlerRegistry<Object, String, String>();
+ final var parserReg = registry.registerParser(TYPE, PARSER);
+ final var serializerReg = registry.registerSerializer(Object.class, SERIALIZER);
assertNotNull(parserReg);
assertNotNull(serializerReg);
*/
package org.opendaylight.protocol.concepts;
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-public class ISOSystemIdentifierTest {
+import org.junit.jupiter.api.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
- @Test(expected = IllegalArgumentException.class)
- public void testISOSystemIdentifier() {
- final byte[] b = new byte[] { 10, 12, 127, 0, 9, 1, 1 };
- new IsoSystemIdentifier(b);
+class ISOSystemIdentifierTest {
+ @Test
+ void testISOSystemIdentifier() {
+ final var ex = assertThrows(IllegalArgumentException.class,
+ () -> new IsoSystemIdentifier(new byte[] { 10, 12, 127, 0, 9, 1, 1 }));
+ assertEquals("Invalid length: 0a0c7f00090101, expected: [[6..6]].", ex.getMessage());
}
@Test
- public void testGetBytes() {
- final byte[] b = new byte[] { 10, 12, 127, 0, 9, 1 };
- final IsoSystemIdentifier id = new IsoSystemIdentifier(b);
- Assert.assertArrayEquals(new byte[] { 10, 12, 127, 0, 9, 1 }, id.getValue());
+ void testGetBytes() {
+ final var id = new IsoSystemIdentifier(new byte[] { 10, 12, 127, 0, 9, 1 });
+ assertArrayEquals(new byte[] { 10, 12, 127, 0, 9, 1 }, id.getValue());
}
-
}
*/
package org.opendaylight.protocol.concepts;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-import org.junit.Test;
-import org.opendaylight.yangtools.concepts.Registration;
-
-public class MultiRegistryTest {
+import org.junit.jupiter.api.Test;
+class MultiRegistryTest {
@Test
- public void testMultiRegistry() {
- final MultiRegistry<Object, Integer> registry = new MultiRegistry<>();
- final String first = "first";
- final String second = "second";
- final String third = "third";
+ void testMultiRegistry() {
+ final var registry = new MultiRegistry<Object, Integer>();
+ final var first = "first";
+ final var second = "second";
+ final var third = "third";
- final Registration a = registry.register(first, 1);
+ final var a = registry.register(first, 1);
registry.register(second, 2);
registry.register(third, 3);
}
@Test
- public void testDifferentNumbers() {
- final MultiRegistry<Object, Number> registry = new MultiRegistry<>();
- final String first = "first";
+ void testDifferentNumbers() {
+ final var registry = new MultiRegistry<Object, Number>();
+ final var first = "first";
registry.register(first, 1);
assertEquals(1, registry.get("first"));
@Test
public void testDifferentClasses() {
- final MultiRegistry<Object, Object> registry = new MultiRegistry<>();
- final String first = "first";
- final String second = "second";
+ final var registry = new MultiRegistry<>();
+ final var first = "first";
+ final var second = "second";
registry.register(first, 1);
assertEquals(1, registry.get("first"));