Navigation Menu

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 / 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 / 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 / SampleBuilderTest2.kt
Last active October 28, 2017 21:36
How to Test Builder - 7
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()
verifyInOrder(mockSampleBuilder) {
configA(true)
@yayaa
yayaa / VerifyInOrder.kt
Last active October 28, 2017 21:30
How to Test Builder - 6
fun <T : Any> verifyInOrder(mock: T, body: T.() -> Unit)
= with(inOrder(mock)) { verify(mock).body() }