public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: Added futher test to HTTPURLConnection.fileNotFound test
@ 2006-02-05 10:18 Wolfgang Baer
  0 siblings, 0 replies; only message in thread
From: Wolfgang Baer @ 2006-02-05 10:18 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

Hi,

I extended the testcase to cover also the needed behaviour for
getInputStream and getErrorStream calls.

2006-02-05  Wolfgang Baer  <WBaer@gmx.de>

	* gnu/testlet/java/net/HttpURLConnection/fileNotFound.java:
	(test): Added tests for calling getInputStream, getErrorStream.

Wolfgang

[-- Attachment #2: fileNotFound.patch --]
[-- Type: text/x-patch, Size: 1865 bytes --]

Index: fileNotFound.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/net/HttpURLConnection/fileNotFound.java,v
retrieving revision 1.1
diff -u -r1.1 fileNotFound.java
--- fileNotFound.java	4 Feb 2006 14:22:39 -0000	1.1
+++ fileNotFound.java	5 Feb 2006 10:17:14 -0000
@@ -27,11 +27,12 @@
 import gnu.testlet.Testlet;
 
 import java.io.FileNotFoundException;
+import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 
 /**
- * Tests that a 404 passes to the caller without exception.
+ * Tests that a 404 condition.
  */
 public class fileNotFound implements Testlet
 {
@@ -44,14 +45,37 @@
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         
         conn.setRequestMethod("GET");
-        int code = conn.getResponseCode();
-        h.check(code == 404);
+        
+        try 
+          {
+            // connect does not throw a FNFE
+            conn.connect();
+            int code = conn.getResponseCode();
+            h.check(code == 404);
+          }
+        catch (FileNotFoundException e)
+          {       
+            h.check(false);
+          }
+        
+        try 
+          {
+            // FNFE is thrown by calling getInputStream
+            conn.getInputStream();
+            h.check(false);
+          }
+        catch (FileNotFoundException e)
+          {
+            h.check(true);
+          }
+        
+        // the errorstream must be set (at least our
+        // URL returns an error page
+        InputStream error = conn.getErrorStream();
+        h.check(error != null);
+        
         conn.disconnect();        
-      }   
-    catch (FileNotFoundException e)
-      {       
-        h.check(false);
-      }
+      }  
     catch (Exception e)
     {       
       h.debug(e);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-02-05 10:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-05 10:18 FYI: Added futher test to HTTPURLConnection.fileNotFound test Wolfgang Baer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).