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
infix fun <T>Boolean.then(action : () -> T): T? { | |
return if (this) | |
action.invoke() | |
else null | |
} | |
infix fun <T>T?.elze(action: () -> T): T { | |
return if (this == null) | |
action.invoke() |
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 DataStore<T> { | |
fun modelListObservable(): Maybe<List<T>> | |
fun modelObservable(id: String): Maybe<T> | |
fun putModels(vararg models: T) | |
fun clear() |
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
@Mock MainView mainViewMock; | |
@Mock PokeDataSource pokeDataSource; | |
@Test | |
public void testOnViewAdded() { | |
reset(mainViewMock); | |
MainPresenterImpl presenter = new MainPresenterImpl( | |
schedulersProvider, pokeDataSource); |
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
@Mock MainView mainViewMock; | |
@Mock PokeDataSource pokeDataSource; | |
@Mock HttpException httpException; | |
@Test | |
public void testDemoResponseError404() { | |
reset(mainViewMock); | |
MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); |
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
@Inject PokeService pokemonService; | |
@Test | |
public void testGetPokemonAbilityStringObservable() { | |
PokeDataSource dataSource = new PokeDataSource(pokemonService); | |
TestObserver observer = new TestObserver(); | |
dataSource.getPokemonAbilityStringObservable("12") | |
.subscribe(observer); | |
observer.assertNoErrors(); |
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
if (throwable instanceof HttpException) { | |
if (((HttpException) throwable).code() == | |
HttpURLConnection.HTTP_NOT_FOUND) { | |
if (getView() != null) { | |
getView().showErrorDialog("Lost!"); | |
} | |
} else if (((HttpException) throwable).code() == | |
HttpURLConnection.HTTP_UNAVAILABLE) { | |
if (getView() != null) { |
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
pokeSource.getPokemonAbilityStringObservable("12") | |
.subscribeOn(provider.io()) | |
.observeOn(provider.ui()) | |
.subscribe(new Consumer<Pokemon>() { | |
@Override | |
public void accept(@NonNull String pokemonAbility) throws Exception { | |
if (getView() != null) { | |
getView().setApiText(pokemonAbility); | |
} |
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
public Observable<String> getPokemonAbilityStringObservable(String id) { | |
return pokemonService.getPokemon(id) | |
.map(new Function<Pokemon, String>() { | |
@Override | |
public String apply(@NonNull Pokemon pokemon) throws Exception { | |
return constructAbility(pokemon); | |
} | |
}); | |
} |
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 | |
public void testDemoResponseErrorSocket() { | |
reset(mainSceneMock); | |
MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService); | |
MockResponse response = new MockResponse(); | |
response.setBody("\"message\":\"Hello\"").throttleBody(1, 2, TimeUnit.SECONDS); |
NewerOlder