-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathutils.spec.js
More file actions
87 lines (76 loc) · 2.59 KB
/
Copy pathutils.spec.js
File metadata and controls
87 lines (76 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { UUID, HashSet, ArrayList } = require('./java.mock');
const {
randomUUID,
jsSetToJavaSet,
jsArrayToJavaSet,
jsArrayToJavaList,
javaListToJsArray,
javaSetToJsArray,
javaSetToJsSet
} = require('../src/utils');
describe('utils.js', () => {
describe('randomUUID', () => {
it('delegates to Java UUID#randomUUID().', () => {
jest.spyOn(UUID, 'randomUUID');
randomUUID();
expect(UUID.randomUUID).toHaveBeenCalled();
});
it('returns Java UUID as string.', () => {
expect(randomUUID()).toBe('UUID');
expect(typeof randomUUID()).toBe('string');
});
});
describe('jsSetToJavaSet', () => {
it('returns Java HashSet.', () => {
expect(jsSetToJavaSet(new Set())).toBeInstanceOf(HashSet);
});
it('adds all items from set to returned HashSet.', () => {
jest.spyOn(HashSet.prototype, 'add');
const hashSet = jsSetToJavaSet(new Set(['item1', 'item2']));
expect(hashSet.add).toHaveBeenNthCalledWith(1, 'item1');
expect(hashSet.add).toHaveBeenNthCalledWith(2, 'item2');
});
});
describe('jsArrayToJavaSet', () => {
it('returns Java HashSet.', () => {
expect(jsArrayToJavaSet([])).toBeInstanceOf(HashSet);
});
it('adds all items from array to returned HashSet.', () => {
jest.spyOn(HashSet.prototype, 'add');
const hashSet = jsArrayToJavaSet(['item1', 'item2']);
expect(hashSet.add).toHaveBeenNthCalledWith(1, 'item1');
expect(hashSet.add).toHaveBeenNthCalledWith(2, 'item2');
});
});
describe('jsArrayToJavaList', () => {
it('returns Java HashSet.', () => {
expect(jsArrayToJavaList([])).toBeInstanceOf(ArrayList);
});
it('adds all items from array to returned ArrayList.', () => {
jest.spyOn(ArrayList.prototype, 'add');
const arrayList = jsArrayToJavaList(['item1', 'item2']);
expect(arrayList.add).toHaveBeenNthCalledWith(1, 'item1');
expect(arrayList.add).toHaveBeenNthCalledWith(2, 'item2');
});
});
describe('javaListToJsArray', () => {
it('delegates to Java#from().', () => {
const list = new ArrayList();
jest.spyOn(Java, 'from');
javaListToJsArray(list);
expect(Java.from).toHaveBeenCalledWith(list);
});
});
describe('javaSetToJsArray', () => {
it('delegates to Java#from().', () => {
jest.spyOn(Java, 'from');
javaSetToJsArray(new HashSet());
expect(Java.from.mock.calls[0][0]).toBeInstanceOf(ArrayList);
});
});
describe('javaSetToJsSet', () => {
it('returns Set.', () => {
expect(javaSetToJsSet(new HashSet())).toBeInstanceOf(Set);
});
});
});