Last active
January 11, 2019 14:23
-
-
Save alwarren/942eeb4e5f1ed56ad74a149cace7e2ed to your computer and use it in GitHub Desktop.
Kotlin static mocks because I'm too lazy to use frameworks.
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
object Mock { | |
val currentWeatherEntry by lazy { currentWeatherEntryMock() } | |
val condition by lazy { conditionMock() } | |
val weatherLocation by lazy { weatherLocationMock() } | |
val currentWeatherResponse by lazy { currentWeatherResponseMock(currentWeatherEntry, weatherLocation) } | |
const val string: String = "string" | |
const val int:Int = 1 | |
const val long: Long = 1L | |
const val double:Double = 1.0 | |
private fun currentWeatherResponseMock( | |
currentWeatherEntry: CurrentWeatherEntry, | |
weatherLocation: WeatherLocation) = CurrentWeatherResponse ( | |
weatherLocation, currentWeatherEntry | |
) | |
private fun conditionMock() = Condition(string, string, int) | |
private fun currentWeatherEntryMock() = CurrentWeatherEntry( | |
int, string, double, double, int, condition, double, | |
double, int, string, double, double, double, double, | |
int, int, double, double, double, double, double | |
) | |
private fun weatherLocationMock() = WeatherLocation( | |
string, string, string, double, double, string, long | |
) | |
object Server { | |
val currentWeatherResponse by lazy { currentWeatherResponse() } | |
private fun currentWeatherResponse(): String { | |
return resource("json/weather/current/response.json") | |
} | |
} | |
object Network { | |
val interceptor by lazy { interceptor() } | |
val offlineInterceptor by lazy { interceptor.setOffline() } | |
private fun interceptor() = MockConnectivityInterceptor() | |
} | |
private fun resource(path: String): String { | |
val clazz = this.javaClass.classLoader | |
return if (clazz != null) { | |
val uri = clazz.getResource(path) | |
val file = File(uri.path) | |
String(file.readBytes()) | |
} else "" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment