View TestConfigurationBuilder.kt
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
const val BASE_URL = "http://127.0.0.1" | |
class TestConfigurationBuilder { | |
private lateinit var baseUrl: String | |
init { | |
testBaseUrl() | |
} | |
fun testBaseUrl() { |
View InstagramErrorContent.kt
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
interface InstagramErrorContent { | |
val photoVideoUrl: String? | |
val tags: List<String>? | |
val errorCode: ErrorCode? | |
} |
View InstagramErrorType.kt
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
sealed class InstagramErrorType : InstagramErrorContent { | |
data class DeclinePost( | |
override val photoVideoUrl: String, | |
override val tags: List<String>, | |
override val errorCode: ErrorCode, | |
val textContent: String, | |
val location: String | |
) : InstagramErrorType() |
View ErrorCode.kt
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
@InstagramErrorCode | |
enum class ErrorCode { | |
Declined, | |
OverLimit, | |
TimeOut | |
} |
View InstagramErrorByClassTest.kt
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
class InstagramErrorByClassTest { | |
@Nested | |
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | |
inner class MixedConstructors { | |
private val instagramErrors = mutableListOf<String>() | |
@AfterAll | |
fun check() { |
View InstagramErrorByTypeTest.kt
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
class InstagramErrorByTypeTest { | |
companion object { | |
@Suppress("unused") | |
@JvmStatic | |
private fun checkSealedClassesByType() = Stream.of( | |
Arguments.of( | |
InstagramErrorType.DeclinePost( | |
photoVideoUrl = "https://www.instagram.com/p/B_2B2nwpS5g/", | |
tags = listOf("pullup", "bodyweight"), | |
errorCode = ErrorCode.Declined, |
View InstagramTypeFactory.kt
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
internal class InstagramTypeFactory : DefaultTypeFactory() { | |
override fun KParameter.createArgument(): Any? = | |
when (type.classifier) { | |
Int::class -> 0 | |
Byte::class -> 0.toByte() | |
Short::class -> 0.toShort() | |
String::class -> "" | |
Float::class -> 0f | |
Long::class -> 0L | |
List::class -> emptyList<String>() |
View InstagramTypeFactory.kt
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
else -> if ((type.classifier as KClass<out Any>).findAnnotation<InstagramErrorCode>() != null) ErrorCode.TimeOut else null |
View InstagramTypeFactory.kt
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
else -> if ((type.classifier as KClass<out Any>).qualifiedName == "sctestingplayground.ErrorCode") ErrorCode.TimeOut else null |
View NumberSeries.kt
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
// Noninformative way | |
fun combineLists(a1: List<Int>, a2: List<Int>): List<Int> = a1.mapIndexed { i, f -> f - a2[i] } | |
// Meaningful distinction | |
fun combinePrices(amazonPrices: List<Int>, ebayPrices: List<Int>): List<Int> = | |
amazonPrices.mapIndexed { index, amazonPrice -> amazonPrice - ebayPrices[index] } |
OlderNewer