Skip to content

Instantly share code, notes, and snippets.

View brunogabriel's full-sized avatar
:octocat:

Bruno Gabriel dos Santos brunogabriel

:octocat:
View GitHub Profile
@brunogabriel
brunogabriel / LinearChart.kt
Created January 12, 2022 15:38
Jetpack Compose - Linear Chart
@Composable
fun LinearChart(
modifier: Modifier = Modifier,
style: LinearChartStyle = LinearChartStyle.Default,
data: List<Int>
) {
Canvas(modifier = modifier) {
// distance between each x point
val distance = size.width / (data.size + 1)
var currentX = 0F
@brunogabriel
brunogabriel / PostsViewModelTest.kt
Created October 5, 2021 20:01
Testes para o PostsViewModel
@Test
fun `should take posts and display it when call takePosts`() {
// given
val posts = listOf<Post>(mockk(), mockk())
val observerDisplayingView = spyk<Observer<Int>>()
val displayingViewResults = mutableListOf<Int>()
val observerPostResult = spyk<Observer<List<Post>>>()
val postResults = mutableListOf<List<Post>>()
@brunogabriel
brunogabriel / PostsViewModel.kt
Created October 5, 2021 19:59
Método getPosts
fun takePosts() {
compositeDisposable + useCase.takePosts()
.subscribeOn(appSchedulers.io)
.observeOn(appSchedulers.main)
.doOnSubscribe { _displayingView.value = DisplayingView.Loading.ordinal }
.subscribeBy(onError = {
_displayingView.value = DisplayingView.Error.ordinal
_errorMessage.value = it.message ?: DEFAULT_ERROR_MESSAGE
}, onSuccess = { result ->
if (result.isNotEmpty()) {
@brunogabriel
brunogabriel / PostsRepositoryTest.kt
Created October 5, 2021 19:57
Testes para PostsRepository
// given
val posts = listOf<PostResponse>(mockk(), mockk())
every { repository.getPosts() } returns Single.just(posts)
// when
val result = repository.getPosts()
// then
result.test()
.assertResult(posts)
@brunogabriel
brunogabriel / PostsRepository.kt
Created October 5, 2021 19:52
Repositório de Posts
interface PostsRepository {
fun getPosts(): Single<List<PostResponse>>
}
class PostsRepositoryImpl @Inject constructor(
private val service: PostService
) : PostsRepository {
override fun getPosts(): Single<List<PostResponse>> = service.getPosts()
}