Skip to content

Update database tests to support onCancelled #298

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 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.firebase.ui;
package com.firebase.ui.database;

import android.app.Application;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

import android.test.AndroidTestCase;

import com.firebase.ui.ApplicationTest;
import com.firebase.ui.database.FirebaseArray;
import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
Expand Down Expand Up @@ -173,9 +172,14 @@ private Bean getBean(FirebaseArray array, int index) {
public static void runAndWaitUntil(final FirebaseArray array, Query ref, Runnable task, Callable<Boolean> done) throws InterruptedException {
final java.util.concurrent.Semaphore semaphore = new java.util.concurrent.Semaphore(0);
array.setOnChangedListener(new FirebaseArray.OnChangedListener() {
public void onChanged(FirebaseArray.OnChangedListener.EventType type, int index, int oldIndex) {
public void onChanged(EventType type, int index, int oldIndex) {
semaphore.release();
}

@Override
public void onCancelled(DatabaseError databaseError) {
throw new IllegalStateException(databaseError.toException());
}
});
task.run();
boolean isDone = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import android.test.AndroidTestCase;

import com.firebase.ui.ApplicationTest;
import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
Expand Down Expand Up @@ -143,9 +143,14 @@ private static void print(FirebaseArray array) {
public static void runAndWaitUntil(final FirebaseArray array, Query ref, Runnable task, Callable<Boolean> done) throws InterruptedException {
final java.util.concurrent.Semaphore semaphore = new java.util.concurrent.Semaphore(0);
array.setOnChangedListener(new FirebaseArray.OnChangedListener() {
public void onChanged(FirebaseArray.OnChangedListener.EventType type, int index, int oldIndex) {
public void onChanged(EventType type, int index, int oldIndex) {
semaphore.release();
}

@Override
public void onCancelled(DatabaseError databaseError) {
throw new IllegalStateException(databaseError.toException());
}
});
task.run();
boolean isDone = false;
Expand Down