Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package your.domain.routing;
- import static org.easymock.EasyMock.*;
- import static org.junit.Assert.*;
- import java.util.Arrays;
- import org.junit.Before;
- import org.junit.Test;
- import your.domain.WebTestCase;
- import your.domain.rhigis.handler.Handler;
- public class FirstAvailableMatchRouterTest extends WebTestCase {
- private FirstAvailableMatchRouter router;
- private Route route1;
- private Route route2;
- private Handler handler;
- @Before
- public void setup() {
- route1 = mock( Route.class );
- route2 = mock( Route.class );
- handler = mock( Handler.class );
- router = new FirstAvailableMatchRouter();
- router.setRoutes( Arrays.asList( route1, route2 ) );
- }
- @Test
- public void testMatchFoundOnFirstRoute() throws Exception {
- expect( request.getRequestURI() ).andReturn( "/context-root/some/uri" );
- expect( request.getContextPath() ).andReturn( "/context-root" );
- expect( route1.matches( "some/uri", request ) ).andReturn( true );
- expect( route1.getHandler() ).andReturn( handler );
- replayWebMocks();
- assertSame( handler, router.route( request ) );
- verifyWebMocks();
- }
- @Test
- public void testMatchFoundOnSecondRoute() throws Exception {
- expect( request.getRequestURI() ).andReturn( "/context-root/some/uri" );
- expect( request.getContextPath() ).andReturn( "/context-root" );
- expect( route1.matches( "some/uri", request ) ).andReturn( false );
- expect( route2.matches( "some/uri", request ) ).andReturn( true );
- expect( route2.getHandler() ).andReturn( handler );
- replayWebMocks();
- assertSame( handler, router.route( request ) );
- verifyWebMocks();
- }
- @Test
- public void testNoMatchFound() throws Exception {
- expect( request.getRequestURI() ).andReturn( "/context-root/some/uri" );
- expect( request.getContextPath() ).andReturn( "/context-root" );
- expect( route1.matches( "some/uri", request ) ).andReturn( false );
- expect( route2.matches( "some/uri", request ) ).andReturn( false );
- replayWebMocks();
- assertSame( Router.NOT_FOUND, router.route( request ) );
- verifyWebMocks();
- }
- }
Add Comment
Please, Sign In to add comment