1818 */
1919package org .netbeans .html .bootagent ;
2020
21+ import java .util .Arrays ;
2122import net .java .html .js .JavaScriptBody ;
23+ import net .java .html .js .JavaScriptResource ;
2224
2325/**
2426 *
2527 * @author Jaroslav Tulach
2628 */
29+ @ JavaScriptResource ("empty.js" )
2730public class JavaScriptBodyTst {
2831
2932 public JavaScriptBodyTst () {
@@ -33,7 +36,56 @@ public void assert42() {
3336 int v = mul (7 , 6 );
3437 assert v == 42 : "Really 42: " + v ;
3538 }
39+
40+ public void assertEmptySymbolDefined () {
41+ assert Boolean .TRUE .equals (eval ("empty" )) : "empty.js should defined empty global symbol" ;
42+ }
43+ public void assertEmpty2SymbolDefined () {
44+ MultiResource .loadIt ();
45+ assert Boolean .TRUE .equals (eval ("empty2" )) : "empty.js should defined empty global symbol" ;
46+ }
47+ public void assertEmpty3SymbolDefined () {
48+ MultiResource .loadIt ();
49+ assert Boolean .TRUE .equals (eval ("empty3" )) : "empty.js should defined empty global symbol" ;
50+ }
51+
52+ public void assertJavaScriptBodyAnnotationPresentInRuntime () throws Exception {
53+ var mul = JavaScriptBodyTst .class .getDeclaredMethod ("mul" , int .class , int .class );
54+ var ann = mul .getAnnotation (JavaScriptBody .class );
55+ assert ann != null : "JavaScriptBody annotation must be found in runtime" ;
56+ assert ann .args ().length == 2 : "Two arguments" ;
57+ assert "x" .equals (ann .args ()[0 ]) : "First argument: " + Arrays .toString (ann .args ());
58+ assert "y" .equals (ann .args ()[1 ]) : "Second argument: " + Arrays .toString (ann .args ());
59+ assert "return x * y;" .equals (ann .body ()) : "Body argument: " + ann .body ();
60+ }
61+
62+ private static void assertResource (JavaScriptResource ann , String file ) {
63+ assert ann != null : "JavaScriptResource annotation must be found in runtime" ;
64+ assert file .equals (ann .value ()) : "Expecting " + file + " but got " + ann .value ();
65+ }
3666
67+ public void assertJavaScriptResourceAnnotationPresentInRuntime () throws Exception {
68+ var ann = JavaScriptBodyTst .class .getAnnotation (JavaScriptResource .class );
69+ assertResource (ann , "empty.js" );
70+ }
71+
72+ public void assertJavaScriptResourceGroupAnnotationPresentInRuntime () throws Exception {
73+ var ann = MultiResource .class .getAnnotation (JavaScriptResource .Group .class );
74+ assert ann != null : "JavaScriptResource.Group annotation must be found in runtime" ;
75+ assert ann .value ().length == 2 : "Two empty*.js resources, was: " + Arrays .toString (ann .value ());
76+ }
77+
3778 @ JavaScriptBody (args = { "x" , "y" }, body = "return x * y;" )
3879 private static native int mul (int x , int y );
80+
81+ @ JavaScriptBody (args = { "code" }, body = "return eval(code);" )
82+ private static native Object eval (String code );
83+
84+ @ JavaScriptResource ("empty_2.js" )
85+ @ JavaScriptResource ("empty_3.js" )
86+ static final class MultiResource {
87+ @ JavaScriptBody (args = {}, body = "" )
88+ static void loadIt () {
89+ }
90+ }
3991}
0 commit comments