1717import org .mockito .InjectMocks ;
1818import org .mockito .Mock ;
1919import org .mockito .MockitoAnnotations ;
20+ import org .springframework .data .domain .Page ;
21+ import org .springframework .data .domain .PageImpl ;
22+ import org .springframework .data .domain .Pageable ;
2023import org .springframework .messaging .simp .SimpMessagingTemplate ;
2124import org .springframework .test .context .ActiveProfiles ;
2225import org .springframework .test .context .junit4 .SpringRunner ;
3033import edu .tamu .app .model .repo .FeatureProposalRepo ;
3134import edu .tamu .app .model .repo .ServiceRepo ;
3235import edu .tamu .app .model .repo .UserRepo ;
36+ import edu .tamu .app .model .repo .specification .FeatureProposalSpecification ;
37+ import edu .tamu .app .model .request .FilteredPageRequest ;
3338import edu .tamu .weaver .auth .model .Credentials ;
3439import 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 ());
0 commit comments