MCPcopy Index your code
hub / github.com/beanshell/beanshell / main

Method main

bsf/src/TestBshBSF.java:7–51  ·  view source on GitHub ↗
( String [] args )

Source from the content-addressed store, hash-verified

5public class TestBshBSF
6{
7 public static void main( String [] args )
8 throws BSFException
9 {
10 BSFManager mgr = new BSFManager();
11
12 // register beanshell with the BSF framework
13 String [] extensions = { "bsh" };
14 mgr.registerScriptingEngine(
15 "beanshell", "bsh.util.BeanShellBSFEngine", extensions );
16
17 mgr.declareBean("foo", "fooString", String.class);
18 mgr.declareBean("bar", "barString", String.class);
19 mgr.registerBean("gee", "geeString");
20
21 BSFEngine beanshellEngine = mgr.loadScriptingEngine("beanshell");
22
23 String script = "foo + bar + bsf.lookupBean(\"gee\")";
24 Object result = beanshellEngine.eval( "Test eval...", -1, -1, script );
25
26 assertTrue( result.equals("fooStringbarStringgeeString" ) );
27
28 // test apply()
29 Vector names = new Vector();
30 names.addElement("name");
31 Vector vals = new Vector();
32 vals.addElement("Pat");
33
34 script = "name + name";
35
36 result = beanshellEngine.apply(
37 "source string...", -1, -1, script, names, vals );
38
39 assertTrue( result.equals("PatPat" ) );
40
41 result = beanshellEngine.eval( "Test eval...", -1, -1, "name" );
42
43 // name should not be set
44 assertTrue( result == null );
45
46 // Verify the primitives are unwrapped
47 result = beanshellEngine.eval( "Test eval...", -1, -1, "1+1");
48
49 assertTrue( result instanceof Integer
50 && ((Integer)result).intValue() == 2 );
51 }
52
53 static void assertTrue( boolean cond ) {
54 if ( cond )

Callers

nothing calls this directly

Calls 6

assertTrueMethod · 0.95
declareBeanMethod · 0.80
applyMethod · 0.80
intValueMethod · 0.80
evalMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected