javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ModelTest.java
branchmodel
changeset 505 4198be34b516
parent 500 f9e80d48e9b4
child 760 4bd6f3bc6c64
child 851 c285a78302af
     1.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ModelTest.java	Mon Jan 21 11:55:27 2013 +0100
     1.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ModelTest.java	Mon Jan 21 13:43:40 2013 +0100
     1.3 @@ -23,6 +23,7 @@
     1.4  import org.apidesign.bck2brwsr.htmlpage.api.Page;
     1.5  import org.apidesign.bck2brwsr.htmlpage.api.Property;
     1.6  import static org.testng.Assert.*;
     1.7 +import org.testng.annotations.BeforeMethod;
     1.8  import org.testng.annotations.Test;
     1.9  
    1.10  /**
    1.11 @@ -34,25 +35,31 @@
    1.12      @Property(name = "unrelated", type = long.class)
    1.13  })
    1.14  public class ModelTest {
    1.15 +    private Model model;
    1.16 +    private static Model leakedModel;
    1.17 +    
    1.18 +    @BeforeMethod
    1.19 +    public void createModel() {
    1.20 +        model = new Model();
    1.21 +    }
    1.22 +    
    1.23      @Test public void classGeneratedWithSetterGetter() {
    1.24 -        Class<?> c = Model.class;
    1.25 -        assertNotNull(c, "Class for empty page generated");
    1.26 -        Model.setValue(10);
    1.27 -        assertEquals(10, Model.getValue(), "Value changed");
    1.28 +        model.setValue(10);
    1.29 +        assertEquals(10, model.getValue(), "Value changed");
    1.30      }
    1.31      
    1.32      @Test public void computedMethod() {
    1.33 -        Model.setValue(4);
    1.34 -        assertEquals(16, Model.getPowerValue());
    1.35 +        model.setValue(4);
    1.36 +        assertEquals(16, model.getPowerValue());
    1.37      }
    1.38      
    1.39      @Test public void derivedPropertiesAreNotified() {
    1.40          MockKnockout my = new MockKnockout();
    1.41          MockKnockout.next = my;
    1.42          
    1.43 -        Model.applyBindings();
    1.44 +        model.applyBindings();
    1.45          
    1.46 -        Model.setValue(33);
    1.47 +        model.setValue(33);
    1.48          
    1.49          assertEquals(my.mutated.size(), 2, "Two properties changed: " + my.mutated);
    1.50          assertTrue(my.mutated.contains("powerValue"), "Power value is in there: " + my.mutated);
    1.51 @@ -60,14 +67,15 @@
    1.52          
    1.53          my.mutated.clear();
    1.54          
    1.55 -        Model.setUnrelated(44);
    1.56 +        model.setUnrelated(44);
    1.57          assertEquals(my.mutated.size(), 1, "One property changed");
    1.58          assertTrue(my.mutated.contains("unrelated"), "Its name is unrelated");
    1.59      }
    1.60      
    1.61      @Test public void computedPropertyCannotWriteToModel() {
    1.62 +        leakedModel = model;
    1.63          try {
    1.64 -            String res = Model.getNotAllowedWrite();
    1.65 +            String res = model.getNotAllowedWrite();
    1.66              fail("We should not be allowed to write to the model: " + res);
    1.67          } catch (IllegalStateException ex) {
    1.68              // OK, we can't read
    1.69 @@ -75,8 +83,9 @@
    1.70      }
    1.71  
    1.72      @Test public void computedPropertyCannotReadToModel() {
    1.73 +        leakedModel = model;
    1.74          try {
    1.75 -            String res = Model.getNotAllowedRead();
    1.76 +            String res = model.getNotAllowedRead();
    1.77              fail("We should not be allowed to read from the model: " + res);
    1.78          } catch (IllegalStateException ex) {
    1.79              // OK, we can't read
    1.80 @@ -90,12 +99,12 @@
    1.81      
    1.82      @ComputedProperty
    1.83      static String notAllowedRead() {
    1.84 -        return "Not allowed callback: " + Model.getUnrelated();
    1.85 +        return "Not allowed callback: " + leakedModel.getUnrelated();
    1.86      }
    1.87  
    1.88      @ComputedProperty
    1.89      static String notAllowedWrite() {
    1.90 -        Model.setUnrelated(11);
    1.91 +        leakedModel.setUnrelated(11);
    1.92          return "Not allowed callback!";
    1.93      }
    1.94