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
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 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
interface DataStore<T> { | |
fun modelListObservable(): Maybe<List<T>> | |
fun modelObservable(id: String): Maybe<T> | |
fun putModels(vararg models: T) | |
fun clear() |
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
@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 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
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 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
@Mock MainView mainViewMock; | |
@Mock PokeDataSource pokeDataSource; | |
@Mock HttpException httpException; | |
@Test | |
public void testDemoResponseError404() { | |
reset(mainViewMock); | |
MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokeDataSource); |
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
@Mock MainView mainViewMock; | |
@Mock PokeDataSource pokeDataSource; | |
@Test | |
public void testOnViewAdded() { | |
reset(mainViewMock); | |
MainPresenterImpl presenter = new MainPresenterImpl( | |
schedulersProvider, pokeDataSource); |
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
@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); |
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
@Test | |
public void testOnSceneAdded() { | |
reset(mainSceneMock); | |
MainPresenterImpl presenter = new MainPresenterImpl(schedulersProvider, pokemonService); | |
presenter.onSceneAdded(mainSceneMock, null); | |
testScheduler.triggerActions(); |
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
public class LocalResponseDispatcher extends QueueDispatcher { | |
@Override | |
public MockResponse dispatch(RecordedRequest request) throws InterruptedException { | |
MockResponse mockResponse = new MockResponse(); | |
String scenario = getScenario(request); | |
if (scenario != null) { | |
try { | |
mockResponse.setBody(readFile(scenario)); |
NewerOlder