Skip to content

Commit

Permalink
Refactoring the test to reflect the expected behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcio Lima committed Nov 21, 2014
1 parent 58eac50 commit b36da4f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
*/
package br.com.caelum.vraptor;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import javax.inject.Inject;
Expand All @@ -34,15 +36,16 @@
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;


@RunWith(WeldJunitRunner.class)
public class VRaptorTest {

@Rule
public ExpectedException exception = ExpectedException.none();

@Inject private VRaptor vRaptor;
@Inject private MockStaticContentHandler handler;
@Inject
private VRaptor vRaptor;
@Inject
private MockStaticContentHandler handler;

@Test
public void shoudlComplainIfNotInAServletEnviroment() throws Exception {
Expand All @@ -54,26 +57,28 @@ public void shoudlComplainIfNotInAServletEnviroment() throws Exception {
}

@Test
public void shouldDeferToContainerIfStaticFile() throws Exception{
public void shouldDeferToContainerIfStaticFile() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);
handler.setRequestingStaticFile(true);
vRaptor.doFilter(request, response, chain);
assertThat(handler.isDeferProcessingToContainerCalled(), is(true));
}

@Test
public void shouldBypassWebsocketRequests() throws Exception{
public void shouldBypassWebsocketRequests() throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
FilterChain chain = mock(FilterChain.class);

when(request.getHeader("Upgrade")).thenReturn("Websocket");

handler.setRequestingStaticFile(false);
vRaptor.doFilter(request, response, chain);
assertThat(handler.isDeferProcessingToContainerCalled(), is(false));
verify(request).getHeader("Upgrade");
verify(chain).doFilter(request, response);

verifyNoMoreInteractions(request, response);
}

}

0 comments on commit b36da4f

Please sign in to comment.