Shows how easy it is to test the model model
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 21 Jan 2013 16:26:47 +0100
branchmodel
changeset 514f761555d8312
parent 513 35e2c701e514
child 515 d303b4e7ad4c
Shows how easy it is to test the model
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java
javaquery/demo-calculator-dynamic/pom.xml
javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java
     1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Mon Jan 21 16:21:14 2013 +0100
     1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Mon Jan 21 16:26:47 2013 +0100
     1.3 @@ -55,7 +55,8 @@
     1.4          body="var e = window.document.getElementById(this.fld_id);\n"
     1.5             + "e[ev.fld_id] = function() { r.run__V(); };\n"
     1.6      )
     1.7 -    final native void on(OnEvent ev, Runnable r);
     1.8 +    final void on(OnEvent ev, Runnable r) {
     1.9 +    }
    1.10  
    1.11      /** Shows alert message dialog in a browser.
    1.12       * @param msg the message to show
     2.1 --- a/javaquery/demo-calculator-dynamic/pom.xml	Mon Jan 21 16:21:14 2013 +0100
     2.2 +++ b/javaquery/demo-calculator-dynamic/pom.xml	Mon Jan 21 16:26:47 2013 +0100
     2.3 @@ -54,5 +54,11 @@
     2.4        <artifactId>javaquery.api</artifactId>
     2.5        <version>0.3-SNAPSHOT</version>
     2.6      </dependency>
     2.7 +    <dependency>
     2.8 +      <groupId>org.testng</groupId>
     2.9 +      <artifactId>testng</artifactId>
    2.10 +      <version>6.5.2</version>
    2.11 +      <scope>test</scope>
    2.12 +    </dependency>
    2.13    </dependencies>
    2.14  </project>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java	Mon Jan 21 16:26:47 2013 +0100
     3.3 @@ -0,0 +1,46 @@
     3.4 +/**
     3.5 + * Back 2 Browser Bytecode Translator
     3.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.7 + *
     3.8 + * This program is free software: you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License as published by
    3.10 + * the Free Software Foundation, version 2 of the License.
    3.11 + *
    3.12 + * This program is distributed in the hope that it will be useful,
    3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 + * GNU General Public License for more details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU General Public License
    3.18 + * along with this program. Look for COPYING file in the top folder.
    3.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    3.20 + */
    3.21 +package org.apidesign.bck2brwsr.demo.calc;
    3.22 +
    3.23 +import static org.testng.Assert.*;
    3.24 +import org.testng.annotations.BeforeMethod;
    3.25 +import org.testng.annotations.Test;
    3.26 +
    3.27 +/** Demonstrating POJO testing of HTML page model.
    3.28 + *
    3.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    3.30 + */
    3.31 +public class CalcTest {
    3.32 +    private Calculator model;
    3.33 +    
    3.34 +
    3.35 +    @BeforeMethod
    3.36 +    public void initModel() {
    3.37 +        model = new Calculator().applyBindings();
    3.38 +    }
    3.39 +
    3.40 +    @Test
    3.41 +    public void testSomeMethod() {
    3.42 +        model.setDisplay(10);
    3.43 +        Calc.applyOp(model, "plus");
    3.44 +        assertEquals(0.0, model.getDisplay(), "Cleared after pressing +");
    3.45 +        model.setDisplay(5);
    3.46 +        Calc.computeTheValue(model);
    3.47 +        assertEquals(15.0, model.getDisplay(), "Shows fifteen");
    3.48 +    }
    3.49 +}