Do not use ExpectedException and clean up checkstyle suppressions.
Change-Id: If91b404f900edbc2035831c04cadb70841f7a60f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
package org.opendaylight.netconf.topology.singleton.impl;
import static java.nio.charset.StandardCharsets.UTF_8;
package org.opendaylight.netconf.topology.singleton.impl;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.MockitoAnnotations.initMocks;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import com.google.common.io.ByteSource;
import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.Futures;
import com.google.common.io.ByteSource;
import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import java.io.InputStream;
import java.net.InetSocketAddress;
import com.google.common.util.concurrent.SettableFuture;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
-import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionException;
import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionException;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
private static final Timeout TIMEOUT = new Timeout(Duration.create(5, "seconds"));
public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
private static final Timeout TIMEOUT = new Timeout(Duration.create(5, "seconds"));
private ActorSystem system = ActorSystem.create();
private final TestKit testKit = new TestKit(system);
private ActorSystem system = ActorSystem.create();
private final TestKit testKit = new TestKit(system);
- @Rule
- public final ExpectedException exception = ExpectedException.none();
-
private ActorRef masterRef;
private RemoteDeviceId remoteDeviceId;
private final SharedSchemaRepository masterSchemaRepository = new SharedSchemaRepository("master");
private ActorRef masterRef;
private RemoteDeviceId remoteDeviceId;
private final SharedSchemaRepository masterSchemaRepository = new SharedSchemaRepository("master");
@Before
public void setup() {
@Before
public void setup() {
remoteDeviceId = new RemoteDeviceId("netconf-topology",
new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9999));
remoteDeviceId = new RemoteDeviceId("netconf-topology",
new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9999));
doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
- doReturn(mockSchemaContextFactory).when(mockSchemaRepository)
- .createEffectiveModelContextFactory();
-
final SchemaSourceRegistration<?> newMockSchemaSourceReg = mock(SchemaSourceRegistration.class);
final EffectiveModelContextFactory newMockSchemaContextFactory = mock(EffectiveModelContextFactory.class);
final SchemaSourceRegistration<?> newMockSchemaSourceReg = mock(SchemaSourceRegistration.class);
final EffectiveModelContextFactory newMockSchemaContextFactory = mock(EffectiveModelContextFactory.class);
// Test missing source failure.
// Test missing source failure.
- exception.expect(MissingSchemaSourceException.class);
-
- final Future<YangTextSchemaSourceSerializationProxy> failedSchemaFuture =
- proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
-
- Await.result(failedSchemaFuture, TIMEOUT.duration());
+ final MissingSchemaSourceException ex = assertThrows(MissingSchemaSourceException.class,
+ () -> {
+ final Future<YangTextSchemaSourceSerializationProxy> failedSchemaFuture =
+ proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
+ Await.result(failedSchemaFuture, TIMEOUT.duration());
+ });
+ assertThat(ex.getMessage(), startsWith("No providers registered for source"));
+ assertThat(ex.getMessage(), containsString(sourceIdentifier.toString()));
- @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"})
- public void testSlaveInvokeRpc() throws Throwable {
+ public void testSlaveInvokeRpc() throws Exception {
final List<SourceIdentifier> sourceIdentifiers =
Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
final List<SourceIdentifier> sourceIdentifiers =
Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
assertEquals(rpcError, resultOutputError.getErrors().iterator().next());
// RPC failure.
assertEquals(rpcError, resultOutputError.getErrors().iterator().next());
// RPC failure.
-
- exception.expect(DOMRpcException.class);
-
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock")))
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock")))
- .when(mockDOMRpcService).invokeRpc(any(), any());
+ .when(mockDOMRpcService).invokeRpc(any(), any());
+ final ListenableFuture<? extends DOMRpcResult> future = slaveDomRPCService.invokeRpc(schemaPath, outputNode);
- try {
- slaveDomRPCService.invokeRpc(schemaPath, outputNode).get(2, TimeUnit.SECONDS);
- } catch (ExecutionException e) {
- throw e.getCause();
- }
+ final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
+ final Throwable cause = e.getCause();
+ assertThat(cause, instanceOf(DOMRpcException.class));
+ assertEquals("mock", cause.getMessage());
- @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"})
- public void testSlaveInvokeAction() throws Throwable {
+ public void testSlaveInvokeAction() throws Exception {
final List<SourceIdentifier> sourceIdentifiers = Lists
.newArrayList(RevisionSourceIdentifier.create("testActionID"));
initializeMaster(sourceIdentifiers);
final List<SourceIdentifier> sourceIdentifiers = Lists
.newArrayList(RevisionSourceIdentifier.create("testActionID"));
initializeMaster(sourceIdentifiers);
assertTrue(result.getErrors().isEmpty());
// Action failure.
assertTrue(result.getErrors().isEmpty());
// Action failure.
- exception.expect(DOMActionException.class);
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringActionException("mock")))
.when(mockDOMActionService).invokeAction(any(), any(), any());
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringActionException("mock")))
.when(mockDOMActionService).invokeAction(any(), any(), any());
- try {
- slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode).get(2, TimeUnit.SECONDS);
- } catch (ExecutionException e) {
- throw e.getCause();
- }
+ final ListenableFuture<? extends DOMActionResult> future = slaveDomActionService.invokeAction(schemaPath,
+ domDataTreeIdentifier, outputNode);
+
+ final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
+ final Throwable cause = e.getCause();
+ assertThat(cause, instanceOf(DOMActionException.class));
+ assertEquals("mock", cause.getMessage());