Sorry JUnit test included requires some user intervention (getting data from System.in)
Kev
Index: DefaultInputHandler.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/input/DefaultInputHandler.java,v
retrieving revision 1.17
diff -u -r1.17 DefaultInputHandler.java
--- DefaultInputHandler.java 9 Mar 2004 16:48:03 -0000 1.17
+++ DefaultInputHandler.java 10 Nov 2004 05:40:40 -0000
@@ -17,7 +17,8 @@
package org.apache.tools.ant.input;
-import java.io.DataInputStream;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
@@ -46,15 +47,15 @@
*/
public void handleInput(InputRequest request) throws BuildException {
String prompt = getPrompt(request);
- DataInputStream in = null;
+ BufferedReader br = null;
try {
- in =
- new DataInputStream(new
KeepAliveInputStream(getInputStream()));
+ br =
+ new BufferedReader(new InputStreamReader(new
KeepAliveInputStream(getInputStream())));
do {
System.err.println(prompt);
System.err.flush();
try {
- String input = in.readLine();
+ String input = br.readLine();
request.setInput(input);
} catch (IOException e) {
throw new BuildException("Failed to read input from"
@@ -62,9 +63,9 @@
}
} while (!request.isInputValid());
} finally {
- if (in != null) {
+ if (br != null) {
try {
- in.close();
+ br.close();
} catch (IOException e) {
throw new BuildException("Failed to close input.", e);
}
Index: DefaultInputHandlerTest.java
===================================================================
RCS file: DefaultInputHandlerTest.java
diff -N DefaultInputHandlerTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DefaultInputHandlerTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,82 @@
+package org.apache.tools.ant.input;
+
+import java.io.IOException;
+import java.io.DataInputStream;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.util.KeepAliveInputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+/**
+ * @author it-kevin
+ *
+ */
+public class DefaultInputHandlerTest extends TestCase {
+
+ private InputRequest oldIr;
+ private InputRequest newIr;
+ private DefaultInputHandler dfh;
+
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ //setup with DataInputStream
+ oldIr = new InputRequest(">");
+ DataInputStream in = null;
+ in = new DataInputStream(new KeepAliveInputStream(System.in));
+ try {
+ String input = in.readLine();
+ oldIr.setInput(input);
+ } catch (IOException e) {
+ throw new BuildException("Failed to read input from"
+ + " Console.", e);
+ }
+
+ //setup with BufferedReader
+ newIr = new InputRequest(">");
+ dfh = new DefaultInputHandler();
+ dfh.handleInput(newIr);
+
+
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Constructor for DefaultInputHandlerTest.
+ * @param arg0
+ */
+ public DefaultInputHandlerTest(String arg0) {
+ super(arg0);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new DefaultInputHandlerTest("testHandleInput"));
+ return suite;
+ }
+
+ public void testHandleInput() {
+ try {
+ assertEquals(oldIr.getInput(), newIr.getInput());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+
+ }
+
+}--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
