Skip to content

Commit ef8ead6

Browse files
committed
Add missing tests for page methods for relevant controllers
Repeat the coverage fix for the ServiceController in all similar controllers. The FeatureProposalController seems to be inconsistent and used other names than "page" for its method.
1 parent 8ddf949 commit ef8ead6

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/test/java/edu/tamu/app/controller/FeatureProposalControllerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import org.mockito.InjectMocks;
1818
import org.mockito.Mock;
1919
import org.mockito.MockitoAnnotations;
20+
import org.springframework.data.domain.Page;
21+
import org.springframework.data.domain.PageImpl;
22+
import org.springframework.data.domain.Pageable;
2023
import org.springframework.messaging.simp.SimpMessagingTemplate;
2124
import org.springframework.test.context.ActiveProfiles;
2225
import org.springframework.test.context.junit4.SpringRunner;
@@ -30,6 +33,8 @@
3033
import edu.tamu.app.model.repo.FeatureProposalRepo;
3134
import edu.tamu.app.model.repo.ServiceRepo;
3235
import edu.tamu.app.model.repo.UserRepo;
36+
import edu.tamu.app.model.repo.specification.FeatureProposalSpecification;
37+
import edu.tamu.app.model.request.FilteredPageRequest;
3338
import edu.tamu.weaver.auth.model.Credentials;
3439
import edu.tamu.weaver.response.ApiResponse;
3540

@@ -56,6 +61,7 @@ public class FeatureProposalControllerTest {
5661
private static FeatureProposal TEST_FEATURE_PROPOSAL3 = new FeatureProposal(TEST_FEATURE_PROPOSAL_TITLE3, TEST_FEATURE_PROPOSAL_DESCRIPTION3, TEST_USER1);
5762
private static FeatureProposal TEST_MODIFIED_FEATURE_PROPOSAL = new FeatureProposal(TEST_MODIFIED_FEATURE_PROPOSAL_TITLE, TEST_MODIFIED_FEATURE_PROPOSAL_DESCRIPTION, TEST_USER2, TEST_SERVICE);
5863
private static List<FeatureProposal> mockFeatureProposalList = new ArrayList<FeatureProposal>(Arrays.asList(new FeatureProposal[] { TEST_FEATURE_PROPOSAL1, TEST_FEATURE_PROPOSAL2, TEST_FEATURE_PROPOSAL3 }));
64+
private static Page<FeatureProposal> mockPageableFeatureProposalList = new PageImpl<FeatureProposal>(Arrays.asList(new FeatureProposal[] { TEST_FEATURE_PROPOSAL1, TEST_FEATURE_PROPOSAL2, TEST_FEATURE_PROPOSAL3 }));
5965

6066
private static User user = new User("123456789");
6167

@@ -80,11 +86,13 @@ public class FeatureProposalControllerTest {
8086
private FeatureProposalController featureProposalController;
8187

8288
@Before
89+
@SuppressWarnings("unchecked")
8390
public void setup() throws UserNotFoundException {
8491
MockitoAnnotations.initMocks(this);
8592
when(credentials.getUin()).thenReturn("123456789");
8693
when(userRepo.findByUsername(any(String.class))).thenReturn(Optional.of(user));
8794
when(featureProposalRepo.findAll()).thenReturn(mockFeatureProposalList);
95+
when(featureProposalRepo.findAll(any(FeatureProposalSpecification.class), any(Pageable.class))).thenReturn(mockPageableFeatureProposalList);
8896
when(featureProposalRepo.findOne(any(Long.class))).thenReturn(TEST_FEATURE_PROPOSAL1);
8997
when(featureProposalRepo.create(any(FeatureProposal.class), any(Credentials.class))).thenReturn(TEST_FEATURE_PROPOSAL1);
9098
when(featureProposalRepo.create(any(Idea.class))).thenReturn(TEST_FEATURE_PROPOSAL1);
@@ -94,6 +102,17 @@ public void setup() throws UserNotFoundException {
94102
doNothing().when(featureProposalRepo).delete(any(FeatureProposal.class));
95103
}
96104

105+
@Test
106+
@SuppressWarnings("unchecked")
107+
public void testPage() {
108+
FilteredPageRequest mockFilter = new FilteredPageRequest();
109+
response = featureProposalController.getAllFeatureProposalsByService(mockFilter);
110+
assertEquals("Not successful at getting paged FeatureProposals", SUCCESS, response.getMeta().getStatus());
111+
112+
Page<FeatureProposal> page = (Page<FeatureProposal>) response.getPayload().get("PageImpl");
113+
assertEquals("The paged list of FeatureProposals is the wrong length", mockPageableFeatureProposalList.getSize(), page.getSize());
114+
}
115+
97116
@Test
98117
public void testFeatureProposal() {
99118
response = featureProposalController.getFeatureProposal(TEST_FEATURE_PROPOSAL1.getId());

src/test/java/edu/tamu/app/controller/IdeaControllerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import org.mockito.InjectMocks;
1818
import org.mockito.Mock;
1919
import org.mockito.MockitoAnnotations;
20+
import org.springframework.data.domain.Page;
21+
import org.springframework.data.domain.PageImpl;
22+
import org.springframework.data.domain.Pageable;
2023
import org.springframework.messaging.simp.SimpMessagingTemplate;
2124
import org.springframework.test.context.ActiveProfiles;
2225
import org.springframework.test.context.junit4.SpringRunner;
@@ -29,6 +32,8 @@
2932
import edu.tamu.app.model.repo.IdeaRepo;
3033
import edu.tamu.app.model.repo.ServiceRepo;
3134
import edu.tamu.app.model.repo.UserRepo;
35+
import edu.tamu.app.model.repo.specification.IdeaSpecification;
36+
import edu.tamu.app.model.request.FilteredPageRequest;
3237
import edu.tamu.weaver.auth.model.Credentials;
3338
import edu.tamu.weaver.response.ApiResponse;
3439

@@ -55,6 +60,7 @@ public class IdeaControllerTest {
5560
private static Idea TEST_IDEA3 = new Idea(TEST_IDEA_TITLE3, TEST_IDEA_DESCRIPTION3, TEST_USER1);
5661
private static Idea TEST_MODIFIED_IDEA = new Idea(TEST_MODIFIED_IDEA_TITLE, TEST_MODIFIED_IDEA_DESCRIPTION, TEST_USER2, TEST_SERVICE);
5762
private static List<Idea> mockIdeaList = new ArrayList<Idea>(Arrays.asList(new Idea[] { TEST_IDEA1, TEST_IDEA2, TEST_IDEA3 }));
63+
private static Page<Idea> mockPageableIdeaList = new PageImpl<Idea>(Arrays.asList(new Idea[] { TEST_IDEA1, TEST_IDEA2, TEST_IDEA3 }));
5864

5965
private static User user = new User("123456789");
6066

@@ -79,11 +85,13 @@ public class IdeaControllerTest {
7985
private IdeaController ideaController;
8086

8187
@Before
88+
@SuppressWarnings("unchecked")
8289
public void setup() throws UserNotFoundException {
8390
MockitoAnnotations.initMocks(this);
8491
when(credentials.getUin()).thenReturn("123456789");
8592
when(userRepo.findByUsername(any(String.class))).thenReturn(Optional.of(user));
8693
when(ideaRepo.findAll()).thenReturn(mockIdeaList);
94+
when(ideaRepo.findAll(any(IdeaSpecification.class), any(Pageable.class))).thenReturn(mockPageableIdeaList);
8795
when(ideaRepo.findOne(any(Long.class))).thenReturn(TEST_IDEA1);
8896
when(ideaRepo.create(any(Idea.class), any(Credentials.class))).thenReturn(TEST_IDEA1);
8997
when(ideaRepo.update(any(Idea.class))).thenReturn(TEST_MODIFIED_IDEA);
@@ -92,6 +100,17 @@ public void setup() throws UserNotFoundException {
92100
doNothing().when(ideaRepo).delete(any(Idea.class));
93101
}
94102

103+
@Test
104+
@SuppressWarnings("unchecked")
105+
public void testPage() {
106+
FilteredPageRequest mockFilter = new FilteredPageRequest();
107+
response = ideaController.page(mockFilter);
108+
assertEquals("Not successful at getting paged Ideas", SUCCESS, response.getMeta().getStatus());
109+
110+
Page<Idea> page = (Page<Idea>) response.getPayload().get("PageImpl");
111+
assertEquals("The paged list of Ideas is the wrong length", mockPageableIdeaList.getSize(), page.getSize());
112+
}
113+
95114
@Test
96115
public void testIdea() {
97116
response = ideaController.getById(TEST_IDEA1.getId());

src/test/java/edu/tamu/app/controller/NoteControllerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import org.mockito.InjectMocks;
1818
import org.mockito.Mock;
1919
import org.mockito.MockitoAnnotations;
20+
import org.springframework.data.domain.Page;
21+
import org.springframework.data.domain.PageImpl;
22+
import org.springframework.data.domain.Pageable;
2023
import org.springframework.messaging.simp.SimpMessagingTemplate;
2124
import org.springframework.test.context.ActiveProfiles;
2225
import org.springframework.test.context.junit4.SpringRunner;
@@ -30,6 +33,8 @@
3033
import edu.tamu.app.model.repo.NoteRepo;
3134
import edu.tamu.app.model.repo.ServiceRepo;
3235
import edu.tamu.app.model.repo.UserRepo;
36+
import edu.tamu.app.model.repo.specification.NoteSpecification;
37+
import edu.tamu.app.model.request.FilteredPageRequest;
3338
import edu.tamu.weaver.auth.model.Credentials;
3439
import edu.tamu.weaver.response.ApiResponse;
3540

@@ -52,6 +57,7 @@ public class NoteControllerTest {
5257
private static Note TEST_NOTE3 = new Note(TEST_NOTE_TITLE3, TEST_USER1);
5358
private static Note TEST_MODIFIED_NOTE = new Note(TEST_MODIFIED_NOTE_TITLE, TEST_USER2, NoteType.ISSUE, "", TEST_SERVICE);
5459
private static List<Note> mockNoteList = new ArrayList<Note>(Arrays.asList(new Note[] { TEST_NOTE1, TEST_NOTE2, TEST_NOTE3 }));
60+
private static Page<Note> mockPageableNoteList = new PageImpl<Note>(Arrays.asList(new Note[] { TEST_NOTE1, TEST_NOTE2, TEST_NOTE3 }));
5561

5662
private static User user = new User("123456789");
5763

@@ -76,11 +82,13 @@ public class NoteControllerTest {
7682
private NoteController noteController;
7783

7884
@Before
85+
@SuppressWarnings("unchecked")
7986
public void setup() throws UserNotFoundException {
8087
MockitoAnnotations.initMocks(this);
8188
when(credentials.getUin()).thenReturn("123456789");
8289
when(userRepo.findByUsername(any(String.class))).thenReturn(Optional.of(user));
8390
when(noteRepo.findAll()).thenReturn(mockNoteList);
91+
when(noteRepo.findAll(any(NoteSpecification.class), any(Pageable.class))).thenReturn(mockPageableNoteList);
8492
when(noteRepo.findOne(any(Long.class))).thenReturn(TEST_NOTE1);
8593
when(noteRepo.create(any(Note.class), any(Credentials.class))).thenReturn(TEST_NOTE1);
8694
when(noteRepo.update(any(Note.class))).thenReturn(TEST_MODIFIED_NOTE);
@@ -89,6 +97,17 @@ public void setup() throws UserNotFoundException {
8997
doNothing().when(noteRepo).delete(any(Note.class));
9098
}
9199

100+
@Test
101+
@SuppressWarnings("unchecked")
102+
public void testPage() {
103+
FilteredPageRequest mockFilter = new FilteredPageRequest();
104+
response = noteController.page(mockFilter);
105+
assertEquals("Not successful at getting paged Notes", SUCCESS, response.getMeta().getStatus());
106+
107+
Page<Note> page = (Page<Note>) response.getPayload().get("PageImpl");
108+
assertEquals("The paged list of Notes is the wrong length", mockPageableNoteList.getSize(), page.getSize());
109+
}
110+
92111
@Test
93112
public void testNote() {
94113
response = noteController.getById(TEST_NOTE1.getId());

0 commit comments

Comments
 (0)