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
import com.dropbox.android.external.store4.Fetcher | |
import com.dropbox.android.external.store4.Store | |
import com.dropbox.android.external.store4.StoreBuilder | |
import com.dropbox.android.external.store4.fresh | |
import com.dropbox.android.sample.Graph | |
import com.dropbox.android.sample.data.model.Post | |
import com.nhaarman.mockitokotlin2.any | |
import com.nhaarman.mockitokotlin2.mock | |
import com.nhaarman.mockitokotlin2.whenever | |
import kotlinx.coroutines.ExperimentalCoroutinesApi |
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
import com.dropbox.android.external.store4.Fetcher | |
import com.dropbox.android.external.store4.Store | |
import com.dropbox.android.external.store4.StoreBuilder | |
import com.dropbox.android.external.store4.fresh | |
import com.dropbox.android.sample.Graph | |
import com.dropbox.android.sample.data.model.Post | |
import io.mockk.coEvery | |
import io.mockk.every | |
import io.mockk.mockk | |
import kotlinx.coroutines.ExperimentalCoroutinesApi |
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
@RunWith(ParameterizedRobolectricTestRunner::class) | |
@Config(sdk = [27]) | |
// parameters declared in the params() are injected through the constructor to the test class | |
class ExampleUnitTest(private val param: Int) { | |
@Test | |
fun addition_isCorrect() { | |
// parameter use in a test | |
assertEquals(param * 2, param + param) | |
} |
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
import android.annotation.SuppressLint | |
import android.os.Bundle | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.databinding.DataBindingUtil | |
import androidx.fragment.app.Fragment | |
import androidx.lifecycle.Observer | |
import com.github.harmittaa.koinexample.R |
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
import androidx.lifecycle.LiveData | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.liveData | |
import com.github.harmittaa.koinexample.model.Weather | |
import com.github.harmittaa.koinexample.model.WeatherRepository | |
import org.koin.dsl.module | |
val viewModelModule = module { | |
factory { ExampleViewModel(get()) } | |
} |
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
import com.github.harmittaa.koinexample.networking.WeatherApi | |
import org.koin.dsl.module | |
val forecastModule = module { | |
factory { WeatherRepository(get()) } | |
} | |
class WeatherRepository(private val weatherApi: WeatherApi) { | |
suspend fun getWeather() = weatherApi.getForecast() | |
} |
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
import com.github.harmittaa.koinexample.model.Weather | |
import retrofit2.http.GET | |
interface WeatherApi { | |
@GET("weather?q=Helsinki&units=metric") | |
suspend fun getForecast(): Weather | |
} |
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
import okhttp3.Interceptor | |
import okhttp3.Response | |
class AuthInterceptor() : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
var req = chain.request() | |
// DONT INCLUDE API KEYS IN YOUR SOURCE CODE | |
val url = req.url().newBuilder().addQueryParameter("APPID", "your_key_here").build() | |
req = req.newBuilder().url(url).build() | |
return chain.proceed(req) |
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
import com.github.harmittaa.koinexample.BuildConfig | |
import okhttp3.OkHttpClient | |
import org.koin.dsl.module | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
val networkModule = module { | |
factory { AuthInterceptor() } | |
factory { provideOkHttpClient(get()) } | |
factory { provideForecastApi(get()) } |
NewerOlder