Guest User

Untitled

a guest
Feb 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. package your.domain.routing;
  2.  
  3. import static org.easymock.EasyMock.*;
  4. import static org.junit.Assert.*;
  5.  
  6. import java.util.Arrays;
  7.  
  8. import org.junit.Before;
  9. import org.junit.Test;
  10.  
  11. import your.domain.WebTestCase;
  12. import your.domain.rhigis.handler.Handler;
  13.  
  14. public class FirstAvailableMatchRouterTest extends WebTestCase {
  15. private FirstAvailableMatchRouter router;
  16. private Route route1;
  17. private Route route2;
  18. private Handler handler;
  19.  
  20. @Before
  21. public void setup() {
  22. route1 = mock( Route.class );
  23. route2 = mock( Route.class );
  24. handler = mock( Handler.class );
  25. router = new FirstAvailableMatchRouter();
  26. router.setRoutes( Arrays.asList( route1, route2 ) );
  27. }
  28.  
  29. @Test
  30. public void testMatchFoundOnFirstRoute() throws Exception {
  31. expect( request.getRequestURI() ).andReturn( "/context-root/some/uri" );
  32. expect( request.getContextPath() ).andReturn( "/context-root" );
  33. expect( route1.matches( "some/uri", request ) ).andReturn( true );
  34. expect( route1.getHandler() ).andReturn( handler );
  35.  
  36. replayWebMocks();
  37. assertSame( handler, router.route( request ) );
  38. verifyWebMocks();
  39. }
  40.  
  41. @Test
  42. public void testMatchFoundOnSecondRoute() throws Exception {
  43. expect( request.getRequestURI() ).andReturn( "/context-root/some/uri" );
  44. expect( request.getContextPath() ).andReturn( "/context-root" );
  45. expect( route1.matches( "some/uri", request ) ).andReturn( false );
  46. expect( route2.matches( "some/uri", request ) ).andReturn( true );
  47. expect( route2.getHandler() ).andReturn( handler );
  48.  
  49. replayWebMocks();
  50. assertSame( handler, router.route( request ) );
  51. verifyWebMocks();
  52. }
  53.  
  54. @Test
  55. public void testNoMatchFound() throws Exception {
  56. expect( request.getRequestURI() ).andReturn( "/context-root/some/uri" );
  57. expect( request.getContextPath() ).andReturn( "/context-root" );
  58. expect( route1.matches( "some/uri", request ) ).andReturn( false );
  59. expect( route2.matches( "some/uri", request ) ).andReturn( false );
  60.  
  61. replayWebMocks();
  62. assertSame( Router.NOT_FOUND, router.route( request ) );
  63. verifyWebMocks();
  64. }
  65. }
Add Comment
Please, Sign In to add comment