-
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
7 changed files
with
93 additions
and
50 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
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -22,8 +22,6 @@ | |
import androidx.arch.core.executor.testing.InstantTaskExecutorRule; | ||
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.model.Mutation; | ||
import com.google.android.gnd.model.Project; | ||
import com.google.android.gnd.model.User; | ||
|
@@ -47,8 +45,13 @@ | |
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.rx.SchedulersModule; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
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; | ||
|
@@ -62,10 +65,15 @@ | |
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
|
||
@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 +209,7 @@ private static void assertEquivalent(ObservationMutation mutation, Observation o | |
|
||
@Before | ||
public void setUp() { | ||
DaggerTestComponent.create().inject(this); | ||
hiltRule.inject(); | ||
} | ||
|
||
@Test | ||
|
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