Skip to content

Commit e8262fa

Browse files
author
egandro
committed
added event listener test
1 parent a1ef11b commit e8262fa

6 files changed

+44
-1
lines changed

test/ListenerInterface.class

265 Bytes
Binary file not shown.

test/ListenerInterface.java

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public interface ListenerInterface {
2+
void onEvent(java.util.ArrayList<String> list, java.lang.Runtime runtime);
3+
}

test/ListenerTester.class

756 Bytes
Binary file not shown.

test/ListenerTester.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class ListenerTester {
2+
private ListenerInterface _listener;
3+
4+
public void setListener(ListenerInterface listener) {
5+
this._listener = listener;
6+
}
7+
8+
public void raiseEvent() {
9+
if(this._listener == null)
10+
return;
11+
12+
java.util.ArrayList<String> list = new java.util.ArrayList<String>();
13+
list.add("hello");
14+
list.add("from");
15+
list.add("Java");
16+
17+
this._listener.onEvent(list, java.lang.Runtime.getRuntime());
18+
}
19+
}

test/dynamicProxy-test.js

+18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ exports['Dynamic Proxy'] = nodeunit.testCase({
5454
test.done();
5555
},
5656

57+
"Listener test": function (test) {
58+
var runData = '';
59+
60+
var myProxy = java.newProxy('ListenerInterface', {
61+
onEvent: function (list, runtime) {
62+
runData = 'onEvent';
63+
}
64+
});
65+
66+
var listenerTester = java.newInstanceSync("ListenerTester");
67+
listenerTester.setListenerSync(myProxy);
68+
listenerTester.raiseEventSync();
69+
70+
test.equals(runData, 'onEvent');
71+
72+
test.done();
73+
},
74+
5775
"thread": function (test) {
5876
var callCount = 0;
5977

testRunner.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ var tests = glob.sync(path.join('testAsyncOptions', '*.js'));
1414
tests.unshift('test test8'); // Arrange to run the primary tests first, in a single process
1515

1616
function runTest(testArgs, done) {
17-
var cmd = 'node_modules/.bin/nodeunit ' + testArgs;
17+
var cmd = 'node_modules/.bin/nodeunit ';
18+
if(process.platform == "win32")
19+
cmd = 'node_modules\\.bin\\nodeunit ';
20+
cmd += testArgs;
1821
childProcess.exec(cmd, function (error, stdout, stderr) {
1922
// It appears that nodeunit merges error output into the stdout
2023
// so these three lines are probably useless.

0 commit comments

Comments
 (0)