Browse Source

removed dependency on robolectric

Daniel Zlotin 7 years ago
parent
commit
964b73b433

+ 1
- 2
lib/android/app/build.gradle View File

1
 apply plugin: 'com.android.library'
1
 apply plugin: 'com.android.library'
2
-apply from: '../prepare-robolectric.gradle'
3
 
2
 
4
 android {
3
 android {
5
     compileSdkVersion 25
4
     compileSdkVersion 25
61
 
60
 
62
     // tests
61
     // tests
63
     testCompile 'junit:junit:4.12'
62
     testCompile 'junit:junit:4.12'
64
-    testCompile 'org.robolectric:robolectric:3.3'
65
     testCompile 'org.assertj:assertj-core:2.5.0'
63
     testCompile 'org.assertj:assertj-core:2.5.0'
66
     testCompile 'org.mockito:mockito-core:2.7.5'
64
     testCompile 'org.mockito:mockito-core:2.7.5'
65
+    testCompile 'org.json:json:20140107'
67
 }
66
 }

+ 0
- 8
lib/android/app/src/test/AndroidManifest.xml View File

1
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-          package="com.reactnativenavigation">
3
-
4
-    <application
5
-        android:name=".TestApplication"
6
-        android:theme="@style/Theme.AppCompat.Light">
7
-    </application>
8
-</manifest>

+ 0
- 6
lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java View File

1
 package com.reactnativenavigation;
1
 package com.reactnativenavigation;
2
 
2
 
3
-import org.junit.runner.RunWith;
4
-import org.robolectric.RobolectricTestRunner;
5
-import org.robolectric.annotation.Config;
6
-
7
-@RunWith(RobolectricTestRunner.class)
8
-@Config(sdk = 25, constants = BuildConfig.class, manifest = "/../../../../../src/test/AndroidManifest.xml")
9
 public abstract class BaseTest {
3
 public abstract class BaseTest {
10
 
4
 
11
 }
5
 }

+ 0
- 8
lib/android/app/src/test/java/com/reactnativenavigation/EnvironmentTest.java View File

6
 import com.facebook.react.common.ReactConstants;
6
 import com.facebook.react.common.ReactConstants;
7
 
7
 
8
 import org.junit.Test;
8
 import org.junit.Test;
9
-import org.robolectric.Robolectric;
10
-import org.robolectric.RuntimeEnvironment;
11
 
9
 
12
 import static org.assertj.core.api.Java6Assertions.assertThat;
10
 import static org.assertj.core.api.Java6Assertions.assertThat;
13
 
11
 
36
 	public void androidR() {
34
 	public void androidR() {
37
 		assertThat(R.string.app_name).isNotZero();
35
 		assertThat(R.string.app_name).isNotZero();
38
 	}
36
 	}
39
-
40
-	@Test
41
-	public void ableToLoadApplication() throws Exception {
42
-		assertThat(RuntimeEnvironment.application).isNotNull();
43
-		assertThat(Robolectric.setupActivity(NavigationActivity.class)).isNotNull();
44
-	}
45
 }
37
 }

+ 0
- 20
lib/android/app/src/test/java/com/reactnativenavigation/TestApplication.java View File

1
-package com.reactnativenavigation;
2
-
3
-import com.reactnativenavigation.controllers.ActivityLifecycleDelegate;
4
-import com.reactnativenavigation.react.NavigationReactNativeHost;
5
-
6
-import static org.mockito.Mockito.mock;
7
-
8
-public class TestApplication extends NavigationApplication {
9
-
10
-	@Override
11
-	public boolean isDebug() {
12
-		return true;
13
-	}
14
-
15
-	@Override
16
-	protected void init() {
17
-		reactNativeHost = mock(NavigationReactNativeHost.class);
18
-		activityLifecycle = mock(ActivityLifecycleDelegate.class);
19
-	}
20
-}

+ 0
- 41
lib/android/app/src/test/java/com/reactnativenavigation/layout/ContainerStackTest.java View File

1
-package com.reactnativenavigation.layout;
2
-
3
-import android.support.annotation.NonNull;
4
-
5
-import com.facebook.react.ReactInstanceManager;
6
-import com.facebook.react.ReactNativeHost;
7
-import com.reactnativenavigation.BaseTest;
8
-import com.reactnativenavigation.NavigationActivity;
9
-import com.reactnativenavigation.layout.containers.Container;
10
-import com.reactnativenavigation.layout.containers.ContainerStack;
11
-
12
-import org.junit.Test;
13
-import org.robolectric.Robolectric;
14
-
15
-import static org.assertj.core.api.Java6Assertions.assertThat;
16
-import static org.mockito.Mockito.mock;
17
-import static org.mockito.Mockito.when;
18
-
19
-public class ContainerStackTest extends BaseTest {
20
-	@Test
21
-	public void push() throws Exception {
22
-		NavigationActivity context = Robolectric.setupActivity(NavigationActivity.class);
23
-		ContainerStack uut = new ContainerStack(context);
24
-		assertThat(uut.isEmpty()).isTrue();
25
-		assertThat(uut.getChildCount()).isZero();
26
-
27
-		Container container = createContainer(context);
28
-		uut.push(container);
29
-		assertThat(uut.isEmpty()).isFalse();
30
-
31
-		assertThat(uut.getChildCount()).isEqualTo(1);
32
-
33
-	}
34
-
35
-	@NonNull
36
-	private Container createContainer(final NavigationActivity context) {
37
-		ReactNativeHost reactNativeHost = mock(ReactNativeHost.class);
38
-		when(reactNativeHost.getReactInstanceManager()).thenReturn(mock(ReactInstanceManager.class));
39
-		return new Container(context, "id", "name", reactNativeHost.getReactInstanceManager());
40
-	}
41
-}

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

1
-package com.reactnativenavigation.react;
2
-
3
-import com.facebook.react.bridge.JavaOnlyMap;
4
-import com.facebook.react.bridge.ReactApplicationContext;
5
-import com.facebook.react.bridge.ReactMethod;
6
-import com.reactnativenavigation.BaseTest;
7
-import com.reactnativenavigation.NavigationActivity;
8
-import com.reactnativenavigation.controllers.CommandsHandler;
9
-
10
-import org.json.JSONObject;
11
-import org.junit.Before;
12
-import org.junit.Test;
13
-import org.mockito.ArgumentCaptor;
14
-import org.robolectric.Robolectric;
15
-
16
-import java.lang.reflect.Method;
17
-
18
-import static org.assertj.core.api.Java6Assertions.assertThat;
19
-import static org.mockito.ArgumentMatchers.any;
20
-import static org.mockito.Mockito.mock;
21
-import static org.mockito.Mockito.times;
22
-import static org.mockito.Mockito.verify;
23
-import static org.mockito.Mockito.verifyZeroInteractions;
24
-import static org.mockito.Mockito.when;
25
-
26
-public class NavigationModuleTest extends BaseTest {
27
-
28
-	private NavigationModule uut;
29
-	private ReactApplicationContext mockReactApplicationContext;
30
-	private CommandsHandler commandsHandler;
31
-
32
-	@Before
33
-	public void beforeEach() {
34
-		mockReactApplicationContext = mock(ReactApplicationContext.class);
35
-		commandsHandler = mock(CommandsHandler.class);
36
-		uut = new NavigationModule(mockReactApplicationContext, commandsHandler);
37
-	}
38
-
39
-	@Test
40
-	public void allReactMethodsProtectAgainstNullActivity() throws Exception {
41
-		assertThat(uut.activity()).isNull();
42
-
43
-		for (Method method : NavigationModule.class.getDeclaredMethods()) {
44
-			if (method.getAnnotation(ReactMethod.class) != null) {
45
-				Object[] args = new Object[method.getParameterTypes().length];
46
-				method.invoke(uut, args);
47
-				verifyZeroInteractions(commandsHandler);
48
-			}
49
-		}
50
-	}
51
-
52
-	@SuppressWarnings("unchecked")
53
-	@Test
54
-	public void parsesArgumentsIntoMap() throws Exception {
55
-		when(mockReactApplicationContext.getCurrentActivity()).thenReturn(Robolectric.buildActivity(NavigationActivity.class).get());
56
-		JavaOnlyMap input = new JavaOnlyMap();
57
-		input.putString("key", "value");
58
-		uut.setRoot(input);
59
-		ArgumentCaptor<JSONObject> captor = ArgumentCaptor.forClass(JSONObject.class);
60
-		verify(commandsHandler, times(1)).setRoot((NavigationActivity) any(), captor.capture());
61
-		assertThat(captor.getAllValues()).hasSize(1);
62
-		assertThat(captor.getValue()).isNotNull();
63
-	}
64
-}

+ 0
- 32
lib/android/app/src/test/java/com/reactnativenavigation/utils/UiThreadTest.java View File

1
-package com.reactnativenavigation.utils;
2
-
3
-import com.reactnativenavigation.BaseTest;
4
-
5
-import org.junit.Test;
6
-import org.robolectric.shadows.ShadowLooper;
7
-
8
-import static org.mockito.Mockito.mock;
9
-import static org.mockito.Mockito.times;
10
-import static org.mockito.Mockito.verify;
11
-import static org.mockito.Mockito.verifyZeroInteractions;
12
-
13
-public class UiThreadTest extends BaseTest {
14
-	@Test
15
-	public void postOnUiThread() throws Exception {
16
-		Runnable task = mock(Runnable.class);
17
-		ShadowLooper.pauseMainLooper();
18
-		UiThread.post(task);
19
-		verifyZeroInteractions(task);
20
-		ShadowLooper.runUiThreadTasks();
21
-		verify(task, times(1)).run();
22
-	}
23
-
24
-	@Test
25
-	public void postDelayedOnUiThread() throws Exception {
26
-		Runnable task = mock(Runnable.class);
27
-		UiThread.postDelayed(task, 1000);
28
-		verifyZeroInteractions(task);
29
-		ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
30
-		verify(task, times(1)).run();
31
-	}
32
-}

+ 0
- 26
lib/android/app/src/test/java/com/reactnativenavigation/utils/UiUtilsTest.java View File

1
-package com.reactnativenavigation.utils;
2
-
3
-import android.view.View;
4
-
5
-import com.reactnativenavigation.BaseTest;
6
-
7
-import org.junit.Test;
8
-import org.robolectric.shadow.api.Shadow;
9
-
10
-import static org.mockito.Mockito.mock;
11
-import static org.mockito.Mockito.times;
12
-import static org.mockito.Mockito.verify;
13
-import static org.mockito.Mockito.verifyZeroInteractions;
14
-
15
-public class UiUtilsTest extends BaseTest {
16
-	@Test
17
-	public void runOnPreDrawOnce() throws Exception {
18
-		View view = Shadow.newInstanceOf(View.class);
19
-		Runnable task = mock(Runnable.class);
20
-		verifyZeroInteractions(task);
21
-
22
-		UiUtils.runOnPreDrawOnce(view, task);
23
-		view.getViewTreeObserver().dispatchOnPreDraw();
24
-		verify(task, times(1)).run();
25
-	}
26
-}

+ 0
- 42
lib/android/prepare-robolectric.gradle View File

1
-def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.3-dependencies")
2
-
3
-configurations.create('robolectricRuntime')
4
-
5
-dependencies {
6
-    testCompile "org.khronos:opengl-api:gl1.1-android-2.1_r1"
7
-
8
-    robolectricRuntime "org.robolectric:android-all:7.1.0_r7-robolectric-0"
9
-    robolectricRuntime "org.robolectric:shadows-core:3.3"
10
-    robolectricRuntime "org.robolectric:robolectric-utils:3.3"
11
-    robolectricRuntime "org.robolectric:robolectric-resources:3.3"
12
-    robolectricRuntime "org.robolectric:robolectric-processor:3.3"
13
-    robolectricRuntime "org.robolectric:robolectric-sandbox:3.3"
14
-    robolectricRuntime "org.robolectric:shadows-support-v4:3.3"
15
-    robolectricRuntime "org.robolectric:shadows-multidex:3.3"
16
-    robolectricRuntime "org.robolectric:shadows-play-services:3.3"
17
-    robolectricRuntime "org.robolectric:shadows-maps:3.3"
18
-}
19
-
20
-rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") {
21
-    println "downloadRobolectricDependencies into " + robolectricDependenciesFolder
22
-    from configurations.robolectricRuntime
23
-    into robolectricDependenciesFolder
24
-}
25
-
26
-project.afterEvaluate {
27
-    tasks.all {
28
-        if (it.name.startsWith("test")) {
29
-            it.dependsOn(rootProject.tasks.findByName("downloadRobolectricDependencies"))
30
-        }
31
-    }
32
-}
33
-
34
-android {
35
-    testOptions {
36
-        unitTests.all {
37
-            systemProperty 'robolectric.offline', 'true'
38
-            systemProperty 'robolectric.dependency.dir', robolectricDependenciesFolder
39
-        }
40
-    }
41
-}
42
-