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
class GreetingServiceMockTest : KoinTest { | |
private val greetingService: GreetingService by inject() | |
@Test | |
fun testGreetingInTheMorning() { | |
startKoin { modules(koinModule) } | |
declareMock<TimeService> { | |
given(this.getHourOfDay()).willReturn(9) | |
} |
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
class MainActivity : AppCompatActivity() { | |
private val greetingService by inject<GreetingService>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val greetings = findViewById<TextView>(R.id.greetingsTextView) | |
greetings.text = "${greetingService.greetings()}" |
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
class KoinApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
startKoin { | |
modules(koinModule) | |
} | |
} | |
} |
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
val koinModule = module { | |
single { MessageData() } | |
single<TimeService> { TimeServiceImpl() } | |
single<GreetingService> { | |
GreetingServiceImpl(get(), get()) | |
} | |
} |
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
data class MessageData(val welcomeMessage: String) |
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
interface GreetingService { | |
fun greetings(): String | |
} | |
class GreetingServiceImpl(private val messageData: MessageData, private val timeService: TimeService) : | |
GreetingService { | |
override fun greetings(): String { | |
val timeOfDay = when (timeService.getHourOfDay()) { |
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
#!/bin/bash | |
set -e | |
echo "----- Build and Publish Snapshot -----" | |
chmod u+x gradlew | |
time1=$(date '+%s') | |
./gradlew --no-daemon --parallel \ |
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
#!/bin/bash | |
set -e | |
echo "----- Build and Publish Snapshot -----" | |
chmod u+x gradlew | |
time1=$(date '+%s') | |
./gradlew --no-daemon --parallel \ |
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
@Singleton | |
open class PayBillManager { | |
@Inject | |
lateinit var db: IPaybillDataProvider | |
open suspend fun save(bill: SavedBill?) { | |
if (bill != null) { | |
db.payBillDao().insert(bill) | |
} |
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
@Dao | |
interface PayBillDao { | |
@Query("SELECT * from saved_bills ORDER BY biller_name") | |
suspend fun getAll(): List<SavedBill> | |
@Insert(onConflict = OnConflictStrategy.REPLACE) | |
suspend fun insert(savedBill: SavedBill) | |
@Query("DELETE from saved_bills where _id = :id") |