#251119: Replacing assert with real assertXYZ method makes it certain the check is really performed in all situations
1.1 --- a/json-tck/src/main/java/net/java/html/js/tests/GCBodyTest.java Sat Apr 11 07:41:04 2015 +0200
1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/GCBodyTest.java Wed Apr 15 10:39:20 2015 +0200
1.3 @@ -45,6 +45,7 @@
1.4 import java.lang.ref.Reference;
1.5 import java.lang.ref.WeakReference;
1.6 import org.netbeans.html.json.tck.KOTest;
1.7 +import static net.java.html.js.tests.JavaScriptBodyTest.*;
1.8
1.9 /**
1.10 *
1.11 @@ -61,7 +62,7 @@
1.12 }
1.13 Sum s = new Sum();
1.14 int res = Bodies.sumIndirect(s, 22, 20);
1.15 - assert res == 42 : "Expecting 42";
1.16 + assertEquals(res, 42, "Expecting 42");
1.17 Reference<?> ref = new WeakReference<Object>(s);
1.18 s = null;
1.19 assertGC(ref, "Can disappear!");
1.20 @@ -71,7 +72,7 @@
1.21 Object obj = Bodies.instance(0);
1.22 Object s = new EmptyInstance();
1.23 Bodies.setX(obj, s);
1.24 - assert s == Bodies.readX(obj);
1.25 + assertEquals(s, Bodies.readX(obj));
1.26 ref = new WeakReference<Object>(s);
1.27 return obj;
1.28 }
1.29 @@ -83,24 +84,24 @@
1.30 }
1.31
1.32 Object obj = assignInst();
1.33 - assert ref != null;
1.34 + assertNotNull(ref, "Reference assigned");
1.35
1.36 assertGC(ref, "Can disappear as it is keepAlive false!");
1.37 - assert obj != null : "Object is still present";
1.38 + assertNotNull(obj, "Object is still present");
1.39 }
1.40
1.41 @KOTest public void strongReceiverBehavior() {
1.42 Object v = new EmptyInstance();
1.43 Receiver r = new Receiver(v);
1.44 r.apply();
1.45 - assert v == r.value : "Value is as expected";
1.46 + assertEquals(v, r.value, "Value is as expected");
1.47 }
1.48
1.49 @KOTest public void gcReceiverBehavior() throws InterruptedException {
1.50 Receiver r = new Receiver(new EmptyInstance());
1.51 assertGC(r.ref, "The empty instance can be GCed even when referenced from JS");
1.52 r.apply();
1.53 - assert r.value == null : "Setter called with null value";
1.54 + assertEquals(r.value, null, "Setter called with null value");
1.55 }
1.56
1.57 private static Reference<?> sendRunnable(final int[] arr) {
2.1 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Sat Apr 11 07:41:04 2015 +0200
2.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java Wed Apr 15 10:39:20 2015 +0200
2.3 @@ -55,31 +55,31 @@
2.4 public class JavaScriptBodyTest {
2.5 @KOTest public void sumTwoNumbers() {
2.6 int res = Bodies.sum(5, 3);
2.7 - assert res == 8 : "Expecting 8: " + res;
2.8 + assertEquals(res, 8, "Expecting 8: " + res);
2.9 }
2.10
2.11 @KOTest public void sumFromCallback() {
2.12 int res = Bodies.sumJS(5, 3);
2.13 - assert res == 8 : "Expecting 8: " + res;
2.14 + assertEquals(res, 8, "Expecting 8: " + res);
2.15 }
2.16
2.17 @KOTest public void accessJsObject() {
2.18 Object o = Bodies.instance(10);
2.19 int ten = Bodies.readIntX(o);
2.20 - assert ten == 10 : "Expecting ten: " + ten;
2.21 + assertEquals(ten, 10, "Expecting ten: " + ten);
2.22 }
2.23
2.24 @KOTest public void callWithNoReturnType() {
2.25 Object o = Bodies.instance(10);
2.26 Bodies.incrementX(o);
2.27 int ten = Bodies.readIntX(o);
2.28 - assert ten == 11 : "Expecting eleven: " + ten;
2.29 + assertEquals(ten, 11, "Expecting eleven: " + ten);
2.30 }
2.31
2.32 @KOTest public void callbackToRunnable() {
2.33 R run = new R();
2.34 Bodies.callback(run);
2.35 - assert run.cnt == 1 : "Can call even private implementation classes: " + run.cnt;
2.36 + assertEquals(run.cnt, 1, "Can call even private implementation classes: " + run.cnt);
2.37 }
2.38
2.39 private R asyncRun;
2.40 @@ -91,7 +91,7 @@
2.41 if (asyncRun.cnt == 0) {
2.42 throw new InterruptedException();
2.43 }
2.44 - assert asyncRun.cnt == 1 : "Even async callback must arrive once: " + asyncRun.cnt;
2.45 + assertEquals(asyncRun.cnt, 1, "Even async callback must arrive once: " + asyncRun.cnt);
2.46 }
2.47
2.48 @KOTest public void asyncCallbackFlushed() throws InterruptedException {
2.49 @@ -100,58 +100,58 @@
2.50 Bodies.asyncCallback(r);
2.51 }
2.52 int fourtyTwo = Bodies.sum(35, 7);
2.53 - assert r.cnt == 10 : "Ten calls: " + r.cnt;
2.54 - assert fourtyTwo == 42 : "Meaning of the world expected: " + fourtyTwo;
2.55 + assertEquals(r.cnt, 10, "Ten calls: " + r.cnt);
2.56 + assertEquals(fourtyTwo, 42, "Meaning of the world expected: " + fourtyTwo);
2.57 }
2.58
2.59 @KOTest public void typeOfCharacter() {
2.60 String charType = Bodies.typeof('a', false);
2.61 - assert "number".equals(charType) : "Expecting number type: " + charType;
2.62 + assertEquals("number", charType, "Expecting number type: " + charType);
2.63 }
2.64 @KOTest public void typeOfBoolean() {
2.65 String booleanType = Bodies.typeof(true, false);
2.66 - assert "boolean".equals(booleanType) : "Expecting boolean type: " + booleanType;
2.67 + assertEquals("boolean", booleanType, "Expecting boolean type: " + booleanType);
2.68 }
2.69
2.70 @KOTest public void typeOfPrimitiveBoolean() {
2.71 String booleanType = Bodies.typeof(true);
2.72 - assert "boolean".equals(booleanType) || "number".equals(booleanType):
2.73 - "Expecting boolean or at least number type: " + booleanType;
2.74 + assertTrue("boolean".equals(booleanType) || "number".equals(booleanType),
2.75 + "Expecting boolean or at least number type: " + booleanType);
2.76 }
2.77
2.78 @KOTest public void typeOfInteger() {
2.79 String intType = Bodies.typeof(1, false);
2.80 - assert "number".equals(intType) : "Expecting number type: " + intType;
2.81 + assertEquals("number", intType, "Expecting number type: " + intType);
2.82 }
2.83
2.84 @KOTest public void typeOfString() {
2.85 String strType = Bodies.typeof("Ahoj", false);
2.86 - assert "string".equals(strType) : "Expecting string type: " + strType;
2.87 + assertEquals("string", strType, "Expecting string type: " + strType);
2.88 }
2.89
2.90 @KOTest public void typeOfDouble() {
2.91 String doubleType = Bodies.typeof(0.33, false);
2.92 - assert "number".equals(doubleType) : "Expecting number type: " + doubleType;
2.93 + assertEquals("number", doubleType, "Expecting number type: " + doubleType);
2.94 }
2.95
2.96 @KOTest public void typeOfBooleanValueOf() {
2.97 String booleanType = Bodies.typeof(true, true);
2.98 - assert "boolean".equals(booleanType) : "Expecting boolean type: " + booleanType;
2.99 + assertEquals("boolean", booleanType, "Expecting boolean type: " + booleanType);
2.100 }
2.101
2.102 @KOTest public void typeOfIntegerValueOf() {
2.103 String intType = Bodies.typeof(1, true);
2.104 - assert "number".equals(intType) : "Expecting number type: " + intType;
2.105 + assertEquals("number", intType, "Expecting number type: " + intType);
2.106 }
2.107
2.108 @KOTest public void typeOfStringValueOf() {
2.109 String strType = Bodies.typeof("Ahoj", true);
2.110 - assert "string".equals(strType) : "Expecting string type: " + strType;
2.111 + assertEquals("string", strType, "Expecting string type: " + strType);
2.112 }
2.113
2.114 @KOTest public void typeOfDoubleValueOf() {
2.115 String doubleType = Bodies.typeof(0.33, true);
2.116 - assert "number".equals(doubleType) : "Expecting number type: " + doubleType;
2.117 + assertEquals("number", doubleType, "Expecting number type: " + doubleType);
2.118 }
2.119
2.120 @KOTest public void computeInARunnable() {
2.121 @@ -163,8 +163,8 @@
2.122 }
2.123 }
2.124 Bodies.callback(new First());
2.125 - assert sum[0] == 42 : "Computed OK " + sum[0];
2.126 - assert sum[1] == 42 : "Computed OK too: " + sum[1];
2.127 + assertEquals(sum[0], 42, "Computed OK " + sum[0]);
2.128 + assertEquals(sum[1], 42, "Computed OK too: " + sum[1]);
2.129 }
2.130
2.131 @KOTest public void doubleCallbackToRunnable() {
2.132 @@ -177,88 +177,88 @@
2.133 }
2.134 }
2.135 Bodies.callback(new First());
2.136 - assert run.cnt == 1 : "Can call even private implementation classes: " + run.cnt;
2.137 - assert r2.cnt == 1 : "Can call even private implementation classes: " + r2.cnt;
2.138 + assertEquals(run.cnt, 1, "Can call even private implementation classes: " + run.cnt);
2.139 + assertEquals(r2.cnt, 1, "Can call even private implementation classes: " + r2.cnt);
2.140 }
2.141
2.142 @KOTest public void identity() {
2.143 Object p = new Object();
2.144 Object r = Bodies.id(p);
2.145 - assert r == p : "The object is the same";
2.146 + assertEquals(r, p, "The object is the same");
2.147 }
2.148
2.149 @KOTest public void encodingString() {
2.150 Object p = "Ji\n\"Hi\"\nHon";
2.151 Object r = Bodies.id(p);
2.152 - assert p.equals(r) : "The object is the same: " + p + " != " + r;
2.153 + assertEquals(p, r, "The object is the same: " + p + " != " + r);
2.154 }
2.155
2.156 @KOTest public void encodingBackslashString() {
2.157 Object p = "{\"firstName\":\"/*\\n * Copyright (c) 2013\",\"lastName\":null,\"sex\":\"MALE\",\"address\":{\"street\":null}}";
2.158 Object r = Bodies.id(p);
2.159 - assert p.equals(r) : "The object is the same: " + p + " != " + r;
2.160 + assertEquals(p, r, "The object is the same: " + p + " != " + r);
2.161 }
2.162
2.163 @KOTest public void nullIsNull() {
2.164 Object p = null;
2.165 Object r = Bodies.id(p);
2.166 - assert r == p : "The null is the same";
2.167 + assertEquals(r, p, "The null is the same");
2.168 }
2.169
2.170 @KOTest public void callbackWithResult() {
2.171 Callable<Boolean> c = new C();
2.172 Object b = Bodies.callback(c);
2.173 - assert b == Boolean.TRUE : "Should return true";
2.174 + assertEquals(b, Boolean.TRUE, "Should return true");
2.175 }
2.176
2.177 @KOTest public void callbackWithParameters() throws InterruptedException {
2.178 Sum s = new Sum();
2.179 int res = Bodies.sumIndirect(s, 40, 2);
2.180 - assert res == 42 : "Expecting 42";
2.181 + assertEquals(res, 42, "Expecting 42");
2.182 }
2.183
2.184 @KOTest public void selectFromStringJavaArray() {
2.185 String[] arr = { "Ahoj", "Wo\nrld" };
2.186 Object res = Bodies.select(arr, 1);
2.187 - assert "Wo\nrld".equals(res) : "Expecting World, but was: " + res;
2.188 + assertEquals("Wo\nrld", res, "Expecting World, but was: " + res);
2.189 }
2.190
2.191 @KOTest public void selectFromObjectJavaArray() {
2.192 Object[] arr = { new Object(), new Object() };
2.193 Object res = Bodies.select(arr, 1);
2.194 - assert arr[1].equals(res) : "Expecting " + arr[1] + ", but was: " + res;
2.195 + assertEquals(arr[1], res, "Expecting " + arr[1] + ", but was: " + res);
2.196 }
2.197
2.198 @KOTest public void lengthOfJavaArray() {
2.199 String[] arr = { "Ahoj", "World" };
2.200 int res = Bodies.length(arr);
2.201 - assert res == 2 : "Expecting 2, but was: " + res;
2.202 + assertEquals(res, 2, "Expecting 2, but was: " + res);
2.203 }
2.204
2.205 @KOTest public void isJavaArray() {
2.206 String[] arr = { "Ahoj", "World" };
2.207 boolean is = Bodies.isArray(arr);
2.208 - assert is: "Expecting it to be an array: " + is;
2.209 + assertTrue(is, "Expecting it to be an array: " + is);
2.210 }
2.211
2.212 @KOTest public void javaArrayInOutIsCopied() {
2.213 String[] arr = { "Ahoj", "Wo\nrld" };
2.214 Object res = Bodies.id(arr);
2.215 - assert res != null : "Non-null is returned";
2.216 - assert res instanceof Object[] : "Returned an array: " + res;
2.217 - assert !(res instanceof String[]) : "Not returned a string array: " + res;
2.218 + assertNotNull(res, "Non-null is returned");
2.219 + assertTrue(res instanceof Object[], "Returned an array: " + res);
2.220 + assertFalse(res instanceof String[], "Not returned a string array: " + res);
2.221
2.222 Object[] ret = (Object[]) res;
2.223 - assert arr.length == ret.length : "Same length: " + ret.length;
2.224 - assert arr[0].equals(ret[0]) : "Same first elem";
2.225 - assert arr[1].equals(ret[1]) : "Same 2nd elem";
2.226 + assertEquals(arr.length, ret.length, "Same length: " + ret.length);
2.227 + assertEquals(arr[0], ret[0], "Same first elem");
2.228 + assertEquals(arr[1], ret[1], "Same 2nd elem");
2.229 }
2.230
2.231 @KOTest public void modifyJavaArrayHasNoEffect() {
2.232 String[] arr = { "Ah\noj", "World" };
2.233 String value = Bodies.modify(arr, 0, "H\tello");
2.234 - assert "H\tello".equals(value) : "Inside JS the value is changed: " + value;
2.235 - assert "Ah\noj".equals(arr[0]) : "From a Java point of view it remains: " + arr[0];
2.236 + assertEquals("H\tello", value, "Inside JS the value is changed: " + value);
2.237 + assertEquals("Ah\noj", arr[0], "From a Java point of view it remains: " + arr[0]);
2.238 }
2.239
2.240 @KOTest
2.241 @@ -271,86 +271,86 @@
2.242 }
2.243 Callable<String[]> a = new A();
2.244 Object b = Bodies.callbackAndPush(a, "Worl\nd!");
2.245 - assert b instanceof Object[] : "Returns an array: " + b;
2.246 + assertTrue(b instanceof Object[], "Returns an array: " + b);
2.247 Object[] arr = (Object[]) b;
2.248 String str = Arrays.toString(arr);
2.249 - assert arr.length == 2 : "Size is two " + str;
2.250 - assert "He\nllo".equals(arr[0]) : "Hello expected: " + arr[0];
2.251 - assert "Worl\nd!".equals(arr[1]) : "World! expected: " + arr[1];
2.252 + assertEquals(arr.length, 2, "Size is two " + str);
2.253 + assertEquals("He\nllo", arr[0], "Hello expected: " + arr[0]);
2.254 + assertEquals("Worl\nd!", arr[1], "World! expected: " + arr[1]);
2.255 }
2.256
2.257 @KOTest public void sumVector() {
2.258 double[] arr = { 1.0, 2.0, 3.0 };
2.259 double res = Bodies.sumVector(arr);
2.260 - assert 6.0 == res : "Expecting six: " + res;
2.261 + assertEquals(6.0, res, "Expecting six: " + res);
2.262 }
2.263
2.264 @KOTest public void sumMatrix() {
2.265 double[][] arr = { { 1.0 }, { 1.0, 1.0 }, { 1.0, 1.0, 1.0 } };
2.266 double res = Bodies.sumMatrix(arr);
2.267 - assert 6.0 == res : "Expecting six: " + res;
2.268 + assertEquals(6.0, res, "Expecting six: " + res);
2.269 }
2.270
2.271 @KOTest public void truth() {
2.272 - assert Bodies.truth() : "True is true";
2.273 + assertTrue(Bodies.truth(), "True is true");
2.274 }
2.275
2.276 @KOTest public void factorial2() {
2.277 - assert new Factorial().factorial(2) == 2;
2.278 + assertEquals(new Factorial().factorial(2), 2);
2.279 }
2.280
2.281 @KOTest public void factorial3() {
2.282 - assert new Factorial().factorial(3) == 6;
2.283 + assertEquals(new Factorial().factorial(3), 6);
2.284 }
2.285
2.286 @KOTest public void factorial4() {
2.287 - assert new Factorial().factorial(4) == 24;
2.288 + assertEquals(new Factorial().factorial(4), 24);
2.289 }
2.290
2.291 @KOTest public void factorial5() {
2.292 - assert new Factorial().factorial(5) == 120;
2.293 + assertEquals(new Factorial().factorial(5), 120);
2.294 }
2.295
2.296 @KOTest public void factorial6() {
2.297 - assert new Factorial().factorial(6) == 720;
2.298 + assertEquals(new Factorial().factorial(6), 720);
2.299 }
2.300
2.301 @KOTest public void sumArray() {
2.302 int r = Bodies.sumArr(new Sum());
2.303 - assert r == 6 : "Sum is six: " + r;
2.304 + assertEquals(r, 6, "Sum is six: " + r);
2.305 }
2.306
2.307 @KOTest public void staticCallback() {
2.308 int r = Bodies.staticCallback();
2.309 - assert r == 42 : "Expecting 42: " + r;
2.310 + assertEquals(r, 42, "Expecting 42: " + r);
2.311 }
2.312
2.313 @KOTest public void delayCallback() {
2.314 Object fn = Bodies.delayCallback();
2.315 Object r = Bodies.invokeFn(fn);
2.316 - assert r != null : "Is not null";
2.317 - assert r instanceof Number : "Is number " + r;
2.318 - assert ((Number)r).intValue() == 42 : "Expecting 42: " + r;
2.319 + assertNotNull(r, "Is not null");
2.320 + assertTrue(r instanceof Number, "Is number " + r);
2.321 + assertEquals(((Number)r).intValue(), 42, "Expecting 42: " + r);
2.322 }
2.323
2.324 @KOTest public void asyncCallFromAJSCallbackNeedToFinishBeforeReturnToJS() {
2.325 int r = Bodies.incAsync();
2.326 - assert r == 42 : "Expecting 42: " + r;
2.327 + assertEquals(r, 42, "Expecting 42: " + r);
2.328 }
2.329
2.330 @KOTest public void iterateArray() {
2.331 String[] arr = { "Ahoj", "Hi", "Ciao" };
2.332 Object[] ret = Bodies.forIn(arr);
2.333 - assert ret.length == 3 : "Three elements returned: " + ret.length;
2.334 - assert ret != arr : "Different arrays";
2.335 - assert ret[0].equals("Ahoj") : "Expecting Ahoj: " + ret[0];
2.336 - assert ret[1].equals("Hi") : "Expecting Hi: " + ret[1];
2.337 - assert ret[2].equals("Ciao") : "Expecting Ciao: " + ret[2];
2.338 + assertEquals(ret.length, 3, "Three elements returned: " + ret.length);
2.339 + assertNotEquals(ret, arr, "Different arrays");
2.340 + assertEquals(ret[0], "Ahoj", "Expecting Ahoj: " + ret[0]);
2.341 + assertEquals(ret[1], "Hi", "Expecting Hi: " + ret[1]);
2.342 + assertEquals(ret[2], "Ciao", "Expecting Ciao: " + ret[2]);
2.343 }
2.344
2.345 @KOTest public void primitiveTypes() {
2.346 String all = Bodies.primitiveTypes(new Sum());
2.347 - assert "Ahojfalse12356.07.0 TheEND".equals(all) : "Valid return type: " + all;
2.348 + assertEquals("Ahojfalse12356.07.0 TheEND", all, "Valid return type: " + all);
2.349 }
2.350
2.351 @KOTest public void problematicString() {
2.352 @@ -362,14 +362,14 @@
2.353 int len = Math.min(orig.length(), js.length());
2.354 for (int i = 0; i < len; i++) {
2.355 if (orig.charAt(i) != js.charAt(i)) {
2.356 - assert false : "Difference at position " + i +
2.357 + fail("Difference at position " + i +
2.358 "\norig: " +
2.359 orig.substring(i - 5, Math.min(i + 10, orig.length())) +
2.360 "\n js: " +
2.361 - js.substring(i - 5, Math.min(i + 10, js.length()));
2.362 + js.substring(i - 5, Math.min(i + 10, js.length())));
2.363 }
2.364 }
2.365 - assert false : "The JS string is different: " + js;
2.366 + fail("The JS string is different: " + js);
2.367 }
2.368
2.369 Later l;
2.370 @@ -391,7 +391,7 @@
2.371 if (l.call != 42) {
2.372 throw new InterruptedException();
2.373 }
2.374 - assert l.call == 42 : "Method was called: " + l.call;
2.375 + assertEquals(l.call, 42, "Method was called: " + l.call);
2.376 }
2.377
2.378 private static class R implements Runnable {
2.379 @@ -404,7 +404,7 @@
2.380
2.381 @Override
2.382 public void run() {
2.383 - assert initThread == Thread.currentThread() : "Expecting to run in " + initThread + " but running in " + Thread.currentThread();
2.384 + assertEquals(initThread, Thread.currentThread(), "Expecting to run in " + initThread + " but running in " + Thread.currentThread());
2.385 cnt++;
2.386 }
2.387 }
2.388 @@ -415,4 +415,60 @@
2.389 return Boolean.TRUE;
2.390 }
2.391 }
2.392 + static void assertEquals(Object a, Object b, String msg) {
2.393 + if (a == b) {
2.394 + return;
2.395 + }
2.396 + if (a != null && a.equals(b)) {
2.397 + return;
2.398 + }
2.399 + throw new AssertionError(msg);
2.400 + }
2.401 + private static void assertNotEquals(Object a, Object b, String msg) {
2.402 + if (a == null) {
2.403 + if (b == null) {
2.404 + throw new AssertionError(msg);
2.405 + }
2.406 + return;
2.407 + }
2.408 + if (a.equals(b)) {
2.409 + throw new AssertionError(msg);
2.410 + }
2.411 + }
2.412 + static void assertEquals(Object a, Object b) {
2.413 + if (a == b) {
2.414 + return;
2.415 + }
2.416 + if (a != null && a.equals(b)) {
2.417 + return;
2.418 + }
2.419 + throw new AssertionError("Expecting " + b + " but found " + a);
2.420 + }
2.421 + private static void fail(String msg) {
2.422 + throw new AssertionError(msg);
2.423 + }
2.424 +
2.425 + private static void assertTrue(boolean c, String msg) {
2.426 + if (!c) {
2.427 + throw new AssertionError(msg);
2.428 + }
2.429 + }
2.430 +
2.431 + private static void assertFalse(boolean c, String msg) {
2.432 + if (c) {
2.433 + throw new AssertionError(msg);
2.434 + }
2.435 + }
2.436 +
2.437 + private static void assertNull(Object o, String msg) {
2.438 + if (o != null) {
2.439 + throw new AssertionError(msg);
2.440 + }
2.441 + }
2.442 +
2.443 + static void assertNotNull(Object o, String msg) {
2.444 + if (o == null) {
2.445 + throw new AssertionError(msg);
2.446 + }
2.447 + }
2.448 }
3.1 --- a/json-tck/src/main/java/net/java/html/json/tests/ConvertTypesTest.java Sat Apr 11 07:41:04 2015 +0200
3.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/ConvertTypesTest.java Wed Apr 15 10:39:20 2015 +0200
3.3 @@ -53,6 +53,9 @@
3.4 import net.java.html.BrwsrCtx;
3.5 import net.java.html.json.Models;
3.6 import org.netbeans.html.json.tck.KOTest;
3.7 +import static net.java.html.json.tests.Utils.assertEquals;
3.8 +import static net.java.html.json.tests.Utils.assertNull;
3.9 +import static net.java.html.json.tests.Utils.assertNotNull;
3.10
3.11 /**
3.12 *
3.13 @@ -105,9 +108,9 @@
3.14
3.15 Person p = Models.fromRaw(newContext(), Person.class, o);
3.16
3.17 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.18 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.19 - assert Sex.MALE.equals(p.getSex()) : "Sex: " + p.getSex();
3.20 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.21 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.22 + assertEquals(Sex.MALE, p.getSex(), "Sex: " + p.getSex());
3.23 }
3.24
3.25 @KOTest
3.26 @@ -117,9 +120,9 @@
3.27
3.28 Person p = Models.parse(c, Person.class, o);
3.29
3.30 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.31 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.32 - assert Sex.MALE.equals(p.getSex()) : "Sex: " + p.getSex();
3.33 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.34 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.35 + assertEquals(Sex.MALE, p.getSex(), "Sex: " + p.getSex());
3.36 }
3.37
3.38 @KOTest
3.39 @@ -129,11 +132,11 @@
3.40
3.41 Person p = Models.parse(c, Person.class, o);
3.42
3.43 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.44 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.45 - assert Sex.MALE.equals(p.getSex()) : "Sex: " + p.getSex();
3.46 - assert p.getAddress() != null : "Some address provided";
3.47 - assert p.getAddress().getStreet().equals("Schnirchova") : "Is Schnirchova: " + p.getAddress();
3.48 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.49 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.50 + assertEquals(Sex.MALE, p.getSex(), "Sex: " + p.getSex());
3.51 + assertNotNull(p.getAddress(), "Some address provided");
3.52 + assertEquals(p.getAddress().getStreet(), "Schnirchova", "Is Schnirchova: " + p.getAddress());
3.53 }
3.54
3.55 @KOTest
3.56 @@ -144,14 +147,14 @@
3.57 List<Person> arr = new ArrayList<Person>();
3.58 Models.parse(c, Person.class, o, arr);
3.59
3.60 - assert arr.size() == 1 : "There is one item in " + arr;
3.61 + assertEquals(arr.size(), 1, "There is one item in " + arr);
3.62
3.63 Person p = arr.get(0);
3.64 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.65 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.66 - assert Sex.MALE.equals(p.getSex()) : "Sex: " + p.getSex();
3.67 - assert p.getAddress() != null : "Some address provided";
3.68 - assert p.getAddress().getStreet().equals("Schnirchova") : "Is Schnirchova: " + p.getAddress();
3.69 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.70 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.71 + assertEquals(Sex.MALE, p.getSex(), "Sex: " + p.getSex());
3.72 + assertNotNull(p.getAddress() , "Some address provided");
3.73 + assertEquals(p.getAddress().getStreet(), "Schnirchova", "Is Schnirchova: " + p.getAddress());
3.74 }
3.75
3.76 @KOTest
3.77 @@ -165,8 +168,8 @@
3.78 final ByteArrayInputStream is = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
3.79 Person p = Models.parse(c, Person.class, is);
3.80
3.81 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.82 - assert null == p.getLastName() : "Last name: " + p.getLastName();
3.83 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.84 + assertNull(p.getLastName(), "Last name: " + p.getLastName());
3.85 }
3.86
3.87 @KOTest
3.88 @@ -181,12 +184,12 @@
3.89 List<Person> arr = new ArrayList<Person>();
3.90 Models.parse(c, Person.class, is, arr);
3.91
3.92 - assert arr.size() == 2 : "There are two items in " + arr;
3.93 - assert arr.get(0) == null : "first is null " + arr;
3.94 + assertEquals(arr.size(), 2, "There are two items in " + arr);
3.95 + assertNull(arr.get(0), "first is null " + arr);
3.96
3.97 Person p = arr.get(1);
3.98 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.99 - assert null == p.getLastName() : "Last name: " + p.getLastName();
3.100 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.101 + assertNull(p.getLastName(), "Last name: " + p.getLastName());
3.102 }
3.103
3.104 @KOTest
3.105 @@ -195,9 +198,9 @@
3.106
3.107 Person p = Models.fromRaw(newContext(), Person.class, o);
3.108
3.109 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.110 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.111 - assert p.getSex() == null : "No sex: " + p.getSex();
3.112 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.113 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.114 + assertNull(p.getSex(), "No sex: " + p.getSex());
3.115 }
3.116
3.117 @KOTest
3.118 @@ -206,9 +209,9 @@
3.119 final InputStream o = createIS(false, false, -1);
3.120 Person p = Models.parse(c, Person.class, o);
3.121
3.122 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.123 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.124 - assert p.getSex() == null : "No sex: " + p.getSex();
3.125 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.126 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.127 + assertNull(p.getSex(), "No sex: " + p.getSex());
3.128 }
3.129
3.130 @KOTest
3.131 @@ -218,11 +221,11 @@
3.132
3.133 Person p = Models.parse(c, Person.class, o);
3.134
3.135 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.136 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.137 - assert Sex.MALE.equals(p.getSex()) : "Sex: " + p.getSex();
3.138 - assert p.getAddress() != null : "Some address provided";
3.139 - assert p.getAddress().getStreet().equals("Schnirchova") : "Is Schnirchova: " + p.getAddress();
3.140 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.141 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.142 + assertEquals(Sex.MALE, p.getSex(), "Sex: " + p.getSex());
3.143 + assertNotNull(p.getAddress(), "Some address provided");
3.144 + assertEquals(p.getAddress().getStreet(), "Schnirchova", "Is Schnirchova: " + p.getAddress());
3.145 }
3.146
3.147 @KOTest
3.148 @@ -231,9 +234,9 @@
3.149 final InputStream o = createIS(false, false, 1);
3.150 Person p = Models.parse(c, Person.class, o);
3.151
3.152 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.153 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.154 - assert p.getSex() == null : "No sex: " + p.getSex();
3.155 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.156 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.157 + assertNull(p.getSex(), "No sex: " + p.getSex());
3.158 }
3.159
3.160 @KOTest
3.161 @@ -242,9 +245,9 @@
3.162 final InputStream o = createIS(false, false, 5);
3.163 Person p = Models.parse(c, Person.class, o);
3.164
3.165 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.166 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.167 - assert p.getSex() == null : "No sex: " + p.getSex();
3.168 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.169 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.170 + assertNull(p.getSex(), "No sex: " + p.getSex());
3.171 }
3.172
3.173 @KOTest
3.174 @@ -255,12 +258,12 @@
3.175 List<Person> res = new ArrayList<Person>();
3.176 Models.parse(c, Person.class, o, res);
3.177
3.178 - assert res.size() == 5 : "Five elements found" + res;
3.179 + assertEquals(res.size(), 5, "Five elements found" + res);
3.180
3.181 for (Person p : res) {
3.182 - assert "son".equals(p.getFirstName()) : "First name: " + p.getFirstName();
3.183 - assert "dj".equals(p.getLastName()) : "Last name: " + p.getLastName();
3.184 - assert p.getSex() == null : "No sex: " + p.getSex();
3.185 + assertEquals("son", p.getFirstName(), "First name: " + p.getFirstName());
3.186 + assertEquals("dj", p.getLastName(), "Last name: " + p.getLastName());
3.187 + assertNull(p.getSex(), "No sex: " + p.getSex());
3.188 }
3.189 }
3.190
4.1 --- a/json-tck/src/main/java/net/java/html/json/tests/GCKnockoutTest.java Sat Apr 11 07:41:04 2015 +0200
4.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/GCKnockoutTest.java Wed Apr 15 10:39:20 2015 +0200
4.3 @@ -49,6 +49,7 @@
4.4 import net.java.html.json.Models;
4.5 import net.java.html.json.Property;
4.6 import org.netbeans.html.json.tck.KOTest;
4.7 +import static net.java.html.json.tests.Utils.assertEquals;
4.8
4.9 @Model(className = "GC", properties = {
4.10 @Property(name = "all", type = Fullname.class, array = true)
4.11 @@ -74,18 +75,18 @@
4.12 Models.applyBindings(m);
4.13
4.14 int cnt = Utils.countChildren(GCKnockoutTest.class, "ul");
4.15 - assert cnt == 1 : "One child, but was " + cnt;
4.16 + assertEquals(cnt, 1, "One child, but was " + cnt);
4.17
4.18 m.getAll().add(new Fullname("HTML", "Java"));
4.19
4.20 cnt = Utils.countChildren(GCKnockoutTest.class, "ul");
4.21 - assert cnt == 2 : "Now two " + cnt;
4.22 + assertEquals(cnt, 2, "Now two " + cnt);
4.23
4.24 Fullname removed = m.getAll().get(0);
4.25 m.getAll().remove(0);
4.26
4.27 cnt = Utils.countChildren(GCKnockoutTest.class, "ul");
4.28 - assert cnt == 1 : "Again One " + cnt;
4.29 + assertEquals(cnt, 1, "Again One " + cnt);
4.30
4.31 Reference<?> ref = new WeakReference<Object>(removed);
4.32 removed = null;
5.1 --- a/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java Sat Apr 11 07:41:04 2015 +0200
5.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/JSONTest.java Wed Apr 15 10:39:20 2015 +0200
5.3 @@ -52,6 +52,10 @@
5.4 import net.java.html.json.OnReceive;
5.5 import net.java.html.json.Property;
5.6 import org.netbeans.html.json.tck.KOTest;
5.7 +import static net.java.html.json.tests.Utils.assertEquals;
5.8 +import static net.java.html.json.tests.Utils.assertNull;
5.9 +import static net.java.html.json.tests.Utils.assertNotNull;
5.10 +import static net.java.html.json.tests.Utils.assertTrue;
5.11
5.12 /** Need to verify that models produce reasonable JSON objects.
5.13 *
5.14 @@ -88,8 +92,8 @@
5.15
5.16 Person p2 = Models.fromRaw(newContext(), Person.class, json);
5.17
5.18 - assert p2.getFirstName().equals(p.getFirstName()) :
5.19 - "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName();
5.20 + assertEquals(p2.getFirstName(), p.getFirstName(),
5.21 + "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName());
5.22 }
5.23
5.24 @KOTest public void toJSONWithEscapeCharactersInABrowser() throws Throwable {
5.25 @@ -108,8 +112,8 @@
5.26
5.27 Person p2 = Models.fromRaw(newContext(), Person.class, json);
5.28
5.29 - assert p2.getFirstName().equals(p.getFirstName()) :
5.30 - "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName();
5.31 + assertEquals(p2.getFirstName(), p.getFirstName(),
5.32 + "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName());
5.33 }
5.34
5.35 @KOTest public void toJSONWithDoubleSlashInABrowser() throws Throwable {
5.36 @@ -128,8 +132,8 @@
5.37
5.38 Person p2 = Models.fromRaw(newContext(), Person.class, json);
5.39
5.40 - assert p2.getFirstName().equals(p.getFirstName()) :
5.41 - "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName();
5.42 + assertEquals(p2.getFirstName(), p.getFirstName(),
5.43 + "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName());
5.44 }
5.45
5.46 @KOTest public void toJSONWithApostrophInABrowser() throws Throwable {
5.47 @@ -148,8 +152,8 @@
5.48
5.49 Person p2 = Models.fromRaw(newContext(), Person.class, json);
5.50
5.51 - assert p2.getFirstName().equals(p.getFirstName()) :
5.52 - "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName();
5.53 + assertEquals(p2.getFirstName(), p.getFirstName(),
5.54 + "Should be the same: " + p.getFirstName() + " != " + p2.getFirstName());
5.55 }
5.56
5.57 private static BrwsrCtx onCallback;
5.58 @@ -174,7 +178,7 @@
5.59 }
5.60
5.61 static void setMessage(JSONik m, Exception t) {
5.62 - assert t != null;
5.63 + assertNotNull(t, "Exception provided");
5.64 m.setFetchedResponse("Exception");
5.65 }
5.66
5.67 @@ -214,10 +218,10 @@
5.68 throw new InterruptedException();
5.69 }
5.70
5.71 - assert "Sitar".equals(p.getFirstName()) : "Expecting Sitar: " + p.getFirstName();
5.72 - assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex();
5.73 + assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName());
5.74 + assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex());
5.75
5.76 - assert ctx == onCallback;
5.77 + assertEquals(ctx, onCallback, "Context is the same");
5.78 }
5.79
5.80 @KOTest public void loadAndParsePlainText() throws Exception {
5.81 @@ -238,15 +242,15 @@
5.82 throw new InterruptedException();
5.83 }
5.84
5.85 - assert s.contains("Sitar") : "The text contains Sitar value: " + s;
5.86 - assert s.contains("MALE") : "The text contains MALE value: " + s;
5.87 + assertTrue(s.contains("Sitar"), "The text contains Sitar value: " + s);
5.88 + assertTrue(s.contains("MALE"), "The text contains MALE value: " + s);
5.89
5.90 Person p = Models.parse(ctx, Person.class, new ByteArrayInputStream(s.getBytes()));
5.91
5.92 - assert "Sitar".equals(p.getFirstName()) : "Expecting Sitar: " + p.getFirstName();
5.93 - assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex();
5.94 + assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName());
5.95 + assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex());
5.96
5.97 - assert ctx == onCallback;
5.98 + assertEquals(ctx, onCallback, "Same context");
5.99 }
5.100
5.101 @KOTest public void loadAndParsePlainTextOnArray() throws Exception {
5.102 @@ -267,15 +271,15 @@
5.103 throw new InterruptedException();
5.104 }
5.105
5.106 - assert s.contains("Sitar") : "The text contains Sitar value: " + s;
5.107 - assert s.contains("MALE") : "The text contains MALE value: " + s;
5.108 + assertTrue(s.contains("Sitar"), "The text contains Sitar value: " + s);
5.109 + assertTrue(s.contains("MALE"), "The text contains MALE value: " + s);
5.110
5.111 Person p = Models.parse(ctx, Person.class, new ByteArrayInputStream(s.getBytes()));
5.112
5.113 - assert "Sitar".equals(p.getFirstName()) : "Expecting Sitar: " + p.getFirstName();
5.114 - assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex();
5.115 + assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName());
5.116 + assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex());
5.117
5.118 - assert ctx == onCallback;
5.119 + assertEquals(ctx, onCallback, "Same context");
5.120 }
5.121
5.122 @OnReceive(url="{url}?callme={me}", jsonp = "me")
5.123 @@ -291,7 +295,7 @@
5.124 "callme"
5.125 );
5.126 orig = scriptElements();
5.127 - assert orig > 0 : "There should be some scripts on the page";
5.128 + assertTrue(orig > 0, "There should be some scripts on the page");
5.129
5.130 js = Models.bind(new JSONik(), newContext());
5.131 js.applyBindings();
5.132 @@ -305,12 +309,12 @@
5.133 throw new InterruptedException();
5.134 }
5.135
5.136 - assert "Mitar".equals(p.getFirstName()) : "Unexpected: " + p.getFirstName();
5.137 - assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex();
5.138 + assertEquals("Mitar", p.getFirstName(), "Unexpected: " + p.getFirstName());
5.139 + assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex());
5.140
5.141 int now = scriptElements();
5.142
5.143 - assert orig == now : "The set of elements is unchanged. Delta: " + (now - orig);
5.144 + assertEquals(orig, now, "The set of elements is unchanged. Delta: " + (now - orig));
5.145 }
5.146
5.147
5.148 @@ -329,7 +333,7 @@
5.149 "http.method", "http.requestBody"
5.150 );
5.151 orig = scriptElements();
5.152 - assert orig > 0 : "There should be some scripts on the page";
5.153 + assertTrue(orig > 0, "There should be some scripts on the page");
5.154
5.155 js = Models.bind(new JSONik(), newContext());
5.156 js.applyBindings();
5.157 @@ -353,9 +357,9 @@
5.158 msg = res;
5.159 }
5.160
5.161 - assert "PUT".equals(res) : "Server was queried with PUT method: " + js.getFetchedResponse();
5.162 + assertEquals("PUT", res, "Server was queried with PUT method: " + js.getFetchedResponse());
5.163
5.164 - assert msg.contains("Jarda") : "Data transferred to the server: " + msg;
5.165 + assertTrue(msg.contains("Jarda"), "Data transferred to the server: " + msg);
5.166 }
5.167
5.168 private static int scriptElements() throws Exception {
5.169 @@ -389,8 +393,8 @@
5.170 throw new InterruptedException();
5.171 }
5.172
5.173 - assert "Sitar".equals(p.getFirstName()) : "Expecting Sitar: " + p.getFirstName();
5.174 - assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex();
5.175 + assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName());
5.176 + assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex());
5.177 }
5.178
5.179 @KOTest public void loadAndParseJSONArraySingle() throws InterruptedException {
5.180 @@ -411,8 +415,8 @@
5.181 throw new InterruptedException();
5.182 }
5.183
5.184 - assert "Gitar".equals(p.getFirstName()) : "Expecting Gitar: " + p.getFirstName();
5.185 - assert Sex.FEMALE.equals(p.getSex()) : "Expecting FEMALE: " + p.getSex();
5.186 + assertEquals("Gitar", p.getFirstName(), "Expecting Gitar: " + p.getFirstName());
5.187 + assertEquals(Sex.FEMALE, p.getSex(), "Expecting FEMALE: " + p.getSex());
5.188 }
5.189
5.190 @KOTest public void loadAndParseArrayInPeople() throws InterruptedException {
5.191 @@ -431,13 +435,13 @@
5.192 throw new InterruptedException();
5.193 }
5.194
5.195 - assert js.getFetchedCount() == 1 : "One person loaded: " + js.getFetchedCount();
5.196 + assertEquals(js.getFetchedCount(), 1, "One person loaded: " + js.getFetchedCount());
5.197
5.198 Person p = js.getFetched();
5.199
5.200 - assert p != null : "We should get our person back: " + p;
5.201 - assert "Gitar".equals(p.getFirstName()) : "Expecting Gitar: " + p.getFirstName();
5.202 - assert Sex.FEMALE.equals(p.getSex()) : "Expecting FEMALE: " + p.getSex();
5.203 + assertNotNull(p, "We should get our person back: " + p);
5.204 + assertEquals("Gitar", p.getFirstName(), "Expecting Gitar: " + p.getFirstName());
5.205 + assertEquals(Sex.FEMALE, p.getSex(), "Expecting FEMALE: " + p.getSex());
5.206 }
5.207
5.208 @KOTest public void loadAndParseArrayOfIntegers() throws InterruptedException {
5.209 @@ -456,7 +460,7 @@
5.210 throw new InterruptedException();
5.211 }
5.212
5.213 - assert js.getFetchedCount() == 6 : "1 + 2 + 3 is " + js.getFetchedCount();
5.214 + assertEquals(js.getFetchedCount(), 6, "1 + 2 + 3 is " + js.getFetchedCount());
5.215 }
5.216
5.217 @OnReceive(url="{url}")
5.218 @@ -481,12 +485,12 @@
5.219 throw new InterruptedException();
5.220 }
5.221
5.222 - assert js.getFetchedCount() == 1 : "Loaded";
5.223 + assertEquals(js.getFetchedCount(), 1, "Loaded");
5.224
5.225 - assert js.getFetchedSex().size() == 3 : "Three values " + js.getFetchedSex();
5.226 - assert js.getFetchedSex().get(0) == Sex.FEMALE : "Female first " + js.getFetchedSex();
5.227 - assert js.getFetchedSex().get(1) == Sex.MALE : "male 2nd " + js.getFetchedSex();
5.228 - assert js.getFetchedSex().get(2) == Sex.MALE : "male 3rd " + js.getFetchedSex();
5.229 + assertEquals(js.getFetchedSex().size(), 3, "Three values " + js.getFetchedSex());
5.230 + assertEquals(js.getFetchedSex().get(0), Sex.FEMALE, "Female first " + js.getFetchedSex());
5.231 + assertEquals(js.getFetchedSex().get(1), Sex.MALE, "male 2nd " + js.getFetchedSex());
5.232 + assertEquals(js.getFetchedSex().get(2), Sex.MALE, "male 3rd " + js.getFetchedSex());
5.233 }
5.234
5.235 @KOTest public void loadAndParseJSONArray() throws InterruptedException {
5.236 @@ -510,9 +514,9 @@
5.237 throw new InterruptedException();
5.238 }
5.239
5.240 - assert js.getFetchedCount() == 2 : "We got two values: " + js.getFetchedCount();
5.241 - assert "Gitar".equals(p.getFirstName()) : "Expecting Gitar: " + p.getFirstName();
5.242 - assert Sex.FEMALE.equals(p.getSex()) : "Expecting FEMALE: " + p.getSex();
5.243 + assertEquals(js.getFetchedCount(), 2, "We got two values: " + js.getFetchedCount());
5.244 + assertEquals("Gitar", p.getFirstName(), "Expecting Gitar: " + p.getFirstName());
5.245 + assertEquals(Sex.FEMALE, p.getSex(), "Expecting FEMALE: " + p.getSex());
5.246 }
5.247
5.248 @KOTest public void loadError() throws InterruptedException {
5.249 @@ -529,7 +533,7 @@
5.250 throw new InterruptedException();
5.251 }
5.252
5.253 - assert "Exception".equals(js.getFetchedResponse()) : js.getFetchedResponse();
5.254 + assertEquals("Exception", js.getFetchedResponse(), "Response " + js.getFetchedResponse());
5.255 }
5.256
5.257 @Model(className = "NameAndValue", properties = {
5.258 @@ -544,13 +548,13 @@
5.259 String txt = "{ \"name\":\"M\" }";
5.260 ByteArrayInputStream is = new ByteArrayInputStream(txt.getBytes("UTF-8"));
5.261 NameAndValue v = Models.parse(newContext(), NameAndValue.class, is);
5.262 - assert "M".equals(v.getName()) : "Name is 'M': " + v.getName();
5.263 - assert 0 == v.getValue() : "Value is empty: " + v.getValue();
5.264 - assert 0 == v.getSmall() : "Small value is empty: " + v.getSmall();
5.265 + assertEquals("M", v.getName(), "Name is 'M': " + v.getName());
5.266 + assertEquals(0L, v.getValue(), "Value is empty: " + v.getValue());
5.267 + assertEquals((byte)0, v.getSmall(), "Small value is empty: " + v.getSmall());
5.268 }
5.269
5.270 @KOTest public void deserializeWrongEnum() throws Exception {
5.271 - PrintStream prev = null;
5.272 + PrintStream prev;
5.273 ByteArrayOutputStream err = new ByteArrayOutputStream();
5.274 try {
5.275 prev = System.err;
5.276 @@ -566,10 +570,10 @@
5.277 String str = "{ \"sex\" : \"unknown\" }";
5.278 ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes("UTF-8"));
5.279 Person p = Models.parse(newContext(), Person.class, is);
5.280 - assert p.getSex() == null : "Wrong sex means null, but was: " + p.getSex();
5.281 + assertNull(p.getSex(), "Wrong sex means null, but was: " + p.getSex());
5.282
5.283 if (err != null) {
5.284 - assert err.toString().contains("unknown") && err.toString().contains("Sex"): "Expecting error: " + err.toString();
5.285 + assertTrue(err.toString().contains("unknown") && err.toString().contains("Sex"), "Expecting error: " + err.toString());
5.286 }
5.287 if (prev != null) {
5.288 try {
6.1 --- a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java Sat Apr 11 07:41:04 2015 +0200
6.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java Wed Apr 15 10:39:20 2015 +0200
6.3 @@ -53,6 +53,10 @@
6.4 import net.java.html.json.Models;
6.5 import net.java.html.json.Property;
6.6 import org.netbeans.html.json.tck.KOTest;
6.7 +import static net.java.html.json.tests.Utils.assertEquals;
6.8 +import static net.java.html.json.tests.Utils.assertNotNull;
6.9 +import static net.java.html.json.tests.Utils.assertTrue;
6.10 +import static net.java.html.json.tests.Utils.assertFalse;
6.11
6.12 /**
6.13 *
6.14 @@ -96,12 +100,12 @@
6.15 m.applyBindings();
6.16
6.17 String v = getSetInput(null);
6.18 - assert "A".equals(v) : "Value is really A: " + v;
6.19 + assertEquals("A", v, "Value is really A: " + v);
6.20
6.21 getSetInput("B");
6.22 triggerEvent("input", "change");
6.23
6.24 - assert Choice.B == m.getChoice(): "Enum property updated: " + m.getChoice();
6.25 + assertEquals(Choice.B, m.getChoice(), "Enum property updated: " + m.getChoice());
6.26 } catch (Throwable t) {
6.27 throw t;
6.28 } finally {
6.29 @@ -120,12 +124,12 @@
6.30 m.applyBindings();
6.31
6.32 String v = getSetInput(null);
6.33 - assert "50.5".equals(v) : "Value is really 50.5: " + v;
6.34 + assertEquals("50.5", v, "Value is really 50.5: " + v);
6.35
6.36 getSetInput("49.5");
6.37 triggerEvent("input", "change");
6.38
6.39 - assert 49.5 == m.getLatitude() : "Double property updated: " + m.getLatitude();
6.40 + assertEquals(49.5, m.getLatitude(), "Double property updated: " + m.getLatitude());
6.41 } catch (Throwable t) {
6.42 throw t;
6.43 } finally {
6.44 @@ -144,12 +148,12 @@
6.45 m.applyBindings();
6.46
6.47 String v = getSetInput(null);
6.48 - assert "true".equals(v) : "Value is really true: " + v;
6.49 + assertEquals("true", v, "Value is really true: " + v);
6.50
6.51 getSetInput("false");
6.52 triggerEvent("input", "change");
6.53
6.54 - assert false == m.isEnabled(): "Boolean property updated: " + m.isEnabled();
6.55 + assertFalse(m.isEnabled(), "Boolean property updated: " + m.isEnabled());
6.56 } catch (Throwable t) {
6.57 throw t;
6.58 } finally {
6.59 @@ -170,12 +174,12 @@
6.60 m.applyBindings();
6.61
6.62 String v = getSetInput(null);
6.63 - assert "Kukuc".equals(v) : "Value is really kukuc: " + v;
6.64 + assertEquals("Kukuc", v, "Value is really kukuc: " + v);
6.65
6.66 getSetInput("Jardo");
6.67 triggerEvent("input", "change");
6.68
6.69 - assert "Jardo".equals(m.getName()) : "Name property updated: " + m.getName();
6.70 + assertEquals("Jardo", m.getName(), "Name property updated: " + m.getName());
6.71 } finally {
6.72 Utils.exposeHTML(KnockoutTest.class, "");
6.73 }
6.74 @@ -228,10 +232,10 @@
6.75 js.applyBindings();
6.76
6.77 String v = getSetSelected(0, null);
6.78 - assert "crud".equals(v) : "Second index (e.g. crud) is selected: " + v;
6.79 + assertEquals("crud", v, "Second index (e.g. crud) is selected: " + v);
6.80
6.81 String sel = getSetSelected(2, Models.toRaw(js.getArchetypes().get(2)));
6.82 - assert "3rd".equals(sel) : "3rd is selected now: " + sel;
6.83 + assertEquals("3rd", sel, "3rd is selected now: " + sel);
6.84 }
6.85
6.86 if (js.getArchetype() != js.getArchetypes().get(2)) {
6.87 @@ -254,7 +258,7 @@
6.88 js.applyBindings();
6.89
6.90 String v = getSetInput(null);
6.91 - assert "Kukuc".equals(v) : "Value is really kukuc: " + v;
6.92 + assertEquals("Kukuc", v, "Value is really kukuc: " + v);
6.93
6.94 Timer t = new Timer("Set to Jardo");
6.95 t.schedule(new TimerTask() {
6.96 @@ -305,17 +309,17 @@
6.97 m.applyBindings();
6.98
6.99 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.100 - assert cnt == 1 : "One child, but was " + cnt;
6.101 + assertEquals(cnt, 1, "One child, but was " + cnt);
6.102
6.103 m.getResults().add("Hi");
6.104
6.105 cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.106 - assert cnt == 2 : "Two children now, but was " + cnt;
6.107 + assertEquals(cnt, 2, "Two children now, but was " + cnt);
6.108
6.109 triggerChildClick("ul", 1);
6.110
6.111 - assert 1 == m.getCallbackCount() : "One callback " + m.getCallbackCount();
6.112 - assert "Hi".equals(m.getName()) : "We got callback from 2nd child " + m.getName();
6.113 + assertEquals(1, m.getCallbackCount(), "One callback " + m.getCallbackCount());
6.114 + assertEquals("Hi", m.getName(), "We got callback from 2nd child " + m.getName());
6.115 } finally {
6.116 Utils.exposeHTML(KnockoutTest.class, "");
6.117 }
6.118 @@ -333,7 +337,7 @@
6.119 js.applyBindings();
6.120
6.121 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.122 - assert cnt == 1 : "One child, but was " + cnt;
6.123 + assertEquals(cnt, 1, "One child, but was " + cnt);
6.124
6.125 Timer t = new Timer("add to array");
6.126 t.schedule(new TimerTask() {
6.127 @@ -353,8 +357,8 @@
6.128 try {
6.129 triggerChildClick("ul", 1);
6.130
6.131 - assert 1 == js.getCallbackCount() : "One callback " + js.getCallbackCount();
6.132 - assert "Hi".equals(js.getName()) : "We got callback from 2nd child " + js.getName();
6.133 + assertEquals(1, js.getCallbackCount(), "One callback " + js.getCallbackCount());
6.134 + assertEquals("Hi", js.getName(), "We got callback from 2nd child " + js.getName());
6.135 } finally {
6.136 Utils.exposeHTML(KnockoutTest.class, "");
6.137 }
6.138 @@ -371,20 +375,20 @@
6.139 m.applyBindings();
6.140
6.141 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.142 - assert cnt == 2 : "Two children now, but was " + cnt;
6.143 + assertEquals(cnt, 2, "Two children now, but was " + cnt);
6.144
6.145 triggerChildClick("ul", 1);
6.146
6.147 - assert "Last".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
6.148 + assertEquals("Last", m.getFirstName(), "We got callback from 2nd child " + m.getFirstName());
6.149
6.150 m.setLastName("Verylast");
6.151
6.152 cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.153 - assert cnt == 2 : "Two children now, but was " + cnt;
6.154 + assertEquals(cnt, 2, "Two children now, but was " + cnt);
6.155
6.156 triggerChildClick("ul", 1);
6.157
6.158 - assert "Verylast".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
6.159 + assertEquals("Verylast", m.getFirstName(), "We got callback from 2nd child " + m.getFirstName());
6.160
6.161 } finally {
6.162 Utils.exposeHTML(KnockoutTest.class, "");
6.163 @@ -405,13 +409,13 @@
6.164 m.applyBindings();
6.165
6.166 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.167 - assert cnt == 2 : "Two children now, but was " + cnt;
6.168 + assertEquals(cnt, 2, "Two children now, but was " + cnt);
6.169
6.170 triggerChildClick("ul", 1);
6.171
6.172 - assert PairModel.ctx == ctx : "Context remains the same";
6.173 + assertEquals(PairModel.ctx, ctx, "Context remains the same");
6.174
6.175 - assert "Last".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
6.176 + assertEquals("Last", m.getFirstName(), "We got callback from 2nd child " + m.getFirstName());
6.177 } finally {
6.178 Utils.exposeHTML(KnockoutTest.class, "");
6.179 }
6.180 @@ -430,11 +434,11 @@
6.181 m.applyBindings();
6.182
6.183 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.184 - assert cnt == 2 : "Two children now, but was " + cnt;
6.185 + assertEquals(cnt, 2, "Two children now, but was " + cnt);
6.186
6.187 triggerChildClick("ul", 1);
6.188
6.189 - assert "Last".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
6.190 + assertEquals("Last", m.getFirstName(), "We got callback from 2nd child " + m.getFirstName());
6.191 } finally {
6.192 Utils.exposeHTML(KnockoutTest.class, "");
6.193 }
6.194 @@ -448,11 +452,11 @@
6.195 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
6.196 m.applyBindings();
6.197
6.198 - assert !m.isEnabled() : "Is disabled";
6.199 + assertFalse(m.isEnabled(), "Is disabled");
6.200
6.201 triggerClick("b");
6.202
6.203 - assert m.isEnabled() : "Now the model is enabled";
6.204 + assertTrue(m.isEnabled(), "Now the model is enabled");
6.205 } finally {
6.206 Utils.exposeHTML(KnockoutTest.class, "");
6.207 }
6.208 @@ -472,12 +476,12 @@
6.209 m.applyBindings();
6.210
6.211 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.212 - assert cnt == 1 : "One child, but was " + cnt;
6.213 + assertEquals(cnt, 1, "One child, but was " + cnt);
6.214
6.215 m.getResults().add("hello");
6.216
6.217 cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.218 - assert cnt == 2 : "Two children now, but was " + cnt;
6.219 + assertEquals(cnt, 2, "Two children now, but was " + cnt);
6.220 } finally {
6.221 Utils.exposeHTML(KnockoutTest.class, "");
6.222 }
6.223 @@ -500,29 +504,29 @@
6.224 m.applyBindings();
6.225
6.226 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.227 - assert cnt == 1 : "One child, but was " + cnt;
6.228 + assertEquals(cnt, 1, "One child, but was " + cnt);
6.229
6.230 final Person second = Models.bind(new Person(), c);
6.231 second.setFirstName("second");
6.232 m.getPeople().add(second);
6.233
6.234 cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.235 - assert cnt == 2 : "Two children now, but was " + cnt;
6.236 + assertEquals(cnt, 2, "Two children now, but was " + cnt);
6.237
6.238 triggerChildClick("ul", 1);
6.239
6.240 - assert 1 == m.getCallbackCount() : "One callback " + m.getCallbackCount();
6.241 + assertEquals(1, m.getCallbackCount(), "One callback " + m.getCallbackCount());
6.242
6.243 cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.244 - assert cnt == 1 : "Again one child, but was " + cnt;
6.245 + assertEquals(cnt , 1, "Again one child, but was " + cnt);
6.246
6.247 String txt = childText("ul", 0);
6.248 - assert "first".equals(txt) : "Expecting 'first': " + txt;
6.249 + assertEquals("first", txt, "Expecting 'first': " + txt);
6.250
6.251 first.setFirstName("changed");
6.252
6.253 txt = childText("ul", 0);
6.254 - assert "changed".equals(txt) : "Expecting 'changed': " + txt;
6.255 + assertEquals("changed", txt, "Expecting 'changed': " + txt);
6.256 } finally {
6.257 Utils.exposeHTML(KnockoutTest.class, "");
6.258 }
6.259 @@ -571,12 +575,12 @@
6.260 m.applyBindings();
6.261
6.262 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.263 - assert cnt == 1 : "One child, but was " + cnt;
6.264 + assertEquals(cnt, 1, "One child, but was " + cnt);
6.265
6.266
6.267 triggerChildClick("ul", 0);
6.268
6.269 - assert first.getSex() == Sex.FEMALE : "Transverted to female: " + first.getSex();
6.270 + assertEquals(first.getSex(), Sex.FEMALE, "Transverted to female: " + first.getSex());
6.271 }
6.272
6.273 @KOTest public void stringArrayModificationVisible() throws Exception {
6.274 @@ -594,18 +598,18 @@
6.275 m.applyBindings();
6.276
6.277 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.278 - assert cnt == 2 : "Two children " + cnt;
6.279 + assertEquals(cnt, 2, "Two children " + cnt);
6.280
6.281 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "results", "Hi");
6.282 - assert arr instanceof Object[] : "Got back an array: " + arr;
6.283 + assertTrue(arr instanceof Object[], "Got back an array: " + arr);
6.284 final int len = ((Object[])arr).length;
6.285
6.286 - assert len == 3 : "Three elements in the array " + len;
6.287 + assertEquals(len, 3, "Three elements in the array " + len);
6.288
6.289 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
6.290 - assert newCnt == 3 : "Three children in the DOM: " + newCnt;
6.291 + assertEquals(newCnt, 3, "Three children in the DOM: " + newCnt);
6.292
6.293 - assert m.getResults().size() == 3 : "Three java strings: " + m.getResults();
6.294 + assertEquals(m.getResults().size(), 3, "Three java strings: " + m.getResults());
6.295 } finally {
6.296 Utils.exposeHTML(KnockoutTest.class, "");
6.297 }
6.298 @@ -626,19 +630,19 @@
6.299 m.applyBindings();
6.300
6.301 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.302 - assert cnt == 2 : "Two children " + cnt;
6.303 + assertEquals(cnt, 2, "Two children " + cnt);
6.304
6.305 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "numbers", 42);
6.306 - assert arr instanceof Object[] : "Got back an array: " + arr;
6.307 + assertTrue(arr instanceof Object[], "Got back an array: " + arr);
6.308 final int len = ((Object[])arr).length;
6.309
6.310 - assert len == 3 : "Three elements in the array " + len;
6.311 + assertEquals(len, 3, "Three elements in the array " + len);
6.312
6.313 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
6.314 - assert newCnt == 3 : "Three children in the DOM: " + newCnt;
6.315 + assertEquals(newCnt, 3, "Three children in the DOM: " + newCnt);
6.316
6.317 - assert m.getNumbers().size() == 3 : "Three java ints: " + m.getNumbers();
6.318 - assert m.getNumbers().get(2) == 42 : "Meaning of world: " + m.getNumbers();
6.319 + assertEquals(m.getNumbers().size(), 3, "Three java ints: " + m.getNumbers());
6.320 + assertEquals(m.getNumbers().get(2), 42, "Meaning of world: " + m.getNumbers());
6.321 } finally {
6.322 Utils.exposeHTML(KnockoutTest.class, "");
6.323 }
6.324 @@ -659,19 +663,19 @@
6.325 m.applyBindings();
6.326
6.327 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.328 - assert cnt == 2 : "Two children " + cnt;
6.329 + assertEquals(cnt, 2, "Two children " + cnt);
6.330
6.331 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "results", "Hi");
6.332 - assert arr instanceof Object[] : "Got back an array: " + arr;
6.333 + assertTrue(arr instanceof Object[], "Got back an array: " + arr);
6.334 final int len = ((Object[])arr).length;
6.335
6.336 - assert len == 3 : "Three elements in the array " + len;
6.337 + assertEquals(len, 3, "Three elements in the array " + len);
6.338
6.339 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
6.340 - assert newCnt == 3 : "Three children in the DOM: " + newCnt;
6.341 + assertEquals(newCnt, 3, "Three children in the DOM: " + newCnt);
6.342
6.343 - assert m.getResultLengths().size() == 3 : "Three java ints: " + m.getResultLengths();
6.344 - assert m.getResultLengths().get(2) == 2 : "Size is two: " + m.getResultLengths();
6.345 + assertEquals(m.getResultLengths().size(), 3, "Three java ints: " + m.getResultLengths());
6.346 + assertEquals(m.getResultLengths().get(2), 2, "Size is two: " + m.getResultLengths());
6.347 } finally {
6.348 Utils.exposeHTML(KnockoutTest.class, "");
6.349 }
6.350 @@ -690,20 +694,20 @@
6.351 m.applyBindings();
6.352
6.353 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
6.354 - assert cnt == 0 : "No children " + cnt;
6.355 + assertEquals(cnt, 0, "No children " + cnt);
6.356
6.357 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "archetypes", new ArchetypeData("aid", "gid", "v", "n", "d", "u"));
6.358 - assert arr instanceof Object[] : "Got back an array: " + arr;
6.359 + assertTrue(arr instanceof Object[], "Got back an array: " + arr);
6.360 final int len = ((Object[])arr).length;
6.361
6.362 - assert len == 1 : "One element in the array " + len;
6.363 + assertEquals(len, 1, "One element in the array " + len);
6.364
6.365 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
6.366 - assert newCnt == 1 : "One child in the DOM: " + newCnt;
6.367 + assertEquals(newCnt, 1, "One child in the DOM: " + newCnt);
6.368
6.369 - assert m.getArchetypes().size() == 1 : "One archetype: " + m.getArchetypes();
6.370 - assert m.getArchetypes().get(0) != null : "Not null: " + m.getArchetypes();
6.371 - assert m.getArchetypes().get(0).getArtifactId().equals("aid") : "'aid' == " + m.getArchetypes();
6.372 + assertEquals(m.getArchetypes().size(), 1, "One archetype: " + m.getArchetypes());
6.373 + assertNotNull(m.getArchetypes().get(0), "Not null: " + m.getArchetypes());
6.374 + assertEquals(m.getArchetypes().get(0).getArtifactId(), "aid", "'aid' == " + m.getArchetypes());
6.375 } finally {
6.376 Utils.exposeHTML(KnockoutTest.class, "");
6.377 }
7.1 --- a/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java Sat Apr 11 07:41:04 2015 +0200
7.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java Wed Apr 15 10:39:20 2015 +0200
7.3 @@ -54,6 +54,7 @@
7.4 import net.java.html.json.Models;
7.5 import net.java.html.json.Property;
7.6 import org.netbeans.html.json.tck.KOTest;
7.7 +import static net.java.html.json.tests.Utils.assertEquals;
7.8
7.9 /** Tests model of a mine field and its behavior in the browser.
7.10 */
7.11 @@ -86,7 +87,7 @@
7.12 m = Models.bind(new Mines(), ctx);
7.13 m.applyBindings();
7.14 int cnt = Utils.countChildren(MinesTest.class, "table");
7.15 - assert cnt == 0 : "Table is empty: " + cnt;
7.16 + assertEquals(cnt, 0, "Table is empty: " + cnt);
7.17 scheduleClick("init", 100);
7.18 }
7.19
7.20 @@ -95,7 +96,7 @@
7.21 if (cnt == 0) {
7.22 throw new InterruptedException();
7.23 }
7.24 - assert cnt == 10 : "There is ten rows in the table now: " + cnt;
7.25 + assertEquals(cnt, 10, "There is ten rows in the table now: " + cnt);
7.26
7.27 Utils.exposeHTML(MinesTest.class, "");
7.28 }
7.29 @@ -108,7 +109,7 @@
7.30 mines.getRows().get(0).getColumns().get(1).setMine(true);
7.31
7.32 int cnt = around(mines, 1, 1);
7.33 - assert cnt == 3 : "There are three mines around. Was: " + cnt;
7.34 + assertEquals(cnt, 3, "There are three mines around. Was: " + cnt);
7.35 }
7.36
7.37 private static void scheduleClick(String id, int delay) throws Exception {
8.1 --- a/json-tck/src/main/java/net/java/html/json/tests/OperationsTest.java Sat Apr 11 07:41:04 2015 +0200
8.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/OperationsTest.java Wed Apr 15 10:39:20 2015 +0200
8.3 @@ -44,6 +44,7 @@
8.4
8.5 import net.java.html.json.Models;
8.6 import org.netbeans.html.json.tck.KOTest;
8.7 +import static net.java.html.json.tests.Utils.assertEquals;
8.8
8.9 /**
8.10 *
8.11 @@ -59,8 +60,8 @@
8.12 js.applyBindings();
8.13 js.setFetched(p);
8.14 Person p = js.getFetched();
8.15 - assert "Sitar".equals(p.getFirstName()) : "Expecting Sitar immediately: " + p.getFirstName();
8.16 - assert Sex.MALE.equals(p.getSex()) : "Expecting MALE immediately: " + p.getSex();
8.17 + assertEquals("Sitar", p.getFirstName(), "Expecting Sitar immediately: " + p.getFirstName());
8.18 + assertEquals(Sex.MALE, p.getSex(), "Expecting MALE immediately: " + p.getSex());
8.19 }
8.20
8.21
8.22 @@ -89,7 +90,7 @@
8.23 throw new InterruptedException();
8.24 }
8.25
8.26 - assert "Sitar".equals(p.getFirstName()) : "Expecting Sitar: " + p.getFirstName();
8.27 - assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex();
8.28 + assertEquals("Sitar", p.getFirstName(), "Expecting Sitar: " + p.getFirstName());
8.29 + assertEquals(Sex.MALE, p.getSex(), "Expecting MALE: " + p.getSex());
8.30 }
8.31 }
9.1 --- a/json-tck/src/main/java/net/java/html/json/tests/Utils.java Sat Apr 11 07:41:04 2015 +0200
9.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/Utils.java Wed Apr 15 10:39:20 2015 +0200
9.3 @@ -184,4 +184,42 @@
9.4 return null;
9.5 }
9.6 }
9.7 +
9.8 + static void fail(String msg) {
9.9 + throw new AssertionError(msg);
9.10 + }
9.11 +
9.12 + static void assertTrue(boolean c, String msg) {
9.13 + if (!c) {
9.14 + throw new AssertionError(msg);
9.15 + }
9.16 + }
9.17 +
9.18 + static void assertFalse(boolean c, String msg) {
9.19 + if (c) {
9.20 + throw new AssertionError(msg);
9.21 + }
9.22 + }
9.23 +
9.24 + static void assertNull(Object o, String msg) {
9.25 + if (o != null) {
9.26 + throw new AssertionError(msg);
9.27 + }
9.28 + }
9.29 +
9.30 + static void assertNotNull(Object o, String msg) {
9.31 + if (o == null) {
9.32 + throw new AssertionError(msg);
9.33 + }
9.34 + }
9.35 +
9.36 + static void assertEquals(Object a, Object b, String msg) {
9.37 + if (a == b) {
9.38 + return;
9.39 + }
9.40 + if (a != null && a.equals(b)) {
9.41 + return;
9.42 + }
9.43 + throw new AssertionError(msg);
9.44 + }
9.45 }
10.1 --- a/json-tck/src/main/java/net/java/html/json/tests/WebSocketTest.java Sat Apr 11 07:41:04 2015 +0200
10.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/WebSocketTest.java Wed Apr 15 10:39:20 2015 +0200
10.3 @@ -48,6 +48,10 @@
10.4 import net.java.html.json.OnReceive;
10.5 import net.java.html.json.Property;
10.6 import org.netbeans.html.json.tck.KOTest;
10.7 +import static net.java.html.json.tests.Utils.assertEquals;
10.8 +import static net.java.html.json.tests.Utils.assertNotNull;
10.9 +import static net.java.html.json.tests.Utils.assertTrue;
10.10 +import static net.java.html.json.tests.Utils.fail;
10.11
10.12 /** Testing support of WebSocket communication.
10.13 *
10.14 @@ -108,8 +112,8 @@
10.15 throw new InterruptedException();
10.16 }
10.17
10.18 - assert "Mitar".equals(p.getFirstName()) : "Unexpected: " + p.getFirstName();
10.19 - assert Sex.FEMALE.equals(p.getSex()) : "Expecting FEMALE: " + p.getSex();
10.20 + assertEquals("Mitar", p.getFirstName(), "Unexpected: " + p.getFirstName());
10.21 + assertEquals(Sex.FEMALE, p.getSex(), "Expecting FEMALE: " + p.getSex());
10.22
10.23 if (js.getOpen() == 2) {
10.24 // close the socket
10.25 @@ -120,7 +124,7 @@
10.26 if (js.getFetchedResponse() == null) {
10.27 throw new InterruptedException();
10.28 }
10.29 - assert "null".equals(js.getFetchedResponse()) : "Should be null: " + js.getFetchedResponse();
10.30 + assertEquals("null", js.getFetchedResponse(), "Should be null: " + js.getFetchedResponse());
10.31 }
10.32
10.33 @KOTest public void errorUsingWebSocket() throws Throwable {
10.34 @@ -136,7 +140,7 @@
10.35 throw new InterruptedException();
10.36 }
10.37
10.38 - assert js.getFetchedResponse() != null : "Error reported";
10.39 + assertNotNull(js.getFetchedResponse(), "Error reported");
10.40 }
10.41
10.42 @KOTest public void haveToOpenTheWebSocket() throws Throwable {
10.43 @@ -146,9 +150,9 @@
10.44 js.setFetched(null);
10.45 try {
10.46 js.querySex("http://wrong.protocol", Sex.MALE);
10.47 - assert false : "Should throw an exception";
10.48 + fail("Should throw an exception");
10.49 } catch (IllegalStateException ex) {
10.50 - assert ex.getMessage().contains("not open") : "Expecting 'not open' msg: " + ex.getMessage();
10.51 + assertTrue(ex.getMessage().contains("not open"), "Expecting 'not open' msg: " + ex.getMessage());
10.52 }
10.53 }
10.54
11.1 --- a/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Sat Apr 11 07:41:04 2015 +0200
11.2 +++ b/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java Wed Apr 15 10:39:20 2015 +0200
11.3 @@ -68,8 +68,6 @@
11.4 import org.netbeans.html.json.spi.Technology;
11.5 import org.netbeans.html.json.spi.Transfer;
11.6 import org.netbeans.html.json.tck.KnockoutTCK;
11.7 -import org.json.JSONException;
11.8 -import org.json.JSONObject;
11.9 import org.openide.util.lookup.ServiceProvider;
11.10 import org.osgi.framework.Bundle;
11.11 import org.osgi.framework.BundleContext;
11.12 @@ -167,16 +165,17 @@
11.13
11.14 @Override
11.15 public Object createJSON(Map<String, Object> values) {
11.16 - JSONObject json = new JSONObject();
11.17 + Object json = createObj();
11.18 for (Map.Entry<String, Object> entry : values.entrySet()) {
11.19 - try {
11.20 - json.put(entry.getKey(), entry.getValue());
11.21 - } catch (JSONException ex) {
11.22 - throw new IllegalStateException(ex);
11.23 - }
11.24 + putObj(json, entry.getKey(), entry.getValue());
11.25 }
11.26 return json;
11.27 }
11.28 +
11.29 + @JavaScriptBody(args = { }, body = "return {};")
11.30 + private static native Object createObj();
11.31 + @JavaScriptBody(args = { "obj", "prop", "val" }, body = "obj[prop] = val;")
11.32 + private static native void putObj(Object obj, String prop, Object val);
11.33
11.34 @Override
11.35 @JavaScriptBody(args = { "s", "args" }, body = ""
12.1 --- a/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java Sat Apr 11 07:41:04 2015 +0200
12.2 +++ b/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java Wed Apr 15 10:39:20 2015 +0200
12.3 @@ -64,8 +64,6 @@
12.4 import org.netbeans.html.json.spi.Technology;
12.5 import org.netbeans.html.json.spi.Transfer;
12.6 import org.netbeans.html.json.tck.KnockoutTCK;
12.7 -import org.json.JSONException;
12.8 -import org.json.JSONObject;
12.9 import org.openide.util.lookup.ServiceProvider;
12.10 import org.osgi.framework.Bundle;
12.11 import org.osgi.framework.BundleContext;
12.12 @@ -161,17 +159,19 @@
12.13
12.14 @Override
12.15 public Object createJSON(Map<String, Object> values) {
12.16 - JSONObject json = new JSONObject();
12.17 + Object json = createObj();
12.18 for (Map.Entry<String, Object> entry : values.entrySet()) {
12.19 - try {
12.20 - json.put(entry.getKey(), entry.getValue());
12.21 - } catch (JSONException ex) {
12.22 - throw new IllegalStateException(ex);
12.23 - }
12.24 + putObj(json, entry.getKey(), entry.getValue());
12.25 }
12.26 return json;
12.27 }
12.28
12.29 + @JavaScriptBody(args = {}, body = "return {};")
12.30 + private static native Object createObj();
12.31 +
12.32 + @JavaScriptBody(args = {"obj", "prop", "val"}, body = "obj[prop] = val;")
12.33 + private static native void putObj(Object obj, String prop, Object val);
12.34 +
12.35 @Override
12.36 @JavaScriptBody(args = { "s", "args" }, body = ""
12.37 + "var f = new Function(s); "