vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 29 Nov 2012 21:42:25 +0100
branchreflection
changeset 222 1f4a029d2826
child 223 860933a7787f
permissions -rw-r--r--
Basic tests for reflection on classes
jaroslav@222
     1
/**
jaroslav@222
     2
 * Back 2 Browser Bytecode Translator
jaroslav@222
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@222
     4
 *
jaroslav@222
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@222
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@222
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@222
     8
 *
jaroslav@222
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@222
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@222
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@222
    12
 * GNU General Public License for more details.
jaroslav@222
    13
 *
jaroslav@222
    14
 * You should have received a copy of the GNU General Public License
jaroslav@222
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@222
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@222
    17
 */
jaroslav@222
    18
package org.apidesign.vm4brwsr;
jaroslav@222
    19
jaroslav@222
    20
import javax.script.Invocable;
jaroslav@222
    21
import org.testng.annotations.Test;
jaroslav@222
    22
import static org.testng.Assert.*;
jaroslav@222
    23
import org.testng.annotations.BeforeClass;
jaroslav@222
    24
jaroslav@222
    25
/**
jaroslav@222
    26
 *
jaroslav@222
    27
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@222
    28
 */
jaroslav@222
    29
public class ClassTest {
jaroslav@222
    30
jaroslav@222
    31
    @Test public void superClassEqualsGetSuperclass() {
jaroslav@222
    32
        assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
jaroslav@222
    33
    }
jaroslav@222
    34
jaroslav@222
    35
    @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
jaroslav@222
    36
        assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptionsZ", Double.valueOf(1.0));
jaroslav@222
    37
    }
jaroslav@222
    38
jaroslav@222
    39
    @Test public void classesAreDifferent() {
jaroslav@222
    40
        assertTrue(Classes.differenceInClasses(), "Classes are not equal");
jaroslav@222
    41
    }
jaroslav@222
    42
jaroslav@222
    43
    @Test public void jsClassesAreDifferent() throws Exception {
jaroslav@222
    44
        assertExec("Classes are not equal", Classes.class, "differenceInClassesZ", Double.valueOf(1.0));
jaroslav@222
    45
    }
jaroslav@222
    46
    
jaroslav@222
    47
    private static CharSequence codeSeq;
jaroslav@222
    48
    private static Invocable code;
jaroslav@222
    49
    
jaroslav@222
    50
    @BeforeClass
jaroslav@222
    51
    public void compileTheCode() throws Exception {
jaroslav@222
    52
        if (codeSeq == null) {
jaroslav@222
    53
            StringBuilder sb = new StringBuilder();
jaroslav@222
    54
            code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Classes");
jaroslav@222
    55
            codeSeq = sb;
jaroslav@222
    56
        }
jaroslav@222
    57
    }
jaroslav@222
    58
    
jaroslav@222
    59
    private void assertExec(
jaroslav@222
    60
        String msg, Class clazz, String method, Object expRes, Object... args
jaroslav@222
    61
    ) throws Exception {
jaroslav@222
    62
        StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
jaroslav@222
    63
    }
jaroslav@222
    64
    
jaroslav@222
    65
}