Migrate to assertThrows() 62/99662/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Feb 2022 17:52:38 +0000 (18:52 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 8 Feb 2022 17:52:38 +0000 (18:52 +0100)
ExpectedException.none() is deprecated, use assertThrows() to narrow
down the code that is expected to throw instead.

Change-Id: Iaeeef4adb3309e1356eb03ff30fb1c6988d5491a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
extension/openflowplugin-extension-nicira/src/test/java/org/opendaylight/openflowplugin/extension/vendor/nicira/convertor/action/RegLoad2ConvertorTest.java

index 7a94ea7dc037261d6a44b936292c32b3ebdfba13..a23b1ce162d767e5baf7d5689a03142569a6875f 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -15,9 +16,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import junitparams.JUnitParamsRunner;
 import junitparams.Parameters;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match.NshFlagsConvertor;
@@ -46,9 +45,6 @@ import org.opendaylight.yangtools.yang.common.Uint8;
 @RunWith(JUnitParamsRunner.class)
 public class RegLoad2ConvertorTest {
 
-    @Rule
-    public ExpectedException thrown = ExpectedException.none();
-
     public static Iterable<Object[]> commonData() {
         return Arrays.asList(new Object[][] {
                 {Uint16.valueOf(0), Uint16.valueOf(0), 0x01, 0x01, 0x01, null},
@@ -90,10 +86,6 @@ public class RegLoad2ConvertorTest {
                                    final Integer mask,
                                    final Class<? extends Exception> expectedException) {
 
-        if (expectedException != null) {
-            thrown.expect(expectedException);
-        }
-
         Dst dst = mock(Dst.class);
         when(dst.getStart()).thenReturn(rangeStart);
         when(dst.getEnd()).thenReturn(rangeEnd);
@@ -106,6 +98,12 @@ public class RegLoad2ConvertorTest {
         when(actionsCase.getNxRegLoad()).thenReturn(nxRegLoad);
 
         RegLoad2Convertor regLoad2Convertor = new RegLoad2Convertor();
+
+        if (expectedException != null) {
+            assertThrows(expectedException, () -> regLoad2Convertor.convert(actionsCase).getActionChoice());
+            return;
+        }
+
         ActionRegLoad2 actionRegLoad = (ActionRegLoad2) regLoad2Convertor.convert(actionsCase).getActionChoice();
 
         MatchEntry matchEntry = actionRegLoad.getNxActionRegLoad2().getMatchEntry().get(0);
@@ -127,10 +125,6 @@ public class RegLoad2ConvertorTest {
                                    final Integer mask,
                                    final Class<? extends Exception> expectedException) {
 
-        if (expectedException != null) {
-            thrown.expect(expectedException);
-        }
-
         NxActionRegLoad2 nxActionRegLoad2 = mock(NxActionRegLoad2.class);
         when(nxActionRegLoad2.getMatchEntry()).thenReturn(Collections.singletonList(
                 NshFlagsConvertor.buildMatchEntry(Uint8.valueOf(value), mask == null ? null : Uint8.valueOf(mask))));
@@ -141,6 +135,12 @@ public class RegLoad2ConvertorTest {
 
         RegLoad2Convertor regLoad2Convertor = new RegLoad2Convertor();
 
+        if (expectedException != null) {
+            assertThrows(expectedException,
+                () -> regLoad2Convertor.convert(action, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS));
+            return;
+        }
+
         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult
                 = regLoad2Convertor.convert(action, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS);
         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult1