Skip to content

Commit

Permalink
#80
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhrobbins committed Jan 11, 2014
1 parent 6cd1bf8 commit dbabe3a
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.robbins.tests.BaseMockingTest;
import org.robbins.tests.UnitTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.test.util.ReflectionTestUtils;


Expand Down Expand Up @@ -173,6 +174,32 @@ public void list() throws ServiceException {
assertThat(results, is(List.class));
}

@Test
public void list_WithSortAsc() throws ServiceException {
List<Tag> mockTagList = Arrays.asList(mockTag);

when(mockMapper.map(mockTag, TagDto.class)).thenReturn(mockTagDto);
when(mockService.findAll(any(Sort.class))).thenReturn(mockTagList);

List<TagDto> results = tagFacade.list(null, null, "name", "asc");

verify(mockService).findAll(any(Sort.class));
assertThat(results, is(List.class));
}

@Test
public void list_WithSortDesc() throws ServiceException {
List<Tag> mockTagList = Arrays.asList(mockTag);

when(mockMapper.map(mockTag, TagDto.class)).thenReturn(mockTagDto);
when(mockService.findAll(any(Sort.class))).thenReturn(mockTagList);

List<TagDto> results = tagFacade.list(null, null, "name", "desc");

verify(mockService).findAll(any(Sort.class));
assertThat(results, is(List.class));
}

@Test
public void list_ReturnNull() throws ServiceException {
when(mockService.findAll()).thenReturn(null);
Expand All @@ -184,7 +211,7 @@ public void list_ReturnNull() throws ServiceException {
}

@Test
public void listWithPage() throws ServiceException {
public void list_WithPageAndSort() throws ServiceException {
List<Tag> mockTagList = Arrays.asList(mockTag);

when(mockMapper.map(mockTag, TagDto.class)).thenReturn(mockTagDto);
Expand All @@ -195,4 +222,17 @@ public void listWithPage() throws ServiceException {
verify(mockService).findAll(any(PageRequest.class));
assertThat(results, is(List.class));
}

@Test
public void list_WithPageNoSort() throws ServiceException {
List<Tag> mockTagList = Arrays.asList(mockTag);

when(mockMapper.map(mockTag, TagDto.class)).thenReturn(mockTagDto);
when(mockService.findAll(any(PageRequest.class))).thenReturn(mockTagList);

List<TagDto> results = tagFacade.list(1, 10, null, null);

verify(mockService).findAll(any(PageRequest.class));
assertThat(results, is(List.class));
}
}

0 comments on commit dbabe3a

Please sign in to comment.