1.1 --- a/json/src/test/java/net/java/html/json/ModelProcessorTest.java Wed Oct 28 19:29:17 2015 +0100
1.2 +++ b/json/src/test/java/net/java/html/json/ModelProcessorTest.java Wed Dec 09 21:39:13 2015 +0100
1.3 @@ -386,6 +386,59 @@
1.4 Compile c = Compile.create(html, code, "1.5");
1.5 assertTrue(c.getErrors().isEmpty(), "No errors: " + c.getErrors());
1.6 }
1.7 +
1.8 + @Test public void instanceNeedsDefaultConstructor() throws IOException {
1.9 + String html = "<html><body>"
1.10 + + "</body></html>";
1.11 + String code = "package x.y.z;\n"
1.12 + + "import net.java.html.json.Model;\n"
1.13 + + "import net.java.html.json.Property;\n"
1.14 + + "import net.java.html.json.ComputedProperty;\n"
1.15 + + "@Model(className=\"XModel\", instance=true, properties={\n"
1.16 + + " @Property(name=\"prop\", type=long.class)\n"
1.17 + + "})\n"
1.18 + + "class X {\n"
1.19 + + " X(int x) {}\n"
1.20 + + "}\n";
1.21 +
1.22 + Compile c = Compile.create(html, code);
1.23 + c.assertError("Needs non-private default constructor when instance=true");
1.24 + }
1.25 +
1.26 + @Test public void instanceNeedsNonPrivateConstructor() throws IOException {
1.27 + String html = "<html><body>"
1.28 + + "</body></html>";
1.29 + String code = "package x.y.z;\n"
1.30 + + "import net.java.html.json.Model;\n"
1.31 + + "import net.java.html.json.Property;\n"
1.32 + + "import net.java.html.json.ComputedProperty;\n"
1.33 + + "@Model(className=\"XModel\", instance=true, properties={\n"
1.34 + + " @Property(name=\"prop\", type=long.class)\n"
1.35 + + "})\n"
1.36 + + "class X {\n"
1.37 + + " private X() {}\n"
1.38 + + "}\n";
1.39 +
1.40 + Compile c = Compile.create(html, code);
1.41 + c.assertError("Needs non-private default constructor when instance=true");
1.42 + }
1.43 +
1.44 + @Test public void instanceNoConstructorIsOK() throws IOException {
1.45 + String html = "<html><body>"
1.46 + + "</body></html>";
1.47 + String code = "package x.y.z;\n"
1.48 + + "import net.java.html.json.Model;\n"
1.49 + + "import net.java.html.json.Property;\n"
1.50 + + "import net.java.html.json.ComputedProperty;\n"
1.51 + + "@Model(className=\"XModel\", instance=true, properties={\n"
1.52 + + " @Property(name=\"prop\", type=long.class)\n"
1.53 + + "})\n"
1.54 + + "class X {\n"
1.55 + + "}\n";
1.56 +
1.57 + Compile c = Compile.create(html, code);
1.58 + c.assertNoErrors();
1.59 + }
1.60
1.61 @Test public void putNeedsDataArgument() throws Exception {
1.62 needsAnArg("PUT");