# HG changeset patch # User Jaroslav Tulach # Date 1358782007 -3600 # Node ID f761555d8312045fcd9253053e63c2e707e7b8a2 # Parent 35e2c701e514537d2330e93cedef2133e57bf430 Shows how easy it is to test the model diff -r 35e2c701e514 -r f761555d8312 javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Mon Jan 21 16:21:14 2013 +0100 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Mon Jan 21 16:26:47 2013 +0100 @@ -55,7 +55,8 @@ body="var e = window.document.getElementById(this.fld_id);\n" + "e[ev.fld_id] = function() { r.run__V(); };\n" ) - final native void on(OnEvent ev, Runnable r); + final void on(OnEvent ev, Runnable r) { + } /** Shows alert message dialog in a browser. * @param msg the message to show diff -r 35e2c701e514 -r f761555d8312 javaquery/demo-calculator-dynamic/pom.xml --- a/javaquery/demo-calculator-dynamic/pom.xml Mon Jan 21 16:21:14 2013 +0100 +++ b/javaquery/demo-calculator-dynamic/pom.xml Mon Jan 21 16:26:47 2013 +0100 @@ -54,5 +54,11 @@ javaquery.api 0.3-SNAPSHOT + + org.testng + testng + 6.5.2 + test + diff -r 35e2c701e514 -r f761555d8312 javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java Mon Jan 21 16:26:47 2013 +0100 @@ -0,0 +1,46 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.demo.calc; + +import static org.testng.Assert.*; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** Demonstrating POJO testing of HTML page model. + * + * @author Jaroslav Tulach + */ +public class CalcTest { + private Calculator model; + + + @BeforeMethod + public void initModel() { + model = new Calculator().applyBindings(); + } + + @Test + public void testSomeMethod() { + model.setDisplay(10); + Calc.applyOp(model, "plus"); + assertEquals(0.0, model.getDisplay(), "Cleared after pressing +"); + model.setDisplay(5); + Calc.computeTheValue(model); + assertEquals(15.0, model.getDisplay(), "Shows fifteen"); + } +}