Mercurial > hg > rhino-tests
changeset 20:625ff78f80c7 draft
Added 14 new negative tests to the ScriptEngineTest suite, some other
tests have been improved by adding additional assertions.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Tue, 07 Aug 2012 11:30:47 +0200 |
parents | 8faf0aad2428 |
children | d1c40cccd80e |
files | ChangeLog src/org/RhinoTests/ScriptEngineTest.java |
diffstat | 2 files changed, 164 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Aug 06 17:05:10 2012 +0200 +++ b/ChangeLog Tue Aug 07 11:30:47 2012 +0200 @@ -1,3 +1,9 @@ +2012-08-07 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/ScriptEngineTest.java: + Added 14 new negative tests, some other tests + have been improved by adding additional assertions. + 2012-08-06 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/BaseRhinoTest.java:
--- a/src/org/RhinoTests/ScriptEngineTest.java Mon Aug 06 17:05:10 2012 +0200 +++ b/src/org/RhinoTests/ScriptEngineTest.java Tue Aug 07 11:30:47 2012 +0200 @@ -82,6 +82,7 @@ * @throws Exception this exception is thrown if none script engine could be found. */ private ScriptEngine tryToFindEngineByName(String name) throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); ScriptEngine scriptEngine = this.engineManager.getEngineByName(name); assertNotNull(scriptEngine, "JavaScript engine manager not found by name '" + name + "'"); return scriptEngine; @@ -95,6 +96,7 @@ * @throws Exception this exception is thrown if none script engine could be found. */ private ScriptEngine tryToFindEngineByMimeType(String mimeType) throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); ScriptEngine scriptEngine = this.engineManager.getEngineByMimeType(mimeType); assertNotNull(scriptEngine, "JavaScript engine manager not found by MIME type '" + mimeType + "'"); return scriptEngine; @@ -149,10 +151,158 @@ } /** + * Test if NPE is thrown if getEngineByName() is called with null. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative1() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + try { + @SuppressWarnings("unused") + ScriptEngine scriptEngine = this.engineManager.getEngineByName(null); + } + catch (NullPointerException e) + { + return; + } + throw new Exception("NPE was not thrown as expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative2() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName(""); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative3() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName(" "); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative4() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName(" "); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative5() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName("\t"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative6() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName(" \t"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative7() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName("\b"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative8() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName("\b\b"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative9() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName(" \b\b"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative10() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName("\000"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative11() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName("\u0000"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative12() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName("really-wrong-name"); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative13() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName(" " + Constants.EngineNames.ENGINE_NAME_rhino); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** + * Test if none script engine is found using wrong name. + * @throws Exception if this test case fails. + */ + protected void testGetEngineByNameNegative14() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); + ScriptEngine scriptEngine = this.engineManager.getEngineByName("\b" + Constants.EngineNames.ENGINE_NAME_rhino); + assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); + } + + /** * Test if script engine could be found using extension "js" * @throws Exception this exception is thrown if none script engine could be found. */ protected void testGetEngineByExtension() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); ScriptEngine scriptEngine = this.engineManager.getEngineByExtension(Constants.FileExtensions.EXTENSION_js); assertNotNull(scriptEngine, "JavaScript engine manager not found"); } @@ -162,6 +312,7 @@ * @throws Exception if this test case fails. */ protected void testGetEngineByExtensionNegative1() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); try { @SuppressWarnings("unused") ScriptEngine scriptEngine = this.engineManager.getEngineByExtension(null); @@ -178,6 +329,7 @@ * @throws Exception if this test case fails. */ protected void testGetEngineByExtensionNegative2() throws Exception { + assertNotNull(engineManager, "Script engine manager was not created"); ScriptEngine scriptEngine = this.engineManager.getEngineByExtension(""); assertNull(scriptEngine, "JavaScript engine manager was found but it's not expected"); } @@ -254,6 +406,8 @@ private void compareTwoFactoriesGetByEngineName(String engineName1, String engineName2) throws Exception { ScriptEngineFactory f1 = getFactoryByEngineName(engineName1); ScriptEngineFactory f2 = getFactoryByEngineName(engineName2); + assertNotNull(f1, "first engine factory is null"); + assertNotNull(f2, "second engine factory is null"); compareTwoScriptFactories(f1, f2); } @@ -264,6 +418,8 @@ private void compareTwoFactoriesGetByMimeType(String mimeType1, String mimeType2) throws Exception { ScriptEngineFactory f1 = getFactoryByMimeType(mimeType1); ScriptEngineFactory f2 = getFactoryByMimeType(mimeType2); + assertNotNull(f1, "first engine factory is null"); + assertNotNull(f2, "second engine factory is null"); compareTwoScriptFactories(f1, f2); } @@ -274,6 +430,8 @@ private void compareTwoFactoriesGetByNameAndMimeType(String engineName, String mimeType) throws Exception { ScriptEngineFactory f1 = getFactoryByEngineName(engineName); ScriptEngineFactory f2 = getFactoryByMimeType(mimeType); + assertNotNull(f1, "first engine factory is null"); + assertNotNull(f2, "second engine factory is null"); compareTwoScriptFactories(f1, f2); }