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
import kotlinx.serialization.Serializable | |
@Serializable | |
class GeofencingResponse(val id: String, val accessCode: String, val nickname: 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
val builder = Retrofit.Builder() | |
.client(getClient(serviceClass)) | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | |
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | |
.addConverterFactory(GuavaOptionalConverterFactory.create()) | |
.addConverterFactory(GsonConverterFactory.create(gson)) | |
.baseUrl(endpointAdapter.getURLString(context, serviceClass.simpleName)) | |
.addConverterFactory(Json.asConverterFactory(MediaType.get("application/json"))) |
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 MessageData @Inject constructor(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
@RunWith(RobolectricTestRunner::class) | |
@Config(sdk = [Build.VERSION_CODES.P]) | |
class GreetingServiceRoboTest { | |
@get:Rule | |
val mockitoRule: MockitoRule = MockitoJUnit.rule() | |
@Mock | |
lateinit var timeService: TimeService |
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 GreetingServiceFakeTest { | |
@Inject | |
lateinit var greetingService: GreetingService | |
@Test | |
fun testGreetingInTheMorning() { | |
val testModule = module { | |
bind<TimeService>().toInstance(object : TimeService { |
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
@RunWith(MockitoJUnitRunner::class) | |
class GreetingServiceMockTest { | |
@get:Rule | |
var toothPickRule = ToothPickRule(this, "scope") | |
@Inject | |
lateinit var greetingService: GreetingService | |
@Mock |
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: GreetingService by inject() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
KTP.openRootScope().inject(this) |
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 ToothpickApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
KTP.openRootScope().installModules(toothpickModule) | |
} | |
} |
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
@InjectConstructor | |
class GreetingServiceImpl(private val messageData: MessageData, private val timeService: TimeService) : | |
GreetingService { |
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 toothpickModule = module { | |
bind<GreetingService>().toClass<GreetingServiceImpl>().singleton() | |
bind<TimeService>().toInstance(TimeServiceImpl()) | |
bind<MessageData>().toInstance(MessageData()) | |
} |