Skip to content

Database tests, minor bugfix #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ android {
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private void signIn(String email, final String password) {
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
mActivityHelper.dismissDialog();

// Save credential in SmartLock (if enabled)
SmartlockUtil.saveCredentialOrFinish(
SignInActivity.this,
Expand All @@ -118,6 +120,8 @@ public void onSuccess(AuthResult authResult) {
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mActivityHelper.dismissDialog();

// Show error message
TextInputLayout passwordInput =
(TextInputLayout) findViewById(R.id.password_layout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

package com.firebase.ui.auth.util;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.when;

import com.firebase.ui.auth.BuildConfig;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
Expand All @@ -32,8 +28,12 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.when;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class)
@Config(constants = BuildConfig.class, sdk=23)
public class HeadlessAPIWrapperImplTest {

private FirebaseAuthWrapperImpl mHeadlessAPIWrapperImpl;
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
Expand Down
2 changes: 1 addition & 1 deletion common/constants.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project.ext.firebase_version = '9.4.0'
project.ext.firebase_version = '9.6.0'
project.ext.support_library_version = '23.4.0'

project.ext.submodules = ['database', 'auth']
Expand Down
6 changes: 6 additions & 0 deletions database/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ android {
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -23,4 +24,9 @@ dependencies {
compile "com.android.support:recyclerview-v7:${project.ext.support_library_version}"

compile "com.google.firebase:firebase-database:${project.ext.firebase_version}"

androidTestCompile 'junit:junit:4.12'
androidTestCompile "com.android.support:support-annotations:${project.ext.support_library_version}"
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@

package com.firebase.ui.database;

import android.app.Application;
import android.content.Context;
import android.test.ApplicationTestCase;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
* Helpers for testing.
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public class ApplicationTest {

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

public ApplicationTest() {
super(Application.class);
}
public ApplicationTest() {}

public static FirebaseApp getAppInstance(Context context) {
try {
Expand All @@ -42,8 +38,8 @@ public static FirebaseApp getAppInstance(Context context) {

public static FirebaseApp initializeApp(Context context) {
return FirebaseApp.initializeApp(context, new FirebaseOptions.Builder()
.setApplicationId("foo-bar")
.setDatabaseUrl("https://firebaseui-tests.firebaseio-demo.com/")
.setApplicationId("fir-ui-tests")
.setDatabaseUrl("https://fir-ui-tests.firebaseio.com/")
.build(), APP_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package com.firebase.ui.database;

import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DatabaseError;
Expand All @@ -27,11 +29,14 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class FirebaseArrayOfObjectsTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
@SmallTest
public class FirebaseArrayOfObjectsTest extends InstrumentationTestCase {
public static class Bean {
int number;
String text;
Expand Down Expand Up @@ -68,7 +73,7 @@ public boolean isBool() {

@Before
public void setUp() throws Exception {
FirebaseApp app = ApplicationTest.getAppInstance(getContext());
FirebaseApp app = ApplicationTest.getAppInstance(getInstrumentation().getContext());
mRef = FirebaseDatabase.getInstance(app).getReference()
.child("firebasearray").child("objects");
mArray = new FirebaseArray(mRef);
Expand All @@ -91,8 +96,13 @@ public Boolean call() throws Exception {

@After
public void tearDown() throws Exception {
mRef.removeValue();
mArray.cleanup();
if (mRef != null) {
mRef.getRoot().removeValue();
}

if (mArray != null) {
mArray.cleanup();
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package com.firebase.ui.database;

import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DatabaseError;
Expand All @@ -27,17 +29,23 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

public class FirebaseArrayTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
@SmallTest
public class FirebaseArrayTest extends InstrumentationTestCase {

private static final int TIMEOUT = 5000;

private DatabaseReference mRef;
private FirebaseArray mArray;

@Before
public void setUp() throws Exception {
FirebaseApp app = ApplicationTest.getAppInstance(getContext());
FirebaseApp app = ApplicationTest.getAppInstance(getInstrumentation().getContext());
mRef = FirebaseDatabase.getInstance(app).getReference().child("firebasearray");
mArray = new FirebaseArray(mRef);
mRef.removeValue();
Expand All @@ -56,8 +64,13 @@ public Boolean call() throws Exception {

@After
public void tearDown() throws Exception {
mArray.cleanup();
mRef.removeValue();
if (mRef != null) {
mRef.getRoot().removeValue();
}

if (mArray != null) {
mArray.cleanup();
}
}

@Test
Expand Down Expand Up @@ -155,7 +168,7 @@ public void onCancelled(DatabaseError databaseError) {
task.run();
boolean isDone = false;
long startedAt = System.currentTimeMillis();
while (!isDone && System.currentTimeMillis() - startedAt < 5000) {
while (!isDone && System.currentTimeMillis() - startedAt < TIMEOUT) {
semaphore.tryAcquire(1, TimeUnit.SECONDS);
try {
isDone = done.call();
Expand Down
8 changes: 8 additions & 0 deletions database/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.firebase.ui.database">

<uses-permission android:name="android.permission.INTERNET" />

<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>

</manifest>
4 changes: 1 addition & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ android {
dependencies {
compile project(':database')
compile project(':auth')

androidTestCompile 'junit:junit:4.12'
}

/**
Expand Down Expand Up @@ -61,7 +59,7 @@ def bintrayUploadTasks() {
*/
def testTasks() {
return project.ext.submodules.collect { name ->
":${name}:test"
":${name}:testDebugUnitTest"
}.toArray()
}

Expand Down