javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ConvertTypesTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 18 Apr 2013 17:34:28 +0200
changeset 1010 e2d1dc505c24
parent 960 4887e22cb810
child 1568 0db00da6f375
permissions -rw-r--r--
Support for null enum values. Transplanted from 7a7686e6f875
jaroslav@934
     1
/**
jaroslav@934
     2
 * Back 2 Browser Bytecode Translator
jaroslav@934
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@934
     4
 *
jaroslav@934
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@934
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@934
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@934
     8
 *
jaroslav@934
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@934
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@934
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@934
    12
 * GNU General Public License for more details.
jaroslav@934
    13
 *
jaroslav@934
    14
 * You should have received a copy of the GNU General Public License
jaroslav@934
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@934
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@934
    17
 */
jaroslav@934
    18
package org.apidesign.bck2brwsr.htmlpage;
jaroslav@934
    19
jaroslav@934
    20
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@934
    21
import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
jaroslav@934
    22
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@934
    23
import org.testng.annotations.Factory;
jaroslav@934
    24
jaroslav@934
    25
/**
jaroslav@934
    26
 *
jaroslav@934
    27
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@934
    28
 */
jaroslav@934
    29
public class ConvertTypesTest {
jaroslav@1010
    30
    @JavaScriptBody(args = { "includeSex" }, body = "var json = new Object();"
jaroslav@934
    31
        + "json.firstName = 'son';\n"
jaroslav@934
    32
        + "json.lastName = 'dj';\n"
jaroslav@1010
    33
        + "if (includeSex) json.sex = 'MALE';\n"
jaroslav@934
    34
        + "return json;"
jaroslav@934
    35
    )
jaroslav@1010
    36
    private static native Object createJSON(boolean includeSex);
jaroslav@934
    37
    
jaroslav@934
    38
    @BrwsrTest
jaroslav@1010
    39
    public void testConvertToPeople() throws Exception {
jaroslav@1010
    40
        final Object o = createJSON(true);
jaroslav@934
    41
        
jaroslav@934
    42
        Person p = new Person(o);
jaroslav@934
    43
        
jaroslav@934
    44
        assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
jaroslav@934
    45
        assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
jaroslav@960
    46
        assert Sex.MALE.equals(p.getSex()) : "Sex: " + p.getSex();
jaroslav@934
    47
    }
jaroslav@1010
    48
jaroslav@1010
    49
    @BrwsrTest
jaroslav@1010
    50
    public void testConvertToPeopleWithoutSex() throws Exception {
jaroslav@1010
    51
        final Object o = createJSON(false);
jaroslav@1010
    52
        
jaroslav@1010
    53
        Person p = new Person(o);
jaroslav@1010
    54
        
jaroslav@1010
    55
        assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
jaroslav@1010
    56
        assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
jaroslav@1010
    57
        assert p.getSex() == null : "No sex: " + p.getSex();
jaroslav@1010
    58
    }
jaroslav@934
    59
    
jaroslav@934
    60
    @Factory public static Object[] create() {
jaroslav@934
    61
        return VMTest.create(ConvertTypesTest.class);
jaroslav@934
    62
    }
jaroslav@934
    63
}