Search in sources :

Example 16 with Character

use of com.karumi.rosie.sample.characters.domain.model.Character in project Rosie by Karumi.

the class MainActivityTest method givenConnectionExceptionObtainingCharacters.

private void givenConnectionExceptionObtainingCharacters() throws Exception {
    when(charactersRepository.getAll(ReadPolicy.CACHE_ONLY)).thenReturn(new ArrayList<Character>());
    when(charactersRepository.getPage(any(Page.class))).thenThrow(new MarvelApiException(ANY_EXCEPTION, new UnknownHostException()));
}
Also used : MarvelApiException(com.karumi.marvelapiclient.MarvelApiException) Character(com.karumi.rosie.sample.characters.domain.model.Character) UnknownHostException(java.net.UnknownHostException) Page(com.karumi.rosie.repository.datasource.paginated.Page)

Example 17 with Character

use of com.karumi.rosie.sample.characters.domain.model.Character in project Rosie by Karumi.

the class MainActivityTest method givenThereAreSomeCharacters.

private List<Character> givenThereAreSomeCharacters(int numberOfCharacters) throws Exception {
    List<Character> characters = new LinkedList<>();
    for (int i = 0; i < numberOfCharacters; i++) {
        Character character = getCharacter(i);
        characters.add(character);
        when(charactersRepository.getByKey(String.valueOf(i))).thenReturn(character);
    }
    PaginatedCollection<Character> paginatedCollection = new PaginatedCollection<>(characters);
    paginatedCollection.setPage(Page.withOffsetAndLimit(0, numberOfCharacters));
    paginatedCollection.setHasMore(false);
    when(charactersRepository.getPage(any(Page.class))).thenReturn(paginatedCollection);
    return characters;
}
Also used : Character(com.karumi.rosie.sample.characters.domain.model.Character) Page(com.karumi.rosie.repository.datasource.paginated.Page) LinkedList(java.util.LinkedList) PaginatedCollection(com.karumi.rosie.repository.PaginatedCollection)

Example 18 with Character

use of com.karumi.rosie.sample.characters.domain.model.Character in project Rosie by Karumi.

the class GetCharacterDetails method getCharacterDetails.

@UseCase
public void getCharacterDetails(String characterKey) throws Exception {
    Character character = charactersRepository.getByKey(characterKey);
    notifySuccess(character);
}
Also used : Character(com.karumi.rosie.sample.characters.domain.model.Character) RosieUseCase(com.karumi.rosie.domain.usecase.RosieUseCase) UseCase(com.karumi.rosie.domain.usecase.annotation.UseCase)

Example 19 with Character

use of com.karumi.rosie.sample.characters.domain.model.Character in project Rosie by Karumi.

the class CharactersApiDataSource method getPage.

@Override
public PaginatedCollection<Character> getPage(Page page) throws MarvelApiException {
    int offset = page.getOffset();
    int limit = page.getLimit();
    MarvelResponse<CharactersDto> charactersApiResponse = characterApiClient.getAll(offset, limit);
    CharactersDto charactersDto = charactersApiResponse.getResponse();
    Collection<Character> characters = mapper.reverseMap(charactersDto.getCharacters());
    PaginatedCollection<Character> charactersPage = new PaginatedCollection<>(characters);
    charactersPage.setPage(page);
    charactersPage.setHasMore(charactersDto.getOffset() + charactersDto.getCount() < charactersDto.getTotal());
    return charactersPage;
}
Also used : Character(com.karumi.rosie.sample.characters.domain.model.Character) CharactersDto(com.karumi.marvelapiclient.model.CharactersDto) PaginatedCollection(com.karumi.rosie.repository.PaginatedCollection)

Example 20 with Character

use of com.karumi.rosie.sample.characters.domain.model.Character in project Rosie by Karumi.

the class CharacterDetailsActivityTest method givenAValidCharacter.

private Character givenAValidCharacter() throws Exception {
    Character character = getCharacter(ANY_CHARACTER_ID);
    when(charactersRepository.getByKey(anyString())).thenReturn(character);
    return character;
}
Also used : Character(com.karumi.rosie.sample.characters.domain.model.Character)

Aggregations

Character (com.karumi.rosie.sample.characters.domain.model.Character)23 NonNull (android.support.annotation.NonNull)10 Page (com.karumi.rosie.repository.datasource.paginated.Page)4 PaginatedCollection (com.karumi.rosie.repository.PaginatedCollection)3 MarvelApiException (com.karumi.marvelapiclient.MarvelApiException)2 InjectedInstrumentationTest (com.karumi.rosie.sample.InjectedInstrumentationTest)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)1 CharactersDto (com.karumi.marvelapiclient.model.CharactersDto)1 RosieUseCase (com.karumi.rosie.domain.usecase.RosieUseCase)1 Success (com.karumi.rosie.domain.usecase.annotation.Success)1 UseCase (com.karumi.rosie.domain.usecase.annotation.UseCase)1 OnSuccessCallback (com.karumi.rosie.domain.usecase.callback.OnSuccessCallback)1 OnErrorCallback (com.karumi.rosie.domain.usecase.error.OnErrorCallback)1 CharacterDetailViewModel (com.karumi.rosie.sample.characters.view.viewmodel.CharacterDetailViewModel)1 CharacterViewModel (com.karumi.rosie.sample.characters.view.viewmodel.CharacterViewModel)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1