Author: sebb
Date: Wed Mar 25 16:52:07 2009
New Revision: 758341

URL: http://svn.apache.org/viewvc?rev=758341&view=rev
Log:
More tests

Modified:
    
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
    
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
    
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java

Modified: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java?rev=758341&r1=758340&r2=758341&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/ScriptEngineManagerTest.java
 Wed Mar 25 16:52:07 2009
@@ -22,6 +22,7 @@
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
+import javax.script.SimpleBindings;
 
 import org.apache.bsf.utils.TestScriptEngine;
 import org.apache.bsf.utils.TestScriptEngineFactory;
@@ -47,10 +48,24 @@
                assertTrue(facs.size() > 0); // need at least one
        }
 
-       public void testGet() {
+       public void testGetPut() {
                mgr.put("x", new Integer(1));
                Object retValue = mgr.get("x");
                assertEquals(new Integer(1), retValue);
+               try {
+            mgr.get(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+               try {
+            mgr.get("");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        assertNull(mgr.get("missing_Key"));
+        assertNull(mgr.get("null_Key"));
+        mgr.put("null_Key", null);
+        assertNull(mgr.get("null_Key"));
        }
 
        public void testGetEngineByExtension() {
@@ -64,12 +79,16 @@
        }
 
        public void testGetEngineByMimeType() {
+        ScriptEngine engine;
+        engine =  mgr.getEngineByMimeType("application/junit");
+        assertNotNull(engine);
+        assertTrue(engine instanceof TestScriptEngine);
        }
 
        public void testGetEngineByName() {
                ScriptEngine engine;
                
-               engine =  mgr.getEngineByName("TestScript");
+               engine =  mgr.getEngineByName("JUnit");
                assertNotNull(engine);
                assertTrue(engine instanceof TestScriptEngine);
        }
@@ -91,24 +110,89 @@
                }
        }
 
-       public void testPut() {
-               //TODO Implement put().
-       }
-
        public void testRegisterEngineExtension() {
-               //TODO Implement registerEngineExtension().
+        try {
+            mgr.registerEngineExtension(null, null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            mgr.registerEngineExtension(null, new TestScriptEngineFactory());
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            mgr.registerEngineExtension("", null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        assertNull(mgr.getEngineByExtension("")); // not yet defined
+        // Empty extensions are allowed
+        mgr.registerEngineExtension("", new TestScriptEngineFactory());
+        assertNotNull(mgr.getEngineByExtension("")); //now defined
+        assertNull(mgr.getEngineByExtension("junit2")); // not yet defined
+        mgr.registerEngineExtension("junit2", new TestScriptEngineFactory());
+        assertNotNull(mgr.getEngineByExtension("junit2")); //now defined
        }
 
        public void testRegisterEngineName() {
-               //TODO Implement registerEngineName().
+        try {
+            mgr.registerEngineName(null, null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            mgr.registerEngineName(null, new TestScriptEngineFactory());
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            mgr.registerEngineName("", null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        assertNull(mgr.getEngineByName("")); // not yet defined
+        // Empty extensions are allowed
+        mgr.registerEngineName("", new TestScriptEngineFactory());
+        assertNotNull(mgr.getEngineByName("")); //now defined
+        assertNull(mgr.getEngineByName("junit2")); // not yet defined
+        mgr.registerEngineName("junit2", new TestScriptEngineFactory());
+        assertNotNull(mgr.getEngineByName("junit2")); //now defined
        }
 
        public void testRegisterEngineMimeType() {
-               //TODO Implement registerEngineMimeType().
-       }
-
-       public void testSetNamespace() {
-               //TODO Implement setNamespace().
+        try {
+            mgr.registerEngineMimeType(null, null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            mgr.registerEngineMimeType(null, new TestScriptEngineFactory());
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            mgr.registerEngineMimeType("", null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        assertNull(mgr.getEngineByMimeType("")); // not yet defined
+        // Empty extensions are allowed
+        mgr.registerEngineMimeType("", new TestScriptEngineFactory());
+        assertNotNull(mgr.getEngineByMimeType("")); //now defined
+        assertNull(mgr.getEngineByMimeType("junit2")); // not yet defined
+        mgr.registerEngineMimeType("junit2", new TestScriptEngineFactory());
+        assertNotNull(mgr.getEngineByMimeType("junit2")); //now defined
+       }
+
+       public void testSetBindings() {
+           mgr.getBindings();
+               try {
+            mgr.setBindings(null);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        mgr.setBindings(new SimpleBindings());
        }
 
 }

Modified: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java?rev=758341&r1=758340&r2=758341&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngine.java
 Wed Mar 25 16:52:07 2009
@@ -18,32 +18,42 @@
 
 package org.apache.bsf.utils;
 
+import java.io.IOException;
 import java.io.Reader;
-import java.io.StringReader;
 
 import javax.script.AbstractScriptEngine;
 import javax.script.Bindings;
 import javax.script.ScriptContext;
 import javax.script.ScriptEngineFactory;
 import javax.script.ScriptException;
+import javax.script.SimpleBindings;
 
+/**
+ * Minimal Script engine used for JUnit tests.
+ */
 public class TestScriptEngine extends AbstractScriptEngine {
 
     public Bindings createBindings() {
-        // TODO Auto-generated method stub
-        return null;
+        return new SimpleBindings();
     }
 
     public Object eval(Reader reader, ScriptContext context)
             throws ScriptException {
-        // TODO Auto-generated method stub
-        return null;
+        StringBuffer sb = new StringBuffer();
+        char cbuf[] = new char[1024];
+        try {
+            while(reader.read(cbuf) != -1){
+                sb.append(cbuf);
+            }
+        } catch (IOException e) {
+            throw new ScriptException(e);
+        }
+        return eval(sb.toString(), context);
     }
 
-
     public Object eval(String script, ScriptContext context)
             throws ScriptException {
-        return eval(new StringReader(script), context);
+        return script;
     }
 
     public ScriptEngineFactory getFactory() {

Modified: 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
URL: 
http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java?rev=758341&r1=758340&r2=758341&view=diff
==============================================================================
--- 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
 (original)
+++ 
jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/utils/TestScriptEngineFactory.java
 Wed Mar 25 16:52:07 2009
@@ -25,7 +25,9 @@
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineFactory;
 
-
+/**
+ * Minimal ScriptEngineFactory for use in JUnit tests.
+ */
 public class TestScriptEngineFactory implements ScriptEngineFactory {
        
 
@@ -49,7 +51,7 @@
                return "1.0";
        }
        public List getMimeTypes() {
-               return Collections.unmodifiableList(Arrays.asList(new 
String[]{}));
+               return Collections.unmodifiableList(Arrays.asList(new 
String[]{"application/junit"}));
        }
        
        public Object getParameter(String key) {
@@ -58,7 +60,7 @@
         } else if (key == ScriptEngine.ENGINE_VERSION) {
             return getEngineVersion();
         } else if (key == ScriptEngine.NAME) {
-            return "JUnit";
+            return getNames();
         } else if (key == ScriptEngine.LANGUAGE) {
             return getLanguageName();
         } else if(key == ScriptEngine.ENGINE_VERSION) {
@@ -71,20 +73,20 @@
 
     public String getMethodCallSyntax(String obj, String method, String[] 
args) {
         // TODO Auto-generated method stub
-        return null;
+        return "callMethod";
     }
 
     public List getNames() {
-        return Collections.unmodifiableList(Arrays.asList(new 
String[]{getLanguageName()}));
+        return Collections.unmodifiableList(Arrays.asList(new 
String[]{"JUnit"}));
     }
 
     public String getOutputStatement(String toDisplay) {
         // TODO Auto-generated method stub
-        return null;
+        return "outputStatment";
     }
 
     public String getProgram(String[] statements) {
         // TODO Auto-generated method stub
-        return null;
+        return "program";
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: bsf-dev-h...@jakarta.apache.org

Reply via email to