Create default instances and just bind them to unit testing context context
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 28 May 2013 20:01:30 +0200
branchcontext
changeset 115b236fc0949e0
parent 114 096e86113681
child 116 33ef89a4a306
Create default instances and just bind them to unit testing context
json-tck/src/main/java/net/java/html/json/tests/JSONTest.java
json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java
     1.1 --- a/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java	Tue May 28 20:00:53 2013 +0200
     1.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java	Tue May 28 20:01:30 2013 +0200
     1.3 @@ -46,7 +46,7 @@
     1.4      private Integer orig;
     1.5      
     1.6      @BrwsrTest public void toJSONInABrowser() throws Throwable {
     1.7 -        Person p = new Person(Utils.newContext());
     1.8 +        Person p = Models.bind(new Person(), Utils.newContext());
     1.9          p.setSex(Sex.MALE);
    1.10          p.setFirstName("Jarda");
    1.11          p.setLastName("Tulach");
    1.12 @@ -97,7 +97,7 @@
    1.13      ))
    1.14      @BrwsrTest public void loadAndParseJSON() throws InterruptedException {
    1.15          if (js == null) {
    1.16 -            js = new JSONik(Utils.newContext());
    1.17 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.18              js.applyBindings();
    1.19  
    1.20              js.fetch("person.json");
    1.21 @@ -129,7 +129,7 @@
    1.22              orig = scriptElements();
    1.23              assert orig > 0 : "There should be some scripts on the page";
    1.24              
    1.25 -            js = new JSONik(Utils.newContext());
    1.26 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.27              js.applyBindings();
    1.28  
    1.29              js.fetchViaJSONP("person.json");
    1.30 @@ -166,10 +166,10 @@
    1.31              orig = scriptElements();
    1.32              assert orig > 0 : "There should be some scripts on the page";
    1.33              
    1.34 -            js = new JSONik(Utils.newContext());
    1.35 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.36              js.applyBindings();
    1.37  
    1.38 -            Person p = new Person(BrwsrCtx.EMPTY);
    1.39 +            Person p = Models.bind(new Person(), BrwsrCtx.EMPTY);
    1.40              p.setFirstName("Jarda");
    1.41              js.putPerson("person.json", p);
    1.42          }
    1.43 @@ -208,7 +208,7 @@
    1.44      ))
    1.45      @BrwsrTest public void loadAndParseJSONSentToArray() throws InterruptedException {
    1.46          if (js == null) {
    1.47 -            js = new JSONik(Utils.newContext());
    1.48 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.49              js.applyBindings();
    1.50  
    1.51              js.fetchArray("person.json");
    1.52 @@ -230,7 +230,7 @@
    1.53      ))
    1.54      @BrwsrTest public void loadAndParseJSONArraySingle() throws InterruptedException {
    1.55          if (js == null) {
    1.56 -            js = new JSONik(Utils.newContext());
    1.57 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.58              js.applyBindings();
    1.59          
    1.60              js.fetch("person.json");
    1.61 @@ -252,7 +252,7 @@
    1.62      ))
    1.63      @BrwsrTest public void loadAndParseArrayInPeople() throws InterruptedException {
    1.64          if (js == null) {
    1.65 -            js = new JSONik(Utils.newContext());
    1.66 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.67              js.applyBindings();
    1.68          
    1.69              js.fetchPeople("people.json");
    1.70 @@ -278,7 +278,7 @@
    1.71      ))
    1.72      @BrwsrTest public void loadAndParseArrayOfIntegers() throws InterruptedException {
    1.73          if (js == null) {
    1.74 -            js = new JSONik(Utils.newContext());
    1.75 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.76              js.applyBindings();
    1.77          
    1.78              js.fetchPeopleAge("people.json");
    1.79 @@ -305,7 +305,7 @@
    1.80      ))
    1.81      @BrwsrTest public void loadAndParseArrayOfEnums() throws InterruptedException {
    1.82          if (js == null) {
    1.83 -            js = new JSONik(Utils.newContext());
    1.84 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.85              js.applyBindings();
    1.86          
    1.87              js.fetchPeopleSex("people.json");
    1.88 @@ -332,7 +332,7 @@
    1.89      ))
    1.90      @BrwsrTest public void loadAndParseJSONArray() throws InterruptedException {
    1.91          if (js == null) {
    1.92 -            js = new JSONik(Utils.newContext());
    1.93 +            js = Models.bind(new JSONik(), Utils.newContext());
    1.94              js.applyBindings();
    1.95              js.fetchArray("person.json");
    1.96          }
     2.1 --- a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java	Tue May 28 20:00:53 2013 +0200
     2.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java	Tue May 28 20:01:30 2013 +0200
     2.3 @@ -24,6 +24,7 @@
     2.4  import net.java.html.json.ComputedProperty;
     2.5  import net.java.html.json.Function;
     2.6  import net.java.html.json.Model;
     2.7 +import net.java.html.json.Models;
     2.8  import net.java.html.json.Property;
     2.9  import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
    2.10  import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
    2.11 @@ -48,7 +49,7 @@
    2.12          "<button id=\"hello\">Say Hello!</button>\n"
    2.13      )
    2.14      @BrwsrTest public void modifyValueAssertChangeInModel() throws Exception {
    2.15 -        KnockoutModel m = new KnockoutModel(Utils.newContext());
    2.16 +        KnockoutModel m = Models.bind(new KnockoutModel(), Utils.newContext());
    2.17          m.setName("Kukuc");
    2.18          m.applyBindings();
    2.19          
    2.20 @@ -82,7 +83,7 @@
    2.21          + "</ul>\n"
    2.22      )
    2.23      @BrwsrTest public void displayContentOfArray() throws Exception {
    2.24 -        KnockoutModel m = new KnockoutModel(Utils.newContext());
    2.25 +        KnockoutModel m = Models.bind(new KnockoutModel(), Utils.newContext());
    2.26          m.getResults().add("Ahoj");
    2.27          m.applyBindings();
    2.28          
    2.29 @@ -104,7 +105,7 @@
    2.30          "<input type='checkbox' id='b' data-bind='checked: enabled'></input>\n"
    2.31      )
    2.32      @BrwsrTest public void checkBoxToBooleanBinding() throws Exception {
    2.33 -        KnockoutModel m = new KnockoutModel(Utils.newContext());
    2.34 +        KnockoutModel m = Models.bind(new KnockoutModel(), Utils.newContext());
    2.35          m.applyBindings();
    2.36          
    2.37          assert !m.isEnabled() : "Is disabled";
    2.38 @@ -122,7 +123,7 @@
    2.39          + "</ul>\n"
    2.40      )
    2.41      @BrwsrTest public void displayContentOfDerivedArray() throws Exception {
    2.42 -        KnockoutModel m = new KnockoutModel(Utils.newContext());
    2.43 +        KnockoutModel m = Models.bind(new KnockoutModel(), Utils.newContext());
    2.44          m.getResults().add("Ahoj");
    2.45          m.applyBindings();
    2.46          
    2.47 @@ -141,9 +142,9 @@
    2.48          + "</ul>\n"
    2.49      )
    2.50      @BrwsrTest public void displayContentOfArrayOfPeople() throws Exception {
    2.51 -        KnockoutModel m = new KnockoutModel(Utils.newContext());
    2.52 +        KnockoutModel m = Models.bind(new KnockoutModel(), Utils.newContext());
    2.53          
    2.54 -        final Person first = new Person(Utils.newContext());
    2.55 +        final Person first = Models.bind(new Person(), Utils.newContext());
    2.56          first.setFirstName("first");
    2.57          m.getPeople().add(first);
    2.58          
    2.59 @@ -152,7 +153,7 @@
    2.60          int cnt = countChildren("ul");
    2.61          assert cnt == 1 : "One child, but was " + cnt;
    2.62          
    2.63 -        final Person second = new Person(Utils.newContext());
    2.64 +        final Person second = Models.bind(new Person(), Utils.newContext());
    2.65          second.setFirstName("second");
    2.66          m.getPeople().add(second);
    2.67  
    2.68 @@ -199,9 +200,9 @@
    2.69      }
    2.70      
    2.71      private void trasfertToFemale() throws Exception {
    2.72 -        KnockoutModel m = new KnockoutModel(Utils.newContext());
    2.73 +        KnockoutModel m = Models.bind(new KnockoutModel(), Utils.newContext());
    2.74  
    2.75 -        final Person first = new Person(Utils.newContext());
    2.76 +        final Person first = Models.bind(new Person(), Utils.newContext());
    2.77          first.setFirstName("first");
    2.78          first.setSex(Sex.MALE);
    2.79          m.getPeople().add(first);