-
Notifications
You must be signed in to change notification settings - Fork 820
/
map.test.ts
88 lines (75 loc) · 2.94 KB
/
map.test.ts
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
88
import { JavaArray } from './../../../velocity/value-mapper/array';
import { JavaMap } from '../../../velocity/value-mapper/map';
import { toJavaString } from '../../../velocity/value-mapper/string';
describe('JavaMap', () => {
let identityMapper = jest.fn().mockImplementation(val => val);
beforeEach(() => {
identityMapper = jest.fn().mockImplementation(val => val);
});
it('New Map', () => {
const obj = { foo: 1, bar: 2 };
const map = new JavaMap(obj, identityMapper);
expect(map.toJSON()).toEqual(obj);
});
it('clear', () => {
const obj = { foo: 1, bar: 2 };
const map = new JavaMap(obj, identityMapper);
map.clear();
expect(map.toJSON()).toEqual({});
});
it('containsKey', () => {
const obj = { foo: 1, bar: 2 };
const map = new JavaMap(obj, identityMapper);
expect(map.containsKey('foo')).toBeTruthy();
expect(map.containsKey('bax')).toBeFalsy();
});
it('containsValue', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.containsValue('Foo Value')).toBeTruthy();
expect(map.containsKey('bax value')).toBeFalsy();
});
it('entrySet', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.entrySet().toJSON()).toEqual([{ key: 'foo', value: 'Foo Value' }, { key: 'bar', value: 'Bar Value' }]);
});
it('equal', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
const map2 = new JavaMap(obj, identityMapper);
expect(map.equals(map2)).toBeTruthy();
});
it('get', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.get('foo')).toEqual('Foo Value');
expect(map.get('foo1')).toBeNull();
});
it('isEmpty', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.isEmpty()).toBeFalsy();
expect(new JavaMap({}, identityMapper).isEmpty()).toBeTruthy();
});
it('keySet', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.keySet().toJSON()).toEqual(['foo', 'bar']);
});
it('keySet returns a JavaArray with each element of type JavaString', () => {
const obj = { foo: 'Foo Value', bar: 'Bar Value' };
const map = new JavaMap(obj, identityMapper);
expect(map.keySet()).toEqual(new JavaArray([toJavaString('foo'), toJavaString('bar')], toJavaString));
});
it('put', () => {
const map = new JavaMap({}, identityMapper);
map.put('foo', 'Foo Value');
expect(map.toJSON()).toEqual({ foo: 'Foo Value' });
});
it('putAll', () => {
const map = new JavaMap({}, identityMapper);
map.putAll({ foo: 'Foo Value', bar: 'Bar Value' });
expect(map.toJSON()).toEqual({ foo: 'Foo Value', bar: 'Bar Value' });
});
});