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
package com.filipkowicz.headeritemdecorator | |
/* | |
solution based on - based on Sevastyan answer on StackOverflow | |
changes: | |
- take to account views offsets | |
- transformed to Kotlin | |
- now works on viewHolders |
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
@Test | |
fun RefactoringTest() { | |
val ACCESS_TOKEN = "access token" | |
val API_RESULT_OK = 200 | |
val service = APIService() | |
val result = service.getSomeData(ACCESS_TOKEN) | |
assertThat(result, `is`(API_RESULT_OK)) | |
} |
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
@Test | |
fun BadNamingTest() { | |
val service = APIService() | |
val result = service.getSomeData("access token") | |
assertThat(result, `is`(200)) | |
} |
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
fun selectMaxValue(first: Int, second: Int, third: Int): Int { | |
...... | |
return 正確的最大數 | |
} | |
...... | |
@Test | |
fun selectMaxValue_whenInputMaxValueIntoFirstParam_thenReturnMaxValue() { | |
val result = chooseTheMaxValue(6, 2, 1) | |
assertThat(result, `is`(6)) | |
} |
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
fun chooseTheMaxValue(first: Int, second: Int, third: Int): Int { | |
// 從三個數中找出最大數 | |
// 假設了一個故意錯誤的邏輯 | |
if (second > third) { | |
return third | |
} | |
if (first > third) { | |
return third |
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
@ExperimentalCoroutinesApi | |
class SearchServiceTest { | |
...... | |
@Test | |
fun searchRepoThenResponse() { | |
val query = "coil+org:coil-kt" | |
enqueueResponse("search-repo.json") | |
val response = runBlocking { |
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
@ExperimentalCoroutinesApi | |
class SearchServiceTest { | |
private lateinit var service: SearchService | |
private lateinit var mockWebServer: MockWebServer | |
@Before | |
fun setup() { | |
mockWebServer = MockWebServer() |
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 SearchService { | |
@GET("search/repositories") | |
suspend fun searchRepo( | |
@Query("q", encoded = true) repo: String = "coil+org:coil-kt" | |
): SearchRepo | |
} | |
@Module | |
class NetworkModule { | |
@Singleton | |
@Provides |
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
dependency { | |
def retrofitVersion = '2.6.1' | |
def mockwebserverVersion = '3.8.1' | |
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" | |
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" | |
implementation "com.squareup.okhttp3:mockwebserver:$mockwebserverVersion" | |
} |
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
val scenario = launchFragmentInContainer { | |
TitleScreen().also { fragment -> | |
fragment.viewLifecycleOwnerLiveData.observeForever { viewLifecycleOwner -> | |
if (viewLifecycleOwner != null) { | |
Navigation.setViewNavController( | |
fragment.requireView(), | |
mockNavController | |
) | |
} | |
} |
NewerOlder