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
class LoginViewModel @Inject constructor(private val repository: UsersRepository) : ViewModel() { | |
var loginInput: MutableLiveData<LoginRequest> = MutableLiveData() | |
val login: LiveData<Resource<User>> = Transformations.switchMap(loginInput) { emailPasswordRequest -> | |
repository.login(emailPasswordRequest) | |
} | |
} | |
class LoginActivity : BaseActivity() { | |
//... |
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 RestaurantsMapActivityTest { | |
@Rule | |
@JvmField | |
var activityRule = ActivityTestRule(RestaurantsMapActivity::class.java) | |
companion object { | |
val packageName = BuildConfig.APPLICATION_ID | |
} |
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 RestaurantsRepositoryTest { | |
@Rule | |
@JvmField | |
var instantExecutor = InstantTaskExecutorRule() | |
@Mock | |
private lateinit var observer: Observer<Resource<List<Restaurant>>> |
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
[ | |
{ | |
"id": 1, | |
"cuisine": 1, | |
"lat": -33.431756, | |
"lng": -70.578719, | |
"price": 8900, | |
"image": "https://www.atrapalo.cl/common/photo/res/44559/106814/ticr_0_0.jpg", | |
"description": "Todo el sabor del Perú está presente en el restaurante Mi Cevichazo." | |
} |
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>> |
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(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
@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 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
fun hasConnection(): Boolean { | |
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val activeNetwork = cm.activeNetworkInfo | |
return activeNetwork != null && activeNetwork.isAvailable && activeNetwork.isConnected | |
} |
NewerOlder