-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from felipecastilhos/feature/add_repository_tests
Adicionando teste a Repositórios
- Loading branch information
Showing
17 changed files
with
211 additions
and
110 deletions.
There are no files selected for viewing
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
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
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
2 changes: 1 addition & 1 deletion
2
...e/domain/repository/DomainModelMappers.kt → ...ome/data/datasource/DomainModelMappers.kt
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
36 changes: 0 additions & 36 deletions
36
...thub/felipecastilhos/pokedexandroid/features/home/data/datasource/HomeRemoteDataSource.kt
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
.../github/felipecastilhos/pokedexandroid/features/home/data/datasource/PokemonDataSource.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.felipecastilhos.pokedexandroid.features.home.data.datasource | ||
|
||
import com.apollographql.apollo.ApolloClient | ||
import com.apollographql.apollo.coroutines.await | ||
import com.github.felipecastilhos.pokedexandroid.GetPokemonQuery | ||
import com.github.felipecastilhos.pokedexandroid.core.coroutines.DispatcherProvider | ||
import com.github.felipecastilhos.pokedexandroid.core.datasource.Resource | ||
import com.github.felipecastilhos.pokedexandroid.core.datasource.remote.RemoteDataSource | ||
import com.github.felipecastilhos.pokedexandroid.core.network.toResource | ||
import com.github.felipecastilhos.pokedexandroid.features.home.domain.models.Pokemon | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
/** | ||
* [PokemonDataSource] is an interface for all remote data source queries | ||
*/ | ||
abstract class PokemonDataSource : RemoteDataSource { | ||
abstract suspend fun search(): Resource<Pokemon?> | ||
} | ||
|
||
/** | ||
* Implementation of [PokemonDataSource] searching in a GraphQl API | ||
*/ | ||
class PokemonGraphQlDataSource @Inject constructor( | ||
private val apolloClient: ApolloClient, | ||
private val dispatcherProvider: DispatcherProvider | ||
) : | ||
PokemonDataSource() { | ||
|
||
override suspend fun search(): Resource<Pokemon?> = withContext(dispatcherProvider.io) { | ||
return@withContext apolloClient.query(GetPokemonQuery())?.await() | ||
.toResource { it?.getPokemon?.mapToDomainModel() } | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ enum class PokemonTypes { | |
Fire, | ||
Water, | ||
Glass, | ||
Eletric, | ||
Electric, | ||
Psychic, | ||
Ice, | ||
Dragon, | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<resources> | ||
<string name="app_name">Pokédex Android</string> | ||
|
||
<string name="server_unexpected_error">"Sem resposta do servidor</string> | ||
<string name="server_no_response">"Ops, algo deu errado</string> | ||
<string name="server_unexpected_error">Ops, algo deu errado</string> | ||
<string name="server_no_response">Sem conexão com o servidor, tente novamente mais tarde</string> | ||
</resources> |
18 changes: 18 additions & 0 deletions
18
app/src/test/java/com/github/felipecastilhos/pokedexandroid/FakePokemonDataSource.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.felipecastilhos.pokedexandroid | ||
|
||
import com.github.felipecastilhos.pokedexandroid.core.datasource.Resource | ||
import com.github.felipecastilhos.pokedexandroid.core.datasource.remote.DataSourceError | ||
import com.github.felipecastilhos.pokedexandroid.features.home.data.datasource.PokemonDataSource | ||
import com.github.felipecastilhos.pokedexandroid.features.home.domain.models.Pokemon | ||
|
||
class FakePokemonDataSource(private val pokemon: Pokemon) : PokemonDataSource() { | ||
override suspend fun search(): Resource<Pokemon> { | ||
return Resource.Success(pokemon) | ||
} | ||
} | ||
|
||
class FakeFailingPokemonDataSource : PokemonDataSource() { | ||
override suspend fun search(): Resource<Pokemon?> { | ||
return Resource.Error(exception = DataSourceError.Unexpected(R.string.server_unexpected_error)) | ||
} | ||
} |
Oops, something went wrong.