forked from joeferner/node-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimportClass-test.js
More file actions
68 lines (56 loc) · 2.06 KB
/
importClass-test.js
File metadata and controls
68 lines (56 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
var java = require("../testHelpers").java;
var nodeunit = require("nodeunit");
var util = require("util");
var _ = require("lodash");
exports['Import Class'] = nodeunit.testCase({
tearDown: function (callback) {
java.setStaticFieldValue("Test", "staticFieldInt", 42);
callback();
},
"import": function (test) {
var Test = java.import('Test');
test.equals(42, Test.staticFieldInt);
Test.staticFieldInt = 200;
test.equals(200, Test.staticFieldInt);
test.equals(100, Test.staticMethodSync(99));
Test.staticMethod(99, function (err, result) {
test.ok(!err);
test.equals(100, result);
var testObj = new Test(5);
test.equals(5, testObj.getIntSync());
test.done();
});
},
"import TestEnum with unsable name": function (test) {
test.expect(5);
var TestEnum = java.import('Test$Enum');
// 'foo' and 'bar' are valid enum names
test.strictEqual(TestEnum.foo.toStringSync(), "foo");
test.strictEqual(TestEnum.bar.toStringSync(), "bar");
_.forEach(['name', 'arguments', 'caller'], function(prop) {
test.throws(
function() {
// The enum also defines 'name', 'caller', and 'attributes', but Javascript prevents us from using them,
// since these are unwritable properties of Function.
var x = TestEnum[prop].toStringSync();
},
TypeError
);
});
test.done();
},
"import TestEnum and use alternate name": function (test) {
test.expect(5);
var TestEnum = java.import('Test$Enum');
// 'foo' and 'bar' are valid enum names
test.strictEqual(TestEnum.foo.toStringSync(), "foo");
test.strictEqual(TestEnum.bar.toStringSync(), "bar");
// 'name', 'caller', and 'arguments' are not, so we must use e.g. 'name_' to reference the enum.
// But note that the value is still e.g. "name".
test.strictEqual(TestEnum.name_.toStringSync(), "name");
test.strictEqual(TestEnum.arguments_.toStringSync(), "arguments");
test.strictEqual(TestEnum.caller_.toStringSync(), "caller");
test.done();
}
});