Skip to content

Commit

Permalink
Porting the lib to RxJava 2. Tests still need to be fixed, example to…
Browse files Browse the repository at this point in the history
… be redone.
  • Loading branch information
erickok committed Nov 9, 2016
1 parent a8c75cd commit b3d87dd
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 516 deletions.
11 changes: 7 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ android {
buildToolsVersion "25.0.0"

defaultConfig {
minSdkVersion 7
minSdkVersion 8
targetSdkVersion 25
versionCode 7
versionName "0.7"
versionCode 20
versionName "2.0-dev"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}

dependencies {
compile 'io.reactivex:rxjava:1.0.16'
compile 'io.reactivex.rxjava2:rxjava:2.0.0'
compile 'nl.qbusict:cupboard:2.1.4'

androidTestCompile 'com.android.support.test:runner:0.5'
}

apply from: '../maven_push.gradle'
52 changes: 15 additions & 37 deletions library/src/androidTest/java/nl/nl2312/rxcupboard/ChangesTest.java
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
package nl.nl2312.rxcupboard;

import android.database.sqlite.SQLiteDatabase;
import android.test.InstrumentationTestCase;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;

import nl.qbusict.cupboard.Cupboard;
import nl.qbusict.cupboard.CupboardBuilder;
import rx.Observable;
import rx.Subscription;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.subscriptions.CompositeSubscription;

public class ChangesTest extends InstrumentationTestCase {
@RunWith(AndroidJUnit4.class)
public class ChangesTest {

private static final String TEST_DATABASE = "RxCupboardTest.db";

private SQLiteDatabase db;
private RxDatabase rxDatabase;

@Override
protected void setUp() throws Exception {
super.setUp();

@Before
public void setUp() throws Exception {
Cupboard cupboard = new CupboardBuilder().build();
cupboard.register(TestEntity.class);
cupboard.register(TestEntity2.class);
getInstrumentation().getContext().deleteDatabase(TEST_DATABASE);
db = new TestDbHelper(getInstrumentation().getContext(), cupboard, TEST_DATABASE).getWritableDatabase();
InstrumentationRegistry.getTargetContext().deleteDatabase(TEST_DATABASE);
db = new TestDbHelper(InstrumentationRegistry.getTargetContext(), cupboard, TEST_DATABASE).getWritableDatabase();
rxDatabase = RxCupboard.with(cupboard, db);
}

/*@Test
public void testAllAndSpecificChanges() {
// Add observable to all database changes and one for only changes in TestEntity2
final AtomicInteger changeAllCount = new AtomicInteger();
final AtomicInteger changeSpecificCount = new AtomicInteger();
Subscription allChanges = rxDatabase.changes().subscribe(new Action1<DatabaseChange>() {
@Override
public void call(DatabaseChange databaseChange) {
changeAllCount.getAndIncrement();
}
});
Subscription specificChanges = rxDatabase.changes(TestEntity2.class).subscribe(new Action1<DatabaseChange>() {
@Override
public void call(DatabaseChange databaseChange) {
assertTrue(databaseChange.entity() instanceof TestEntity2);
changeSpecificCount.getAndIncrement();
}
});

long time = System.currentTimeMillis();
final TestEntity testEntity = new TestEntity();
testEntity.string = "Test";
Expand Down Expand Up @@ -283,12 +263,10 @@ public void onDelete(TestEntity entity) {
changes.unsubscribe();
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
}*/

@After
public void tearDown() throws Exception {
db.close();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
package nl.nl2312.rxcupboard;

import android.provider.ContactsContract;
import android.test.InstrumentationTestCase;
import android.util.Log;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.reactivex.functions.Predicate;
import nl.qbusict.cupboard.Cupboard;
import nl.qbusict.cupboard.CupboardBuilder;
import rx.functions.Action1;

public class ContentProviderTest extends InstrumentationTestCase {
@RunWith(AndroidJUnit4.class)
public class ContentProviderTest {

private Cupboard cupboard;

@Override
protected void setUp() throws Exception {
super.setUp();

@Before
public void setUp() throws Exception {
cupboard = new CupboardBuilder().useAnnotations().build();
cupboard.register(Contact.class);

}

public void testCursor() {
@Test
public void contentProvider_query() throws InterruptedException {

RxContentProvider rxContentProvider = RxCupboard.with(cupboard, getInstrumentation().getContext(), ContactsContract.Contacts.CONTENT_URI);
RxContentProvider rxContentProvider = RxCupboard.with(cupboard, InstrumentationRegistry.getTargetContext(),
ContactsContract.Contacts.CONTENT_URI);

// Should emit some items
rxContentProvider.query(Contact.class).doOnNext(new Action1<Contact>() {
@Override
public void call(Contact contact) {
Log.println(Log.ASSERT, "ContentProviderTest", contact.display_name);
}
}).count().subscribe(new Action1<Integer>() {
@Override
public void call(Integer count) {
assertTrue(count > 0);
}
});
rxContentProvider.query(Contact.class)
.count()
.test()
.assertTerminated()
.assertValue(new Predicate<Long>() {
@Override
public boolean test(Long count) throws Exception {
return count >= 0;
}
});

}

Expand Down
Loading

0 comments on commit b3d87dd

Please sign in to comment.