emul/mini/src/test/java/org/apidesign/bck2brwsr/emul/reflect/MethodImplTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 03 Feb 2013 17:55:48 +0100
branchreflection
changeset 651 e6fdcaab8dc7
parent 650 2569d9dd4b28
permissions -rw-r--r--
The test is my creation and deserves standard bck2brwsr header
jaroslav@651
     1
/**
jaroslav@651
     2
 * Back 2 Browser Bytecode Translator
jaroslav@651
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@650
     4
 *
jaroslav@651
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@651
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@651
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@650
     8
 *
jaroslav@651
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@651
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@651
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@651
    12
 * GNU General Public License for more details.
jaroslav@650
    13
 *
jaroslav@651
    14
 * You should have received a copy of the GNU General Public License
jaroslav@651
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@651
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@650
    17
 */
jaroslav@650
    18
package org.apidesign.bck2brwsr.emul.reflect;
jaroslav@650
    19
jaroslav@650
    20
import java.lang.reflect.Method;
jaroslav@650
    21
import java.util.Enumeration;
jaroslav@650
    22
import org.testng.annotations.Test;
jaroslav@650
    23
jaroslav@650
    24
/**
jaroslav@650
    25
 *
jaroslav@650
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@650
    27
 */
jaroslav@650
    28
public class MethodImplTest {
jaroslav@650
    29
    
jaroslav@650
    30
    public MethodImplTest() {
jaroslav@650
    31
    }
jaroslav@650
    32
    
jaroslav@650
    33
    public static String[] arr(String... arr) {
jaroslav@650
    34
        return arr;
jaroslav@650
    35
    }
jaroslav@650
    36
jaroslav@650
    37
    @Test
jaroslav@650
    38
    public void testSignatureForMethodWithAnArray() throws NoSuchMethodException {
jaroslav@650
    39
        Method m = MethodImplTest.class.getMethod("arr", String[].class);
jaroslav@650
    40
        String sig = MethodImpl.toSignature(m);
jaroslav@650
    41
        int sep = sig.indexOf("__");
jaroslav@650
    42
        assert sep > 0 : "Separator found " + sig;
jaroslav@650
    43
        
jaroslav@650
    44
        Enumeration<Class> en = MethodImpl.signatureParser(sig.substring(sep + 2));
jaroslav@650
    45
        
jaroslav@650
    46
        assert en.nextElement() == m.getReturnType() : "Return type is the same";
jaroslav@650
    47
        assert en.nextElement() == m.getParameterTypes()[0] : "1st param type is the same";
jaroslav@650
    48
    }
jaroslav@650
    49
}