forked from segmentio/analytics-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAliasTest.java
More file actions
40 lines (28 loc) · 1.02 KB
/
Copy pathAliasTest.java
File metadata and controls
40 lines (28 loc) · 1.02 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
package com.github.segmentio;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import com.github.segmentio.models.Traits;
public class AliasTest {
@BeforeClass
public static void setup() {
Analytics.initialize("testsecret");
}
@Test
public void testAlias() {
int random = (int)Math.floor((Math.random() * 99999) + 50);
String anonymous = "anonymous_user" + random;
String identified = "identified" + random + "@gmail.com";
System.out.println(String.format("Test: %s => %s", anonymous, identified));
// the anonymous user does actions ...
Analytics.track(anonymous, "Anonymous Event");
// the anonymous user signs up and is aliased
Analytics.alias(anonymous, identified);
// the identified user is identified
Analytics.identify(identified, new Traits("plan", "Free"));
// the identified user does actions ...
Analytics.track(identified, "Identified Action");
Analytics.flush();
Assert.assertEquals(4, Analytics.getStatistics().getSuccessful().getCount());
}
}