Skip to content

Instantly share code, notes, and snippets.

View yayaa's full-sized avatar

Yahya Bayramoğlu yayaa

View GitHub Profile
@yayaa
yayaa / CompromisedFruitSolution.kt
Created January 10, 2019 19:11
Improving the code - 4
fun main() {
getFruits()
.filter { it.name != null && !it.isRotten && it.color == Color.BLACK }
.forEach { println("Yay! It's an orange ${it.name}") }
}
@yayaa
yayaa / SequenceFruitSelection.kt
Last active January 9, 2019 22:19
Improving the code - 3
fun main() {
getFruits()
.asSequence()
.filter { it.name != null }
.filter { !it.isRotten }
.filter { it.color == Color.ORANGE }
.forEach { println("Yay! It's an orange ${it.name}") }
}
@yayaa
yayaa / SimpleFruitSelection.kt
Last active January 9, 2019 22:19
Improving the code - 2
fun main() {
getFruits()
.filter { it.name != null }
.filter { !it.isRotten }
.filter { it.color == Color.ORANGE }
.forEach { println("Yay! It's an orange ${it.name}") }
}
@yayaa
yayaa / FruitsExample.kt
Last active January 9, 2019 22:18
Improving the code - 1
data class Fruit(
val name: String?,
val isRotten: Boolean,
val color: Color
)
fun getFruits(): List<Fruit> { TODO() }
fun main() {
val fruits = getFruits()
@yayaa
yayaa / ComponentGeneratorSamples.kt
Last active December 23, 2017 16:27
ComponentDispatcher - 1
class SampleCoreComponentGenerator : CoreComponentGenerator<YourCoreComponent>() {
override fun generate(application: Application): YourCoreComponent {
// Create your component here...
}
}
class Feature1ComponentGenerator : FeatureComponentGenerator<YourFeatureComponent>() {
override fun generate(application: Application, coreComponent: YourCoreComponent?): YourFeatureComponent {
// Create your component here... Please notice, if you don't create
// an implementation of `CoreComponentGenerator` here coreComponent will be null.
@yayaa
yayaa / ComponentDispatcherInit.kt
Last active December 23, 2017 16:25
ComponentDispatcher - 3
class SampleApplication : Application() {
private lateinit var componentDispatcher: ComponentDispatcher
override fun onCreate() {
super.onCreate()
componentDispatcher = ComponentDispatcher(this)
}
fun getComponentDispatcher() = componentDispatcher
@yayaa
yayaa / CoreAndroidManifest.xml
Created November 28, 2017 22:50
ComponentDispatcher - 2
<application>
<meta-data
android:name="@string/component_generator_features"
android:resource="@array/component_generators" />
<meta-data
android:name="@string/component_generator_core"
android:value="com.yayandroid.componentdispatcher.sample.base.SampleCoreComponentGenerator" />
</application
@yayaa
yayaa / MockBuilderWithPairList.kt
Last active October 29, 2017 17:26
How to Test Builder - 5
inline fun <reified T: Any> mockBuilder(itemList: List<Pair<Class<*>, *>>)
= mock<T>(defaultAnswer = AnswerWithPairList(T::class.java, itemList))
// OR
inline fun <reified T: Any> mockBuilder(itemList: List<*>)
= mock<T>(defaultAnswer = AnswerWithPairList(T::class.java,
itemList.map { Pair(it!!::class.java, it) }))
@yayaa
yayaa / SampleBuilderTest.kt
Last active October 28, 2017 21:36
How to Test Builder - 3
class SampleBuilderTest {
val mockSampleObject = mock<SampleObject>()
val mockSampleBuilder = mockBuilder<SampleObject.Builder>(mockSampleObject)
@Test fun `when super business logic runs should do important stuff with correct configuration`() {
SampleLogic(mockSampleBuilder).superBusinessLogic()
verify(mockSampleBuilder).configA(true)
verify(mockSampleBuilder).configB("something")