| @@ 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/CastClassException.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 CastClassException = require(path.join(root, "CastClassException.js")); |
|
| 15 | ||
| 16 | // :: TESTING |
|
| 17 | ||
| 18 | // test the CastClassException 'class' |
|
| 19 | describe("CastClassException", () => { |
|
| 20 | ||
| 21 | // :: INHERITED PROTOTYPE |
|
| 22 | ||
| 23 | it("should inherit from 'Object'", () => { |
|
| 24 | expect(new CastClassException()).toEqual(jasmine.any(Object)); |
|
| 25 | }); |
|
| 26 | ||
| 27 | it("should inherit from 'Throwable'", () => { |
|
| 28 | expect(new CastClassException()).toEqual(jasmine.any(Throwable)); |
|
| 29 | }); |
|
| 30 | ||
| 31 | it("should inherit from 'Exception'", () => { |
|
| 32 | expect(new CastClassException()).toEqual(jasmine.any(Exception)); |
|
| 33 | }); |
|
| 34 | ||
| 35 | it("should inherit from 'RuntimeException'", () => { |
|
| 36 | expect(new CastClassException()).toEqual(jasmine.any(RuntimeException)); |
|
| 37 | }); |
|
| 38 | ||
| 39 | it("should have a prototype method named 'toString()'", () => { |
|
| 40 | expect(CastClassException.prototype).toHaveMethod("toString"); |
|
| 41 | }); |
|
| 42 | ||
| 43 | it("should have a prototype method named 'native()'", () => { |
|
| 44 | expect(CastClassException.prototype).toHaveMethod("native"); |
|
| 45 | }); |
|
| 46 | ||
| 47 | it("should have a prototype property string named 'name'", () => { |
|
| 48 | expect(CastClassException.prototype).toHaveString("name"); |
|
| 49 | }); |
|
| 50 | ||
| 51 | it("should have a prototype property string named 'message'", () => { |
|
| 52 | expect(CastClassException.prototype).toHaveString("message"); |
|
| 53 | }); |
|
| 54 | ||
| 55 | it("should have a prototype property string named 'code'", () => { |
|
| 56 | expect(CastClassException.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(CastClassException.prototype.name).toEqual("CastClassException"); |
|
| 65 | }); |
|
| 66 | ||
| 67 | it("should have a dummy default value as message", () => { |
|
| 68 | expect(CastClassException.prototype.message).toEqual("thrown"); |
|
| 69 | }); |
|
| 70 | ||
| 71 | it("should have a null default value as code", () => { |
|
| 72 | expect(CastClassException.prototype.code).toBeNull(); |
|
| 73 | }); |
|
| 74 | ||
| 75 | // :: CONSTRUCTOR |
|
| 76 | ||
| 77 | it("should instantiate without parameters", () => { |
|
| 78 | let arg1, arg2, test; |
|
| 79 | test = (() => new CastClassException(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 CastClassException()); |
|
| 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, CastClassException.prototype.message]; |
|
| 98 | const args2 = [undefined, null, Math.round(Math.random() * 0xFFFFFFFF)]; |
|
| 99 | test1 = (() => new CastClassException(arg1)); |
|
| 100 | test2 = (() => new CastClassException(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 CastClassException(arg1, arg2)); |
|
| 118 | test21 = (() => new CastClassException(null, arg2)); |
|
| 119 | test11 = (() => new CastClassException(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 CastClassException(arg1); |
|
| 143 | for (let j = 0; j < 2; j += 1) { |
|
| 144 | const arg2 = (j % 2 === 0 ? code : null); |
|
| 145 | const source2 = new CastClassException(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(CastClassException.prototype.message); |
|
| 151 | expect(source2.message).toEqual(CastClassException.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 = "CastClassException"; |
|
| 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 CastClassException(arg1); |
|
| 173 | for (let j = 0; j < 2; j += 1) { |
|
| 174 | const arg2 = (j % 2 === 0 ? code : null); |
|
| 175 | const source2 = new CastClassException(arg1, arg2); |
|
| 176 | const str1 = source1.toString(); |
|
| 177 | const str2 = source2.toString(); |
|
| 178 | let exp1, exp2; |
|
| 179 | exp1 = exp2 = "CastClassException"; |
|
| 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 += ": " + CastClassException.prototype.message + '.'; |
|
| 188 | exp2 += ": " + CastClassException.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 CastClassException(arg1); |
|
| 200 | for (let j = 0; j < 2; j += 1) { |
|
| 201 | const arg2 = (j % 2 === 0 ? code : null); |
|
| 202 | const source2 = new CastClassException(arg1, arg2); |
|
| 203 | const err1 = source1.native(); |
|
| 204 | const err2 = source2.native(); |
|
| 205 | const exp1 = (i % 2 === 0 ? message : CastClassException.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 | }); |
|