This is an automated email from the ASF dual-hosted git repository. jtulach pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-html4j.git
commit 4ec660c0b0e16ddc0e51b82c2fecd5a9525c4ad7 Author: Jaroslav Tulach <[email protected]> AuthorDate: Fri Feb 15 06:52:12 2019 +0100 Moving exposed properties check into own class --- .../java/html/js/tests/ExposedPropertiesTest.java | 168 +++++++++++++++++++++ .../net/java/html/js/tests/JavaScriptBodyTest.java | 151 +----------------- .../org/netbeans/html/json/tck/JavaScriptTCK.java | 3 +- 3 files changed, 175 insertions(+), 147 deletions(-) diff --git a/json-tck/src/main/java/net/java/html/js/tests/ExposedPropertiesTest.java b/json-tck/src/main/java/net/java/html/js/tests/ExposedPropertiesTest.java new file mode 100644 index 0000000..96e4610 --- /dev/null +++ b/json-tck/src/main/java/net/java/html/js/tests/ExposedPropertiesTest.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package net.java.html.js.tests; + +import java.util.List; +import static net.java.html.js.tests.JavaScriptBodyTest.assertEquals; +import static net.java.html.js.tests.JavaScriptBodyTest.assertNull; +import static net.java.html.js.tests.JavaScriptBodyTest.fail; +import net.java.html.json.Models; +import org.netbeans.html.json.tck.KOTest; + +public class ExposedPropertiesTest { + @KOTest + public void exposedPropertiesOfAJavaObject() { + Sum s = new Sum(); + Object[] props = Bodies.forIn(s); + + List<Object> all = Models.asList(props); + assertEquals(0, all.size(), "No own properties: " + all); + } + + @KOTest + public void exposedEqualsOfAJavaObject() { + Sum s = new Sum(); + assertNoProp(s, "equals", s); + } + + @KOTest + public void exposedHashCodeOfAJavaObject() { + Sum s = new Sum(); + + assertNoProp(s, "hashCode", null); + } + + @KOTest + public void exposedWaitOfAJavaObject() { + Sum s = new Sum(); + + assertNoProp(s, "wait", null); + } + + @KOTest + public void exposedGetClassOfAJavaObject() { + Sum s = new Sum(); + + assertNoProp(s, "getClass", null); + } + + @KOTest + public void exposedNotifyOfAJavaObject() { + Sum s = new Sum(); + + assertNoProp(s, "notify", null); + } + + @KOTest + public void exposedNotifyAllOfAJavaObject() { + Sum s = new Sum(); + + assertNoProp(s, "notifyAll", null); + } + + @KOTest + public void exposedEqualsOfAJavaArray() { + Object s = new Object[5]; + assertNoProp(s, "equals", s); + } + + @KOTest + public void exposedHashCodeOfAJavaArray() { + Object s = new Object[5]; + + assertNoProp(s, "hashCode", null); + } + + @KOTest + public void exposedWaitOfAJavaArray() { + Object s = new Object[5]; + + assertNoProp(s, "wait", null); + } + + @KOTest + public void exposedGetClassOfAJavaArray() { + Object s = new Object[5]; + + assertNoProp(s, "getClass", null); + } + + @KOTest + public void exposedNotifyOfAJavaArray() { + Object s = new Object[5]; + + assertNoProp(s, "notify", null); + } + + @KOTest + public void exposedNotifyAllOfAJavaArray() { + Object s = new Object[5]; + + assertNoProp(s, "notifyAll", null); + } + + @KOTest + public void exposedEqualsOfAJavaPrimitiveArray() { + Object s = new int[5]; + assertNoProp(s, "equals", s); + } + + @KOTest + public void exposedHashCodeOfAJavaPrimitiveArray() { + Object s = new int[5]; + + assertNoProp(s, "hashCode", null); + } + + @KOTest + public void exposedWaitOfAJavaPrimitiveArray() { + Object s = new int[5]; + + assertNoProp(s, "wait", null); + } + + @KOTest + public void exposedGetClassOfAJavaPrimitiveArray() { + Object s = new int[5]; + + assertNoProp(s, "getClass", null); + } + + @KOTest + public void exposedNotifyOfAJavaPrimitiveArray() { + Object s = new int[5]; + + assertNoProp(s, "notify", null); + } + + private static void assertNoProp(Object obj, String name, Object arg) { + Object prop = Bodies.get(obj, name); + assertNull(prop, "Expecting no value for property " + name + ", but was " + Bodies.typeof(prop, false)); + + try { + Object res = Bodies.invoke(obj, name, arg); + if (name.equals(res)) { + return; + } + fail("Invoking " + name + " on " + obj + " returned " + res); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java index 57e3083..86f15f4 100644 --- a/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java @@ -134,22 +134,6 @@ public class JavaScriptBodyTest { assertEquals("number", doubleType, "Expecting number type: " + doubleType); } - private static void assertNoProp(Object obj, String name, Object arg) { - Object prop = Bodies.get(obj, name); - assertNull(prop, "Expecting no value for property " + name + ", but was " + Bodies.typeof(prop, false)); - - try { - Object res = Bodies.invoke(obj, name, arg); - if (name.equals(res)) { - return; - } - fail("Invoking " + name + " on " + obj + " returned " + res); - } catch (Exception e) { - e.printStackTrace(); - } - - } - enum Two { ONE, TWO; } @@ -399,132 +383,6 @@ public class JavaScriptBodyTest { assertEquals(nullAndUnknown, 1, "Only one slot"); } - @KOTest - public void exposedPropertiesOfAJavaObject() { - Sum s = new Sum(); - Object[] props = Bodies.forIn(s); - - List<Object> all = Models.asList(props); - assertEquals(0, all.size(), "No own properties: " + all); - } - - - @KOTest - public void exposedEqualsOfAJavaObject() { - Sum s = new Sum(); - assertNoProp(s, "equals", s); - } - - @KOTest - public void exposedHashCodeOfAJavaObject() { - Sum s = new Sum(); - - assertNoProp(s, "hashCode", null); - } - - @KOTest - public void exposedWaitOfAJavaObject() { - Sum s = new Sum(); - - assertNoProp(s, "wait", null); - } - - @KOTest - public void exposedGetClassOfAJavaObject() { - Sum s = new Sum(); - - assertNoProp(s, "getClass", null); - } - - @KOTest - public void exposedNotifyOfAJavaObject() { - Sum s = new Sum(); - - assertNoProp(s, "notify", null); - } - - @KOTest - public void exposedNotifyAllOfAJavaObject() { - Sum s = new Sum(); - - assertNoProp(s, "notifyAll", null); - } - - @KOTest - public void exposedEqualsOfAJavaArray() { - Object s = new Object[5]; - assertNoProp(s, "equals", s); - } - - @KOTest - public void exposedHashCodeOfAJavaArray() { - Object s = new Object[5]; - - assertNoProp(s, "hashCode", null); - } - - @KOTest - public void exposedWaitOfAJavaArray() { - Object s = new Object[5]; - - assertNoProp(s, "wait", null); - } - - @KOTest - public void exposedGetClassOfAJavaArray() { - Object s = new Object[5]; - - assertNoProp(s, "getClass", null); - } - - @KOTest - public void exposedNotifyOfAJavaArray() { - Object s = new Object[5]; - - assertNoProp(s, "notify", null); - } - - @KOTest - public void exposedNotifyAllOfAJavaArray() { - Object s = new Object[5]; - - assertNoProp(s, "notifyAll", null); - } - - @KOTest - public void exposedEqualsOfAJavaPrimitiveArray() { - Object s = new int[5]; - assertNoProp(s, "equals", s); - } - - @KOTest - public void exposedHashCodeOfAJavaPrimitiveArray() { - Object s = new int[5]; - - assertNoProp(s, "hashCode", null); - } - - @KOTest - public void exposedWaitOfAJavaPrimitiveArray() { - Object s = new int[5]; - - assertNoProp(s, "wait", null); - } - - @KOTest - public void exposedGetClassOfAJavaPrimitiveArray() { - Object s = new int[5]; - - assertNoProp(s, "getClass", null); - } - - @KOTest - public void exposedNotifyOfAJavaPrimitiveArray() { - Object s = new int[5]; - - assertNoProp(s, "notify", null); - } - @KOTest public void problematicString() { String orig = Bodies.problematicString(); String js = Bodies.problematicCallback(); @@ -654,23 +512,24 @@ public class JavaScriptBodyTest { } throw new AssertionError("Expecting " + b + " but found " + a); } - private static void fail(String msg) { + + static void fail(String msg) { throw new AssertionError(msg); } - private static void assertTrue(boolean c, String msg) { + static void assertTrue(boolean c, String msg) { if (!c) { throw new AssertionError(msg); } } - private static void assertFalse(boolean c, String msg) { + static void assertFalse(boolean c, String msg) { if (c) { throw new AssertionError(msg); } } - private static void assertNull(Object o, String msg) { + static void assertNull(Object o, String msg) { if (o != null) { throw new AssertionError(msg); } diff --git a/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java b/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java index 84c7cec..09b8315 100644 --- a/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/JavaScriptTCK.java @@ -20,6 +20,7 @@ package org.netbeans.html.json.tck; import net.java.html.js.tests.GCBodyTest; import net.java.html.js.tests.JavaScriptBodyTest; +import net.java.html.js.tests.ExposedPropertiesTest; import org.netbeans.html.boot.spi.Fn; import org.netbeans.html.boot.spi.Fn.Presenter; @@ -42,7 +43,7 @@ public abstract class JavaScriptTCK { */ protected static Class<?>[] testClasses() { return new Class[] { - JavaScriptBodyTest.class, GCBodyTest.class + JavaScriptBodyTest.class, GCBodyTest.class, ExposedPropertiesTest.class }; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
