This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: Added futher test to HTTPURLConnection.fileNotFound test
- From: Wolfgang Baer <WBaer at gmx dot de>
- To: mauve-patches at sources dot redhat dot com
- Date: Sun, 05 Feb 2006 11:21:51 +0100
- Subject: FYI: Added futher test to HTTPURLConnection.fileNotFound test
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
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);