Skip to content

Commit 11bc4ce

Browse files
authored
Database tests, minor bugfix (#322)
1 parent 9fb5779 commit 11bc4ce

File tree

11 files changed

+66
-30
lines changed

11 files changed

+66
-30
lines changed

auth/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ android {
1111
versionCode 1
1212
versionName "1.0"
1313
}
14+
1415
buildTypes {
1516
release {
1617
minifyEnabled false

auth/src/main/java/com/firebase/ui/auth/ui/email/SignInActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ private void signIn(String email, final String password) {
105105
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
106106
@Override
107107
public void onSuccess(AuthResult authResult) {
108+
mActivityHelper.dismissDialog();
109+
108110
// Save credential in SmartLock (if enabled)
109111
SmartlockUtil.saveCredentialOrFinish(
110112
SignInActivity.this,
@@ -118,6 +120,8 @@ public void onSuccess(AuthResult authResult) {
118120
.addOnFailureListener(new OnFailureListener() {
119121
@Override
120122
public void onFailure(@NonNull Exception e) {
123+
mActivityHelper.dismissDialog();
124+
121125
// Show error message
122126
TextInputLayout passwordInput =
123127
(TextInputLayout) findViewById(R.id.password_layout);

auth/src/test/java/com/firebase/ui/auth/util/HeadlessAPIWrapperImplTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
package com.firebase.ui.auth.util;
1616

17-
import static junit.framework.Assert.assertFalse;
18-
import static junit.framework.Assert.assertTrue;
19-
import static org.mockito.Mockito.when;
20-
2117
import com.firebase.ui.auth.BuildConfig;
2218
import com.google.android.gms.common.ConnectionResult;
2319
import com.google.android.gms.common.GoogleApiAvailability;
@@ -32,8 +28,12 @@
3228
import org.robolectric.RuntimeEnvironment;
3329
import org.robolectric.annotation.Config;
3430

31+
import static junit.framework.Assert.assertFalse;
32+
import static junit.framework.Assert.assertTrue;
33+
import static org.mockito.Mockito.when;
34+
3535
@RunWith(RobolectricGradleTestRunner.class)
36-
@Config(constants = BuildConfig.class)
36+
@Config(constants = BuildConfig.class, sdk=23)
3737
public class HeadlessAPIWrapperImplTest {
3838

3939
private FirebaseAuthWrapperImpl mHeadlessAPIWrapperImpl;

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
mavenLocal()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.1.3'
9+
classpath 'com.android.tools.build:gradle:2.2.0'
1010
classpath 'com.google.gms:google-services:3.0.0'
1111

1212
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

common/constants.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project.ext.firebase_version = '9.4.0'
1+
project.ext.firebase_version = '9.6.0'
22
project.ext.support_library_version = '23.4.0'
33

44
project.ext.submodules = ['database', 'auth']

database/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ android {
1010
versionCode 1
1111
versionName "1.0"
1212
}
13+
1314
buildTypes {
1415
release {
1516
minifyEnabled false
@@ -23,4 +24,9 @@ dependencies {
2324
compile "com.android.support:recyclerview-v7:${project.ext.support_library_version}"
2425

2526
compile "com.google.firebase:firebase-database:${project.ext.firebase_version}"
27+
28+
androidTestCompile 'junit:junit:4.12'
29+
androidTestCompile "com.android.support:support-annotations:${project.ext.support_library_version}"
30+
androidTestCompile 'com.android.support.test:runner:0.5'
31+
androidTestCompile 'com.android.support.test:rules:0.5'
2632
}

library/src/test/java/com/firebase/ui/database/ApplicationTest.java renamed to database/src/androidTest/java/com/firebase/ui/database/ApplicationTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,19 @@
1414

1515
package com.firebase.ui.database;
1616

17-
import android.app.Application;
1817
import android.content.Context;
19-
import android.test.ApplicationTestCase;
2018

2119
import com.google.firebase.FirebaseApp;
2220
import com.google.firebase.FirebaseOptions;
2321

2422
/**
25-
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
23+
* Helpers for testing.
2624
*/
27-
public class ApplicationTest extends ApplicationTestCase<Application> {
25+
public class ApplicationTest {
2826

2927
private static final String APP_NAME = "firebaseui-tests";
3028

31-
public ApplicationTest() {
32-
super(Application.class);
33-
}
29+
public ApplicationTest() {}
3430

3531
public static FirebaseApp getAppInstance(Context context) {
3632
try {
@@ -42,8 +38,8 @@ public static FirebaseApp getAppInstance(Context context) {
4238

4339
public static FirebaseApp initializeApp(Context context) {
4440
return FirebaseApp.initializeApp(context, new FirebaseOptions.Builder()
45-
.setApplicationId("foo-bar")
46-
.setDatabaseUrl("https://firebaseui-tests.firebaseio-demo.com/")
41+
.setApplicationId("fir-ui-tests")
42+
.setDatabaseUrl("https://fir-ui-tests.firebaseio.com/")
4743
.build(), APP_NAME);
4844
}
4945
}

library/src/test/java/com/firebase/ui/database/FirebaseArrayOfObjectsTest.java renamed to database/src/androidTest/java/com/firebase/ui/database/FirebaseArrayOfObjectsTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
package com.firebase.ui.database;
1616

17-
import android.test.AndroidTestCase;
17+
import android.support.test.runner.AndroidJUnit4;
18+
import android.test.InstrumentationTestCase;
19+
import android.test.suitebuilder.annotation.SmallTest;
1820

1921
import com.google.firebase.FirebaseApp;
2022
import com.google.firebase.database.DatabaseError;
@@ -27,11 +29,14 @@
2729
import org.junit.After;
2830
import org.junit.Before;
2931
import org.junit.Test;
32+
import org.junit.runner.RunWith;
3033

3134
import java.util.concurrent.Callable;
3235
import java.util.concurrent.TimeUnit;
3336

34-
public class FirebaseArrayOfObjectsTest extends AndroidTestCase {
37+
@RunWith(AndroidJUnit4.class)
38+
@SmallTest
39+
public class FirebaseArrayOfObjectsTest extends InstrumentationTestCase {
3540
public static class Bean {
3641
int number;
3742
String text;
@@ -68,7 +73,7 @@ public boolean isBool() {
6873

6974
@Before
7075
public void setUp() throws Exception {
71-
FirebaseApp app = ApplicationTest.getAppInstance(getContext());
76+
FirebaseApp app = ApplicationTest.getAppInstance(getInstrumentation().getContext());
7277
mRef = FirebaseDatabase.getInstance(app).getReference()
7378
.child("firebasearray").child("objects");
7479
mArray = new FirebaseArray(mRef);
@@ -91,8 +96,13 @@ public Boolean call() throws Exception {
9196

9297
@After
9398
public void tearDown() throws Exception {
94-
mRef.removeValue();
95-
mArray.cleanup();
99+
if (mRef != null) {
100+
mRef.getRoot().removeValue();
101+
}
102+
103+
if (mArray != null) {
104+
mArray.cleanup();
105+
}
96106
}
97107

98108
@Test

library/src/test/java/com/firebase/ui/database/FirebaseArrayTest.java renamed to database/src/androidTest/java/com/firebase/ui/database/FirebaseArrayTest.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
package com.firebase.ui.database;
1616

17-
import android.test.AndroidTestCase;
17+
import android.support.test.runner.AndroidJUnit4;
18+
import android.test.InstrumentationTestCase;
19+
import android.test.suitebuilder.annotation.SmallTest;
1820

1921
import com.google.firebase.FirebaseApp;
2022
import com.google.firebase.database.DatabaseError;
@@ -27,17 +29,23 @@
2729
import org.junit.After;
2830
import org.junit.Before;
2931
import org.junit.Test;
32+
import org.junit.runner.RunWith;
3033

3134
import java.util.concurrent.Callable;
3235
import java.util.concurrent.TimeUnit;
3336

34-
public class FirebaseArrayTest extends AndroidTestCase {
37+
@RunWith(AndroidJUnit4.class)
38+
@SmallTest
39+
public class FirebaseArrayTest extends InstrumentationTestCase {
40+
41+
private static final int TIMEOUT = 5000;
42+
3543
private DatabaseReference mRef;
3644
private FirebaseArray mArray;
3745

3846
@Before
3947
public void setUp() throws Exception {
40-
FirebaseApp app = ApplicationTest.getAppInstance(getContext());
48+
FirebaseApp app = ApplicationTest.getAppInstance(getInstrumentation().getContext());
4149
mRef = FirebaseDatabase.getInstance(app).getReference().child("firebasearray");
4250
mArray = new FirebaseArray(mRef);
4351
mRef.removeValue();
@@ -56,8 +64,13 @@ public Boolean call() throws Exception {
5664

5765
@After
5866
public void tearDown() throws Exception {
59-
mArray.cleanup();
60-
mRef.removeValue();
67+
if (mRef != null) {
68+
mRef.getRoot().removeValue();
69+
}
70+
71+
if (mArray != null) {
72+
mArray.cleanup();
73+
}
6174
}
6275

6376
@Test
@@ -155,7 +168,7 @@ public void onCancelled(DatabaseError databaseError) {
155168
task.run();
156169
boolean isDone = false;
157170
long startedAt = System.currentTimeMillis();
158-
while (!isDone && System.currentTimeMillis() - startedAt < 5000) {
171+
while (!isDone && System.currentTimeMillis() - startedAt < TIMEOUT) {
159172
semaphore.tryAcquire(1, TimeUnit.SECONDS);
160173
try {
161174
isDone = done.call();

database/src/main/AndroidManifest.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.firebase.ui.database">
3+
34
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application>
7+
<meta-data
8+
android:name="com.google.android.gms.version"
9+
android:value="@integer/google_play_services_version" />
10+
</application>
11+
412
</manifest>

library/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ android {
2222
dependencies {
2323
compile project(':database')
2424
compile project(':auth')
25-
26-
androidTestCompile 'junit:junit:4.12'
2725
}
2826

2927
/**
@@ -61,7 +59,7 @@ def bintrayUploadTasks() {
6159
*/
6260
def testTasks() {
6361
return project.ext.submodules.collect { name ->
64-
":${name}:test"
62+
":${name}:testDebugUnitTest"
6563
}.toArray()
6664
}
6765

0 commit comments

Comments
 (0)