Remove more throws declarations 60/113960/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 12 Oct 2024 07:59:23 +0000 (09:59 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 12 Oct 2024 08:46:57 +0000 (10:46 +0200)
We have a few more test cases which do not need the throws declarations,
this cleans them up.

Change-Id: I8179b9ad63152cbfac4cd9d0225ea89cc6e61666
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
21 files changed:
binding/mdsal-binding-test-utils/src/test/java/org/opendaylight/mdsal/binding/testutils/DataBrokerFailuresTest.java
dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreThreePhaseCommitCohortTest.java
dom/mdsal-dom-inmemory-datastore/src/test/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDataStoreTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/AbstractDOMForwardedTransactionTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/DOMDataTreePrefixTableTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMDataBrokerTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMDataReadOnlyTransactionTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMDataWriteTransactionTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMRpcProviderServiceTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ForwardingDOMRpcResultTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/RegistrationTreeSnapshotTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/store/AbstractDOMStoreTransactionTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/store/AbstractSnapshotBackedTransactionChainTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/store/ForwardingDOMStoreThreePhaseCommitCohortTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/store/SnapshotBackedTransactionsTest.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/store/SnapshotBackedWriteTransactionTest.java
entityownership/mdsal-eos-dom-simple/src/test/java/org/opendaylight/mdsal/eos/dom/simple/SimpleDOMEntityOwnershipServiceTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/HostBuilderTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressBuilderTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpAddressNoZoneBuilderTest.java
model/ietf/rfc6991-ietf-inet-types/src/test/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev130715/IpPrefixBuilderTest.java

index 9afb021f4630d26a6d1f1056387f546d81569fa7..8166f63d223d7668aff3911828dccf42ce5aedd8 100644 (file)
@@ -113,7 +113,7 @@ public class DataBrokerFailuresTest {
     }
 
     @Test
-    public void testFailButCommitAnywayReadWriteTransaction() throws Exception {
+    public void testFailButCommitAnywayReadWriteTransaction() {
         dbFailures.failButCommitAnyway();
         checkCommitFails();
     }
index 30b86d3ef811c2d9440137fd79c51a97461a57da..a5ca5748c7ad594a0591bcaaabc1a12d64b57f26 100644 (file)
@@ -61,7 +61,7 @@ public class InMemoryDOMStoreThreePhaseCommitCohortTest {
     }
 
     @Test
-    public void canCommitWithOperationError() throws Exception {
+    public void canCommitWithOperationError() {
         doReturn(modification).when(snapshot).newModification();
         final var operationError = new RuntimeException();
         final var cohort = new InMemoryDOMStoreThreePhaseCommitCohort(dataStore,
index 3f84c6ae95bc6e3339ed698d4789eaf3e6c86dfc..d20f99e544cdab8b7eee1ced0d00c622dc780500 100644 (file)
@@ -344,7 +344,7 @@ public class InMemoryDataStoreTest {
     }
 
     @Test
-    public void testReadyWithMissingMandatoryData() throws Exception {
+    public void testReadyWithMissingMandatoryData() {
         DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
         var testNode = ImmutableNodes.newContainerBuilder()
                 .withNodeIdentifier(new NodeIdentifier(TestModel.MANDATORY_DATA_TEST_QNAME))
index 78cb1d59c50a8551772215fe31c7f1a081c16789..89b94a71854d42f400a4fc4a36bbc3a5f14fdec9 100644 (file)
@@ -32,7 +32,7 @@ public class AbstractDOMForwardedTransactionTest {
     public DOMStoreTransaction operationalTx;
 
     @Test
-    public void closeSubtransactionsTest() throws Exception {
+    public void closeSubtransactionsTest() {
         doThrow(UnsupportedOperationException.class).when(configTx).close();
 
         final var forwardedTx = new DOMForwardedTransactionTestImpl("test",
index d9413726eff89b79628854d45f20c73f283d5e9a..0ed91ac6660b9384463cc02e798e1bb89003a223 100644 (file)
@@ -7,23 +7,22 @@
  */
 package org.opendaylight.mdsal.dom.spi;
 
-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.junit.jupiter.api.Test;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
-public class DOMDataTreePrefixTableTest {
-
+class DOMDataTreePrefixTableTest {
     @Test
-    public void basicTest() throws Exception {
-        final DOMDataTreePrefixTable<Object> domDataTreePrefixTable = DOMDataTreePrefixTable.create();
-        final Object testObject = new Object();
-        final YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.of(QName.create("", "test"));
-        final DOMDataTreeIdentifier domDataTreeIdentifier =
+    void basicTest() {
+        final var domDataTreePrefixTable = DOMDataTreePrefixTable.create();
+        final var testObject = new Object();
+        final var yangInstanceIdentifier = YangInstanceIdentifier.of(QName.create("", "test"));
+        final var domDataTreeIdentifier =
                 DOMDataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL, yangInstanceIdentifier);
 
         domDataTreePrefixTable.store(domDataTreeIdentifier, testObject);
@@ -32,7 +31,7 @@ public class DOMDataTreePrefixTableTest {
         domDataTreePrefixTable.remove(domDataTreeIdentifier);
         assertNull(domDataTreePrefixTable.lookup(domDataTreeIdentifier));
 
-        final DOMDataTreeIdentifier invalidDOMDataTreeIdentifier =
+        final var invalidDOMDataTreeIdentifier =
                 DOMDataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, yangInstanceIdentifier);
         domDataTreePrefixTable.remove(invalidDOMDataTreeIdentifier);
         assertNull(domDataTreePrefixTable.lookup(invalidDOMDataTreeIdentifier));
index 77a0eb2b154d82ce79051288084453d35ea57ca7..2856c3bdd870f71d5ae90923c6312d25f115cb9a 100644 (file)
@@ -38,7 +38,7 @@ class ForwardingDOMDataBrokerTest {
     private DOMDataTreeWriteTransaction writeTx;
 
     @Test
-    void basicTest() throws Exception {
+    void basicTest() {
         final var impl = new ForwardingDOMDataBroker() {
             @Override
             protected DOMDataBroker delegate() {
index 10e0c192eb4b4f1b8b3e7fb9284bf88bed8ff04b..90a1448ada89c7dd8b06e8ec4c5150e08265d949 100644 (file)
@@ -11,38 +11,46 @@ import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ForwardingDOMDataReadOnlyTransactionTest extends ForwardingDOMDataReadOnlyTransaction {
+@ExtendWith(MockitoExtension.class)
+class ForwardingDOMDataReadOnlyTransactionTest {
     @Mock(name = "domDataTreeReadTransaction")
-    public DOMDataTreeReadTransaction domDataTreeReadTransaction;
-
-    @Test
-    public void basicTest() throws Exception {
-        doReturn(null).when(domDataTreeReadTransaction).read(null, null);
-        this.read(null, null);
-        verify(domDataTreeReadTransaction).read(null, null);
-
-        doReturn(null).when(domDataTreeReadTransaction).exists(null, null);
-        this.exists(null, null);
-        verify(domDataTreeReadTransaction).exists(null, null);
-
-        doReturn(null).when(domDataTreeReadTransaction).getIdentifier();
-        this.getIdentifier();
-        verify(domDataTreeReadTransaction).getIdentifier();
-
-        doNothing().when(domDataTreeReadTransaction).close();
-        this.close();
-        verify(domDataTreeReadTransaction).close();
+    private DOMDataTreeReadTransaction delegate;
+
+    private ForwardingDOMDataReadOnlyTransaction tx;
+
+    @BeforeEach
+    void beforeEach() {
+        tx = new ForwardingDOMDataReadOnlyTransaction() {
+            @Override
+            protected DOMDataTreeReadTransaction delegate() {
+                return delegate;
+            }
+        };
     }
 
-    @Override
-    protected DOMDataTreeReadTransaction delegate() {
-        return domDataTreeReadTransaction;
+    @Test
+    void basicTest() {
+        doReturn(null).when(delegate).read(null, null);
+        tx.read(null, null);
+        verify(delegate).read(null, null);
+
+        doReturn(null).when(delegate).exists(null, null);
+        tx.exists(null, null);
+        verify(delegate).exists(null, null);
+
+        doReturn(null).when(delegate).getIdentifier();
+        tx.getIdentifier();
+        verify(delegate).getIdentifier();
+
+        doNothing().when(delegate).close();
+        tx.close();
+        verify(delegate).close();
     }
 }
\ No newline at end of file
index 70682dc1f21302b9a172814e19eeb9079559eebb..609bc851545d795ebd427ee2888d1c27b0bc80d7 100644 (file)
@@ -11,46 +11,54 @@ import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ForwardingDOMDataWriteTransactionTest extends ForwardingDOMDataWriteTransaction {
+@ExtendWith(MockitoExtension.class)
+class ForwardingDOMDataWriteTransactionTest {
     @Mock(name = "domDataTreeWriteTransaction")
-    public DOMDataTreeWriteTransaction domDataTreeWriteTransaction;
+    private DOMDataTreeWriteTransaction delegate;
 
-    @Test
-    public void basicTest() throws Exception {
-        doReturn(null).when(domDataTreeWriteTransaction).getIdentifier();
-        this.getIdentifier();
-        verify(domDataTreeWriteTransaction).getIdentifier();
-
-        doNothing().when(domDataTreeWriteTransaction).put(null, null, null);
-        this.put(null, null, null);
-        verify(domDataTreeWriteTransaction).put(null, null, null);
-
-        doNothing().when(domDataTreeWriteTransaction).merge(null, null, null);
-        this.merge(null, null, null);
-        verify(domDataTreeWriteTransaction).merge(null, null, null);
-
-        doNothing().when(domDataTreeWriteTransaction).delete(null, null);
-        this.delete(null, null);
-        verify(domDataTreeWriteTransaction).delete(null, null);
-
-        doReturn(null).when(domDataTreeWriteTransaction).commit();
-        this.commit();
-        verify(domDataTreeWriteTransaction).commit();
-
-        doReturn(false).when(domDataTreeWriteTransaction).cancel();
-        this.cancel();
-        verify(domDataTreeWriteTransaction).cancel();
+    private ForwardingDOMDataWriteTransaction tx;
+
+    @BeforeEach
+    void beforeEach() {
+        tx = new ForwardingDOMDataWriteTransaction() {
+            @Override
+            protected DOMDataTreeWriteTransaction delegate() {
+                return delegate;
+            }
+        };
     }
 
-    @Override
-    protected DOMDataTreeWriteTransaction delegate() {
-        return domDataTreeWriteTransaction;
+    @Test
+    void basicTest() {
+        doReturn(null).when(delegate).getIdentifier();
+        tx.getIdentifier();
+        verify(delegate).getIdentifier();
+
+        doNothing().when(delegate).put(null, null, null);
+        tx.put(null, null, null);
+        verify(delegate).put(null, null, null);
+
+        doNothing().when(delegate).merge(null, null, null);
+        tx.merge(null, null, null);
+        verify(delegate).merge(null, null, null);
+
+        doNothing().when(delegate).delete(null, null);
+        tx.delete(null, null);
+        verify(delegate).delete(null, null);
+
+        doReturn(null).when(delegate).commit();
+        tx.commit();
+        verify(delegate).commit();
+
+        doReturn(false).when(delegate).cancel();
+        tx.cancel();
+        verify(delegate).cancel();
     }
 }
index 9cff3605e6baa127325ffe1bf11f87707cacb923..67b19ae2e3cd3ad91c642c8e7945b0c2479903b8 100644 (file)
@@ -8,39 +8,44 @@
 package org.opendaylight.mdsal.dom.spi;
 
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
-import java.util.Collections;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import java.util.Set;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.dom.api.DOMRpcImplementation;
 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ForwardingDOMRpcProviderServiceTest extends ForwardingDOMRpcProviderService {
-
-    @Mock(name = "domRpcProviderService")
-    public DOMRpcProviderService domRpcProviderService;
-
-    @Test
-    public void basicTest() throws Exception {
-        final DOMRpcImplementation domRpcImplementation = mock(DOMRpcImplementation.class);
-
-        doReturn(null).when(domRpcProviderService).registerRpcImplementation(domRpcImplementation);
-        this.registerRpcImplementation(domRpcImplementation);
-        verify(domRpcProviderService).registerRpcImplementation(domRpcImplementation);
-
-        doReturn(null).when(domRpcProviderService).registerRpcImplementation(domRpcImplementation,
-                Collections.emptySet());
-        this.registerRpcImplementation(domRpcImplementation, Collections.emptySet());
-        verify(domRpcProviderService).registerRpcImplementation(domRpcImplementation, Collections.emptySet());
+@ExtendWith(MockitoExtension.class)
+class ForwardingDOMRpcProviderServiceTest {
+    @Mock
+    private DOMRpcProviderService delegate;
+    @Mock
+    private DOMRpcImplementation domRpcImplementation;
+
+    private ForwardingDOMRpcProviderService service;
+
+    @BeforeEach
+    void beforeEach() {
+        service = new ForwardingDOMRpcProviderService() {
+            @Override
+            protected DOMRpcProviderService delegate() {
+                return delegate;
+            }
+        };
     }
 
-    @Override
-    protected DOMRpcProviderService delegate() {
-        return domRpcProviderService;
+    @Test
+    void basicTest() {
+        doReturn(null).when(delegate).registerRpcImplementation(domRpcImplementation);
+        service.registerRpcImplementation(domRpcImplementation);
+        verify(delegate).registerRpcImplementation(domRpcImplementation);
+
+        doReturn(null).when(delegate).registerRpcImplementation(domRpcImplementation, Set.of());
+        service.registerRpcImplementation(domRpcImplementation, Set.of());
+        verify(delegate).registerRpcImplementation(domRpcImplementation, Set.of());
     }
 }
\ No newline at end of file
index 1f4b6b295d8004aa090fe4b4228a40a54e84307c..7831a204e23f3c846e63eceae666ad79ba6aa4a1 100644 (file)
@@ -10,30 +10,38 @@ package org.opendaylight.mdsal.dom.spi;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ForwardingDOMRpcResultTest extends ForwardingDOMRpcResult {
-    @Mock(name = "domRpcResult")
-    public DOMRpcResult delegate;
+@ExtendWith(MockitoExtension.class)
+class ForwardingDOMRpcResultTest {
+    @Mock
+    private DOMRpcResult delegate;
+
+    private ForwardingDOMRpcResult result;
+
+    @BeforeEach
+    void beforeEach() {
+        result = new ForwardingDOMRpcResult() {
+            @Override
+            protected DOMRpcResult delegate() {
+                return delegate;
+            }
+        };
+    }
 
     @Test
-    public void basicTest() throws Exception {
+    void basicTest() {
         doReturn(null).when(delegate).errors();
-        errors();
+        result.errors();
         verify(delegate).errors();
 
         doReturn(null).when(delegate).value();
-        value();
+        result.value();
         verify(delegate).value();
     }
-
-    @Override
-    protected DOMRpcResult delegate() {
-        return delegate;
-    }
 }
\ No newline at end of file
index 776977909041522439469d29cb4d86eda4c9486b..77ea672e7859c7347253b0fe103a502919e7e38b 100644 (file)
@@ -26,7 +26,7 @@ class RegistrationTreeSnapshotTest {
     private Lock lock;
 
     @Test
-    void basicTest() throws Exception {
+    void basicTest() {
         final var pathArgument = new NodeIdentifier(QName.create("", "pathArgument"));
         final var registrationTreeNode = new Node<>(null, pathArgument);
         try (var registrationTreeSnapshot = new AbstractRegistrationTree.Snapshot<>(lock, registrationTreeNode)) {
index 3997730ae43c67f2d97e1de7a0bf0e13451e308b..63dcb4ca973a3c8a175aa98a4b84d26df19e06a5 100644 (file)
@@ -14,11 +14,10 @@ import static org.junit.Assert.assertTrue;
 import org.junit.Test;
 
 public class AbstractDOMStoreTransactionTest extends AbstractDOMStoreTransaction<String> {
-
     private static final String IDENTIFIER = "testIdentifier";
 
     @Test
-    public void basicTest() throws Exception {
+    public void basicTest() {
         assertEquals(IDENTIFIER, this.getIdentifier());
         assertTrue(this.toString().contains(IDENTIFIER));
         assertNull(this.getDebugContext());
index ca43ae65917098c412ee9eaa33ed24a235fced1a..fae581fafcfd608081aa52414220e0dcdcd3d2cc 100644 (file)
@@ -28,7 +28,7 @@ public class AbstractSnapshotBackedTransactionChainTest {
     public SnapshotBackedWriteTransaction<Object> snapshotBackedWriteTransaction;
 
     @Test
-    public void basicTest() throws Exception {
+    public void basicTest() {
         doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
 
         final var chain = new AbstractSnapshotBackedTransactionChain<>() {
index d8bba2232843b62157bdedb4f8bdfaaeaaa5159a..2516d3435a3e4a725edeb85900aaddcf03832165 100644 (file)
@@ -10,37 +10,45 @@ package org.opendaylight.mdsal.dom.spi.store;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class ForwardingDOMStoreThreePhaseCommitCohortTest extends ForwardingDOMStoreThreePhaseCommitCohort {
-    @Mock(name = "domStoreThreePhaseCommitCohort")
-    public DOMStoreThreePhaseCommitCohort domStoreThreePhaseCommitCohort;
-
-    @Test
-    public void basicTest() throws Exception {
-        doReturn(null).when(domStoreThreePhaseCommitCohort).canCommit();
-        this.canCommit();
-        verify(domStoreThreePhaseCommitCohort).canCommit();
-
-        doReturn(null).when(domStoreThreePhaseCommitCohort).preCommit();
-        this.preCommit();
-        verify(domStoreThreePhaseCommitCohort).preCommit();
-
-        doReturn(null).when(domStoreThreePhaseCommitCohort).commit();
-        this.commit();
-        verify(domStoreThreePhaseCommitCohort).commit();
-
-        doReturn(null).when(domStoreThreePhaseCommitCohort).abort();
-        this.abort();
-        verify(domStoreThreePhaseCommitCohort).abort();
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class ForwardingDOMStoreThreePhaseCommitCohortTest {
+    @Mock
+    private DOMStoreThreePhaseCommitCohort delegate;
+
+    private ForwardingDOMStoreThreePhaseCommitCohort cohort;
+
+    @BeforeEach
+    void beforeEach() {
+        cohort = new ForwardingDOMStoreThreePhaseCommitCohort() {
+            @Override
+            protected DOMStoreThreePhaseCommitCohort delegate() {
+                return delegate;
+            }
+        };
     }
 
-    @Override
-    protected DOMStoreThreePhaseCommitCohort delegate() {
-        return domStoreThreePhaseCommitCohort;
+    @Test
+    void basicTest() {
+        doReturn(null).when(delegate).canCommit();
+        cohort.canCommit();
+        verify(delegate).canCommit();
+
+        doReturn(null).when(delegate).preCommit();
+        cohort.preCommit();
+        verify(delegate).preCommit();
+
+        doReturn(null).when(delegate).commit();
+        cohort.commit();
+        verify(delegate).commit();
+
+        doReturn(null).when(delegate).abort();
+        cohort.abort();
+        verify(delegate).abort();
     }
 }
\ No newline at end of file
index b36e2ab06dddd711b27fe19cb0356be78cde9ee8..753b572c78b3e1cdca9dc92f3cec674dfee18142 100644 (file)
@@ -7,21 +7,28 @@
  */
 package org.opendaylight.mdsal.dom.spi.store;
 
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
 
-public class SnapshotBackedTransactionsTest {
+@ExtendWith(MockitoExtension.class)
+class SnapshotBackedTransactionsTest {
+    @Mock
+    private DataTreeSnapshot dataTreeSnapshot;
+    @Mock
+    private DataTreeModification dataTreeModification;
+    @Mock
+    private TransactionReadyPrototype<Object> transactionReadyPrototype;
+
     @Test
-    public void basicTest() throws Exception {
-        final DataTreeSnapshot dataTreeSnapshot = mock(DataTreeSnapshot.class);
-        final DataTreeModification dataTreeModification = mock(DataTreeModification.class);
-        final TransactionReadyPrototype<Object> transactionReadyPrototype =  mock(TransactionReadyPrototype.class);
+    void basicTest() {
         doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
 
         assertNotNull(SnapshotBackedTransactions.newReadTransaction(new Object(), false, dataTreeSnapshot));
index de792167cdda7d1d0806eca830baf016092ca630..082111e24871cb132ed8c2506c0904cc8a557307 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.mdsal.dom.spi.store;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
@@ -20,9 +22,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import com.google.common.base.MoreObjects;
-import java.io.Serial;
 import java.util.Optional;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
@@ -32,7 +32,6 @@ import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot;
 
 public class SnapshotBackedWriteTransactionTest {
-
     private static final DataTreeSnapshot DATA_TREE_SNAPSHOT = mock(DataTreeSnapshot.class);
     private static final DataTreeModification DATA_TREE_MODIFICATION = mock(DataTreeModification.class);
     private static final TransactionReadyPrototype<Object> TRANSACTION_READY_PROTOTYPE =
@@ -41,10 +40,11 @@ public class SnapshotBackedWriteTransactionTest {
             mock(DOMStoreThreePhaseCommitCohort.class);
     private static final ContainerNode NORMALIZED_NODE = mock(ContainerNode.class);
     private static final Optional<ContainerNode> NORMALIZED_NODE_OPTIONAL = Optional.of(NORMALIZED_NODE);
-    private static SnapshotBackedWriteTransaction<Object> snapshotBackedWriteTransaction;
+
+    private SnapshotBackedWriteTransaction<Object> snapshotBackedWriteTransaction;
 
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         doReturn(DATA_TREE_MODIFICATION).when(DATA_TREE_SNAPSHOT).newModification();
         doNothing().when(DATA_TREE_MODIFICATION).ready();
         doNothing().when(DATA_TREE_MODIFICATION).write(any(), any());
@@ -62,7 +62,7 @@ public class SnapshotBackedWriteTransactionTest {
     }
 
     @Test
-    public void basicTest() throws Exception {
+    public void basicTest() {
         snapshotBackedWriteTransaction.write(YangInstanceIdentifier.of(), NORMALIZED_NODE);
         verify(DATA_TREE_MODIFICATION).write(any(), any());
 
@@ -82,10 +82,10 @@ public class SnapshotBackedWriteTransactionTest {
     }
 
     @Test
-    public void readyTest() throws Exception {
-        SnapshotBackedWriteTransaction<Object> tx = new SnapshotBackedWriteTransaction<>(new Object(), false,
-                DATA_TREE_SNAPSHOT, TRANSACTION_READY_PROTOTYPE);
-        Assert.assertNotNull(tx.ready());
+    public void readyTest() {
+        final var tx = new SnapshotBackedWriteTransaction<>(new Object(), false, DATA_TREE_SNAPSHOT,
+            TRANSACTION_READY_PROTOTYPE);
+        assertNotNull(tx.ready());
         verify(TRANSACTION_READY_PROTOTYPE).transactionReady(any(), any(), eq(null));
         tx.close();
     }
@@ -94,36 +94,39 @@ public class SnapshotBackedWriteTransactionTest {
     public void readyWithException() {
         Exception thrown = new RuntimeException();
         doThrow(thrown).when(DATA_TREE_MODIFICATION).ready();
-        Assert.assertNotNull(snapshotBackedWriteTransaction.ready());
+        assertNotNull(snapshotBackedWriteTransaction.ready());
         verify(TRANSACTION_READY_PROTOTYPE).transactionReady(any(), any(), same(thrown));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void writeWithException() throws Exception {
+    @Test
+    public void writeWithException() {
         doAnswer(inv -> {
             throw new TestException();
         }).when(DATA_TREE_MODIFICATION).write(any(), any());
-        snapshotBackedWriteTransaction.write(YangInstanceIdentifier.of(), NORMALIZED_NODE);
+        assertThrows(IllegalArgumentException.class,
+            () -> snapshotBackedWriteTransaction.write(YangInstanceIdentifier.of(), NORMALIZED_NODE));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void mergeWithException() throws Exception {
+    @Test
+    public void mergeWithException() {
         doAnswer(inv -> {
             throw new TestException();
         }).when(DATA_TREE_MODIFICATION).merge(any(), any());
-        snapshotBackedWriteTransaction.merge(YangInstanceIdentifier.of(), NORMALIZED_NODE);
+        assertThrows(IllegalArgumentException.class,
+            () -> snapshotBackedWriteTransaction.merge(YangInstanceIdentifier.of(), NORMALIZED_NODE));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void deleteWithException() throws Exception {
+    @Test
+    public void deleteWithException() {
         doAnswer(inv -> {
             throw new TestException();
         }).when(DATA_TREE_MODIFICATION).delete(any());
-        snapshotBackedWriteTransaction.delete(YangInstanceIdentifier.of());
+        assertThrows(IllegalArgumentException.class,
+            () -> snapshotBackedWriteTransaction.delete(YangInstanceIdentifier.of()));
     }
 
     private static final class TestException extends Exception {
-        @Serial
+        @java.io.Serial
         private static final long serialVersionUID = 1L;
     }
 }
\ No newline at end of file
index 5678d36b55ade26a8228aa19f7878e39c4c3f328..5047d35f129aba06e6f632ee2cfd7ec8c00ccea9 100644 (file)
@@ -84,7 +84,7 @@ class SimpleDOMEntityOwnershipServiceTest {
     }
 
     @Test
-    void testToString() throws Exception {
+    void testToString() {
         final var uuid = UUID.randomUUID();
         final var expected = String.format("SimpleDOMEntityOwnershipService{uuid=%s, entities={}, listeners={}}", uuid);
         assertEquals(expected, new SimpleDOMEntityOwnershipService(uuid).toString());
index 0c1d955d43cf632970afb498031b8a1802eaf5d3..cd221d58132385c93b3c72253af8f80059f0e9bd 100644 (file)
@@ -14,7 +14,7 @@ import org.junit.jupiter.api.Test;
 
 class HostBuilderTest {
     @Test
-    void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() {
         testIpv4("1.1.1.1");
         testIpv4("192.168.155.100");
         testIpv4("1.192.1.221");
index ff1689b9e5f00291e559f9e04177648d77e00a1a..930c92892cf104225e25b2b77debb53f51478b93 100644 (file)
@@ -14,7 +14,7 @@ import org.junit.jupiter.api.Test;
 
 class IpAddressBuilderTest {
     @Test
-    void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() {
         testIpv4("1.1.1.1");
         testIpv4("192.168.155.100");
         testIpv4("1.192.1.221");
index bf4ea48bab4b337e9821e6b53359d12d061731d3..cb1af64f59572efbb35d12c4a2ad297b0d4613e2 100644 (file)
@@ -14,7 +14,7 @@ import org.junit.jupiter.api.Test;
 
 class IpAddressNoZoneBuilderTest {
     @Test
-    void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() {
         testIpv4("1.1.1.1");
         testIpv4("192.168.155.100");
         testIpv4("1.192.1.221");
index fb2ddb498375e832a048b2ee83502a8764d6ad81..d6e03464d482ea5d4cfcb62df88ae99614713691 100644 (file)
@@ -14,7 +14,7 @@ import org.junit.jupiter.api.Test;
 
 class IpPrefixBuilderTest {
     @Test
-    void testGetDefaultInstance() throws Exception {
+    void testGetDefaultInstance() {
         testIpv6("ff00::/8");
         testIpv4("192.0.2.1/24");
     }