You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2014/06/23 13:01:20 UTC

svn commit: r1604747 - /jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java

Author: andy
Date: Mon Jun 23 11:01:20 2014
New Revision: 1604747

URL: http://svn.apache.org/r1604747
Log:
Use try-with-resources where possible

Modified:
    jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java

Modified: jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java?rev=1604747&r1=1604746&r2=1604747&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java (original)
+++ jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java Mon Jun 23 11:01:20 2014
@@ -18,7 +18,6 @@
 
 package org.apache.jena.fuseki.http;
 
-import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.atlas.junit.BaseTest ;
 import org.apache.jena.atlas.web.HttpException ;
 import org.apache.jena.atlas.web.TypedInputStream ;
@@ -50,16 +49,13 @@ public class TestHttpOp extends BaseTest
     // Basic operations
     
     @Test public void httpGet_01() {
-        TypedInputStream in = HttpOp.execHttpGet(pingURL) ;
-        IO.close(in) ;
+        try ( TypedInputStream in = HttpOp.execHttpGet(pingURL) ) {}
     }
     
     @Test(expected=HttpException.class) 
     public void httpGet_02() {
-        try {
-            TypedInputStream in = HttpOp.execHttpGet(ServerTest.urlRoot+"does-not-exist") ;
-            IO.close(in) ;
-        } catch(HttpException ex) {
+        try ( TypedInputStream in = HttpOp.execHttpGet(ServerTest.urlRoot+"does-not-exist") ) { }
+        catch(HttpException ex) {
             assertEquals(HttpSC.NOT_FOUND_404, ex.getResponseCode()) ;
             throw ex ;
         }
@@ -75,41 +71,25 @@ public class TestHttpOp extends BaseTest
     }
     
     @Test public void httpGet_05() {
-        TypedInputStream in = HttpOp.execHttpGet(simpleQuery) ;
-        IO.close(in) ;
+        try ( TypedInputStream in = HttpOp.execHttpGet(simpleQuery) ) {}
     }
     
     // SPARQL Query
     
     @Test public void queryGet_01() {
-        TypedInputStream in = HttpOp.execHttpGet(simpleQuery) ;
-        IO.close(in) ;
+        try ( TypedInputStream in = HttpOp.execHttpGet(simpleQuery) ) {}
     }
 
     @Test(expected=HttpException.class)
     public void queryGet_02() {
-        try {
-            // No query.
-            TypedInputStream in = HttpOp.execHttpGet(queryURL+"?query=") ;
-            IO.close(in) ;
-        } catch (HttpException ex) {
+        // No query.
+        try ( TypedInputStream in = HttpOp.execHttpGet(queryURL+"?query=") ) {}
+        catch (HttpException ex) {
             assertEquals(ex.getResponseCode(), HttpSC.BAD_REQUEST_400) ;
             throw ex ; 
         }
     }
 
-//    @Test(expected=HttpException.class)
-//    public void queryGet_03() {
-//        try {
-//            // Service description.
-//            TypedInputStream in = HttpOp.execHttpGet(queryURL) ;
-//            IO.close(in) ;
-//        } catch (HttpException ex) {
-//            assertEquals(ex.getResponseCode(), HttpSC.NOT_FOUND_404) ;
-//            throw ex ; 
-//        }
-//    }
-
     @Test(expected=HttpException.class)
     public void httpPost_01() {
         try {
@@ -143,23 +123,19 @@ public class TestHttpOp extends BaseTest
     @Test public void httpPost_04() {
         Params params = new Params() ;
         params.addParam("query", "ASK{}") ;
-        TypedInputStream in = HttpOp.execHttpPostFormStream(queryURL, params, WebContent.contentTypeResultsJSON) ;
-        IO.close(in) ;
+        try ( TypedInputStream in = HttpOp.execHttpPostFormStream(queryURL, params, WebContent.contentTypeResultsJSON) ) {}
     }
     
     @Test(expected=HttpException.class)
     public void httpPost_05() {
         Params params = new Params() ;
         params.addParam("query", "ASK{}") ;
-        TypedInputStream in = null ;
-        try {
-            // Query to Update 
-            in = HttpOp.execHttpPostFormStream(updateURL, params, WebContent.contentTypeResultsJSON) ;
-        } catch (HttpException ex) {
+        // Query to Update
+        try ( TypedInputStream in = HttpOp.execHttpPostFormStream(updateURL, params, WebContent.contentTypeResultsJSON) ) { }
+        catch (HttpException ex) {
             assertEquals(ex.getResponseCode(), HttpSC.BAD_REQUEST_400) ;
             throw ex ;
         }
-        finally { IO.close(in) ; }
     }
     
     @Test public void httpPost_06() {