From b36da4f571938ac2ed3638beed7d8732534c4959 Mon Sep 17 00:00:00 2001 From: Marcio Lima Date: Thu, 20 Nov 2014 23:54:52 -0200 Subject: [PATCH] Refactoring the test to reflect the expected behaviour --- .../br/com/caelum/vraptor/VRaptorTest.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorTest.java index 9d08a77b5..726aacc9d 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorTest.java @@ -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; @@ -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 { @@ -54,7 +57,7 @@ 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); @@ -62,18 +65,20 @@ public void shouldDeferToContainerIfStaticFile() throws Exception{ 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); } - + }