-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathLayoutFactoryTest.java
More file actions
79 lines (69 loc) · 2.57 KB
/
LayoutFactoryTest.java
File metadata and controls
79 lines (69 loc) · 2.57 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.reactnativenavigation.utils;
import com.facebook.react.ReactHost;
import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.options.LayoutFactory;
import com.reactnativenavigation.options.LayoutNode;
import com.reactnativenavigation.react.events.EventEmitter;
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.HashMap;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class LayoutFactoryTest extends BaseTest {
private LayoutFactory uut;
private ReactHost reactHost;
@Override
public void beforeEach() {
super.beforeEach();
reactHost = mock(ReactHost.class);
uut = new LayoutFactory(reactHost);
uut.init(
newActivity(),
Mockito.mock(EventEmitter.class),
new ChildControllersRegistry(),
new HashMap<>()
);
}
@Test
public void sanity() throws JSONException {
assertThat(uut.create(component())).isNotNull();
}
@Test
public void shouldParseOptionsWhenReactContextIsNull() {
when(reactHost.getCurrentReactContext()).thenReturn(null);
try {
uut.create(component());
} catch (Exception e) {
fail("Create should not fail! when react instance has null context");
}
}
@Test
public void defaultOptionsAreNotNull() {
assertThat(uut.getDefaultOptions()).isNotNull();
boolean exceptionThrown = false;
try {
//noinspection ConstantConditions
uut.setDefaultOptions(null);
} catch (AssertionError exception) {
exceptionThrown = true;
}
assertThat(exceptionThrown).isTrue();
}
private LayoutNode component() throws JSONException {
final JSONObject component = new JSONObject();
final JSONObject layout = new JSONObject();
final JSONObject backgroundColor = new JSONObject();
backgroundColor.put("dark",0);
backgroundColor.put("light",1);
layout.put("backgroundColor",backgroundColor );
component.put("name", "com.component");
component.put("options",new JSONObject().put("layout", layout));
return new LayoutNode("Component1", LayoutNode.Type.Component, component, null);
}
}