mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-03 19:00:52 +01:00
52 lines
1.4 KiB
Java
52 lines
1.4 KiB
Java
package sonia.scm;
|
|
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.mockito.Mock;
|
|
import org.mockito.junit.MockitoJUnitRunner;
|
|
|
|
import javax.servlet.RequestDispatcher;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import static org.junit.Assert.*;
|
|
import static org.mockito.Mockito.doThrow;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
public class ForwardingPushStateDispatcherTest {
|
|
|
|
@Mock
|
|
private HttpServletRequest request;
|
|
|
|
@Mock
|
|
private RequestDispatcher requestDispatcher;
|
|
|
|
@Mock
|
|
private HttpServletResponse response;
|
|
|
|
private ForwardingPushStateDispatcher dispatcher = new ForwardingPushStateDispatcher();
|
|
|
|
@Test
|
|
public void testDispatch() throws ServletException, IOException {
|
|
when(request.getRequestDispatcher("/index.html")).thenReturn(requestDispatcher);
|
|
|
|
dispatcher.dispatch(request, response, "/something");
|
|
|
|
verify(requestDispatcher).forward(request, response);
|
|
}
|
|
|
|
@Test(expected = IOException.class)
|
|
public void testWrapServletException() throws ServletException, IOException {
|
|
when(request.getRequestDispatcher("/index.html")).thenReturn(requestDispatcher);
|
|
doThrow(ServletException.class).when(requestDispatcher).forward(request, response);
|
|
|
|
dispatcher.dispatch(request, response, "/something");
|
|
}
|
|
|
|
}
|