-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
100 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
gnd/src/main/java/com/google/android/gnd/persistence/local/LocalDatabaseModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.google.android.gnd.persistence.local; | ||
|
||
import android.content.Context; | ||
import androidx.room.Room; | ||
import com.google.android.gnd.Config; | ||
import com.google.android.gnd.persistence.local.room.LocalDatabase; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.hilt.InstallIn; | ||
import dagger.hilt.android.components.ApplicationComponent; | ||
import dagger.hilt.android.qualifiers.ApplicationContext; | ||
import javax.inject.Singleton; | ||
|
||
@InstallIn(ApplicationComponent.class) | ||
@Module | ||
public abstract class LocalDatabaseModule { | ||
|
||
@Provides | ||
@Singleton | ||
static LocalDatabase localDatabase(@ApplicationContext Context context) { | ||
return Room.databaseBuilder(context, LocalDatabase.class, Config.DB_NAME) | ||
// TODO(#128): Disable before official release. | ||
.fallbackToDestructiveMigration() | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
gnd/src/main/java/com/google/android/gnd/rx/SchedulersModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.google.android.gnd.rx; | ||
|
||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.hilt.InstallIn; | ||
import dagger.hilt.android.components.ApplicationComponent; | ||
import javax.inject.Singleton; | ||
|
||
@InstallIn(ApplicationComponent.class) | ||
@Module | ||
public abstract class SchedulersModule { | ||
|
||
@Binds | ||
@Singleton | ||
abstract Schedulers schedulers(RxSchedulers rxSchedulers); | ||
} |
25 changes: 0 additions & 25 deletions
25
gnd/src/test/java/com/google/android/gnd/TestApplication.java
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
gnd/src/test/java/com/google/android/gnd/inject/TestApplicationModule.java
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
gnd/src/test/java/com/google/android/gnd/inject/TestComponent.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,14 @@ | |
import static com.google.common.truth.Truth.assertThat; | ||
import static org.hamcrest.Matchers.samePropertyValuesAs; | ||
|
||
import android.content.Context; | ||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule; | ||
import androidx.room.Room; | ||
import androidx.test.core.app.ApplicationProvider; | ||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.LatLngBounds; | ||
import com.google.android.gnd.TestApplication; | ||
import com.google.android.gnd.inject.DaggerTestComponent; | ||
import com.google.android.gnd.GndApplicationModule; | ||
import com.google.android.gnd.TestScheduler; | ||
import com.google.android.gnd.model.Mutation; | ||
import com.google.android.gnd.model.Project; | ||
import com.google.android.gnd.model.User; | ||
|
@@ -47,13 +50,28 @@ | |
import com.google.android.gnd.model.observation.ResponseDelta; | ||
import com.google.android.gnd.model.observation.ResponseMap; | ||
import com.google.android.gnd.model.observation.TextResponse; | ||
import com.google.android.gnd.persistence.local.room.LocalDatabase; | ||
import com.google.android.gnd.rx.Schedulers; | ||
import com.google.android.gnd.rx.SchedulersModule; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import dagger.hilt.InstallIn; | ||
import dagger.hilt.android.components.ApplicationComponent; | ||
import dagger.hilt.android.qualifiers.ApplicationContext; | ||
import dagger.hilt.android.testing.BindValue; | ||
import dagger.hilt.android.testing.HiltAndroidRule; | ||
import dagger.hilt.android.testing.HiltAndroidTest; | ||
import dagger.hilt.android.testing.HiltTestApplication; | ||
import dagger.hilt.android.testing.UninstallModules; | ||
import io.reactivex.subscribers.TestSubscriber; | ||
import java.util.AbstractCollection; | ||
import java.util.Date; | ||
import java8.util.Optional; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.hamcrest.MatcherAssert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
|
@@ -62,10 +80,40 @@ | |
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
|
||
@InstallIn(ApplicationComponent.class) | ||
@Module | ||
abstract class TestLocalDatabaseModule { | ||
@Provides | ||
static Context contextProvider() { | ||
return ApplicationProvider.getApplicationContext(); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
static LocalDatabase localDatabaseProvider(Context context) { | ||
return Room.inMemoryDatabaseBuilder(context, LocalDatabase.class) | ||
.allowMainThreadQueries() | ||
.build(); | ||
} | ||
} | ||
|
||
@InstallIn(ApplicationComponent.class) | ||
@Module | ||
abstract class TestSchedulersModule { | ||
@Binds | ||
@Singleton | ||
abstract Schedulers schedulers(TestScheduler testScheduler); | ||
} | ||
|
||
@HiltAndroidTest | ||
@UninstallModules({SchedulersModule.class,LocalDatabaseModule.class}) | ||
@Config(application = HiltTestApplication.class) | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(application = TestApplication.class) | ||
public class LocalDataStoreTest { | ||
|
||
@Rule public HiltAndroidRule hiltRule = new HiltAndroidRule(this); | ||
|
||
private static final User TEST_USER = | ||
User.builder().setId("user id").setEmail("[email protected]").setDisplayName("user 1").build(); | ||
|
||
|
@@ -201,7 +249,7 @@ private static void assertEquivalent(ObservationMutation mutation, Observation o | |
|
||
@Before | ||
public void setUp() { | ||
DaggerTestComponent.create().inject(this); | ||
hiltRule.inject(); | ||
} | ||
|
||
@Test | ||
|