@@ 2-213 (lines=212) @@ | ||
1 | // spec/NoSuchElementException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const NoSuchElementException = require(path.join(root, "NoSuchElementException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the NoSuchElementException 'class' |
|
19 | describe("NoSuchElementException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new NoSuchElementException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new NoSuchElementException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new NoSuchElementException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new NoSuchElementException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(NoSuchElementException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(NoSuchElementException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(NoSuchElementException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(NoSuchElementException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(NoSuchElementException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(NoSuchElementException.prototype.name).toEqual("NoSuchElementException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(NoSuchElementException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(NoSuchElementException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new NoSuchElementException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new NoSuchElementException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, NoSuchElementException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new NoSuchElementException(arg1)); |
|
100 | test2 = (() => new NoSuchElementException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new NoSuchElementException(arg1, arg2)); |
|
118 | test21 = (() => new NoSuchElementException(null, arg2)); |
|
119 | test11 = (() => new NoSuchElementException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new NoSuchElementException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new NoSuchElementException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(NoSuchElementException.prototype.message); |
|
151 | expect(source2.message).toEqual(NoSuchElementException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "NoSuchElementException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new NoSuchElementException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new NoSuchElementException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "NoSuchElementException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + NoSuchElementException.prototype.message + '.'; |
|
188 | exp2 += ": " + NoSuchElementException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new NoSuchElementException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new NoSuchElementException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : NoSuchElementException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/UnsupportedOperationException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const UnsupportedOperationException = require(path.join(root, "UnsupportedOperationException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the UnsupportedOperationException 'class' |
|
19 | describe("UnsupportedOperationException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new UnsupportedOperationException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new UnsupportedOperationException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new UnsupportedOperationException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new UnsupportedOperationException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(UnsupportedOperationException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(UnsupportedOperationException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(UnsupportedOperationException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(UnsupportedOperationException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(UnsupportedOperationException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(UnsupportedOperationException.prototype.name).toEqual("UnsupportedOperationException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(UnsupportedOperationException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(UnsupportedOperationException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new UnsupportedOperationException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new UnsupportedOperationException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, UnsupportedOperationException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new UnsupportedOperationException(arg1)); |
|
100 | test2 = (() => new UnsupportedOperationException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new UnsupportedOperationException(arg1, arg2)); |
|
118 | test21 = (() => new UnsupportedOperationException(null, arg2)); |
|
119 | test11 = (() => new UnsupportedOperationException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new UnsupportedOperationException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new UnsupportedOperationException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(UnsupportedOperationException.prototype.message); |
|
151 | expect(source2.message).toEqual(UnsupportedOperationException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "UnsupportedOperationException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new UnsupportedOperationException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new UnsupportedOperationException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "UnsupportedOperationException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + UnsupportedOperationException.prototype.message + '.'; |
|
188 | exp2 += ": " + UnsupportedOperationException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new UnsupportedOperationException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new UnsupportedOperationException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : UnsupportedOperationException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/IllegalArgumentException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const IllegalArgumentException = require(path.join(root, "IllegalArgumentException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the IllegalArgumentException 'class' |
|
19 | describe("IllegalArgumentException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new IllegalArgumentException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new IllegalArgumentException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new IllegalArgumentException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new IllegalArgumentException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(IllegalArgumentException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(IllegalArgumentException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(IllegalArgumentException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(IllegalArgumentException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(IllegalArgumentException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(IllegalArgumentException.prototype.name).toEqual("IllegalArgumentException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(IllegalArgumentException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(IllegalArgumentException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new IllegalArgumentException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new IllegalArgumentException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, IllegalArgumentException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new IllegalArgumentException(arg1)); |
|
100 | test2 = (() => new IllegalArgumentException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new IllegalArgumentException(arg1, arg2)); |
|
118 | test21 = (() => new IllegalArgumentException(null, arg2)); |
|
119 | test11 = (() => new IllegalArgumentException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new IllegalArgumentException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new IllegalArgumentException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(IllegalArgumentException.prototype.message); |
|
151 | expect(source2.message).toEqual(IllegalArgumentException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "IllegalArgumentException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new IllegalArgumentException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new IllegalArgumentException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "IllegalArgumentException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + IllegalArgumentException.prototype.message + '.'; |
|
188 | exp2 += ": " + IllegalArgumentException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new IllegalArgumentException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new IllegalArgumentException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : IllegalArgumentException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/NullPointerException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const NullPointerException = require(path.join(root, "NullPointerException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the NullPointerException 'class' |
|
19 | describe("NullPointerException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new NullPointerException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new NullPointerException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new NullPointerException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new NullPointerException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(NullPointerException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(NullPointerException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(NullPointerException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(NullPointerException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(NullPointerException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(NullPointerException.prototype.name).toEqual("NullPointerException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(NullPointerException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(NullPointerException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new NullPointerException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new NullPointerException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, NullPointerException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new NullPointerException(arg1)); |
|
100 | test2 = (() => new NullPointerException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new NullPointerException(arg1, arg2)); |
|
118 | test21 = (() => new NullPointerException(null, arg2)); |
|
119 | test11 = (() => new NullPointerException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new NullPointerException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new NullPointerException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(NullPointerException.prototype.message); |
|
151 | expect(source2.message).toEqual(NullPointerException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "NullPointerException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new NullPointerException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new NullPointerException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "NullPointerException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + NullPointerException.prototype.message + '.'; |
|
188 | exp2 += ": " + NullPointerException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new NullPointerException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new NullPointerException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : NullPointerException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/CompletionException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const CompletionException = require(path.join(root, "CompletionException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the CompletionException 'class' |
|
19 | describe("CompletionException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new CompletionException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new CompletionException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new CompletionException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new CompletionException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(CompletionException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(CompletionException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(CompletionException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(CompletionException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(CompletionException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(CompletionException.prototype.name).toEqual("CompletionException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(CompletionException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(CompletionException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new CompletionException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new CompletionException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, CompletionException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new CompletionException(arg1)); |
|
100 | test2 = (() => new CompletionException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new CompletionException(arg1, arg2)); |
|
118 | test21 = (() => new CompletionException(null, arg2)); |
|
119 | test11 = (() => new CompletionException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new CompletionException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new CompletionException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(CompletionException.prototype.message); |
|
151 | expect(source2.message).toEqual(CompletionException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "CompletionException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new CompletionException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new CompletionException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "CompletionException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + CompletionException.prototype.message + '.'; |
|
188 | exp2 += ": " + CompletionException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new CompletionException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new CompletionException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : CompletionException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/IndexOutOfBoundsException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const IndexOutOfBoundsException = require(path.join(root, "IndexOutOfBoundsException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the IndexOutOfBoundsException 'class' |
|
19 | describe("IndexOutOfBoundsException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new IndexOutOfBoundsException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new IndexOutOfBoundsException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new IndexOutOfBoundsException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new IndexOutOfBoundsException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(IndexOutOfBoundsException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(IndexOutOfBoundsException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(IndexOutOfBoundsException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(IndexOutOfBoundsException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(IndexOutOfBoundsException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(IndexOutOfBoundsException.prototype.name).toEqual("IndexOutOfBoundsException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(IndexOutOfBoundsException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(IndexOutOfBoundsException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new IndexOutOfBoundsException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new IndexOutOfBoundsException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, IndexOutOfBoundsException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new IndexOutOfBoundsException(arg1)); |
|
100 | test2 = (() => new IndexOutOfBoundsException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new IndexOutOfBoundsException(arg1, arg2)); |
|
118 | test21 = (() => new IndexOutOfBoundsException(null, arg2)); |
|
119 | test11 = (() => new IndexOutOfBoundsException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new IndexOutOfBoundsException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new IndexOutOfBoundsException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(IndexOutOfBoundsException.prototype.message); |
|
151 | expect(source2.message).toEqual(IndexOutOfBoundsException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "IndexOutOfBoundsException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new IndexOutOfBoundsException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new IndexOutOfBoundsException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "IndexOutOfBoundsException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + IndexOutOfBoundsException.prototype.message + '.'; |
|
188 | exp2 += ": " + IndexOutOfBoundsException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new IndexOutOfBoundsException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new IndexOutOfBoundsException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : IndexOutOfBoundsException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/BufferOverflowException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const BufferOverflowException = require(path.join(root, "BufferOverflowException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the BufferOverflowException 'class' |
|
19 | describe("BufferOverflowException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new BufferOverflowException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new BufferOverflowException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new BufferOverflowException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new BufferOverflowException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(BufferOverflowException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(BufferOverflowException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(BufferOverflowException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(BufferOverflowException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(BufferOverflowException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(BufferOverflowException.prototype.name).toEqual("BufferOverflowException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(BufferOverflowException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(BufferOverflowException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new BufferOverflowException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new BufferOverflowException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, BufferOverflowException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new BufferOverflowException(arg1)); |
|
100 | test2 = (() => new BufferOverflowException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new BufferOverflowException(arg1, arg2)); |
|
118 | test21 = (() => new BufferOverflowException(null, arg2)); |
|
119 | test11 = (() => new BufferOverflowException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new BufferOverflowException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new BufferOverflowException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(BufferOverflowException.prototype.message); |
|
151 | expect(source2.message).toEqual(BufferOverflowException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "BufferOverflowException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new BufferOverflowException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new BufferOverflowException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "BufferOverflowException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + BufferOverflowException.prototype.message + '.'; |
|
188 | exp2 += ": " + BufferOverflowException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new BufferOverflowException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new BufferOverflowException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : BufferOverflowException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/NegativeArraySizeException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const NegativeArraySizeException = require(path.join(root, "NegativeArraySizeException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the NegativeArraySizeException 'class' |
|
19 | describe("NegativeArraySizeException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new NegativeArraySizeException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new NegativeArraySizeException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new NegativeArraySizeException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new NegativeArraySizeException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(NegativeArraySizeException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(NegativeArraySizeException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(NegativeArraySizeException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(NegativeArraySizeException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(NegativeArraySizeException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(NegativeArraySizeException.prototype.name).toEqual("NegativeArraySizeException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(NegativeArraySizeException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(NegativeArraySizeException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new NegativeArraySizeException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new NegativeArraySizeException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, NegativeArraySizeException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new NegativeArraySizeException(arg1)); |
|
100 | test2 = (() => new NegativeArraySizeException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new NegativeArraySizeException(arg1, arg2)); |
|
118 | test21 = (() => new NegativeArraySizeException(null, arg2)); |
|
119 | test11 = (() => new NegativeArraySizeException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new NegativeArraySizeException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new NegativeArraySizeException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(NegativeArraySizeException.prototype.message); |
|
151 | expect(source2.message).toEqual(NegativeArraySizeException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "NegativeArraySizeException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new NegativeArraySizeException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new NegativeArraySizeException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "NegativeArraySizeException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + NegativeArraySizeException.prototype.message + '.'; |
|
188 | exp2 += ": " + NegativeArraySizeException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new NegativeArraySizeException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new NegativeArraySizeException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : NegativeArraySizeException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/BufferUnderflowException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const BufferUnderflowException = require(path.join(root, "BufferUnderflowException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the BufferUnderflowException 'class' |
|
19 | describe("BufferUnderflowException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new BufferUnderflowException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new BufferUnderflowException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new BufferUnderflowException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new BufferUnderflowException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(BufferUnderflowException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(BufferUnderflowException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(BufferUnderflowException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(BufferUnderflowException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(BufferUnderflowException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(BufferUnderflowException.prototype.name).toEqual("BufferUnderflowException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(BufferUnderflowException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(BufferUnderflowException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new BufferUnderflowException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new BufferUnderflowException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, BufferUnderflowException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new BufferUnderflowException(arg1)); |
|
100 | test2 = (() => new BufferUnderflowException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new BufferUnderflowException(arg1, arg2)); |
|
118 | test21 = (() => new BufferUnderflowException(null, arg2)); |
|
119 | test11 = (() => new BufferUnderflowException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new BufferUnderflowException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new BufferUnderflowException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(BufferUnderflowException.prototype.message); |
|
151 | expect(source2.message).toEqual(BufferUnderflowException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "BufferUnderflowException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new BufferUnderflowException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new BufferUnderflowException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "BufferUnderflowException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + BufferUnderflowException.prototype.message + '.'; |
|
188 | exp2 += ": " + BufferUnderflowException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new BufferUnderflowException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new BufferUnderflowException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : BufferUnderflowException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/EmptyStackException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const EmptyStackException = require(path.join(root, "EmptyStackException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the EmptyStackException 'class' |
|
19 | describe("EmptyStackException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new EmptyStackException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new EmptyStackException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new EmptyStackException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new EmptyStackException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(EmptyStackException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(EmptyStackException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(EmptyStackException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(EmptyStackException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(EmptyStackException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(EmptyStackException.prototype.name).toEqual("EmptyStackException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(EmptyStackException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(EmptyStackException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new EmptyStackException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new EmptyStackException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, EmptyStackException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new EmptyStackException(arg1)); |
|
100 | test2 = (() => new EmptyStackException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new EmptyStackException(arg1, arg2)); |
|
118 | test21 = (() => new EmptyStackException(null, arg2)); |
|
119 | test11 = (() => new EmptyStackException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new EmptyStackException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new EmptyStackException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(EmptyStackException.prototype.message); |
|
151 | expect(source2.message).toEqual(EmptyStackException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "EmptyStackException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new EmptyStackException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new EmptyStackException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "EmptyStackException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + EmptyStackException.prototype.message + '.'; |
|
188 | exp2 += ": " + EmptyStackException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new EmptyStackException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new EmptyStackException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : EmptyStackException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/MissingResourceException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const MissingResourceException = require(path.join(root, "MissingResourceException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the MissingResourceException 'class' |
|
19 | describe("MissingResourceException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new MissingResourceException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new MissingResourceException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new MissingResourceException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new MissingResourceException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(MissingResourceException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(MissingResourceException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(MissingResourceException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(MissingResourceException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(MissingResourceException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(MissingResourceException.prototype.name).toEqual("MissingResourceException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(MissingResourceException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(MissingResourceException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new MissingResourceException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new MissingResourceException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, MissingResourceException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new MissingResourceException(arg1)); |
|
100 | test2 = (() => new MissingResourceException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new MissingResourceException(arg1, arg2)); |
|
118 | test21 = (() => new MissingResourceException(null, arg2)); |
|
119 | test11 = (() => new MissingResourceException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new MissingResourceException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new MissingResourceException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(MissingResourceException.prototype.message); |
|
151 | expect(source2.message).toEqual(MissingResourceException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "MissingResourceException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new MissingResourceException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new MissingResourceException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "MissingResourceException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + MissingResourceException.prototype.message + '.'; |
|
188 | exp2 += ": " + MissingResourceException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new MissingResourceException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new MissingResourceException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : MissingResourceException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/DateTimeException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const DateTimeException = require(path.join(root, "DateTimeException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the DateTimeException 'class' |
|
19 | describe("DateTimeException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new DateTimeException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new DateTimeException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new DateTimeException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new DateTimeException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(DateTimeException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(DateTimeException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(DateTimeException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(DateTimeException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(DateTimeException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(DateTimeException.prototype.name).toEqual("DateTimeException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(DateTimeException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(DateTimeException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new DateTimeException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new DateTimeException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, DateTimeException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new DateTimeException(arg1)); |
|
100 | test2 = (() => new DateTimeException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new DateTimeException(arg1, arg2)); |
|
118 | test21 = (() => new DateTimeException(null, arg2)); |
|
119 | test11 = (() => new DateTimeException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new DateTimeException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new DateTimeException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(DateTimeException.prototype.message); |
|
151 | expect(source2.message).toEqual(DateTimeException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "DateTimeException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new DateTimeException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new DateTimeException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "DateTimeException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + DateTimeException.prototype.message + '.'; |
|
188 | exp2 += ": " + DateTimeException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new DateTimeException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new DateTimeException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : DateTimeException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/ConcurrentModificationException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const ConcurrentModificationException = require(path.join(root, "ConcurrentModificationException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the ConcurrentModificationException 'class' |
|
19 | describe("ConcurrentModificationException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new ConcurrentModificationException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new ConcurrentModificationException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new ConcurrentModificationException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new ConcurrentModificationException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(ConcurrentModificationException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(ConcurrentModificationException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(ConcurrentModificationException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(ConcurrentModificationException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(ConcurrentModificationException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(ConcurrentModificationException.prototype.name).toEqual("ConcurrentModificationException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(ConcurrentModificationException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(ConcurrentModificationException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new ConcurrentModificationException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new ConcurrentModificationException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, ConcurrentModificationException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new ConcurrentModificationException(arg1)); |
|
100 | test2 = (() => new ConcurrentModificationException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new ConcurrentModificationException(arg1, arg2)); |
|
118 | test21 = (() => new ConcurrentModificationException(null, arg2)); |
|
119 | test11 = (() => new ConcurrentModificationException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new ConcurrentModificationException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new ConcurrentModificationException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(ConcurrentModificationException.prototype.message); |
|
151 | expect(source2.message).toEqual(ConcurrentModificationException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "ConcurrentModificationException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new ConcurrentModificationException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new ConcurrentModificationException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "ConcurrentModificationException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + ConcurrentModificationException.prototype.message + '.'; |
|
188 | exp2 += ": " + ConcurrentModificationException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new ConcurrentModificationException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new ConcurrentModificationException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : ConcurrentModificationException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/ZoneRulesException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const DateTimeException = require(path.join(root, "DateTimeException.js")); |
|
15 | const ZoneRulesException = require(path.join(root, "ZoneRulesException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the ZoneRulesException 'class' |
|
20 | describe("ZoneRulesException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new ZoneRulesException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new ZoneRulesException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new ZoneRulesException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new ZoneRulesException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'DateTimeException'", () => { |
|
41 | expect(new ZoneRulesException()).toEqual(jasmine.any(DateTimeException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(ZoneRulesException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(ZoneRulesException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(ZoneRulesException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(ZoneRulesException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(ZoneRulesException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(ZoneRulesException.prototype.name).toEqual("ZoneRulesException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(ZoneRulesException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(ZoneRulesException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new ZoneRulesException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new ZoneRulesException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, ZoneRulesException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new ZoneRulesException(arg1)); |
|
105 | test2 = (() => new ZoneRulesException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new ZoneRulesException(arg1, arg2)); |
|
123 | test21 = (() => new ZoneRulesException(null, arg2)); |
|
124 | test11 = (() => new ZoneRulesException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new ZoneRulesException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new ZoneRulesException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(ZoneRulesException.prototype.message); |
|
156 | expect(source2.message).toEqual(ZoneRulesException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "ZoneRulesException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new ZoneRulesException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new ZoneRulesException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "ZoneRulesException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + ZoneRulesException.prototype.message + '.'; |
|
193 | exp2 += ": " + ZoneRulesException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new ZoneRulesException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new ZoneRulesException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : ZoneRulesException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/DateTimeParseException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const DateTimeException = require(path.join(root, "DateTimeException.js")); |
|
15 | const DateTimeParseException = require(path.join(root, "DateTimeParseException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the DateTimeParseException 'class' |
|
20 | describe("DateTimeParseException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new DateTimeParseException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new DateTimeParseException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new DateTimeParseException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new DateTimeParseException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'DateTimeException'", () => { |
|
41 | expect(new DateTimeParseException()).toEqual(jasmine.any(DateTimeException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(DateTimeParseException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(DateTimeParseException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(DateTimeParseException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(DateTimeParseException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(DateTimeParseException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(DateTimeParseException.prototype.name).toEqual("DateTimeParseException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(DateTimeParseException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(DateTimeParseException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new DateTimeParseException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new DateTimeParseException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, DateTimeParseException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new DateTimeParseException(arg1)); |
|
105 | test2 = (() => new DateTimeParseException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new DateTimeParseException(arg1, arg2)); |
|
123 | test21 = (() => new DateTimeParseException(null, arg2)); |
|
124 | test11 = (() => new DateTimeParseException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new DateTimeParseException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new DateTimeParseException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(DateTimeParseException.prototype.message); |
|
156 | expect(source2.message).toEqual(DateTimeParseException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "DateTimeParseException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new DateTimeParseException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new DateTimeParseException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "DateTimeParseException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + DateTimeParseException.prototype.message + '.'; |
|
193 | exp2 += ": " + DateTimeParseException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new DateTimeParseException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new DateTimeParseException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : DateTimeParseException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/IllegalCharsetNameException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const IllegalArgumentException = require(path.join(root, "IllegalArgumentException.js")); |
|
15 | const IllegalCharsetNameException = require(path.join(root, "IllegalCharsetNameException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the IllegalCharsetNameException 'class' |
|
20 | describe("IllegalCharsetNameException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new IllegalCharsetNameException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new IllegalCharsetNameException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new IllegalCharsetNameException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new IllegalCharsetNameException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'IllegalArgumentException'", () => { |
|
41 | expect(new IllegalCharsetNameException()).toEqual(jasmine.any(IllegalArgumentException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(IllegalCharsetNameException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(IllegalCharsetNameException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(IllegalCharsetNameException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(IllegalCharsetNameException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(IllegalCharsetNameException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(IllegalCharsetNameException.prototype.name).toEqual("IllegalCharsetNameException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(IllegalCharsetNameException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(IllegalCharsetNameException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new IllegalCharsetNameException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new IllegalCharsetNameException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, IllegalCharsetNameException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new IllegalCharsetNameException(arg1)); |
|
105 | test2 = (() => new IllegalCharsetNameException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new IllegalCharsetNameException(arg1, arg2)); |
|
123 | test21 = (() => new IllegalCharsetNameException(null, arg2)); |
|
124 | test11 = (() => new IllegalCharsetNameException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new IllegalCharsetNameException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new IllegalCharsetNameException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(IllegalCharsetNameException.prototype.message); |
|
156 | expect(source2.message).toEqual(IllegalCharsetNameException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "IllegalCharsetNameException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new IllegalCharsetNameException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new IllegalCharsetNameException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "IllegalCharsetNameException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + IllegalCharsetNameException.prototype.message + '.'; |
|
193 | exp2 += ": " + IllegalCharsetNameException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new IllegalCharsetNameException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new IllegalCharsetNameException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : IllegalCharsetNameException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/ReadOnlyBufferException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const UnsupportedOperationException = require(path.join(root, "UnsupportedOperationException.js")); |
|
15 | const ReadOnlyBufferException = require(path.join(root, "ReadOnlyBufferException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the ReadOnlyBufferException 'class' |
|
20 | describe("ReadOnlyBufferException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new ReadOnlyBufferException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new ReadOnlyBufferException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new ReadOnlyBufferException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new ReadOnlyBufferException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'UnsupportedOperationException'", () => { |
|
41 | expect(new ReadOnlyBufferException()).toEqual(jasmine.any(UnsupportedOperationException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(ReadOnlyBufferException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(ReadOnlyBufferException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(ReadOnlyBufferException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(ReadOnlyBufferException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(ReadOnlyBufferException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(ReadOnlyBufferException.prototype.name).toEqual("ReadOnlyBufferException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(ReadOnlyBufferException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(ReadOnlyBufferException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new ReadOnlyBufferException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new ReadOnlyBufferException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, ReadOnlyBufferException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new ReadOnlyBufferException(arg1)); |
|
105 | test2 = (() => new ReadOnlyBufferException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new ReadOnlyBufferException(arg1, arg2)); |
|
123 | test21 = (() => new ReadOnlyBufferException(null, arg2)); |
|
124 | test11 = (() => new ReadOnlyBufferException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new ReadOnlyBufferException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new ReadOnlyBufferException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(ReadOnlyBufferException.prototype.message); |
|
156 | expect(source2.message).toEqual(ReadOnlyBufferException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "ReadOnlyBufferException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new ReadOnlyBufferException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new ReadOnlyBufferException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "ReadOnlyBufferException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + ReadOnlyBufferException.prototype.message + '.'; |
|
193 | exp2 += ": " + ReadOnlyBufferException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new ReadOnlyBufferException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new ReadOnlyBufferException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : ReadOnlyBufferException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/StringIndexOutOfBoundsException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const IndexOutOfBoundsException = require(path.join(root, "IndexOutOfBoundsException.js")); |
|
15 | const StringIndexOutOfBoundsException = require(path.join(root, "StringIndexOutOfBoundsException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the StringIndexOutOfBoundsException 'class' |
|
20 | describe("StringIndexOutOfBoundsException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new StringIndexOutOfBoundsException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new StringIndexOutOfBoundsException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new StringIndexOutOfBoundsException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new StringIndexOutOfBoundsException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'IndexOutOfBoundsException'", () => { |
|
41 | expect(new StringIndexOutOfBoundsException()).toEqual(jasmine.any(IndexOutOfBoundsException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(StringIndexOutOfBoundsException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(StringIndexOutOfBoundsException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(StringIndexOutOfBoundsException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(StringIndexOutOfBoundsException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(StringIndexOutOfBoundsException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(StringIndexOutOfBoundsException.prototype.name).toEqual("StringIndexOutOfBoundsException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(StringIndexOutOfBoundsException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(StringIndexOutOfBoundsException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new StringIndexOutOfBoundsException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new StringIndexOutOfBoundsException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, StringIndexOutOfBoundsException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new StringIndexOutOfBoundsException(arg1)); |
|
105 | test2 = (() => new StringIndexOutOfBoundsException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new StringIndexOutOfBoundsException(arg1, arg2)); |
|
123 | test21 = (() => new StringIndexOutOfBoundsException(null, arg2)); |
|
124 | test11 = (() => new StringIndexOutOfBoundsException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new StringIndexOutOfBoundsException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new StringIndexOutOfBoundsException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(StringIndexOutOfBoundsException.prototype.message); |
|
156 | expect(source2.message).toEqual(StringIndexOutOfBoundsException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "StringIndexOutOfBoundsException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new StringIndexOutOfBoundsException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new StringIndexOutOfBoundsException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "StringIndexOutOfBoundsException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + StringIndexOutOfBoundsException.prototype.message + '.'; |
|
193 | exp2 += ": " + StringIndexOutOfBoundsException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new StringIndexOutOfBoundsException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new StringIndexOutOfBoundsException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : StringIndexOutOfBoundsException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/InvalidPathException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const IllegalArgumentException = require(path.join(root, "IllegalArgumentException.js")); |
|
15 | const InvalidPathException = require(path.join(root, "InvalidPathException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the InvalidPathException 'class' |
|
20 | describe("InvalidPathException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new InvalidPathException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new InvalidPathException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new InvalidPathException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new InvalidPathException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'IllegalArgumentException'", () => { |
|
41 | expect(new InvalidPathException()).toEqual(jasmine.any(IllegalArgumentException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(InvalidPathException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(InvalidPathException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(InvalidPathException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(InvalidPathException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(InvalidPathException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(InvalidPathException.prototype.name).toEqual("InvalidPathException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(InvalidPathException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(InvalidPathException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new InvalidPathException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new InvalidPathException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, InvalidPathException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new InvalidPathException(arg1)); |
|
105 | test2 = (() => new InvalidPathException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new InvalidPathException(arg1, arg2)); |
|
123 | test21 = (() => new InvalidPathException(null, arg2)); |
|
124 | test11 = (() => new InvalidPathException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new InvalidPathException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new InvalidPathException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(InvalidPathException.prototype.message); |
|
156 | expect(source2.message).toEqual(InvalidPathException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "InvalidPathException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new InvalidPathException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new InvalidPathException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "InvalidPathException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + InvalidPathException.prototype.message + '.'; |
|
193 | exp2 += ": " + InvalidPathException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new InvalidPathException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new InvalidPathException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : InvalidPathException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/UnsupportedCharsetException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const IllegalArgumentException = require(path.join(root, "IllegalArgumentException.js")); |
|
15 | const UnsupportedCharsetException = require(path.join(root, "UnsupportedCharsetException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the UnsupportedCharsetException 'class' |
|
20 | describe("UnsupportedCharsetException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new UnsupportedCharsetException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new UnsupportedCharsetException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new UnsupportedCharsetException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new UnsupportedCharsetException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'IllegalArgumentException'", () => { |
|
41 | expect(new UnsupportedCharsetException()).toEqual(jasmine.any(IllegalArgumentException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(UnsupportedCharsetException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(UnsupportedCharsetException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(UnsupportedCharsetException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(UnsupportedCharsetException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(UnsupportedCharsetException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(UnsupportedCharsetException.prototype.name).toEqual("UnsupportedCharsetException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(UnsupportedCharsetException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(UnsupportedCharsetException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new UnsupportedCharsetException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new UnsupportedCharsetException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, UnsupportedCharsetException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new UnsupportedCharsetException(arg1)); |
|
105 | test2 = (() => new UnsupportedCharsetException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new UnsupportedCharsetException(arg1, arg2)); |
|
123 | test21 = (() => new UnsupportedCharsetException(null, arg2)); |
|
124 | test11 = (() => new UnsupportedCharsetException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new UnsupportedCharsetException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new UnsupportedCharsetException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(UnsupportedCharsetException.prototype.message); |
|
156 | expect(source2.message).toEqual(UnsupportedCharsetException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "UnsupportedCharsetException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new UnsupportedCharsetException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new UnsupportedCharsetException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "UnsupportedCharsetException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + UnsupportedCharsetException.prototype.message + '.'; |
|
193 | exp2 += ": " + UnsupportedCharsetException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new UnsupportedCharsetException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new UnsupportedCharsetException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : UnsupportedCharsetException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-218 (lines=217) @@ | ||
1 | // spec/ArrayIndexOutOfBoundsException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const IndexOutOfBoundsException = require(path.join(root, "IndexOutOfBoundsException.js")); |
|
15 | const ArrayIndexOutOfBoundsException = require(path.join(root, "ArrayIndexOutOfBoundsException.js")); |
|
16 | ||
17 | // :: TESTING |
|
18 | ||
19 | // test the ArrayIndexOutOfBoundsException 'class' |
|
20 | describe("ArrayIndexOutOfBoundsException", () => { |
|
21 | ||
22 | // :: INHERITED PROTOTYPE |
|
23 | ||
24 | it("should inherit from 'Object'", () => { |
|
25 | expect(new ArrayIndexOutOfBoundsException()).toEqual(jasmine.any(Object)); |
|
26 | }); |
|
27 | ||
28 | it("should inherit from 'Throwable'", () => { |
|
29 | expect(new ArrayIndexOutOfBoundsException()).toEqual(jasmine.any(Throwable)); |
|
30 | }); |
|
31 | ||
32 | it("should inherit from 'Exception'", () => { |
|
33 | expect(new ArrayIndexOutOfBoundsException()).toEqual(jasmine.any(Exception)); |
|
34 | }); |
|
35 | ||
36 | it("should inherit from 'RuntimeException'", () => { |
|
37 | expect(new ArrayIndexOutOfBoundsException()).toEqual(jasmine.any(RuntimeException)); |
|
38 | }); |
|
39 | ||
40 | it("should inherit from 'IndexOutOfBoundsException'", () => { |
|
41 | expect(new ArrayIndexOutOfBoundsException()).toEqual(jasmine.any(IndexOutOfBoundsException)); |
|
42 | }); |
|
43 | ||
44 | it("should have a prototype method named 'toString()'", () => { |
|
45 | expect(ArrayIndexOutOfBoundsException.prototype).toHaveMethod("toString"); |
|
46 | }); |
|
47 | ||
48 | it("should have a prototype method named 'native()'", () => { |
|
49 | expect(ArrayIndexOutOfBoundsException.prototype).toHaveMethod("native"); |
|
50 | }); |
|
51 | ||
52 | it("should have a prototype property string named 'name'", () => { |
|
53 | expect(ArrayIndexOutOfBoundsException.prototype).toHaveString("name"); |
|
54 | }); |
|
55 | ||
56 | it("should have a prototype property string named 'message'", () => { |
|
57 | expect(ArrayIndexOutOfBoundsException.prototype).toHaveString("message"); |
|
58 | }); |
|
59 | ||
60 | it("should have a prototype property string named 'code'", () => { |
|
61 | expect(ArrayIndexOutOfBoundsException.prototype).toHaveMember("code"); |
|
62 | }); |
|
63 | ||
64 | // :: EXTENDED PROTOTYPE |
|
65 | ||
66 | // :: PROTOTYPE VALUES |
|
67 | ||
68 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
69 | expect(ArrayIndexOutOfBoundsException.prototype.name).toEqual("ArrayIndexOutOfBoundsException"); |
|
70 | }); |
|
71 | ||
72 | it("should have a dummy default value as message", () => { |
|
73 | expect(ArrayIndexOutOfBoundsException.prototype.message).toEqual("thrown"); |
|
74 | }); |
|
75 | ||
76 | it("should have a null default value as code", () => { |
|
77 | expect(ArrayIndexOutOfBoundsException.prototype.code).toBeNull(); |
|
78 | }); |
|
79 | ||
80 | // :: CONSTRUCTOR |
|
81 | ||
82 | it("should instantiate without parameters", () => { |
|
83 | let arg1, arg2, test; |
|
84 | test = (() => new ArrayIndexOutOfBoundsException(arg1, arg2)); |
|
85 | for (let i = 0; i < 2; i += 1) { |
|
86 | for (let j = 0; j < 2; j += 1) { |
|
87 | arg1 = (i % 2 === 0 ? undefined : null); |
|
88 | arg2 = (j % 2 === 0 ? undefined : null); |
|
89 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
90 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
92 | } |
|
93 | } |
|
94 | test = (() => new ArrayIndexOutOfBoundsException()); |
|
95 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
96 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
97 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
98 | }); |
|
99 | ||
100 | it("should instantiate with parameters", () => { |
|
101 | let arg1, arg2, test1, test2; |
|
102 | const args1 = [undefined, null, ArrayIndexOutOfBoundsException.prototype.message]; |
|
103 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
104 | test1 = (() => new ArrayIndexOutOfBoundsException(arg1)); |
|
105 | test2 = (() => new ArrayIndexOutOfBoundsException(arg1, arg2)); |
|
106 | for (let i = 0; i < args1.length; i += 1) { |
|
107 | arg1 = args1[i]; |
|
108 | for (let j = 0; j < args2.length; j += 1) { |
|
109 | arg2 = args2[j]; |
|
110 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
111 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
112 | } |
|
113 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
114 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
115 | } |
|
116 | }); |
|
117 | ||
118 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
119 | let arg1, arg2, test21, test22, test11; |
|
120 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
121 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
122 | test22 = (() => new ArrayIndexOutOfBoundsException(arg1, arg2)); |
|
123 | test21 = (() => new ArrayIndexOutOfBoundsException(null, arg2)); |
|
124 | test11 = (() => new ArrayIndexOutOfBoundsException(arg1)); |
|
125 | if (typeof Symbol === "function") { |
|
126 | noStr.push(Symbol("symbol")); |
|
127 | noNmb.push(Symbol("symbol")); |
|
128 | } |
|
129 | for (let i = 0; i < noStr.length; i += 1) { |
|
130 | arg1 = noStr[i]; |
|
131 | for (let j = 0; j < noNmb.length; j += 1) { |
|
132 | arg2 = noNmb[j]; |
|
133 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
134 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
135 | } |
|
136 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
137 | } |
|
138 | }); |
|
139 | ||
140 | // :: MEMBER PROPERTIES |
|
141 | ||
142 | it("should have all correct properties once instantiated", () => { |
|
143 | const message = "asdf"; |
|
144 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
145 | for (let i = 0; i < 2; i += 1) { |
|
146 | const arg1 = (i % 2 === 0 ? message : null); |
|
147 | const source1 = new ArrayIndexOutOfBoundsException(arg1); |
|
148 | for (let j = 0; j < 2; j += 1) { |
|
149 | const arg2 = (j % 2 === 0 ? code : null); |
|
150 | const source2 = new ArrayIndexOutOfBoundsException(arg1, arg2); |
|
151 | if (i % 2 === 0) { |
|
152 | expect(source1.message).toEqual(message); |
|
153 | expect(source2.message).toEqual(message); |
|
154 | } else { |
|
155 | expect(source1.message).toEqual(ArrayIndexOutOfBoundsException.prototype.message); |
|
156 | expect(source2.message).toEqual(ArrayIndexOutOfBoundsException.prototype.message); |
|
157 | } |
|
158 | if (j % 2 === 0) { |
|
159 | expect(source2.code).toEqual(code); |
|
160 | } else { |
|
161 | expect(source2.code).toBeNull(); |
|
162 | } |
|
163 | expect(source1.code).toBeNull(); |
|
164 | } |
|
165 | } |
|
166 | }); |
|
167 | ||
168 | // :: MEMBER METHODS |
|
169 | ||
170 | const name = "ArrayIndexOutOfBoundsException"; |
|
171 | const message = "asdf"; |
|
172 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
173 | ||
174 | it("#toString()", () => { |
|
175 | for (let i = 0; i < 2; i += 1) { |
|
176 | const arg1 = (i % 2 === 0 ? message : null); |
|
177 | const source1 = new ArrayIndexOutOfBoundsException(arg1); |
|
178 | for (let j = 0; j < 2; j += 1) { |
|
179 | const arg2 = (j % 2 === 0 ? code : null); |
|
180 | const source2 = new ArrayIndexOutOfBoundsException(arg1, arg2); |
|
181 | const str1 = source1.toString(); |
|
182 | const str2 = source2.toString(); |
|
183 | let exp1, exp2; |
|
184 | exp1 = exp2 = "ArrayIndexOutOfBoundsException"; |
|
185 | if (j % 2 === 0) { |
|
186 | exp2 += " (0x" + code.toString(16) + ')'; |
|
187 | } |
|
188 | if (i % 2 === 0) { |
|
189 | exp1 += ": " + message + '.'; |
|
190 | exp2 += ": " + message + '.'; |
|
191 | } else { |
|
192 | exp1 += ": " + ArrayIndexOutOfBoundsException.prototype.message + '.'; |
|
193 | exp2 += ": " + ArrayIndexOutOfBoundsException.prototype.message + '.'; |
|
194 | } |
|
195 | expect(str1).toEqual(exp1); |
|
196 | expect(str2).toEqual(exp2); |
|
197 | } |
|
198 | } |
|
199 | }); |
|
200 | ||
201 | it("#native()", () => { |
|
202 | for (let i = 0; i < 2; i += 1) { |
|
203 | const arg1 = (i % 2 === 0 ? message : null); |
|
204 | const source1 = new ArrayIndexOutOfBoundsException(arg1); |
|
205 | for (let j = 0; j < 2; j += 1) { |
|
206 | const arg2 = (j % 2 === 0 ? code : null); |
|
207 | const source2 = new ArrayIndexOutOfBoundsException(arg1, arg2); |
|
208 | const err1 = source1.native(); |
|
209 | const err2 = source2.native(); |
|
210 | const exp1 = (i % 2 === 0 ? message : ArrayIndexOutOfBoundsException.prototype.message); |
|
211 | const exp2 = exp1; |
|
212 | expect(err1).toEqual(new Error(exp1)); |
|
213 | expect(err2).toEqual(new Error(exp2)); |
|
214 | } |
|
215 | } |
|
216 | }); |
|
217 | ||
218 | }); |
@@ 2-213 (lines=212) @@ | ||
1 | // spec/ClassCastException.spec.js |
|
2 | "use strict"; |
|
3 | ||
4 | // :: DEPENDENCIES |
|
5 | ||
6 | // load native dependencies |
|
7 | const path = require("path"); |
|
8 | ||
9 | // load local dependencies |
|
10 | const root = path.dirname(__dirname); |
|
11 | const Throwable = require(path.join(root, "Throwable.js")); |
|
12 | const Exception = require(path.join(root, "Exception.js")); |
|
13 | const RuntimeException = require(path.join(root, "RuntimeException.js")); |
|
14 | const ClassCastException = require(path.join(root, "ClassCastException.js")); |
|
15 | ||
16 | // :: TESTING |
|
17 | ||
18 | // test the ClassCastException 'class' |
|
19 | describe("ClassCastException", () => { |
|
20 | ||
21 | // :: INHERITED PROTOTYPE |
|
22 | ||
23 | it("should inherit from 'Object'", () => { |
|
24 | expect(new ClassCastException()).toEqual(jasmine.any(Object)); |
|
25 | }); |
|
26 | ||
27 | it("should inherit from 'Throwable'", () => { |
|
28 | expect(new ClassCastException()).toEqual(jasmine.any(Throwable)); |
|
29 | }); |
|
30 | ||
31 | it("should inherit from 'Exception'", () => { |
|
32 | expect(new ClassCastException()).toEqual(jasmine.any(Exception)); |
|
33 | }); |
|
34 | ||
35 | it("should inherit from 'RuntimeException'", () => { |
|
36 | expect(new ClassCastException()).toEqual(jasmine.any(RuntimeException)); |
|
37 | }); |
|
38 | ||
39 | it("should have a prototype method named 'toString()'", () => { |
|
40 | expect(ClassCastException.prototype).toHaveMethod("toString"); |
|
41 | }); |
|
42 | ||
43 | it("should have a prototype method named 'native()'", () => { |
|
44 | expect(ClassCastException.prototype).toHaveMethod("native"); |
|
45 | }); |
|
46 | ||
47 | it("should have a prototype property string named 'name'", () => { |
|
48 | expect(ClassCastException.prototype).toHaveString("name"); |
|
49 | }); |
|
50 | ||
51 | it("should have a prototype property string named 'message'", () => { |
|
52 | expect(ClassCastException.prototype).toHaveString("message"); |
|
53 | }); |
|
54 | ||
55 | it("should have a prototype property string named 'code'", () => { |
|
56 | expect(ClassCastException.prototype).toHaveMember("code"); |
|
57 | }); |
|
58 | ||
59 | // :: EXTENDED PROTOTYPE |
|
60 | ||
61 | // :: PROTOTYPE VALUES |
|
62 | ||
63 | it("should have the 'class' name in the prototype property named 'name'", () => { |
|
64 | expect(ClassCastException.prototype.name).toEqual("ClassCastException"); |
|
65 | }); |
|
66 | ||
67 | it("should have a dummy default value as message", () => { |
|
68 | expect(ClassCastException.prototype.message).toEqual("thrown"); |
|
69 | }); |
|
70 | ||
71 | it("should have a null default value as code", () => { |
|
72 | expect(ClassCastException.prototype.code).toBeNull(); |
|
73 | }); |
|
74 | ||
75 | // :: CONSTRUCTOR |
|
76 | ||
77 | it("should instantiate without parameters", () => { |
|
78 | let arg1, arg2, test; |
|
79 | test = (() => new ClassCastException(arg1, arg2)); |
|
80 | for (let i = 0; i < 2; i += 1) { |
|
81 | for (let j = 0; j < 2; j += 1) { |
|
82 | arg1 = (i % 2 === 0 ? undefined : null); |
|
83 | arg2 = (j % 2 === 0 ? undefined : null); |
|
84 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
85 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
86 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
87 | } |
|
88 | } |
|
89 | test = (() => new ClassCastException()); |
|
90 | expect(test).not.toThrowError("parameter 'name' must be a 'string'"); |
|
91 | expect(test).not.toThrowError("parameter 'message' must be a 'string'"); |
|
92 | expect(test).not.toThrowError("parameter 'code' must be a 'number'"); |
|
93 | }); |
|
94 | ||
95 | it("should instantiate with parameters", () => { |
|
96 | let arg1, arg2, test1, test2; |
|
97 | const args1 = [undefined, null, ClassCastException.prototype.message]; |
|
98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
99 | test1 = (() => new ClassCastException(arg1)); |
|
100 | test2 = (() => new ClassCastException(arg1, arg2)); |
|
101 | for (let i = 0; i < args1.length; i += 1) { |
|
102 | arg1 = args1[i]; |
|
103 | for (let j = 0; j < args2.length; j += 1) { |
|
104 | arg2 = args2[j]; |
|
105 | expect(test2).not.toThrowError("parameter 'message' must be a 'string'"); |
|
106 | expect(test2).not.toThrowError("parameter 'code' must be a 'number'"); |
|
107 | } |
|
108 | expect(test1).not.toThrowError("parameter 'message' must be a 'string'"); |
|
109 | expect(test1).not.toThrowError("parameter 'code' must be a 'number'"); |
|
110 | } |
|
111 | }); |
|
112 | ||
113 | it("should throw an Error if 'message' or 'code' are invalid parameters", () => { |
|
114 | let arg1, arg2, test21, test22, test11; |
|
115 | const noStr = [{}, true, false, 42, 3.1416, -42, -3.1416, () => null]; |
|
116 | const noNmb = [{}, true, false, '', "qwerty", () => null]; |
|
117 | test22 = (() => new ClassCastException(arg1, arg2)); |
|
118 | test21 = (() => new ClassCastException(null, arg2)); |
|
119 | test11 = (() => new ClassCastException(arg1)); |
|
120 | if (typeof Symbol === "function") { |
|
121 | noStr.push(Symbol("symbol")); |
|
122 | noNmb.push(Symbol("symbol")); |
|
123 | } |
|
124 | for (let i = 0; i < noStr.length; i += 1) { |
|
125 | arg1 = noStr[i]; |
|
126 | for (let j = 0; j < noNmb.length; j += 1) { |
|
127 | arg2 = noNmb[j]; |
|
128 | expect(test22).toThrowError("parameter 'message' must be a 'string'"); |
|
129 | expect(test21).toThrowError("parameter 'code' must be a 'number'"); |
|
130 | } |
|
131 | expect(test11).toThrowError("parameter 'message' must be a 'string'"); |
|
132 | } |
|
133 | }); |
|
134 | ||
135 | // :: MEMBER PROPERTIES |
|
136 | ||
137 | it("should have all correct properties once instantiated", () => { |
|
138 | const message = "asdf"; |
|
139 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
140 | for (let i = 0; i < 2; i += 1) { |
|
141 | const arg1 = (i % 2 === 0 ? message : null); |
|
142 | const source1 = new ClassCastException(arg1); |
|
143 | for (let j = 0; j < 2; j += 1) { |
|
144 | const arg2 = (j % 2 === 0 ? code : null); |
|
145 | const source2 = new ClassCastException(arg1, arg2); |
|
146 | if (i % 2 === 0) { |
|
147 | expect(source1.message).toEqual(message); |
|
148 | expect(source2.message).toEqual(message); |
|
149 | } else { |
|
150 | expect(source1.message).toEqual(ClassCastException.prototype.message); |
|
151 | expect(source2.message).toEqual(ClassCastException.prototype.message); |
|
152 | } |
|
153 | if (j % 2 === 0) { |
|
154 | expect(source2.code).toEqual(code); |
|
155 | } else { |
|
156 | expect(source2.code).toBeNull(); |
|
157 | } |
|
158 | expect(source1.code).toBeNull(); |
|
159 | } |
|
160 | } |
|
161 | }); |
|
162 | ||
163 | // :: MEMBER METHODS |
|
164 | ||
165 | const name = "ClassCastException"; |
|
166 | const message = "asdf"; |
|
167 | const code = Math.round(Math.random() * 0xFFFFFFFF); |
|
168 | ||
169 | it("#toString()", () => { |
|
170 | for (let i = 0; i < 2; i += 1) { |
|
171 | const arg1 = (i % 2 === 0 ? message : null); |
|
172 | const source1 = new ClassCastException(arg1); |
|
173 | for (let j = 0; j < 2; j += 1) { |
|
174 | const arg2 = (j % 2 === 0 ? code : null); |
|
175 | const source2 = new ClassCastException(arg1, arg2); |
|
176 | const str1 = source1.toString(); |
|
177 | const str2 = source2.toString(); |
|
178 | let exp1, exp2; |
|
179 | exp1 = exp2 = "ClassCastException"; |
|
180 | if (j % 2 === 0) { |
|
181 | exp2 += " (0x" + code.toString(16) + ')'; |
|
182 | } |
|
183 | if (i % 2 === 0) { |
|
184 | exp1 += ": " + message + '.'; |
|
185 | exp2 += ": " + message + '.'; |
|
186 | } else { |
|
187 | exp1 += ": " + ClassCastException.prototype.message + '.'; |
|
188 | exp2 += ": " + ClassCastException.prototype.message + '.'; |
|
189 | } |
|
190 | expect(str1).toEqual(exp1); |
|
191 | expect(str2).toEqual(exp2); |
|
192 | } |
|
193 | } |
|
194 | }); |
|
195 | ||
196 | it("#native()", () => { |
|
197 | for (let i = 0; i < 2; i += 1) { |
|
198 | const arg1 = (i % 2 === 0 ? message : null); |
|
199 | const source1 = new ClassCastException(arg1); |
|
200 | for (let j = 0; j < 2; j += 1) { |
|
201 | const arg2 = (j % 2 === 0 ? code : null); |
|
202 | const source2 = new ClassCastException(arg1, arg2); |
|
203 | const err1 = source1.native(); |
|
204 | const err2 = source2.native(); |
|
205 | const exp1 = (i % 2 === 0 ? message : ClassCastException.prototype.message); |
|
206 | const exp2 = exp1; |
|
207 | expect(err1).toEqual(new Error(exp1)); |
|
208 | expect(err2).toEqual(new Error(exp2)); |
|
209 | } |
|
210 | } |
|
211 | }); |
|
212 | ||
213 | }); |