Skip to content

Commit 488cd28

Browse files
author
Sayaan Saha
committed
Finised unit test
1 parent b36a48a commit 488cd28

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

AndroidSDKTests/src/test/java/com/leanplum/internal/RequestTest.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@
3737

3838
import java.lang.reflect.InvocationTargetException;
3939
import java.lang.reflect.Method;
40-
import java.sql.Time;
4140
import java.time.Instant;
4241
import java.util.ArrayList;
43-
import java.util.Date;
4442
import java.util.HashMap;
4543
import java.util.List;
4644
import java.util.Map;
47-
import java.util.concurrent.CountDownLatch;
4845

4946
import static org.mockito.AdditionalMatchers.not;
5047
import static org.mockito.Matchers.eq;
@@ -79,32 +76,11 @@ public void testMultiThreaded() {
7976
Map<String, Object> params = new HashMap<>();
8077
params.put("data1", "value1");
8178
params.put("data2", "value2");
82-
Waiter waiter = new Waiter() {
83-
public Instant t1, t2, t3, t4;
84-
@Override
85-
public void beforeRead() {
86-
t1 = Instant.now();
87-
}
88-
89-
@Override
90-
public void afterRead() {
91-
t2 = Instant.now();
92-
}
93-
94-
@Override
95-
public void beforeWrite() {
96-
t3 = Instant.now();
97-
}
98-
99-
@Override
100-
public void afterWrite() {
101-
t4 = Instant.now();
102-
}
103-
};
104-
Request request = new Request("POST", Constants.Methods.START, params, waiter);
105-
request.setAppId("fskadfshdbfa", "weew22323");
79+
ThreadWaiter waiter = new ThreadWaiter();
80+
Request request = new Request("POST", Constants.Methods.START, params);
81+
request.setAppId("fskadfshdbfa", "wee5w4waer422323");
10682
request.sendIfConnected();
107-
83+
waiter.assertCallSequence();
10884

10985
}
11086
/**
@@ -363,4 +339,30 @@ private List<Map<String, Object>> mockRequests(int requestSize) {
363339
return requests;
364340
}
365341

342+
private static class ThreadWaiter implements Waiter{
343+
Instant t1, t2, t3, t4;
344+
@Override
345+
public void beforeRead() {
346+
t1 = Instant.now();
347+
}
348+
349+
@Override
350+
public void afterRead() {
351+
t2 = Instant.now();
352+
}
353+
354+
@Override
355+
public void beforeWrite() {
356+
t3 = Instant.now();
357+
}
358+
359+
@Override
360+
public void afterWrite() {
361+
t4 = Instant.now();
362+
}
363+
364+
public void assertCallSequence() {
365+
assert(t4.isBefore(t1));
366+
}
367+
}
366368
}

0 commit comments

Comments
 (0)