Enforce pcep-spi checkstyle
[bgpcep.git] / pcep / spi / src / test / java / org / opendaylight / protocol / pcep / spi / AbstractObjectWithTlvsTest.java
index 4f7b00760405e8dd7426c33e2bb47590e1f3c904..201665afd3b59a8e0d2fca7d828213821070511f 100644 (file)
@@ -8,17 +8,23 @@
 package org.opendaylight.protocol.pcep.spi;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.only;
+import static org.mockito.Mockito.verify;
 
 import com.google.common.collect.Lists;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
+import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
@@ -30,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlvBuilder;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class AbstractObjectWithTlvsTest {
 
     private static final EnterpriseNumber EN = new EnterpriseNumber(0L);
@@ -46,53 +53,54 @@ public class AbstractObjectWithTlvsTest {
 
     private class Abs extends AbstractObjectWithTlvsParser<TlvsBuilder> {
 
-        protected Abs(TlvRegistry tlvReg, VendorInformationTlvRegistry viTlvReg) {
+        protected Abs(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
             super(tlvReg, viTlvReg, 0, 0);
         }
 
         @Override
-        public Object parseObject(ObjectHeader header, ByteBuf buffer) {
+        public Object parseObject(final ObjectHeader header, final ByteBuf buffer) {
             return null;
         }
 
         @Override
-        public void serializeObject(Object object, ByteBuf buffer) {
+        public void serializeObject(final Object object, final ByteBuf buffer) {
         }
 
         @Override
-        public void addTlv(final TlvsBuilder builder, final Tlv tlv) {
-            builder.setOfList((OfList) tlv);
+        public void addTlv(final TlvsBuilder builder, final Tlv newTlv) {
+            builder.setOfList((OfList) newTlv);
         }
 
         @Override
-        protected void addVendorInformationTlvs(TlvsBuilder builder, List<VendorInformationTlv> tlvs) {
+        protected void addVendorInformationTlvs(final TlvsBuilder builder, final List<VendorInformationTlv> tlvs) {
             builder.setVendorInformationTlv(tlvs);
         }
     }
 
     @Before
     public void setUp() throws PCEPDeserializerException {
-        MockitoAnnotations.initMocks(this);
-        this.tlv = new OfListBuilder().setCodes(Lists.newArrayList(new OfId(10))).build();
+        this.tlv = new OfListBuilder().setCodes(Collections.singletonList(new OfId(10))).build();
         this.viTlv = new VendorInformationTlvBuilder().setEnterpriseNumber(EN).build();
-        Mockito.doNothing().when(this.viTlvRegistry).serializeVendorInformationTlv(Mockito.any(VendorInformationTlv.class), Mockito.any(ByteBuf.class));
-        Mockito.doReturn(Optional.of(this.viTlv)).when(this.viTlvRegistry).parseVendorInformationTlv(EN, Unpooled.wrappedBuffer(new byte[0]));
-        Mockito.doNothing().when(this.tlvRegistry).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));
-        Mockito.doReturn(this.tlv).when(this.tlvRegistry).parseTlv(4, Unpooled.wrappedBuffer(new byte[] { 5, 6 }));
+        doNothing().when(this.viTlvRegistry).serializeVendorInformationTlv(any(VendorInformationTlv.class),
+            any(ByteBuf.class));
+        doReturn(Optional.of(this.viTlv)).when(this.viTlvRegistry).parseVendorInformationTlv(EN,
+            Unpooled.wrappedBuffer(new byte[0]));
+        doNothing().when(this.tlvRegistry).serializeTlv(any(Tlv.class), any(ByteBuf.class));
+        doReturn(this.tlv).when(this.tlvRegistry).parseTlv(4, Unpooled.wrappedBuffer(new byte[] { 5, 6 }));
     }
 
     @Test
     public void testParseTlvs() throws PCEPDeserializerException {
-        Abs a = new Abs(this.tlvRegistry, this.viTlvRegistry);
+        Abs abs = new Abs(this.tlvRegistry, this.viTlvRegistry);
         ByteBuf buffer = Unpooled.buffer();
-        a.serializeTlv(this.tlv, buffer);
+        abs.serializeTlv(this.tlv, buffer);
 
-        Mockito.verify(this.tlvRegistry, Mockito.only()).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));
+        verify(this.tlvRegistry, only()).serializeTlv(any(Tlv.class), any(ByteBuf.class));
 
-        TlvsBuilder b = new TlvsBuilder();
-        a.parseTlvs(b, Unpooled.wrappedBuffer(new byte[] { 0, 4, 0, 2, 5, 6, 0, 0 }));
+        TlvsBuilder builder = new TlvsBuilder();
+        abs.parseTlvs(builder, Unpooled.wrappedBuffer(new byte[] { 0, 4, 0, 2, 5, 6, 0, 0 }));
 
-        assertEquals(this.tlv, b.getOfList());
+        assertEquals(this.tlv, builder.getOfList());
     }
 
     @Test
@@ -101,10 +109,12 @@ public class AbstractObjectWithTlvsTest {
         final ByteBuf buffer = Unpooled.buffer();
 
         parser.serializeVendorInformationTlvs(Lists.newArrayList(this.viTlv), buffer);
-        Mockito.verify(this.viTlvRegistry, Mockito.only()).serializeVendorInformationTlv(Mockito.any(VendorInformationTlv.class), Mockito.any(ByteBuf.class));
+        verify(this.viTlvRegistry, only()).serializeVendorInformationTlv(any(VendorInformationTlv.class),
+            any(ByteBuf.class));
 
         final TlvsBuilder tlvsBuilder = new TlvsBuilder();
-        parser.parseTlvs(tlvsBuilder, Unpooled.wrappedBuffer(new byte[] { 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 }));
+        parser.parseTlvs(tlvsBuilder, Unpooled.wrappedBuffer(
+            new byte[] { 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 }));
         assertEquals(this.viTlv, tlvsBuilder.getVendorInformationTlv().get(0));
     }
 }