You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2020/12/26 14:40:04 UTC
[netbeans-html4j] 09/25: Separating generic TCK into its own class
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/netbeans-html4j.git
commit 6e6cca878662de0f5dfa2c54a097b67232a09c13
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Tue Dec 22 07:25:25 2020 +0100
Separating generic TCK into its own class
---
.../html/presenters/spi/test/CallbackTest.java | 7 +---
.../html/presenters/spi/test/GenericTCK.java | 32 ++++++++++++++
.../html/presenters/spi/test/GenericTest.java | 21 +---------
.../html/presenters/spi/test/SynchronizedTest.java | 36 +++++++++++++++-
.../netbeans/html/presenters/spi/test/Testing.java | 49 +++-------------------
5 files changed, 75 insertions(+), 70 deletions(-)
diff --git a/generic/src/test/java/org/netbeans/html/presenters/spi/test/CallbackTest.java b/generic/src/test/java/org/netbeans/html/presenters/spi/test/CallbackTest.java
index 9aa2aeb..cdf0341 100644
--- a/generic/src/test/java/org/netbeans/html/presenters/spi/test/CallbackTest.java
+++ b/generic/src/test/java/org/netbeans/html/presenters/spi/test/CallbackTest.java
@@ -19,7 +19,6 @@
package org.netbeans.html.presenters.spi.test;
import java.lang.reflect.Method;
-import java.util.concurrent.CountDownLatch;
import java.util.logging.Level;
import javax.script.ScriptException;
import static org.testng.Assert.assertEquals;
@@ -39,7 +38,7 @@ public class CallbackTest {
private static final class CBP extends Testing {
@Override
- protected void loadJS(String js, CountDownLatch notify) {
+ protected void loadJS(String js) {
dispatch(new Runnable () {
@Override
public void run() {
@@ -48,12 +47,10 @@ public class CallbackTest {
LOG.log(Level.FINE, "counter res: {0}", res);
} catch (ScriptException ex) {
LOG.log(Level.SEVERE, null, ex);
- } finally {
- notify.countDown();
}
}
});
- super.loadJS(js, notify);
+ super.loadJS(js);
}
@Override void beforeTest(Class<?> testClass) throws Exception {
diff --git a/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTCK.java b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTCK.java
new file mode 100644
index 0000000..cd8a87e
--- /dev/null
+++ b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTCK.java
@@ -0,0 +1,32 @@
+package org.netbeans.html.presenters.spi.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.netbeans.html.boot.spi.Fn;
+import org.netbeans.html.json.tck.JavaScriptTCK;
+import org.netbeans.html.presenters.spi.ProtoPresenter;
+import static org.testng.Assert.assertNotNull;
+
+final class GenericTCK extends JavaScriptTCK {
+ static final GenericTCK INSTANCE = new GenericTCK();
+
+ private final Map<ProtoPresenter, Testing> MAP = new HashMap<>();
+ private GenericTCK() {
+ }
+
+ @Override
+ public boolean executeNow(String script) throws Exception {
+ Testing t = MAP.get(Fn.activePresenter());
+ assertNotNull(t, "Testing framework found");
+ return t.sync ? t.eng.eval(script) != this : false;
+ }
+
+ public static Class[] tests() {
+ return testClasses();
+ }
+
+ void register(ProtoPresenter presenter, Testing testing) {
+ MAP.put(presenter, testing);
+ }
+
+}
diff --git a/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java
index 9999365..668d127 100644
--- a/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java
+++ b/generic/src/test/java/org/netbeans/html/presenters/spi/test/GenericTest.java
@@ -22,17 +22,13 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
import net.java.html.boot.BrowserBuilder;
import org.netbeans.html.boot.spi.Fn;
-import org.netbeans.html.json.tck.JavaScriptTCK;
import org.netbeans.html.json.tck.KOTest;
-import static org.testng.Assert.assertNotNull;
import org.testng.annotations.Factory;
-public class GenericTest extends JavaScriptTCK {
+public class GenericTest {
private static Class<?> browserClass;
public GenericTest() {
@@ -76,19 +72,6 @@ public class GenericTest extends JavaScriptTCK {
}
}
- @Override
- public void executeNow(String script) throws Exception {
- Testing t = Testing.MAP.get(Fn.activePresenter());
- assertNotNull(t, "Testing framework found");
- CountDownLatch cdl = new CountDownLatch(1);
- t.loadJS(script, cdl);
- cdl.await(5, TimeUnit.SECONDS);
- }
-
- public static Class[] tests() {
- return testClasses();
- }
-
static synchronized Class<?> loadClass() throws InterruptedException {
while (browserClass == null) {
GenericTest.class.wait();
@@ -104,6 +87,6 @@ public class GenericTest extends JavaScriptTCK {
public static void initialized() throws Exception {
Class<?> classpathClass = ClassLoader.getSystemClassLoader().loadClass(GenericTest.class.getName());
Method m = classpathClass.getMethod("ready", Class.class);
- m.invoke(null, GenericTest.class);
+ m.invoke(null, GenericTCK.class);
}
}
diff --git a/generic/src/test/java/org/netbeans/html/presenters/spi/test/SynchronizedTest.java b/generic/src/test/java/org/netbeans/html/presenters/spi/test/SynchronizedTest.java
index fe7b3cb..cf20bad 100644
--- a/generic/src/test/java/org/netbeans/html/presenters/spi/test/SynchronizedTest.java
+++ b/generic/src/test/java/org/netbeans/html/presenters/spi/test/SynchronizedTest.java
@@ -18,12 +18,44 @@
*/
package org.netbeans.html.presenters.spi.test;
+import java.net.URL;
+import java.util.logging.Level;
import static org.netbeans.html.presenters.spi.test.GenericTest.createTests;
+import static org.netbeans.html.presenters.spi.test.Testing.LOG;
import org.testng.annotations.Factory;
public class SynchronizedTest {
@Factory public static Object[] compatibilityTests() throws Exception {
- return createTests(new Testing.Synchronized());
+ return createTests(new Synchronized());
}
-
+
+ private static class Synchronized extends Testing {
+ public Synchronized() {
+ super(true, (r) -> r.run());
+ }
+
+ @Override
+ protected void loadJS(final String js) {
+ try {
+ Object res = eng.eval(js);
+ LOG.log(Level.FINE, "Result: {0}", res);
+ } catch (Throwable ex) {
+ LOG.log(Level.SEVERE, "Can't process " + js, ex);
+ }
+ }
+
+ @Override
+ public void displayPage(URL url, Runnable r) {
+ r.run();
+ }
+
+ @Override
+ public void dispatch(Runnable r) {
+ r.run();
+ }
+
+ @Override
+ void beforeTest(Class<?> declaringClass) throws Exception {
+ }
+ } // end of Synchronized
}
diff --git a/generic/src/test/java/org/netbeans/html/presenters/spi/test/Testing.java b/generic/src/test/java/org/netbeans/html/presenters/spi/test/Testing.java
index ccab68a..da3bb7b 100644
--- a/generic/src/test/java/org/netbeans/html/presenters/spi/test/Testing.java
+++ b/generic/src/test/java/org/netbeans/html/presenters/spi/test/Testing.java
@@ -19,9 +19,6 @@
package org.netbeans.html.presenters.spi.test;
import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.logging.Level;
@@ -39,7 +36,6 @@ class Testing {
final ScriptEngine eng;
final boolean sync;
final ProtoPresenter presenter;
- static final Map<ProtoPresenter, Testing> MAP = new HashMap<>();
public Testing() {
this(false);
@@ -55,14 +51,12 @@ class Testing {
.app("Testing")
.type("test")
.dispatcher(QUEUE, false)
- .loadJavaScript((s) -> {
- loadJS(s, new java.util.concurrent.CountDownLatch(1));
- }, sync)
+ .loadJavaScript(this::loadJS, sync)
.displayer(this::displayPage)
.preparator(this::callbackFn, true)
.logger(this::log)
.build();
- MAP.put(this.presenter, this);
+ GenericTCK.INSTANCE.register(this.presenter, this);
ScriptEngineManager sem = new ScriptEngineManager();
eng = sem.getEngineByMimeType("text/javascript");
@@ -71,7 +65,8 @@ class Testing {
eng.eval("function alert(m) { Packages.java.lang.System.out.println(m); };");
} catch (ScriptException ex) {
throw new IllegalStateException(ex);
- }
+ }
+
}
protected void log(int priority, String msg, Object... args) {
@@ -127,7 +122,7 @@ class Testing {
ready.callbackIsPrepared("testingCB");
}
- protected void loadJS(final String js, CountDownLatch notify) {
+ protected void loadJS(final String js) {
QUEUE.execute(new Runnable() {
public void run() {
try {
@@ -135,8 +130,6 @@ class Testing {
LOG.log(Level.FINE, "Result: {0}", res);
} catch (Throwable ex) {
LOG.log(Level.SEVERE, "Can't process " + js, ex);
- } finally {
- notify.countDown();
}
}
});
@@ -152,36 +145,4 @@ class Testing {
void beforeTest(Class<?> declaringClass) throws Exception {
}
-
- static class Synchronized extends Testing {
- public Synchronized() {
- super(true, (r) -> r.run());
- }
-
- @Override
- protected void loadJS(final String js, CountDownLatch notify) {
- try {
- Object res = eng.eval(js);
- LOG.log(Level.FINE, "Result: {0}", res);
- } catch (Throwable ex) {
- LOG.log(Level.SEVERE, "Can't process " + js, ex);
- } finally {
- notify.countDown();
- }
- }
-
- @Override
- public void displayPage(URL url, Runnable r) {
- r.run();
- }
-
- @Override
- public void dispatch(Runnable r) {
- r.run();
- }
-
- @Override
- void beforeTest(Class<?> declaringClass) throws Exception {
- }
- } // end of Synchronized
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists