### Question:
JythonScriptEngine implements ScriptEngine { @Override public void shutdown() throws EngineException { final PyObject exitfunc = m_systemState.__findattr__("exitfunc"); if (exitfunc != null) { try { exitfunc.__call__(); } catch (final PyException e) { throw new JythonScriptExecutionException( "calling script exit function", e); } } } JythonScriptEngine(final ScriptLocation script); @Override WorkerRunnable createWorkerRunnable(); @Override WorkerRunnable createWorkerRunnable(final Object testRunner); @Override void shutdown(); @Override String getDescription();  }### Answer:
@Test public void testInitialisePathScriptWorkingDirectory() throws Exception { final File directory = new File(getDirectory(), "bah/foo"); assertTrue(directory.mkdirs()); final ScriptLocation script = new ScriptLocation(new Directory(new File(getDirectory(), "bah")), new File(getDirectory(), "script")); createFile(script.getFile(), "import foo", "class TestRunner:pass"); final ScriptEngine scriptEngine = new JythonScriptEngine(script); scriptEngine.shutdown(); }
@Test public void testInitialisePathScriptDirectory() throws Exception { final File directory = new File(getDirectory(), "bah/foo"); assertTrue(directory.mkdirs()); final ScriptLocation script = new ScriptLocation(new Directory(new File("bah")), new File(getDirectory(), "script")); createFile(script.getFile(), "import bah.foo", "class TestRunner:pass"); final ScriptEngine scriptEngine = new JythonScriptEngine(script); scriptEngine.shutdown(); }
@Test public void testShutdownExitHook() throws Exception { callback(null); createFile( m_script.getFile(), "from net.grinder.scriptengine.jython import TestJythonScriptEngine", "import sys", "def f():", " TestJythonScriptEngine.callback(TestJythonScriptEngine)", "sys.exitfunc = f", "class TestRunner:pass"); final JythonScriptEngine scriptEngine = new JythonScriptEngine(m_script); scriptEngine.shutdown(); assertSame(TestJythonScriptEngine.class, s_lastCallbackObject); }
@Test public void testShutdownBadHook() throws Exception { createFile( m_script.getFile(), "import sys", "def f():", " raise Exception('a problem')", "sys.exitfunc = f", "class TestRunner:pass"); final JythonScriptEngine scriptEngine = new JythonScriptEngine(m_script); try { scriptEngine.shutdown(); fail("Expected JythonScriptExecutionException"); } catch (final JythonScriptExecutionException e) { assertContains(e.getShortMessage(), "a problem"); } }