vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 01 Dec 2012 08:52:30 +0100
branchreflection
changeset 225 25e350c6385f
parent 223 860933a7787f
child 231 dde8422fb5ae
permissions -rw-r--r--
Adding each constructor function field
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. Look for COPYING file in the top folder.
    16  * If not, see http://opensource.org/licenses/GPL-2.0.
    17  */
    18 package org.apidesign.vm4brwsr;
    19 
    20 import javax.script.Invocable;
    21 import org.testng.annotations.Test;
    22 import static org.testng.Assert.*;
    23 import org.testng.annotations.BeforeClass;
    24 
    25 /**
    26  *
    27  * @author Jaroslav Tulach <jtulach@netbeans.org>
    28  */
    29 public class ClassTest {
    30 
    31     @Test public void superClassEqualsGetSuperclass() {
    32         assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
    33     }
    34 
    35     @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
    36         assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptionsZ", Double.valueOf(1.0));
    37     }
    38 
    39     @Test public void classesAreDifferent() {
    40         assertTrue(Classes.differenceInClasses(), "Classes are not equal");
    41     }
    42 
    43     @Test public void jsClassesAreDifferent() throws Exception {
    44         assertExec("Classes are not equal", Classes.class, "differenceInClassesZ", Double.valueOf(1.0));
    45     }
    46 
    47     @Test public void javaInstanceName() throws Exception {
    48         assertEquals(Classes.classForInstance(), "java.io.IOException");
    49     }
    50     @Test public void jsInstanceName() throws Exception {
    51         assertExec("I/O name", Classes.class, "classForInstanceLjava_lang_String", "java.io.IOException");
    52     }
    53     @Test public void javaName() throws Exception {
    54         assertEquals(Classes.name(), "java.io.IOException");
    55     }
    56     @Test public void jsName() throws Exception {
    57         assertExec("I/O name", Classes.class, "nameLjava_lang_String", "java.io.IOException");
    58     }
    59     @Test public void javaSimpleName() throws Exception {
    60         assertEquals(Classes.simpleName(), "IOException");
    61     }
    62     @Test public void jsGetsSimpleName() throws Exception {
    63         assertExec("I/O simple name", Classes.class, "simpleNameLjava_lang_String", "IOException");
    64     }
    65     @Test public void javaCanonicalName() {
    66         assertEquals(Classes.canonicalName(), "java.io.IOException");
    67     }
    68     @Test public void jsCanonicalName() throws Exception {
    69         assertExec("I/O simple name", Classes.class, "canonicalNameLjava_lang_String", "java.io.IOException");
    70     }
    71     
    72     private static CharSequence codeSeq;
    73     private static Invocable code;
    74     
    75     @BeforeClass
    76     public void compileTheCode() throws Exception {
    77         if (codeSeq == null) {
    78             StringBuilder sb = new StringBuilder();
    79             code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Classes");
    80             codeSeq = sb;
    81         }
    82     }
    83     
    84     private void assertExec(
    85         String msg, Class clazz, String method, Object expRes, Object... args
    86     ) throws Exception {
    87         StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
    88     }
    89     
    90 }