Skip to content

Commit c5e9f46

Browse files
author
irgendeinich
committed
Fix up the tests
1 parent 3d54f8b commit c5e9f46

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

android/src/main/java/com/pspdfkit/react/PSPDFKitPackage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class PSPDFKitPackage implements ReactPackage {
3131
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
3232
List<NativeModule> modules = new ArrayList<>();
3333
modules.add(new PSPDFKitModule(reactContext));
34+
modules.add(new TestingModule(reactContext));
3435
return modules;
3536
}
3637

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.pspdfkit.react;
2+
3+
import android.support.annotation.NonNull;
4+
5+
import com.facebook.react.bridge.ReactApplicationContext;
6+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
7+
import com.facebook.react.bridge.ReactMethod;
8+
9+
import java.util.HashMap;
10+
11+
public class TestingModule extends ReactContextBaseJavaModule {
12+
13+
private static final HashMap<String, String> values = new HashMap<>();
14+
15+
public TestingModule(ReactApplicationContext reactContext) {
16+
super(reactContext);
17+
}
18+
19+
@Override
20+
public String getName() {
21+
return "TestingModule";
22+
}
23+
24+
@ReactMethod
25+
public void setValue(@NonNull String key, @NonNull String value) {
26+
synchronized (values) {
27+
values.put(key, value);
28+
values.notifyAll();
29+
}
30+
}
31+
32+
public static void resetValues() {
33+
synchronized (values) {
34+
values.clear();
35+
}
36+
}
37+
38+
public static String getValue(@NonNull String key) throws InterruptedException {
39+
synchronized (values) {
40+
while (!values.containsKey(key)) {
41+
values.wait(1000);
42+
}
43+
return values.get(key);
44+
}
45+
}
46+
}

samples/Catalog/android/app/src/androidTest/java/com/pspdfkit/react/PdfViewTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void testGetEmptyAnnotations() throws InterruptedException {
9292
onView(withText("GET")).perform(click());
9393
String annotations = TestingModule.getValue("annotations");
9494

95-
assertEquals("[]", annotations);
95+
assertEquals("{\"annotations\":[]}", annotations);
9696
}
9797

9898
@Test
@@ -111,11 +111,10 @@ public void testGetAnnotation() throws InterruptedException, JSONException {
111111

112112
// Get annotations for first page should return nothing.
113113
onView(withText("GET")).perform(click());
114-
JSONArray annotations = new JSONArray(TestingModule.getValue("annotations"));
115-
116-
114+
JSONObject annotations = new JSONObject(TestingModule.getValue("annotations"));
115+
117116
JSONObject originalInstantJson = new JSONObject(annotation.toInstantJson());
118-
assertEquals(JsonUtilities.jsonObjectToMap(originalInstantJson), JsonUtilities.jsonObjectToMap(annotations.getJSONObject(0)));
117+
assertEquals(JsonUtilities.jsonObjectToMap(originalInstantJson), JsonUtilities.jsonObjectToMap(annotations.getJSONArray("annotations").getJSONObject(0)));
119118
}
120119

121120
}

0 commit comments

Comments
 (0)