Browse Source

JSONObject

Daniel Zlotin 7 years ago
parent
commit
b0871a8a10

+ 3
- 3
lib/android/app/src/main/java/com/reactnativenavigation/controllers/CommandsHandler.java View File

12
 import com.reactnativenavigation.layout.parse.LayoutNode;
12
 import com.reactnativenavigation.layout.parse.LayoutNode;
13
 import com.reactnativenavigation.utils.UiThread;
13
 import com.reactnativenavigation.utils.UiThread;
14
 
14
 
15
-import java.util.Map;
15
+import org.json.JSONObject;
16
 
16
 
17
 public class CommandsHandler {
17
 public class CommandsHandler {
18
 
18
 
19
-	public void setRoot(final NavigationActivity activity, final Map<String, Object> layoutTree) {
19
+	public void setRoot(final NavigationActivity activity, final JSONObject layoutTree) {
20
 		LayoutFactory factory =
20
 		LayoutFactory factory =
21
 				new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
21
 				new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
22
 					@Override
22
 					@Override
34
 		activity.setContentView(rootView);
34
 		activity.setContentView(rootView);
35
 	}
35
 	}
36
 
36
 
37
-	public void push(final NavigationActivity activity, String onContainerId, final Map<String, Object> layoutTree) {
37
+	public void push(final NavigationActivity activity, String onContainerId, JSONObject layoutTree) {
38
 		LayoutFactory factory =
38
 		LayoutFactory factory =
39
 				new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
39
 				new LayoutFactory(activity, new LayoutFactory.ReactRootViewCreator() {
40
 					@Override
40
 					@Override

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/layout/LayoutFactory.java View File

81
 	}
81
 	}
82
 
82
 
83
 	private View createContainerView(LayoutNode node) {
83
 	private View createContainerView(LayoutNode node) {
84
-		final String name = (String) node.data.get("name");
84
+		final String name = node.data.optString("name");
85
 		Container container = new Container(activity, reactRootViewCreator, node.id, name);
85
 		Container container = new Container(activity, reactRootViewCreator, node.id, name);
86
 		container.setId(CompatUtils.generateViewId());
86
 		container.setId(CompatUtils.generateViewId());
87
 		return container;
87
 		return container;

+ 17
- 17
lib/android/app/src/main/java/com/reactnativenavigation/layout/parse/LayoutNode.java View File

1
 package com.reactnativenavigation.layout.parse;
1
 package com.reactnativenavigation.layout.parse;
2
 
2
 
3
+import org.json.JSONArray;
4
+import org.json.JSONObject;
5
+
3
 import java.util.ArrayList;
6
 import java.util.ArrayList;
4
-import java.util.HashMap;
5
 import java.util.List;
7
 import java.util.List;
6
-import java.util.Map;
7
 
8
 
8
 public class LayoutNode {
9
 public class LayoutNode {
9
 	public enum Type {
10
 	public enum Type {
22
 
23
 
23
 	public final String id;
24
 	public final String id;
24
 	public final Type type;
25
 	public final Type type;
25
-	public final Map<String, Object> data;
26
-
26
+	public final JSONObject data;
27
 	public final List<LayoutNode> children;
27
 	public final List<LayoutNode> children;
28
 
28
 
29
 	public LayoutNode(String id, Type type) {
29
 	public LayoutNode(String id, Type type) {
30
-		this(id, type, new HashMap<String, Object>(), new ArrayList<LayoutNode>());
30
+		this(id, type, new JSONObject(), new ArrayList<LayoutNode>());
31
 	}
31
 	}
32
 
32
 
33
-	public LayoutNode(String id, Type type, Map<String, Object> data, List<LayoutNode> children) {
33
+	public LayoutNode(String id, Type type, JSONObject data, List<LayoutNode> children) {
34
 		this.id = id;
34
 		this.id = id;
35
 		this.type = type;
35
 		this.type = type;
36
 		this.data = data;
36
 		this.data = data;
38
 	}
38
 	}
39
 
39
 
40
 	@SuppressWarnings("unchecked")
40
 	@SuppressWarnings("unchecked")
41
-	public static LayoutNode fromTree(Map<String, Object> layoutTree) {
42
-		String id = (String) layoutTree.get("id");
43
-		LayoutNode.Type type = LayoutNode.Type.fromString((String) layoutTree.get("type"));
41
+	public static LayoutNode fromTree(JSONObject layoutTree) {
42
+		String id = layoutTree.optString("id");
43
+		LayoutNode.Type type = LayoutNode.Type.fromString(layoutTree.optString("type"));
44
 
44
 
45
-		Map<String, Object> data;
46
-		if (layoutTree.containsKey("data")) {
47
-			data = (Map<String, Object>) layoutTree.get("data");
45
+		JSONObject data;
46
+		if (layoutTree.has("data")) {
47
+			data = layoutTree.optJSONObject("data");
48
 		} else {
48
 		} else {
49
-			data = new HashMap<>();
49
+			data = new JSONObject();
50
 		}
50
 		}
51
 
51
 
52
 		List<LayoutNode> children = new ArrayList<>();
52
 		List<LayoutNode> children = new ArrayList<>();
53
-		if (layoutTree.containsKey("children")) {
54
-			List<Object> rawChildren = (List<Object>) layoutTree.get("children");
55
-			for (Object rawChild : rawChildren) {
56
-				children.add(LayoutNode.fromTree((Map<String, Object>) rawChild));
53
+		if (layoutTree.has("children")) {
54
+			JSONArray rawChildren = layoutTree.optJSONArray("children");
55
+			for (int i = 0; i < rawChildren.length(); i++) {
56
+				children.add(LayoutNode.fromTree(rawChildren.optJSONObject(i)));
57
 			}
57
 			}
58
 		}
58
 		}
59
 
59
 

+ 38
- 35
lib/android/app/src/main/java/com/reactnativenavigation/react/ArgsParser.java View File

4
 import com.facebook.react.bridge.ReadableMap;
4
 import com.facebook.react.bridge.ReadableMap;
5
 import com.facebook.react.bridge.ReadableMapKeySetIterator;
5
 import com.facebook.react.bridge.ReadableMapKeySetIterator;
6
 
6
 
7
-import java.util.ArrayList;
8
-import java.util.HashMap;
9
-import java.util.List;
10
-import java.util.Map;
7
+import org.json.JSONArray;
8
+import org.json.JSONException;
9
+import org.json.JSONObject;
11
 
10
 
12
 public class ArgsParser {
11
 public class ArgsParser {
13
-	public static Map<String, Object> parse(ReadableMap map) {
14
-		Map<String, Object> result = new HashMap<>();
15
-		ReadableMapKeySetIterator it = map.keySetIterator();
16
-		while (it.hasNextKey()) {
17
-			String key = it.nextKey();
18
-			switch (map.getType(key)) {
19
-				case String:
20
-					result.put(key, map.getString(key));
21
-					break;
22
-				case Number:
23
-					result.put(key, parseNumber(map, key));
24
-					break;
25
-				case Boolean:
26
-					result.put(key, map.getBoolean(key));
27
-					break;
28
-				case Array:
29
-					result.put(key, parseArray(map.getArray(key)));
30
-					break;
31
-				case Map:
32
-					result.put(key, parse(map.getMap(key)));
33
-					break;
34
-				default:
35
-					break;
12
+	public static JSONObject parse(ReadableMap map) {
13
+		try {
14
+			ReadableMapKeySetIterator it = map.keySetIterator();
15
+			JSONObject result = new JSONObject();
16
+			while (it.hasNextKey()) {
17
+				String key = it.nextKey();
18
+				switch (map.getType(key)) {
19
+					case String:
20
+						result.put(key, map.getString(key));
21
+						break;
22
+					case Number:
23
+						result.put(key, parseNumber(map, key));
24
+						break;
25
+					case Boolean:
26
+						result.put(key, map.getBoolean(key));
27
+						break;
28
+					case Array:
29
+						result.put(key, parse(map.getArray(key)));
30
+						break;
31
+					case Map:
32
+						result.put(key, parse(map.getMap(key)));
33
+						break;
34
+					default:
35
+						break;
36
+				}
36
 			}
37
 			}
38
+			return result;
39
+		} catch (JSONException e) {
40
+			throw new RuntimeException(e);
37
 		}
41
 		}
38
-		return result;
39
 	}
42
 	}
40
 
43
 
41
-	public static List<Object> parseArray(ReadableArray arr) {
42
-		List<Object> result = new ArrayList<>();
44
+	public static JSONArray parse(ReadableArray arr) {
45
+		JSONArray result = new JSONArray();
43
 		for (int i = 0; i < arr.size(); i++) {
46
 		for (int i = 0; i < arr.size(); i++) {
44
 			switch (arr.getType(i)) {
47
 			switch (arr.getType(i)) {
45
 				case String:
48
 				case String:
46
-					result.add(arr.getString(i));
49
+					result.put(arr.getString(i));
47
 					break;
50
 					break;
48
 				case Number:
51
 				case Number:
49
-					result.add(parseNumber(arr, i));
52
+					result.put(parseNumber(arr, i));
50
 					break;
53
 					break;
51
 				case Boolean:
54
 				case Boolean:
52
-					result.add(arr.getBoolean(i));
55
+					result.put(arr.getBoolean(i));
53
 					break;
56
 					break;
54
 				case Array:
57
 				case Array:
55
-					result.add(parseArray(arr.getArray(i)));
58
+					result.put(parse(arr.getArray(i)));
56
 					break;
59
 					break;
57
 				case Map:
60
 				case Map:
58
-					result.add(parse(arr.getMap(i)));
61
+					result.put(parse(arr.getMap(i)));
59
 					break;
62
 					break;
60
 				default:
63
 				default:
61
 					break;
64
 					break;

+ 13
- 14
lib/android/app/src/test/java/com/reactnativenavigation/layout/LayoutFactoryTest.java View File

11
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
11
 import com.reactnativenavigation.layout.bottomtabs.BottomTabsLayout;
12
 import com.reactnativenavigation.layout.parse.LayoutNode;
12
 import com.reactnativenavigation.layout.parse.LayoutNode;
13
 
13
 
14
+import org.json.JSONException;
15
+import org.json.JSONObject;
14
 import org.junit.Before;
16
 import org.junit.Before;
15
 import org.junit.Ignore;
17
 import org.junit.Ignore;
16
 import org.junit.Test;
18
 import org.junit.Test;
18
 
20
 
19
 import java.util.Arrays;
21
 import java.util.Arrays;
20
 import java.util.Collections;
22
 import java.util.Collections;
21
-import java.util.HashMap;
22
 import java.util.List;
23
 import java.util.List;
23
 
24
 
24
 import static org.assertj.core.api.Java6Assertions.assertThat;
25
 import static org.assertj.core.api.Java6Assertions.assertThat;
170
 	}
171
 	}
171
 
172
 
172
 	@Test
173
 	@Test
173
-	public void pushScreenToFirstBottomTab() {
174
+	public void pushScreenToFirstBottomTab() throws Exception {
174
 		BottomTabs bottomTabsMock = mock(BottomTabs.class);
175
 		BottomTabs bottomTabsMock = mock(BottomTabs.class);
175
 		when(bottomTabsMock.size()).thenReturn(0, 1);
176
 		when(bottomTabsMock.size()).thenReturn(0, 1);
176
 
177
 
193
 	}
194
 	}
194
 
195
 
195
 	@Test
196
 	@Test
196
-	public void popScreenFromFirstBottomTab() {
197
+	public void popScreenFromFirstBottomTab() throws Exception {
197
 		BottomTabs bottomTabsMock = mock(BottomTabs.class);
198
 		BottomTabs bottomTabsMock = mock(BottomTabs.class);
198
 		when(bottomTabsMock.size()).thenReturn(0, 1);
199
 		when(bottomTabsMock.size()).thenReturn(0, 1);
199
 
200
 
263
 		assertThat(result.getChildAt(0)).isEqualTo(mockView);
264
 		assertThat(result.getChildAt(0)).isEqualTo(mockView);
264
 	}
265
 	}
265
 
266
 
266
-	private void pushContainer(ContainerStackLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
267
+	private void pushContainer(ContainerStackLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) throws Exception {
267
 		when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
268
 		when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
268
 		View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
269
 		View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
269
 		containerStackLayout.push(pushedContainer);
270
 		containerStackLayout.push(pushedContainer);
270
 	}
271
 	}
271
 
272
 
272
-	private void pushContainer(BottomTabsLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) {
273
+	private void pushContainer(BottomTabsLayout containerStackLayout, String screenId, String reactRootViewKey, View rootView) throws Exception {
273
 		when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
274
 		when(reactRootViewCreator.create(eq(screenId), eq(reactRootViewKey))).thenReturn(rootView);
274
 		View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
275
 		View pushedContainer = createLayoutFactory().create(createContainerNode(screenId, reactRootViewKey));
275
 		containerStackLayout.push(pushedContainer);
276
 		containerStackLayout.push(pushedContainer);
276
 	}
277
 	}
277
 
278
 
278
 	@Test
279
 	@Test
279
-	public void popScreenFromScreenStackLayout() {
280
+	public void popScreenFromScreenStackLayout() throws Exception {
280
 		when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
281
 		when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
281
 		final LayoutNode container = createContainerNode();
282
 		final LayoutNode container = createContainerNode();
282
 		final LayoutNode stackNode = createContainerStackNode(container);
283
 		final LayoutNode stackNode = createContainerStackNode(container);
295
 	@Ignore
296
 	@Ignore
296
 	public void throwsExceptionForUnknownType() throws Exception {
297
 	public void throwsExceptionForUnknownType() throws Exception {
297
 		when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
298
 		when(reactRootViewCreator.create(eq(NODE_ID), eq(REACT_ROOT_VIEW_KEY))).thenReturn(mockView);
298
-		final LayoutNode node = new LayoutNode(NODE_ID, null, Collections.<String, Object>emptyMap(), Collections.<LayoutNode>emptyList());
299
+		final LayoutNode node = new LayoutNode(NODE_ID, null, new JSONObject(), Collections.<LayoutNode>emptyList());
299
 
300
 
300
 		createLayoutFactory().create(node);
301
 		createLayoutFactory().create(node);
301
 	}
302
 	}
314
 		return new LayoutFactory(activity, reactRootViewCreator, bottomTabsCreator);
315
 		return new LayoutFactory(activity, reactRootViewCreator, bottomTabsCreator);
315
 	}
316
 	}
316
 
317
 
317
-	private LayoutNode createContainerNode() {
318
+	private LayoutNode createContainerNode() throws Exception {
318
 		return createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
319
 		return createContainerNode(NODE_ID, REACT_ROOT_VIEW_KEY);
319
 	}
320
 	}
320
 
321
 
321
-	private LayoutNode createSideMenuLeftNode() {
322
+	private LayoutNode createSideMenuLeftNode() throws Exception {
322
 		List<LayoutNode> children = Arrays.asList(createContainerNode());
323
 		List<LayoutNode> children = Arrays.asList(createContainerNode());
323
 		return new LayoutNode("SideMenuLeft", LayoutNode.Type.SideMenuLeft, null, children);
324
 		return new LayoutNode("SideMenuLeft", LayoutNode.Type.SideMenuLeft, null, children);
324
 	}
325
 	}
325
 
326
 
326
-	private LayoutNode createSideMenuRightNode() {
327
+	private LayoutNode createSideMenuRightNode() throws Exception {
327
 		List<LayoutNode> children = Arrays.asList(createContainerNode());
328
 		List<LayoutNode> children = Arrays.asList(createContainerNode());
328
 		return new LayoutNode("SideMenuRight", LayoutNode.Type.SideMenuRight, null, children);
329
 		return new LayoutNode("SideMenuRight", LayoutNode.Type.SideMenuRight, null, children);
329
 	}
330
 	}
330
 
331
 
331
-	private LayoutNode createContainerNode(final String id, final String name) {
332
-		return new LayoutNode(id, LayoutNode.Type.Container, new HashMap<String, Object>() {{
333
-			put("name", name);
334
-		}}, null);
332
+	private LayoutNode createContainerNode(final String id, final String name) throws JSONException {
333
+		return new LayoutNode(id, LayoutNode.Type.Container, new JSONObject().put("name", name), null);
335
 	}
334
 	}
336
 
335
 
337
 	private LayoutNode createSideMenuContainerNode(List<LayoutNode> children) {
336
 	private LayoutNode createSideMenuContainerNode(List<LayoutNode> children) {

+ 9
- 21
lib/android/app/src/test/java/com/reactnativenavigation/layout/parse/LayoutNodeTest.java View File

2
 
2
 
3
 import com.reactnativenavigation.BaseTest;
3
 import com.reactnativenavigation.BaseTest;
4
 
4
 
5
+import org.json.JSONObject;
5
 import org.junit.Test;
6
 import org.junit.Test;
6
 
7
 
7
-import java.util.ArrayList;
8
-import java.util.HashMap;
9
-import java.util.List;
10
-import java.util.Map;
11
-
12
 import static org.assertj.core.api.Java6Assertions.assertThat;
8
 import static org.assertj.core.api.Java6Assertions.assertThat;
13
-import static org.assertj.core.api.Java6Assertions.entry;
14
 
9
 
15
 public class LayoutNodeTest extends BaseTest {
10
 public class LayoutNodeTest extends BaseTest {
16
 	@Test
11
 	@Test
18
 		LayoutNode node = new LayoutNode("the id", LayoutNode.Type.Container);
13
 		LayoutNode node = new LayoutNode("the id", LayoutNode.Type.Container);
19
 		assertThat(node.id).isEqualTo("the id");
14
 		assertThat(node.id).isEqualTo("the id");
20
 		assertThat(node.type).isEqualTo(LayoutNode.Type.Container);
15
 		assertThat(node.type).isEqualTo(LayoutNode.Type.Container);
21
-		assertThat(node.data).isEmpty();
16
+		assertThat(node.data.keys()).isEmpty();
22
 		assertThat(node.children).isEmpty();
17
 		assertThat(node.children).isEmpty();
23
 	}
18
 	}
24
 
19
 
34
 
29
 
35
 	@Test
30
 	@Test
36
 	public void parseFromTree() throws Exception {
31
 	public void parseFromTree() throws Exception {
37
-		Map<String, Object> tree = new HashMap<>();
38
-		tree.put("id", "node1");
39
-		tree.put("type", "ContainerStack");
40
-		Map<String, Object> rawData = new HashMap<>();
41
-		rawData.put("dataKey", "dataValue");
42
-		tree.put("data", rawData);
43
-		List<Object> rawChildren = new ArrayList<>();
44
-		Map<String, Object> rawChild = new HashMap<>();
45
-		rawChild.put("id", "childId1");
46
-		rawChild.put("type", "Container");
47
-		rawChildren.add(rawChild);
48
-		tree.put("children", rawChildren);
32
+		JSONObject tree = new JSONObject("{id: node1, " +
33
+				"type: ContainerStack, " +
34
+				"data: {dataKey: dataValue}, " +
35
+				"children: [{id: childId1, type: Container}]}");
49
 
36
 
50
 		LayoutNode result = LayoutNode.fromTree(tree);
37
 		LayoutNode result = LayoutNode.fromTree(tree);
51
 
38
 
52
 		assertThat(result).isNotNull();
39
 		assertThat(result).isNotNull();
53
 		assertThat(result.id).isEqualTo("node1");
40
 		assertThat(result.id).isEqualTo("node1");
54
 		assertThat(result.type).isEqualTo(LayoutNode.Type.ContainerStack);
41
 		assertThat(result.type).isEqualTo(LayoutNode.Type.ContainerStack);
55
-		assertThat(result.data).containsOnly(entry("dataKey", "dataValue"));
42
+		assertThat(result.data.length()).isEqualTo(1);
43
+		assertThat(result.data.getString("dataKey")).isEqualTo("dataValue");
56
 		assertThat(result.children).hasSize(1);
44
 		assertThat(result.children).hasSize(1);
57
 		assertThat(result.children.get(0).id).isEqualTo("childId1");
45
 		assertThat(result.children.get(0).id).isEqualTo("childId1");
58
 		assertThat(result.children.get(0).type).isEqualTo(LayoutNode.Type.Container);
46
 		assertThat(result.children.get(0).type).isEqualTo(LayoutNode.Type.Container);
59
-		assertThat(result.children.get(0).data).isEmpty();
47
+		assertThat(result.children.get(0).data.keys()).isEmpty();
60
 		assertThat(result.children.get(0).children).isEmpty();
48
 		assertThat(result.children.get(0).children).isEmpty();
61
 	}
49
 	}
62
 }
50
 }

+ 28
- 17
lib/android/app/src/test/java/com/reactnativenavigation/react/ArgsParserTest.java View File

4
 import com.facebook.react.bridge.JavaOnlyMap;
4
 import com.facebook.react.bridge.JavaOnlyMap;
5
 import com.reactnativenavigation.BaseTest;
5
 import com.reactnativenavigation.BaseTest;
6
 
6
 
7
+import org.json.JSONArray;
8
+import org.json.JSONObject;
7
 import org.junit.Test;
9
 import org.junit.Test;
8
 
10
 
9
-import java.util.ArrayList;
10
-import java.util.HashMap;
11
-import java.util.List;
12
-import java.util.Map;
13
-
14
 import static org.assertj.core.api.Java6Assertions.assertThat;
11
 import static org.assertj.core.api.Java6Assertions.assertThat;
15
-import static org.assertj.core.api.Java6Assertions.entry;
16
 
12
 
17
 public class ArgsParserTest extends BaseTest {
13
 public class ArgsParserTest extends BaseTest {
18
 	@Test
14
 	@Test
19
-	public void parsesToMap() throws Exception {
15
+	public void parsesMap() throws Exception {
20
 		JavaOnlyMap input = new JavaOnlyMap();
16
 		JavaOnlyMap input = new JavaOnlyMap();
21
 		input.putString("keyString", "stringValue");
17
 		input.putString("keyString", "stringValue");
22
 		input.putInt("keyInt", 123);
18
 		input.putInt("keyInt", 123);
23
 		input.putDouble("keyDouble", 123.456);
19
 		input.putDouble("keyDouble", 123.456);
24
 		input.putBoolean("keyBoolean", true);
20
 		input.putBoolean("keyBoolean", true);
25
 		input.putArray("keyArray", new JavaOnlyArray());
21
 		input.putArray("keyArray", new JavaOnlyArray());
22
+		input.putMap("keyMap", new JavaOnlyMap());
26
 		input.putNull("bla");
23
 		input.putNull("bla");
27
 
24
 
28
-		Map<String, Object> result = ArgsParser.parse(input);
25
+		JSONObject result = ArgsParser.parse(input);
26
+
27
+
28
+		assertThat(result.keys()).containsOnly(
29
+				"keyString",
30
+				"keyInt",
31
+				"keyDouble",
32
+				"keyBoolean",
33
+				"keyMap",
34
+				"keyArray");
29
 
35
 
30
-		assertThat(result).containsOnly(
31
-				entry("keyString", "stringValue"),
32
-				entry("keyInt", 123),
33
-				entry("keyDouble", 123.456),
34
-				entry("keyBoolean", true),
35
-				entry("keyArray", new ArrayList<>())
36
-		);
36
+		assertThat(result.get("keyString")).isEqualTo("stringValue");
37
+		assertThat(result.get("keyInt")).isEqualTo(123);
38
+		assertThat(result.get("keyDouble")).isEqualTo(123.456);
39
+		assertThat(result.get("keyBoolean")).isEqualTo(true);
40
+		assertThat(result.getJSONObject("keyMap").keys()).isEmpty();
41
+		assertThat(result.getJSONArray("keyArray").length()).isZero();
37
 	}
42
 	}
38
 
43
 
39
 	@Test
44
 	@Test
47
 		input.pushMap(new JavaOnlyMap());
52
 		input.pushMap(new JavaOnlyMap());
48
 		input.pushNull();
53
 		input.pushNull();
49
 
54
 
50
-		List<Object> result = ArgsParser.parseArray(input);
51
-		assertThat(result).containsExactly("Hello", 123, 123.456, true, new ArrayList<>(), new HashMap<>());
55
+		JSONArray result = ArgsParser.parse(input);
56
+		assertThat(result.length()).isEqualTo(6);
57
+		assertThat(result.get(0)).isEqualTo("Hello");
58
+		assertThat(result.get(1)).isEqualTo(123);
59
+		assertThat(result.get(2)).isEqualTo(123.456);
60
+		assertThat(result.get(3)).isEqualTo(true);
61
+		assertThat(result.getJSONArray(4).length()).isZero();
62
+		assertThat(result.getJSONObject(5).keys()).isEmpty();
52
 	}
63
 	}
53
 }
64
 }

+ 3
- 3
lib/android/app/src/test/java/com/reactnativenavigation/react/NavigationModuleTest.java View File

8
 import com.reactnativenavigation.NavigationApplication;
8
 import com.reactnativenavigation.NavigationApplication;
9
 import com.reactnativenavigation.controllers.CommandsHandler;
9
 import com.reactnativenavigation.controllers.CommandsHandler;
10
 
10
 
11
+import org.json.JSONObject;
11
 import org.junit.Before;
12
 import org.junit.Before;
12
 import org.junit.Test;
13
 import org.junit.Test;
13
 import org.mockito.ArgumentCaptor;
14
 import org.mockito.ArgumentCaptor;
14
 import org.robolectric.Robolectric;
15
 import org.robolectric.Robolectric;
15
 
16
 
16
 import java.lang.reflect.Method;
17
 import java.lang.reflect.Method;
17
-import java.util.HashMap;
18
 
18
 
19
 import static org.assertj.core.api.Java6Assertions.assertThat;
19
 import static org.assertj.core.api.Java6Assertions.assertThat;
20
 import static org.mockito.ArgumentMatchers.any;
20
 import static org.mockito.ArgumentMatchers.any;
63
 		JavaOnlyMap input = new JavaOnlyMap();
63
 		JavaOnlyMap input = new JavaOnlyMap();
64
 		input.putString("key", "value");
64
 		input.putString("key", "value");
65
 		uut.setRoot(input);
65
 		uut.setRoot(input);
66
-		ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(HashMap.class);
67
-		verify(NavigationApplication.instance.getConfig().commandsHandler, times(1)).setRoot((NavigationActivity) any(), (HashMap<String, Object>) captor.capture());
66
+		ArgumentCaptor<JSONObject> captor = ArgumentCaptor.forClass(JSONObject.class);
67
+		verify(NavigationApplication.instance.getConfig().commandsHandler, times(1)).setRoot((NavigationActivity) any(), captor.capture());
68
 		assertThat(captor.getAllValues()).hasSize(1);
68
 		assertThat(captor.getAllValues()).hasSize(1);
69
 		assertThat(captor.getValue()).isNotNull();
69
 		assertThat(captor.getValue()).isNotNull();
70
 	}
70
 	}

+ 1
- 1
scripts/test.unit.android.js View File

2
 run();
2
 run();
3
 
3
 
4
 function run() {
4
 function run() {
5
-  exec.execSync(`cd lib/android && ./gradlew clean unitTest`);
5
+  exec.execSync(`cd lib/android && ./gradlew ${process.env.CI ? 'clean' : ''} unitTest`);
6
 }
6
 }