Cleanup use of deprecated constructs
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / schema / YangLibrarySchemaYangSourceProviderTest.java
index 623e61a3376121f8a13be5935a89d5844c7d7cb2..1634c1db44867420540cf1e744eb95c61b1ab1d3 100644 (file)
@@ -7,15 +7,20 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.schema;
 
-import com.google.common.base.Optional;
-import com.google.common.io.ByteStreams;
-import com.google.common.util.concurrent.CheckedFuture;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
+
+import com.google.common.util.concurrent.ListenableFuture;
 import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.Map;
-import org.hamcrest.CoreMatchers;
-import org.junit.Assert;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
@@ -25,14 +30,13 @@ import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 
 public class YangLibrarySchemaYangSourceProviderTest {
-
     private SourceIdentifier workingSid;
     private YangLibrarySchemaYangSourceProvider yangLibrarySchemaYangSourceProvider;
 
     @Before
     public void setUp() throws Exception {
         final URL url = getClass().getResource("/schemas/config-test-rpc.yang");
-        workingSid = RevisionSourceIdentifier.create("abc", Optional.<String>absent());
+        workingSid = RevisionSourceIdentifier.create("abc", Optional.empty());
         final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
         final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
         yangLibrarySchemaYangSourceProvider = new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
@@ -40,27 +44,29 @@ public class YangLibrarySchemaYangSourceProviderTest {
 
     @Test
     public void testGetSource() throws Exception {
-        CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
-                yangLibrarySchemaYangSourceProvider.getSource(workingSid);
-        final String x = new String(ByteStreams.toByteArray(source.checkedGet().openStream()));
-        Assert.assertThat(x, CoreMatchers.containsString("module config-test-rpc"));
+        ListenableFuture<? extends YangTextSchemaSource> source = yangLibrarySchemaYangSourceProvider
+                .getSource(workingSid);
+
+        final String x = source.get().asCharSource(StandardCharsets.UTF_8).read();
+        assertThat(x, containsString("module config-test-rpc"));
     }
 
-    @Test(expected = SchemaSourceException.class)
-    public void testGetSourceFailure() throws Exception {
+    @Test
+    public void testGetSourceFailure() throws InterruptedException, MalformedURLException {
         final URL url = new URL("http://non-existing-entity.yang");
         final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
         final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
         final YangLibrarySchemaYangSourceProvider failingYangLibrarySchemaYangSourceProvider =
                 new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
 
-        CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
-                failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
-        source.checkedGet();
+        final ListenableFuture<?> future = failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
+        final ExecutionException ex = assertThrows(ExecutionException.class, () -> future.get());
+        assertThat(ex.getCause(), instanceOf(SchemaSourceException.class));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testGetSourceNotAvailable() throws Exception {
-        yangLibrarySchemaYangSourceProvider.getSource(RevisionSourceIdentifier.create("aaaaa"));
+        assertThrows(IllegalArgumentException.class,
+            () -> yangLibrarySchemaYangSourceProvider.getSource(RevisionSourceIdentifier.create("aaaaa")));
     }
 }