Skip to content

Commit c912737

Browse files
committed
fix test in LeanplumTest
1 parent 6d1a422 commit c912737

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static void deleteSentRequests(int requestsCount) {
648648
}
649649
}
650650

651-
protected List<Map<String, Object>> getUnsentRequests() {
651+
public List<Map<String, Object>> getUnsentRequests() {
652652
List<Map<String, Object>> requestData;
653653

654654
synchronized (Request.class) {
@@ -1019,3 +1019,25 @@ public static String getResponseError(JSONObject response) {
10191019
}
10201020
}
10211021
}
1022+
1023+
class RequestManager
1024+
{
1025+
private static RequestManager single_instance = null;
1026+
1027+
// variable of type String
1028+
public String s;
1029+
1030+
// private constructor restricted to this class itself
1031+
private RequestManager() {
1032+
s = "Hello I am a string part of Singleton class";
1033+
}
1034+
1035+
// static method to create instance of Singleton class
1036+
public static RequestManager getInstance()
1037+
{
1038+
if (single_instance == null)
1039+
single_instance = new RequestManager();
1040+
1041+
return single_instance;
1042+
}
1043+
}

AndroidSDKTests/src/test/java/com/leanplum/LeanplumTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,14 @@ public void testCrashes() throws Exception {
398398
LeanplumEventDataManager.init(Leanplum.getContext());
399399

400400
// Add two events to database.
401-
new Request("POST", Constants.Methods.GET_INBOX_MESSAGES, null).sendEventually();
402-
new Request("POST", Constants.Methods.LOG, null).sendEventually();
401+
Request request1 = new Request("POST", Constants.Methods.GET_INBOX_MESSAGES, null);
402+
Request request2 = new Request("POST", Constants.Methods.LOG, null);
403403

404+
request1.sendEventually();
405+
request2.sendEventually();
404406
// Get a number of events in the database.
405407
// Expectation: 2 events.
406-
Method getUnsentRequests = Request.class.getDeclaredMethod("getUnsentRequests");
407-
getUnsentRequests.setAccessible(true);
408-
List unsentRequests = (List) getUnsentRequests.invoke(Request.class);
408+
List unsentRequests = request1.getUnsentRequests();
409409
assertNotNull(unsentRequests);
410410
assertEquals(2, unsentRequests.size());
411411

@@ -427,7 +427,7 @@ public void testCrashes() throws Exception {
427427

428428
// Get a number of events in the database. Checks if ours two events still here.
429429
// Expectation: 2 events.
430-
unsentRequests = (List) getUnsentRequests.invoke(Request.class);
430+
unsentRequests = request1.getUnsentRequests();
431431
assertNotNull(unsentRequests);
432432
assertEquals(2, unsentRequests.size());
433433

@@ -444,7 +444,7 @@ public void onRequest(String httpMethod, String apiMethod, Map<String, Object> p
444444

445445
// Get a number of events in the database. Make sure we sent all events.
446446
// Expectation: 0 events.
447-
unsentRequests = (List) getUnsentRequests.invoke(Request.class);
447+
unsentRequests = request1.getUnsentRequests();
448448
assertNotNull(unsentRequests);
449449
assertEquals(0, unsentRequests.size());
450450

0 commit comments

Comments
 (0)