From cbb8ff7ece8acaabf054121438d2a9bcc8947c98 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 23 Apr 2023 11:21:55 +0200 Subject: [PATCH] Migrate tests away from Optional.get() Upgraded modernizer plugin is flagging these violations, migrate to alternatives. Change-Id: I4f99b5cd6910819b8b50deda35d1b97445ecde2d Signed-off-by: Robert Varga --- .../ClientAttributePrependHandlerTest.java | 2 +- .../routing/policy/spi/AppendActionTest.java | 4 +-- .../routing/policy/spi/AsPathLengthTest.java | 33 ++++++++---------- .../policy/spi/AttributesEqualTests.java | 10 +++--- .../statement/ExportDefaultStatementTest.java | 4 ++- .../statement/ImportDefaultStatementTest.java | 11 +++--- .../statement/MatchAfiSafiNotInTest.java | 2 +- .../policy/statement/MatchAsPathSetTest.java | 7 ++-- .../statement/MatchBgpNeighborSetTest.java | 8 ++--- .../policy/statement/MatchCommunityTest.java | 6 ++-- .../policy/statement/MatchExtComTest.java | 34 +++++++++---------- .../policy/statement/SetCommunityTest.java | 19 +++++------ .../policy/statement/SetExtCommunityTest.java | 19 +++++------ .../statement/VpnNonMemberHandlerTest.java | 2 +- .../protocol/bgp/parser/spi/UtilsTest.java | 20 +++++------ .../bgp/rib/spi/AbstractRIBSupportTest.java | 34 +++++++++---------- .../protocol/pcep/pcc/mock/PCCMockCommon.java | 4 +-- 17 files changed, 104 insertions(+), 115 deletions(-) diff --git a/bgp/extensions/route-target/src/test/java/org/opendaylight/protocol/bgp/route/targetcontrain/impl/route/policy/ClientAttributePrependHandlerTest.java b/bgp/extensions/route-target/src/test/java/org/opendaylight/protocol/bgp/route/targetcontrain/impl/route/policy/ClientAttributePrependHandlerTest.java index 0f3330bb49..4617f6b6e6 100644 --- a/bgp/extensions/route-target/src/test/java/org/opendaylight/protocol/bgp/route/targetcontrain/impl/route/policy/ClientAttributePrependHandlerTest.java +++ b/bgp/extensions/route-target/src/test/java/org/opendaylight/protocol/bgp/route/targetcontrain/impl/route/policy/ClientAttributePrependHandlerTest.java @@ -56,7 +56,7 @@ public class ClientAttributePrependHandlerTest extends AbstractStatementRegistry @Test public void testPreprendClientAttribute() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("client-attribute-append-test")).findFirst().get(); + .filter(st -> st.getName().equals("client-attribute-append-test")).findFirst().orElseThrow(); final Attributes att = new AttributesBuilder() .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder() .setGlobal(IPV4).build()).build()) diff --git a/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AppendActionTest.java b/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AppendActionTest.java index 41b5ad4b4d..52b81bc3a0 100644 --- a/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AppendActionTest.java +++ b/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AppendActionTest.java @@ -51,7 +51,7 @@ public class AppendActionTest extends AbstractStatementRegistryTest { @Test public void testMultipleAppend() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("multiple-append-test")).findFirst().get(); + .filter(st -> st.getName().equals("multiple-append-test")).findFirst().orElseThrow(); final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -74,7 +74,7 @@ public class AppendActionTest extends AbstractStatementRegistryTest { @Test public void testNextHopSelf() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("next-hop-self-append-test")).findFirst().get(); + .filter(st -> st.getName().equals("next-hop-self-append-test")).findFirst().orElseThrow(); final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( diff --git a/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AsPathLengthTest.java b/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AsPathLengthTest.java index e706c8a7d8..69ad5b9f3f 100644 --- a/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AsPathLengthTest.java +++ b/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AsPathLengthTest.java @@ -12,8 +12,6 @@ import static org.junit.Assert.assertNull; import static org.mockito.Mockito.doReturn; import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -47,15 +45,15 @@ public class AsPathLengthTest extends AbstractStatementRegistryTest { @Test public void testASPathLengthEq() { final AsPathBuilder asPath = new AsPathBuilder(); - asPath.setSegments(Collections.singletonList(new SegmentsBuilder() - .setAsSequence(Arrays.asList( + asPath.setSegments(List.of(new SegmentsBuilder() + .setAsSequence(List.of( AsNumber.getDefaultInstance("1"), AsNumber.getDefaultInstance("2"), AsNumber.getDefaultInstance("3"))) .build())); Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("as-path-eq-length-test")).findFirst().get(); + .filter(st -> st.getName().equals("as-path-eq-length-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setAsPath(asPath.build()) .build()); @@ -68,8 +66,8 @@ public class AsPathLengthTest extends AbstractStatementRegistryTest { statement); assertNotNull(result.getAttributes()); - asPath.setSegments(Collections.singletonList(new SegmentsBuilder() - .setAsSequence(Arrays.asList( + asPath.setSegments(List.of(new SegmentsBuilder() + .setAsSequence(List.of( AsNumber.getDefaultInstance("1"), AsNumber.getDefaultInstance("3"))) .build())); @@ -87,15 +85,15 @@ public class AsPathLengthTest extends AbstractStatementRegistryTest { @Test public void testASPathLengthGe() { final AsPathBuilder asPath = new AsPathBuilder(); - asPath.setSegments(Collections.singletonList(new SegmentsBuilder() - .setAsSequence(Arrays.asList( + asPath.setSegments(List.of(new SegmentsBuilder() + .setAsSequence(List.of( AsNumber.getDefaultInstance("1"), AsNumber.getDefaultInstance("2"), AsNumber.getDefaultInstance("3"))) .build())); Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("as-path-ge-length-test")).findFirst().get(); + .filter(st -> st.getName().equals("as-path-ge-length-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setAsPath(asPath.build()) .build()); @@ -108,9 +106,8 @@ public class AsPathLengthTest extends AbstractStatementRegistryTest { statement); assertNull(result.getAttributes()); - asPath.setSegments(Collections.singletonList(new SegmentsBuilder() - .setAsSequence(Collections.singletonList( - AsNumber.getDefaultInstance("3"))) + asPath.setSegments(List.of(new SegmentsBuilder() + .setAsSequence(List.of(AsNumber.getDefaultInstance("3"))) .build())); attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setAsPath(asPath.build()).build()); @@ -126,15 +123,15 @@ public class AsPathLengthTest extends AbstractStatementRegistryTest { @Test public void testASPathLengthLe() { final AsPathBuilder asPath = new AsPathBuilder(); - asPath.setSegments(Collections.singletonList(new SegmentsBuilder() - .setAsSequence(Arrays.asList( + asPath.setSegments(List.of(new SegmentsBuilder() + .setAsSequence(List.of( AsNumber.getDefaultInstance("1"), AsNumber.getDefaultInstance("2"), AsNumber.getDefaultInstance("3"))) .build())); Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("as-path-le-length-test")).findFirst().get(); + .filter(st -> st.getName().equals("as-path-le-length-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setAsPath(asPath.build()) .build()); @@ -147,8 +144,8 @@ public class AsPathLengthTest extends AbstractStatementRegistryTest { statement); assertNotNull(result.getAttributes()); - asPath.setSegments(Collections.singletonList(new SegmentsBuilder() - .setAsSequence(Collections.singletonList(AsNumber.getDefaultInstance("3"))).build())); + asPath.setSegments(List.of(new SegmentsBuilder() + .setAsSequence(List.of(AsNumber.getDefaultInstance("3"))).build())); attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setAsPath(asPath.build()).build()); result = statementRegistry.applyExportStatement( diff --git a/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AttributesEqualTests.java b/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AttributesEqualTests.java index 2b2ca7d1e8..df509f8f31 100644 --- a/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AttributesEqualTests.java +++ b/bgp/openconfig-rp-spi/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/spi/AttributesEqualTests.java @@ -54,7 +54,7 @@ public class AttributesEqualTests extends AbstractStatementRegistryTest { @Test public void testMedEq() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("med-eq-test")).findFirst().get(); + .filter(st -> st.getName().equals("med-eq-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setMultiExitDisc(new MultiExitDiscBuilder().setMed(Uint32.valueOf(200)).build()) .build()); @@ -83,7 +83,7 @@ public class AttributesEqualTests extends AbstractStatementRegistryTest { @Test public void testOriginEq() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("origin-eq-test")).findFirst().get(); + .filter(st -> st.getName().equals("origin-eq-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build()) .build()); @@ -112,7 +112,7 @@ public class AttributesEqualTests extends AbstractStatementRegistryTest { @Test public void testNextHopIn() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("nexthop-in-test")).findFirst().get(); + .filter(st -> st.getName().equals("nexthop-in-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setCNextHop(new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder() .setGlobal(new Ipv6AddressNoZone("2001:db8::1")).build()).build()) @@ -143,7 +143,7 @@ public class AttributesEqualTests extends AbstractStatementRegistryTest { @Test public void testLocalPref() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("local-pref-eq-test")).findFirst().get(); + .filter(st -> st.getName().equals("local-pref-eq-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(350)).build()) .build()); @@ -172,7 +172,7 @@ public class AttributesEqualTests extends AbstractStatementRegistryTest { @Test public void testAfiSafiIn() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("afi-safi-in-test")).findFirst().get(); + .filter(st -> st.getName().equals("afi-safi-in-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(350)).build()) .build()); diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ExportDefaultStatementTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ExportDefaultStatementTest.java index e487bb4f3d..7ddb8cc887 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ExportDefaultStatementTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ExportDefaultStatementTest.java @@ -126,7 +126,9 @@ public class ExportDefaultStatementTest extends AbstractStatementRegistryConsume doReturn(toPeerRole).when(exportParameters).getToPeerRole(); doReturn(AS).when(exportParameters).getToPeerLocalAs(); return defaultExportStatements.stream() - .filter(st -> st.getName().equals(statementName)).findFirst().get(); + .filter(st -> st.getName().equals(statementName)) + .findFirst() + .orElseThrow(); } private void assertApplyExportStatement( diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ImportDefaultStatementTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ImportDefaultStatementTest.java index e6dd8ba85d..be38482003 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ImportDefaultStatementTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/ImportDefaultStatementTest.java @@ -42,8 +42,8 @@ public class ImportDefaultStatementTest extends AbstractStatementRegistryConsume public void testFromEbgp() { final Statement statement = getStatement("from-external"); - final RouteAttributeContainer attributeContainer - = routeAttributeContainerFalse(ImportAttributeTestUtil.createInput()); + final RouteAttributeContainer attributeContainer = + routeAttributeContainerFalse(ImportAttributeTestUtil.createInput()); assertApplyImportStatement(statement, PeerRole.Ebgp, attributeContainer, ImportAttributeTestUtil.createOutput()); @@ -54,8 +54,7 @@ public class ImportDefaultStatementTest extends AbstractStatementRegistryConsume final Statement statement = getStatement("from-non-external"); final Attributes expected = ImportAttributeTestUtil.createInput(); - final RouteAttributeContainer attributeContainer - = routeAttributeContainerFalse(expected); + final RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(expected); assertApplyImportStatement(statement, PeerRole.Ibgp, attributeContainer, expected); assertApplyImportStatement(statement, PeerRole.RrClient, attributeContainer, expected); @@ -64,7 +63,9 @@ public class ImportDefaultStatementTest extends AbstractStatementRegistryConsume private Statement getStatement(final String statementName) { return defaultImportStatements.stream() - .filter(st -> st.getName().equals(statementName)).findFirst().get(); + .filter(st -> st.getName().equals(statementName)) + .findFirst() + .orElseThrow(); } private void assertApplyImportStatement( diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAfiSafiNotInTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAfiSafiNotInTest.java index eb1fa925a0..47327cbef4 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAfiSafiNotInTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAfiSafiNotInTest.java @@ -46,7 +46,7 @@ public class MatchAfiSafiNotInTest extends AbstractStatementRegistryConsumerTest @Test public void testExtComAny() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("match-afi-safi-not-in-test")).findFirst().get(); + .filter(st -> st.getName().equals("match-afi-safi-not-in-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAsPathSetTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAsPathSetTest.java index 5e4e0c27e8..bf4a478c48 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAsPathSetTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchAsPathSetTest.java @@ -40,11 +40,10 @@ public class MatchAsPathSetTest extends AbstractStatementRegistryConsumerTest { baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER); } - @Test public void testMatchAsPathAny() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("reject-match-as-path-any-set")).findFirst().get(); + .filter(st -> st.getName().equals("reject-match-as-path-any-set")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -65,7 +64,7 @@ public class MatchAsPathSetTest extends AbstractStatementRegistryConsumerTest { @Test public void testMatchAsPathAll() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("reject-match-as-path-all-set")).findFirst().get(); + .filter(st -> st.getName().equals("reject-match-as-path-all-set")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() .setAsPath(new AsPathBuilder().setSegments(List.of( new SegmentsBuilder().setAsSequence(List.of( @@ -93,7 +92,7 @@ public class MatchAsPathSetTest extends AbstractStatementRegistryConsumerTest { @Test public void testMatchAsPathInverse() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("reject-match-as-path-inverse-set")).findFirst().get(); + .filter(st -> st.getName().equals("reject-match-as-path-inverse-set")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder() .setAsPath(new AsPathBuilder().setSegments(List.of( diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchBgpNeighborSetTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchBgpNeighborSetTest.java index 8aaae91f55..95e68961d4 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchBgpNeighborSetTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchBgpNeighborSetTest.java @@ -41,7 +41,7 @@ public class MatchBgpNeighborSetTest extends AbstractStatementRegistryConsumerTe @Test public void testMatchFromBgpNeighborAny() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("reject-from-neighbor-test")).findFirst().get(); + .filter(st -> st.getName().equals("reject-from-neighbor-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); @@ -61,7 +61,7 @@ public class MatchBgpNeighborSetTest extends AbstractStatementRegistryConsumerTe @Test public void testMatchFromBgpNeighborInvert() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("reject-from-neighbor-invert-test")).findFirst().get(); + .filter(st -> st.getName().equals("reject-from-neighbor-invert-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); @@ -80,7 +80,7 @@ public class MatchBgpNeighborSetTest extends AbstractStatementRegistryConsumerTe @Test public void testMatchToBgpNeighborAny() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("reject-to-neighbor-test")).findFirst().get(); + .filter(st -> st.getName().equals("reject-to-neighbor-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); @@ -101,7 +101,7 @@ public class MatchBgpNeighborSetTest extends AbstractStatementRegistryConsumerTe @Test public void testMatchToBgpNeighborInvert() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("reject-to-neighbor-invert-test")).findFirst().get(); + .filter(st -> st.getName().equals("reject-to-neighbor-invert-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchCommunityTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchCommunityTest.java index eab342a49e..95436d90cd 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchCommunityTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchCommunityTest.java @@ -42,7 +42,7 @@ public class MatchCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testComAny() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("community-any-test")).findFirst().get(); + .filter(st -> st.getName().equals("community-any-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -63,7 +63,7 @@ public class MatchCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testComInvert() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("community-invert-test")).findFirst().get(); + .filter(st -> st.getName().equals("community-invert-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -84,7 +84,7 @@ public class MatchCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testComAll() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("community-all-test")).findFirst().get(); + .filter(st -> st.getName().equals("community-all-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchExtComTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchExtComTest.java index 6890311ef6..e992b4cd89 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchExtComTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/MatchExtComTest.java @@ -5,7 +5,6 @@ * 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.bgp.openconfig.routing.policy.statement; import static org.junit.Assert.assertNotNull; @@ -13,8 +12,6 @@ import static org.junit.Assert.assertNull; import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse; import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.EncapsulationTunnelType.Vxlan; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -51,22 +48,25 @@ public class MatchExtComTest extends AbstractStatementRegistryConsumerTest { @Test public void testExtComAny() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("ext-community-any-test")).findFirst().get(); - RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( - new AttributesBuilder().build()); + .filter(st -> st.getName().equals("ext-community-any-test")).findFirst().orElseThrow(); + RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement); assertNotNull(result.getAttributes()); attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() - .setExtendedCommunities(Collections.singletonList(new ExtendedCommunitiesBuilder() - .setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder() - .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder() - .setAs4SpecificCommon(new As4SpecificCommonBuilder() - .setAsNumber(AsNumber.getDefaultInstance("65000")) - .setLocalAdministrator(Uint16.valueOf(123)) - .build()).build()).build()).build())).build()); + .setExtendedCommunities(List.of(new ExtendedCommunitiesBuilder() + .setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder() + .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder() + .setAs4SpecificCommon(new As4SpecificCommonBuilder() + .setAsNumber(AsNumber.getDefaultInstance("65000")) + .setLocalAdministrator(Uint16.valueOf(123)) + .build()) + .build()) + .build()) + .build())) + .build()); result = statementRegistry.applyExportStatement( baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement); @@ -76,7 +76,7 @@ public class MatchExtComTest extends AbstractStatementRegistryConsumerTest { @Test public void testExtComAll() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("ext-community-all-test")).findFirst().get(); + .filter(st -> st.getName().equals("ext-community-all-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -84,7 +84,7 @@ public class MatchExtComTest extends AbstractStatementRegistryConsumerTest { assertNotNull(result.getAttributes()); - attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setExtendedCommunities(Arrays.asList( + attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setExtendedCommunities(List.of( new ExtendedCommunitiesBuilder().setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder() .setAs4RouteOriginExtendedCommunity( new As4RouteOriginExtendedCommunityBuilder() @@ -104,7 +104,7 @@ public class MatchExtComTest extends AbstractStatementRegistryConsumerTest { @Test public void testExtComInvert() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("ext-community-invert-test")).findFirst().get(); + .filter(st -> st.getName().equals("ext-community-invert-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -112,7 +112,7 @@ public class MatchExtComTest extends AbstractStatementRegistryConsumerTest { assertNull(result.getAttributes()); attributeContainer = routeAttributeContainerFalse(new AttributesBuilder() - .setExtendedCommunities(Collections.singletonList(new ExtendedCommunitiesBuilder() + .setExtendedCommunities(List.of(new ExtendedCommunitiesBuilder() .setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder() .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder() .setAs4SpecificCommon(new As4SpecificCommonBuilder() diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetCommunityTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetCommunityTest.java index 54d8fbed4f..dab6f19f50 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetCommunityTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetCommunityTest.java @@ -5,15 +5,12 @@ * 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.bgp.openconfig.routing.policy.statement; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -31,13 +28,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib. import org.opendaylight.yangtools.yang.common.Uint16; public class SetCommunityTest extends AbstractStatementRegistryConsumerTest { - private final Attributes multipleCom = new AttributesBuilder().setCommunities(Arrays.asList( + private final Attributes multipleCom = new AttributesBuilder().setCommunities(List.of( new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("65")).setSemantics(Uint16.valueOf(10)) .build(), new CommunitiesBuilder().setAsNumber(AsNumber.getDefaultInstance("66")).setSemantics(Uint16.valueOf(11)) .build() )).build(); - private final Attributes emptyCom = new AttributesBuilder().setCommunities(Collections.emptyList()).build(); + private final Attributes emptyCom = new AttributesBuilder().setCommunities(List.of()).build(); @Mock private BGPRouteEntryExportParameters exportParameters; private List basicStatements; @@ -55,7 +52,7 @@ public class SetCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testInlineAdd() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-community-inline-add-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-community-inline-add-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -67,7 +64,7 @@ public class SetCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testInlineReplace() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-community-inline-replace-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-community-inline-replace-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -79,7 +76,7 @@ public class SetCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testInlineRemove() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-community-inline-remove-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-community-inline-remove-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(multipleCom); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -91,7 +88,7 @@ public class SetCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testReferenceAdd() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-community-reference-add-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-community-reference-add-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -103,7 +100,7 @@ public class SetCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testReferenceReplace() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-community-reference-replace-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-community-reference-replace-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -115,7 +112,7 @@ public class SetCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testReferenceRemove() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-community-reference-remove-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-community-reference-remove-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(multipleCom); RouteAttributeContainer result = statementRegistry.applyExportStatement( diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetExtCommunityTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetExtCommunityTest.java index 2ff4f5a297..05cf5d41ab 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetExtCommunityTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/SetExtCommunityTest.java @@ -12,8 +12,6 @@ import static org.mockito.Mockito.doReturn; import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse; import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.EncapsulationTunnelType.Vxlan; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -37,7 +35,7 @@ import org.opendaylight.yangtools.yang.common.Uint16; import org.opendaylight.yangtools.yang.common.Uint32; public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { - private final Attributes multipleExtCom = new AttributesBuilder().setExtendedCommunities(Arrays.asList( + private final Attributes multipleExtCom = new AttributesBuilder().setExtendedCommunities(List.of( new ExtendedCommunitiesBuilder().setExtendedCommunity(new EncapsulationCaseBuilder() .setEncapsulationExtendedCommunity(new EncapsulationExtendedCommunityBuilder() .setTunnelType(Vxlan).build()).build()).build(), @@ -47,8 +45,7 @@ public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { .setLocalAdministrator(Uint16.valueOf(123)) .setAsNumber(new AsNumber(Uint32.valueOf(65000))).build()) .build()).build()).build())).build(); - private final Attributes emptyExtCom = new AttributesBuilder() - .setExtendedCommunities(Collections.emptyList()).build(); + private final Attributes emptyExtCom = new AttributesBuilder().setExtendedCommunities(List.of()).build(); @Mock private BGPRouteEntryExportParameters exportParameters; private List basicStatements; @@ -66,7 +63,7 @@ public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testInlineAdd() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-ext-community-inline-add-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-ext-community-inline-add-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -78,7 +75,7 @@ public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testInlineReplace() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-ext-community-inline-replace-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-ext-community-inline-replace-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -90,7 +87,7 @@ public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testInlineRemove() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-ext-community-inline-remove-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-ext-community-inline-remove-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(multipleExtCom); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -102,7 +99,7 @@ public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testReferenceAdd() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-ext-community-reference-add-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-ext-community-reference-add-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -114,7 +111,7 @@ public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testReferenceReplace() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-ext-community-reference-replace-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-ext-community-reference-replace-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder().build()); RouteAttributeContainer result = statementRegistry.applyExportStatement( @@ -126,7 +123,7 @@ public class SetExtCommunityTest extends AbstractStatementRegistryConsumerTest { @Test public void testReferenceRemove() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("set-ext-community-reference-remove-test")).findFirst().get(); + .filter(st -> st.getName().equals("set-ext-community-reference-remove-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(multipleExtCom); RouteAttributeContainer result = statementRegistry.applyExportStatement( diff --git a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/VpnNonMemberHandlerTest.java b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/VpnNonMemberHandlerTest.java index b1fa49d833..cc2b48b664 100644 --- a/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/VpnNonMemberHandlerTest.java +++ b/bgp/openconfig-rp-statement/src/test/java/org/opendaylight/protocol/bgp/openconfig/routing/policy/statement/VpnNonMemberHandlerTest.java @@ -54,7 +54,7 @@ public class VpnNonMemberHandlerTest extends AbstractStatementRegistryConsumerTe @Test public void testExtComAny() { Statement statement = basicStatements.stream() - .filter(st -> st.getName().equals("vpn-non-member-test")).findFirst().get(); + .filter(st -> st.getName().equals("vpn-non-member-test")).findFirst().orElseThrow(); RouteAttributeContainer attributeContainer = routeAttributeContainerFalse( new AttributesBuilder() .setExtendedCommunities(List.of(new ExtendedCommunitiesBuilder() diff --git a/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/UtilsTest.java b/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/UtilsTest.java index f67bfab260..35091b04e2 100644 --- a/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/UtilsTest.java +++ b/bgp/parser-spi/src/test/java/org/opendaylight/protocol/bgp/parser/spi/UtilsTest.java @@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.parser.spi; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.doReturn; import com.google.common.primitives.UnsignedBytes; @@ -30,9 +29,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type @RunWith(MockitoJUnitRunner.StrictStubs.class) public class UtilsTest { - - @Mock private AddressFamilyRegistry afiReg; - @Mock private SubsequentAddressFamilyRegistry safiReg; + @Mock + private AddressFamilyRegistry afiReg; + @Mock + private SubsequentAddressFamilyRegistry safiReg; @Before public void setUp() { @@ -98,8 +98,8 @@ public class UtilsTest { public void testMultiprotocolCapabilitiesUtil() throws BGPParsingException { final byte[] bytes = new byte[] {0, 1, 0, 1}; final ByteBuf bytesBuf = Unpooled.copiedBuffer(bytes); - final BgpTableType parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, afiReg, - safiReg).get(); + final BgpTableType parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, afiReg, safiReg) + .orElseThrow(); assertEquals(Ipv4AddressFamily.VALUE, parsedAfiSafi.getAfi()); assertEquals(UnicastSubsequentAddressFamily.VALUE, parsedAfiSafi.getSafi()); @@ -113,18 +113,14 @@ public class UtilsTest { public void testUnsupportedAfi() { final byte[] bytes = new byte[] {0, 2, 0, 1}; final ByteBuf bytesBuf = Unpooled.copiedBuffer(bytes); - final Optional parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, afiReg, - safiReg); - assertFalse(parsedAfiSafi.isPresent()); + assertEquals(Optional.empty(), MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, afiReg, safiReg)); } @Test public void testUnsupportedSafi() { final byte[] bytes = new byte[] {0, 1, 0, 3}; final ByteBuf bytesBuf = Unpooled.copiedBuffer(bytes); - final Optional parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, afiReg, - safiReg); - assertFalse(parsedAfiSafi.isPresent()); + assertEquals(Optional.empty(), MultiprotocolCapabilitiesUtil.parseMPAfiSafi(bytesBuf, afiReg, safiReg)); } @Test(expected = ParameterLengthOverflowException.class) diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java index 0d5c7af870..635dede9c1 100644 --- a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java @@ -84,7 +84,7 @@ public abstract class AbstractRIBSupportTest abstractRIBSupport; protected final void setUpTestCustomizer(final AbstractRIBSupport ribSupport) throws Exception { - this.abstractRIBSupport = ribSupport; + abstractRIBSupport = ribSupport; } @Before @@ -95,7 +95,7 @@ public abstract class AbstractRIBSupportTest { @@ -103,15 +103,15 @@ public abstract class AbstractRIBSupportTest(); - this.insertedRoutes = new ArrayList<>(); + }).when(tx).delete(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class)); + deletedRoutes = new ArrayList<>(); + insertedRoutes = new ArrayList<>(); } @Override protected final AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() { final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer(); - this.adapter = customizer.getAdapterContext(); + adapter = customizer.getAdapterContext(); return customizer; } @@ -143,29 +143,29 @@ public abstract class AbstractRIBSupportTest createRoutes(final S routes) { Preconditions.checkArgument(routes.implementedInterface() - .equals(this.abstractRIBSupport.routesContainerClass())); + .equals(abstractRIBSupport.routesContainerClass())); final InstanceIdentifier routesIId = routesIId(); - final Map.Entry normalizedNode = this.adapter.currentSerializer() + final Map.Entry normalizedNode = adapter.currentSerializer() .toNormalizedNode(routesIId, routes); final ContainerNode container = (ContainerNode) normalizedNode.getValue(); final NodeIdentifier routeNid = new NodeIdentifier(getRouteListQname()); - return ((MapNode) verifyNotNull(container.childByArg(routeNid))).body(); + return ((MapNode) container.getChildByArg(routeNid)).body(); } private TablesKey getTablesKey() { - return new TablesKey(this.abstractRIBSupport.getAfi(), this.abstractRIBSupport.getSafi()); + return new TablesKey(abstractRIBSupport.getAfi(), abstractRIBSupport.getSafi()); } private InstanceIdentifier tablesIId() { @@ -174,22 +174,22 @@ public abstract class AbstractRIBSupportTest routesIId() { final InstanceIdentifier tables = tablesIId(); - return tables.child(this.abstractRIBSupport.routesCaseClass(), this.abstractRIBSupport.routesContainerClass()); + return tables.child(abstractRIBSupport.routesCaseClass(), abstractRIBSupport.routesContainerClass()); } protected final YangInstanceIdentifier getTablePath() { final InstanceIdentifier tables = tablesIId(); - return this.adapter.currentSerializer().toYangInstanceIdentifier(tables); + return adapter.currentSerializer().toYangInstanceIdentifier(tables); } protected final YangInstanceIdentifier getRoutePath() { final InstanceIdentifier routesIId = routesIId(); - return this.adapter.currentSerializer().toYangInstanceIdentifier(routesIId).node(getRouteListQname()); + return adapter.currentSerializer().toYangInstanceIdentifier(routesIId).node(getRouteListQname()); } private QName getRouteListQname() { - return BindingReflections.findQName(this.abstractRIBSupport.routesListClass()) - .bindTo(BindingReflections.getQNameModule(this.abstractRIBSupport.routesCaseClass())); + return BindingReflections.findQName(abstractRIBSupport.routesListClass()) + .bindTo(BindingReflections.getQNameModule(abstractRIBSupport.routesCaseClass())); } protected final NodeIdentifierWithPredicates createRouteNIWP(final S routes) { diff --git a/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java b/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java index a393b8996c..37c8a5a6bd 100644 --- a/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java +++ b/pcep/pcc-mock/src/test/java/org/opendaylight/protocol/pcep/pcc/mock/PCCMockCommon.java @@ -158,8 +158,8 @@ public abstract class PCCMockCommon { final List messages; checkReceivedMessages(pceSessionListener, expectedTotalMessages); if (startAtNumberLsp.isPresent()) { - messages = pceSessionListener.messages().subList(startAtNumberLsp.get(), - startAtNumberLsp.get() + expectedNumberOfLsp); + final int offset = startAtNumberLsp.orElseThrow(); + messages = pceSessionListener.messages().subList(offset, offset + expectedNumberOfLsp); } else { messages = pceSessionListener.messages(); } -- 2.36.6