This file contains hidden or 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
@Entity | |
data class Restaurant(@PrimaryKey val id: Int, val cuisine: Int?, val name: String?, | |
val lat: Double, val lng: Double, val price: Int, | |
val image: String = "", val description: String = "") : Serializable |
This file contains hidden or 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
@Dao | |
interface RestaurantsDao { | |
@Query("SELECT * FROM restaurant") | |
fun queryRestaurants(): LiveData<List<Restaurant>> | |
@Query("SELECT * FROM restaurant WHERE cuisine LIKE :cuisine") | |
fun queryRestaurantsByCuisine(cuisine: Int): LiveData<List<Restaurant>> | |
@Insert(onConflict = REPLACE) |
This file contains hidden or 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
@Database(entities = arrayOf(Restaurant::class), version = 1) | |
abstract class Database : RoomDatabase() { | |
abstract fun restaurantsDao(): RestaurantsDao | |
} |
This file contains hidden or 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
buildTypes { | |
// | |
debug { | |
buildConfigField 'String', 'URL', '"http://192.168.1.195:8080/"' | |
} | |
release { | |
buildConfigField 'String', 'URL', '"https://my-json-server.typicode.com/tolmachevroman/demo/"' | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} |
This file contains hidden or 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
fun hasConnection(): Boolean { | |
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val activeNetwork = cm.activeNetworkInfo | |
return activeNetwork != null && activeNetwork.isAvailable && activeNetwork.isConnected | |
} |
This file contains hidden or 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
@RunWith(JUnit4::class) | |
class UtilsTest { | |
@Test | |
fun hasConnectionTest() { | |
val context = Mockito.mock<Context>(Context::class.java) | |
val connManager = Mockito.mock(ConnectivityManager::class.java) | |
val networkInfo = Mockito.mock(NetworkInfo::class.java) | |
val packageManager = Mockito.mock(PackageManager::class.java) | |
val utils = Utils(context) |
This file contains hidden or 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
@RunWith(JUnit4::class) | |
class RestaurantsViewModelTest { | |
@Rule | |
@JvmField | |
var instantExecutor = InstantTaskExecutorRule() | |
@Mock | |
lateinit var repository: RestaurantsRepository |
This file contains hidden or 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
@RunWith(JUnit4::class) | |
class WebServiceTest { | |
@Rule | |
@JvmField | |
var instantExecutor = InstantTaskExecutorRule() | |
private lateinit var webService: WebService | |
private lateinit var mockWebServer: MockWebServer |
This file contains hidden or 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
android { | |
// ... | |
sourceSets { | |
String sharedTestDir = 'src/sharedTest/utils' | |
test { | |
java.srcDirs += "$projectDir/$sharedTestDir" | |
} | |
androidTest { | |
java.srcDirs += "$projectDir/$sharedTestDir" |
This file contains hidden or 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
@RunWith(AndroidJUnit4::class) | |
class RestaurantsDaoTest { | |
@Rule | |
@JvmField | |
var instantExecutor = InstantTaskExecutorRule() | |
@Mock | |
private lateinit var observer: Observer<List<Restaurant>> |