-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSessionImplTests.java
More file actions
767 lines (677 loc) · 25.7 KB
/
SessionImplTests.java
File metadata and controls
767 lines (677 loc) · 25.7 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
package ly.count.sdk.java.internal;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import ly.count.sdk.java.Config;
import ly.count.sdk.java.Countly;
import ly.count.sdk.java.Session;
import ly.count.sdk.java.View;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@RunWith(JUnit4.class)
public class SessionImplTests {
@Before
public void beforeTest() {
TestUtils.createCleanTestState();
}
@After
public void stop() {
Countly.instance().halt();
}
/**
* "constructor"
* gets a valid long ID to create a session with
* returned session should have the input ID
*/
@Test
public void constructor() {
Countly.instance().init(TestUtils.getConfigSessions());
assertEquals(new Long(12_345L), createSessionImpl(12_345L).getId());
}
/**
* "constructor"
* gets a null ID to create a session with
* returned session should have ID > 0 that is generated automatically
*/
@Test
public void constructor_nullId() {
Countly.instance().init(TestUtils.getConfigSessions());
assertTrue(createSessionImpl(null).getId() > 0);// The ID should be generated and not null
}
/**
* "begin(long)" with already began session
* Try to begin already began session, validate that it is not changed
* returned result should be null
*/
@Test
public void begin_began() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
validateBeganSession((SessionImpl) session.begin());
Assert.assertNull(session.begin(0L));
validateBeganSession(session);
}
/**
* "begin(long)" with already ended session
* Try to begin already ended session, validate that it is not changed
* returned result should be null
*/
@Test
public void begin_ended() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
validateBeganSession((SessionImpl) session.begin());
validateUpdatedSession((SessionImpl) session.update());
session.end();
validateEndedSession(session);
Assert.assertNull(session.begin(0L));
}
/**
* "begin(long)" with null SDKCore instance
* Try to begin a session, validate that it is not started
* returned result should be null
*/
@Test
public void begin_nullInstance() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
SDKCore.instance = null;
Assert.assertNull(session.begin(0L));
validateNotStarted(session);
}
/**
* "begin(long)"
* Try to begin a session, validate that it began
* returned result should be true
*/
@Test
public void begin() throws ExecutionException, InterruptedException {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
Assert.assertTrue(session.begin(0L).get());
validateBeganSession(session);
}
/**
* "begin()" with backend mode enabled
* Try to begin a session, validate that it is not started
* returned result should be null
*/
@Test
public void begin_backendModeEnabled() {
Countly.instance().init(TestUtils.getConfigSessions().enableBackendMode());
validateNotStarted((SessionImpl) Countly.session());
}
/**
* "update(long)" with not began session
* Try to update a session, validate that it is not started and updated
* returned result should be null
*/
@Test
public void update_notStarted() throws ExecutionException, InterruptedException {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
Assert.assertNull(session.update(0L));
validateNotStarted(session);
}
/**
* "update(long)" with ended session
* Try to update a session, validate that it's result is null
* returned result should be null
*/
@Test
public void update_ended() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
validateBeganSession((SessionImpl) session.begin());
validateUpdatedSession((SessionImpl) session.update());
session.end();
validateEndedSession(session);
Assert.assertNull(session.update(0L));
}
/**
* "update(long)" with null SDKCore instance
* Try to update a session, validate that it is not updated
* returned result should be null
*/
@Test
public void update_nullInstance() throws ExecutionException, InterruptedException {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
validateBeganSession((SessionImpl) session.begin());
SDKCore.instance = null;
Assert.assertNull(session.update(0L));
validateBeganSession(session);
}
/**
* "update(long)"
* Try to update a session, validate that it is updated
* returned result should be true
*/
@Test
public void update() throws ExecutionException, InterruptedException {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
validateBeganSession((SessionImpl) session.begin());
Assert.assertTrue(session.update(0L).get());
validateUpdatedSession(session);
}
/**
* "update()" with backend mode enabled
* Try to update a session, validate that it is not started and updated
* returned result should be not started and updated
*/
@Test
public void update_backendModeEnabled() {
Countly.instance().init(TestUtils.getConfigSessions().enableBackendMode());
SessionImpl session = (SessionImpl) Countly.session();
validateNotStarted((SessionImpl) session.update());
}
/**
* "end" with not started session
* Try to end a session, validate that it is not ended
* returned result should be null
*/
@Test
public void end_notStarted() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
Assert.assertNull(session.end(0L, null, null));
}
/**
* "end" with ended session
* Try to end a session, validate the result
* returned result should be null
*/
@Test
public void end_ended() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
validateBeganSession((SessionImpl) session.begin());
validateUpdatedSession((SessionImpl) session.update());
session.end();
validateEndedSession(session);
Assert.assertNull(session.end(0L, null, null));
}
/**
* "end" with null SDKCore instance
* Try to end a session, validate that it is not started and ended
* returned result should be null
*/
@Test
public void end_nullInstance() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
SDKCore.instance = null;
Assert.assertNull(session.end(0L, null, null));
validateNotStarted(session);
}
/**
* "end"
* Try to end a session, validate that it is ended, started and updated
* returned value result be true
*
* @throws ExecutionException if the computation threw an exception
* @throws InterruptedException if thread is interrupted
*/
@Test
public void end() throws ExecutionException, InterruptedException {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
Assert.assertTrue(session.begin(0L).get());
Assert.assertTrue(session.update(0L).get());
Assert.assertTrue(session.end(0L, Assert::assertTrue, null).get());
Thread.sleep(200);
validateEndedSession(session);
}
/**
* "end" with backend mode enabled
* Try to end a session, validate that it is not started and ended
* returned result should be not started, updated and ended
*/
@Test
public void end_backendModeEnabled() {
Countly.instance().init(TestUtils.getConfigSessions().enableBackendMode());
SessionImpl session = (SessionImpl) Countly.session();
session.begin().end();
validateNotStarted(session);
}
/**
* "changeDeviceIdWithMerge"
* Passing mock device id and validating that it is set
* device id should be same as the one passed to the function
*/
@Test
public void changeDeviceIdWithMerge() {
validateDeviceIdMerge("newDeviceId", "newDeviceId", true);
}
/**
* "changeDeviceIdWithMerge" with null id
* Passing null device id and validating that it is not set
* should be same as the initial device id
*/
@Test
public void changeDeviceIdWithMerge_nullId() {
validateDeviceIdMerge(null, TestUtils.DEVICE_ID, true);
}
/**
* "changeDeviceIdWithMerge" with empty id
* Passing empty device id and validating that it is not set
* should be same as the initial device id
*/
@Test
public void changeDeviceIdWithMerge_emptyId() {
validateDeviceIdMerge("", TestUtils.DEVICE_ID, true);
}
/**
* "changeDeviceIdWithMerge" with backend mode enabled
* Passing mock device id and validating that it is not set
* should be same as the initial device id
*/
@Test
public void changeDeviceIdWithMerge_backendModeEnabled() {
validateDeviceIdMerge("newDeviceId", TestUtils.DEVICE_ID, true, TestUtils.getConfigSessions().enableBackendMode());
}
/**
* "changeDeviceIdWithoutMerge"
* Passing mock device id and validating that it is set
* device id should be same as the one passed to the function
*/
@Test
public void changeDeviceIdWithoutMerge() {
validateDeviceIdMerge("newDeviceId", "newDeviceId", false);
}
/**
* "changeDeviceIdWithoutMerge" with null id
* Passing null device id and validating that it is not set
* should be same as the initial device id
*/
@Test
public void changeDeviceIdWithoutMerge_nullId() {
validateDeviceIdMerge(null, TestUtils.DEVICE_ID, false);
}
/**
* "changeDeviceIdWithoutMerge" with empty id
* Passing empty device id and validating that it is not set
* should be same as the initial device id
*/
@Test
public void changeDeviceIdWithoutMerge_emptyId() {
validateDeviceIdMerge("", TestUtils.DEVICE_ID, false);
}
/**
* "changeDeviceIdWithoutMerge" with backend mode enabled
* Passing mock device id and validating that it is not set
* should be same as the initial device id
*/
@Test
public void changeDeviceIdWithoutMerge_backendModeEnabled() {
validateDeviceIdMerge("newDeviceId", TestUtils.DEVICE_ID, false, TestUtils.getConfigSessions().enableBackendMode());
}
/**
* "user" with null SDKCore instance
* Setting SDKCore.instance to null and calling "user()" function
* returned value should be null
*/
@Test
public void user_instanceNull() {
Countly.instance().init(TestUtils.getConfigSessions());
SDKCore.instance = null;
Assert.assertNull(Countly.session().user());
}
/**
* "user"
* Calling function should return user
* returned value should be not null
*/
@Test
public void user() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
Assert.assertNotNull(session.user());
}
/**
* "addParam" with null key and value
* Given key and value are null, validating that they are added,
* added mock null key and value should exist in the params
*/
@Test
public void addParam_nullKeyValue() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
session.addParam(null, null);
Assert.assertNull(session.params.get("null"));
}
/**
* "addLocation" with no consent to location
* mocked location given to function and validating from params
* location should not be existed in the params
*/
@Test
public void addLocation_locationNotEnabled() {
addLocation_base(TestUtils.getConfigSessions(), null);
}
/**
* "addLocation"
* mocked latitude longitude given to function and validating from params
* given location should be existed in the params
*/
@Test
public void addLocation() {
addLocation_base(TestUtils.getConfigSessions(Config.Feature.Location), "1.0,2.0");
}
/**
* "addLocation" with backend mode enabled
* mocked location given to function and validating from params
* location should not be existed in the params
*/
@Test
public void addLocation_backendModeEnabled() {
addLocation_base(TestUtils.getConfigSessions().enableBackendMode(), null);
}
private void addLocation_base(Config config, Object expected) {
Countly.instance().init(config);
SessionImpl session = (SessionImpl) Countly.session();
session.addLocation(1.0, 2.0);
session.begin(null);
if (expected == null) {
Assert.assertEquals(1, TestUtils.getCurrentRQ().length);
} else {
Assert.assertEquals(expected, TestUtils.getCurrentRQ()[0].get("location"));
}
}
/**
* "addCrashReport" with no consent to crash reporting
* mocked exception given to function and validating function calls
* SDKCore.instance().onCrash() should not be called
*/
@Test
public void addCrashReport_crashReportingNotEnabled() {
addCrashReport_base(TestUtils.getConfigSessions(), 0);
}
/**
* "addCrashReport"
* mocked exception given to function and validating function calls
* SDKCore.instance().onCrash() should be called once
*/
@Test
public void addCrashReport() {
addCrashReport_base(TestUtils.getConfigSessions(Config.Feature.CrashReporting), 1);
Map<String, String>[] requests = TestUtils.getCurrentRQ();
Assert.assertTrue(requests[0].containsKey("crash"));
Assert.assertTrue(!requests[0].get("crash").isEmpty());
}
/**
* "addCrashReport" with backend mode enabled
* mocked exception given to function and validating function calls
* SDKCore.instance().onCrash() should not be called and expected log should be logged
*/
@Test
public void addCrashReport_backendModeEnabled() {
addCrashReport_base(TestUtils.getConfigSessions().enableBackendMode(), 0);
}
private void addCrashReport_base(Config config, int rqSize) {
Countly.instance().init(config);
SessionImpl session = (SessionImpl) Countly.session();
session.addCrashReport(new Exception(), false);
Assert.assertEquals(rqSize, TestUtils.getCurrentRQ().length);
}
/**
* "hashCode"
* should return the same value as the ID
*/
@Test
public void hashCode_id() {
Countly.instance().init(TestUtils.getConfigSessions());
assertEquals(new Long(12_345L).hashCode(), createSessionImpl(12_345L).hashCode());
}
/**
* "equals"
* both mocked sessions are same
* should return true
*/
@Test
public void equals_test() {
//test keyword added for codacy
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session().update();
session.end();
session.addParam("test", "value");
SessionImpl session2 = (SessionImpl) Countly.session().update();
session2.end();
session2.began = session.began;
session2.updated = session.updated;
session2.ended = session.ended;
session2.addParam("test", "value");
session.id = 12345L;
session2.id = 12345L;
Assert.assertTrue(session.equals(session2));
}
/**
* "equals" different class
* should return false
*/
@Test
public void equals_notInstanceOf() {
Countly.instance().init(TestUtils.getConfigSessions());
Assert.assertFalse(createSessionImpl(12_345L).equals(new Object()));
}
/**
* "equals" different IDs
* should return false
*/
@Test
public void equals_differentId() {
validateNotEquals(1, (session, session2) -> ts -> {
});
}
/**
* "equals" different began
* should return false
*/
@Test
public void equals_differentBegan() {
validateNotEquals(0, (session1, session2) -> ts -> {
session1.began = ts;
session2.began = ts + 1;
});
}
/**
* "equals" different updated
* should return false
*/
@Test
public void equals_differentUpdated() {
validateNotEquals(0, (session1, session2) -> ts -> {
session1.updated = ts;
session2.updated = ts + 1;
});
}
/**
* "equals" different ended
* should return false
*/
@Test
public void equals_differentEnded() {
validateNotEquals(0, (session1, session2) -> ts -> {
session1.ended = ts;
session2.ended = ts + 1;
});
}
/**
* "equals" different params
* should return false
*/
@Test
public void equals_differentParams() {
validateNotEquals(0, (session1, session2) -> ts -> session1.addParam("key", "value"));
}
/**
* "view" with no consent to views
* mocked view name given to function and validating function calls
* expected log should be logged
*/
@Test
public void view_viewsNotEnabled() {
Countly.instance().init(TestUtils.getConfigSessions());
SessionImpl session = (SessionImpl) Countly.session();
session.L = spy(session.L);
View view = session.view("view");
verify(session.L, times(1)).i("[SessionImpl] view: Skipping view - feature is not enabled");
Assert.assertNull(view);
}
/**
* "view"
* mocked view name given to function and validating from EQ
* view should be recorded to EQ
*/
@Test
public void view() {
Countly.instance().init(TestUtils.getConfigSessions(Config.Feature.Views, Config.Feature.Events).setEventQueueSizeToSend(4));
SessionImpl session = (SessionImpl) Countly.session();
TestUtils.validateEQSize(0);
session.view("view");
ModuleViewsTests.validateView("view", 0.0, 0, 1, true, true, null, "_CLY_", "");
}
/**
* "view"
* mocked view name given to function and validating EQ size and from EQ
* start, stop and next view should be recorded to EQ
*/
@Test
public void view_stopStartedAndNext() {
InternalConfig config = new InternalConfig(TestUtils.getConfigSessions(Config.Feature.Views, Config.Feature.Events).setEventQueueSizeToSend(4));
config.viewIdGenerator = TestUtils.idGenerator();
Countly.instance().init(config);
SessionImpl session = (SessionImpl) Countly.session();
TestUtils.validateEQSize(0);
session.view("start");
TestUtils.validateEQSize(1);
session.view("next");
ModuleViewsTests.validateView("start", 0.0, 0, 3, true, true, null, TestUtils.keysValues[0], "");
ModuleViewsTests.validateView("start", 0.0, 1, 3, false, false, null, TestUtils.keysValues[0], "");
ModuleViewsTests.validateView("next", 0.0, 2, 3, false, true, null, TestUtils.keysValues[1], TestUtils.keysValues[0]);
}
/**
* Validates that when session calls are made, if any user properties are set,
* they are sent before sending that session call
* Validated with all session calls: begin, update, end
*
* @throws InterruptedException if thread is interrupted
*/
@Test
public void userPropsOnSessions() throws InterruptedException {
Countly.instance().init(TestUtils.getConfigSessions(Config.Feature.UserProfiles));
Countly.instance().userProfile().setProperty("name", "John Doe");
Countly.instance().userProfile().setProperty("custom_key", "custom_value");
Countly.session().begin();
Map<String, String>[] RQ = TestUtils.getCurrentRQ();
UserEditorTests.validateUserDetailsRequestInRQ(TestUtils.map("user_details", TestUtils.json("name", "John Doe", "custom", TestUtils.map("custom_key", "custom_value"))), 0, 2);
Assert.assertEquals("1", RQ[1].get("begin_session"));
Thread.sleep(2000); // wait for session to update
Countly.instance().userProfile().save();
RQ = TestUtils.getCurrentRQ();
Assert.assertEquals(2, RQ.length); // Validate that user properties are flushed
Countly.instance().userProfile().setProperty("email", "john@doe.com");
Countly.session().update();
RQ = TestUtils.getCurrentRQ();
Assert.assertEquals(TestUtils.json("email", "john@doe.com"), RQ[2].get("user_details"));
Assert.assertEquals("2", RQ[3].get("session_duration"));
Thread.sleep(2000); // wait for session to update
Countly.instance().userProfile().save();
RQ = TestUtils.getCurrentRQ();
Assert.assertEquals(4, RQ.length); // Validate that user properties are flushed with update call
Countly.instance().userProfile().setProperty("done", "yes");
Countly.session().end();
RQ = TestUtils.getCurrentRQ();
Assert.assertEquals(TestUtils.json("custom", TestUtils.map("done", "yes")), RQ[4].get("user_details"));
Assert.assertEquals("1", RQ[5].get("end_session"));
}
/**
* Validates that when session calls are made, if any user properties are set,
* they are not packed because auto-send is disabled
*
* @throws InterruptedException if thread is interrupted
*/
@Test
public void userPropsOnSessions_reversed() throws InterruptedException {
Countly.instance().init(TestUtils.getConfigSessions(Config.Feature.UserProfiles).disableAutoSendUserPropertiesOnSessions());
Countly.instance().userProfile().setProperty("name", "John Doe");
Countly.instance().userProfile().setProperty("custom_key", "custom_value");
Countly.session().begin();
Map<String, String>[] RQ = TestUtils.getCurrentRQ();
Assert.assertEquals(1, RQ.length);
Assert.assertEquals("1", RQ[0].get("begin_session"));
Thread.sleep(2000); // wait for session to update
Countly.session().update();
RQ = TestUtils.getCurrentRQ();
Assert.assertEquals(2, RQ.length);
Assert.assertEquals("2", RQ[1].get("session_duration"));
Thread.sleep(2000);
Countly.session().end();
RQ = TestUtils.getCurrentRQ();
Assert.assertEquals(3, RQ.length);
Assert.assertEquals("1", RQ[2].get("end_session"));
}
private void validateNotEquals(int idOffset, BiFunction<SessionImpl, SessionImpl, Consumer<Long>> setter) {
Countly.instance().init(TestUtils.getConfigSessions());
long ts = TimeUtils.timestampMs();
SessionImpl session = createSessionImpl(12_345L);
SessionImpl session2 = createSessionImpl(12_345L + idOffset);
setter.apply(session, session).accept(ts);
Assert.assertFalse(session.equals(session2));
}
private void validateDeviceIdMerge(String deviceId, String expected, boolean merge) {
validateDeviceIdMerge(deviceId, expected, merge, TestUtils.getConfigSessions());
}
private void validateDeviceIdMerge(String deviceId, String expected, boolean merge, Config config) {
Countly.instance().init(config);
Session session = Countly.session();
if (merge) {
session.changeDeviceIdWithMerge(deviceId);
} else {
session.changeDeviceIdWithoutMerge(deviceId);
}
assertEquals(expected, session.getDeviceId());
}
private SessionImpl validateBeganSession(SessionImpl session) {
Assert.assertNotNull(session.began);
Assert.assertNull(session.updated);
Assert.assertNull(session.ended);
Assert.assertTrue(session.isActive());
return session;
}
private SessionImpl validateUpdatedSession(SessionImpl session) {
Assert.assertNotNull(session.began);
Assert.assertNotNull(session.updated);
Assert.assertNull(session.ended);
Assert.assertTrue(session.isActive());
return session;
}
private SessionImpl validateEndedSession(SessionImpl session) {
Assert.assertNotNull(session.began);
Assert.assertNotNull(session.ended);
Assert.assertFalse(session.isActive());
return session;
}
private void validateNotStarted(SessionImpl session) {
Assert.assertNull(session.began);
Assert.assertNull(session.updated);
Assert.assertNull(session.ended);
Assert.assertFalse(session.isActive());
}
private SessionImpl createSessionImpl(Long id) {
InternalConfig ic = new InternalConfig(TestUtils.getBaseConfig());
ic.setLogger(new Log(Config.LoggingLevel.OFF, null));
return new SessionImpl(ic, id);
}
}