From f8d4218ce6d5632f97abdd45e415ffcae6314251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Mon, 22 Sep 2014 23:45:29 -0300 Subject: [PATCH 1/7] Removing unnecessary test --- .../vraptor/observer/DeserializingObserverTest.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/DeserializingObserverTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/DeserializingObserverTest.java index 550c14b5b..d9c9a1c1c 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/DeserializingObserverTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/DeserializingObserverTest.java @@ -21,8 +21,6 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -import java.io.IOException; - import javax.servlet.http.HttpServletRequest; import org.junit.Before; @@ -43,7 +41,6 @@ public class DeserializingObserverTest { - private DeserializingObserver observer; private ControllerMethod consumeXml; private ControllerMethod doesntConsume; @@ -169,14 +166,4 @@ public void willSetOnlyNonNullParameters() throws Exception { assertEquals(methodInfo.getValuedParameters()[0].getValue(), "original1"); assertEquals(methodInfo.getValuedParameters()[1].getValue(), "deserialized"); } - - @Test(expected = IOException.class) - public void shouldThrowInterceptionExceptionIfAnIOExceptionOccurs() throws Exception { - when(request.getInputStream()).thenThrow(new IOException()); - when(request.getContentType()).thenReturn("application/xml"); - - final Deserializer deserializer = mock(Deserializer.class); - when(deserializers.deserializerFor("application/xml", container)).thenReturn(deserializer); - observer.deserializes(new InterceptorsReady(consumeXml), request, methodInfo, status); - } } From cc9580d8b7825bb8a6c651d55083a78add0ca3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Mon, 22 Sep 2014 23:50:24 -0300 Subject: [PATCH 2/7] First attempt to use JUnit exception rules --- .../CommonsUploadMultipartObserver.java | 2 +- .../br/com/caelum/vraptor/VRaptorTest.java | 9 ++++++- .../ControllerNotFoundHandlerTest.java | 14 +++++++---- .../DefaultMethodNotAllowedHandlerTest.java | 10 ++++++-- .../vraptor/controller/HttpMethodTest.java | 24 +++++++++++++++---- .../vraptor/core/DefaultConvertersTest.java | 15 ++++++++++-- .../ToInstantiateInterceptorHandlerTest.java | 13 ++++++++-- .../environment/DefaultEnvironmentTest.java | 9 ++++++- .../EnvironmentPropertyProducerTest.java | 8 ++++++- .../ServletBasedEnvironmentTest.java | 9 ++++++- .../http/DefaultControllerTranslatorTest.java | 13 +++++++++- .../vraptor/http/ParametersProviderTest.java | 10 +++++++- .../route/PathAnnotationRoutesParserTest.java | 5 ++++ .../caelum/vraptor/http/route/RulesTest.java | 9 ++++++- ...tsNeedReturnBooleanValidationRuleTest.java | 5 ++++ ...mAndInternalAcceptsValidationRuleTest.java | 5 ++++ .../NoInterceptMethodsValidationRuleTest.java | 5 ++++ .../NoStackParamValidationRuleTest.java | 5 ++++ .../vraptor/interceptor/StepInvokerTest.java | 5 ++++ ...ologicalSortedInterceptorRegistryTest.java | 5 ++++ .../vraptor/observer/ExecuteMethodTest.java | 3 +++ .../observer/ParametersInstantiatorTest.java | 9 ++++++- .../CommonsUploadMultipartObserverTest.java | 12 ++++++++-- .../DefaultDeserializersTest.java | 4 ++++ .../DeserializesHandlerTest.java | 5 ++++ .../gson/GsonDeserializerTest.java | 10 +++++++- .../xstream/XStreamXMLSerializationTest.java | 5 ++++ .../xstream/XStreamXmlDeserializerTest.java | 11 ++++++++- .../vraptor/validator/MessagesTest.java | 11 ++++++++- .../vraptor/view/DefaultLogicResultTest.java | 9 ++++++- .../vraptor/view/DefaultPageResultTest.java | 5 ++++ .../DefaultValidationViewsFactoryTest.java | 4 ++++ 32 files changed, 238 insertions(+), 30 deletions(-) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserver.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserver.java index e48273e3b..f6dc71a48 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserver.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserver.java @@ -144,7 +144,7 @@ protected void processFile(FileItem item, String name, MutableRequest request) { logger.debug("Uploaded file: {} with {}", name, upload); } catch (IOException e) { - throw new InvalidParameterException("Cant parse uploaded file " + item.getName(), e); + throw new InvalidParameterException("Can't parse uploaded file " + item.getName(), e); } } 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 c46cde305..cf994c886 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 @@ -28,17 +28,24 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.junit.Rule; import org.junit.Test; +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; - @Test(expected = ServletException.class) + @Test public void shoudlComplainIfNotInAServletEnviroment() throws Exception { + exception.expect(ServletException.class); + ServletRequest request = mock(ServletRequest.class); ServletResponse response = mock(ServletResponse.class); vRaptor.doFilter(request, response, null); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/ControllerNotFoundHandlerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/ControllerNotFoundHandlerTest.java index c8bb62181..1f560fae0 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/ControllerNotFoundHandlerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/ControllerNotFoundHandlerTest.java @@ -27,7 +27,9 @@ import javax.servlet.ServletException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -38,6 +40,9 @@ public class ControllerNotFoundHandlerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private ControllerNotFoundHandler notFoundHandler; private @Mock MutableRequest webRequest; private @Mock MutableResponse webResponse; @@ -56,16 +61,17 @@ public void couldntFindDefersRequestToContainer() throws Exception { verify(chain, only()).doFilter(webRequest, webResponse); } - @Test(expected=InterceptionException.class) + @Test public void shouldThrowInterceptionExceptionIfIOExceptionOccurs() throws Exception { + exception.expect(InterceptionException.class); doThrow(new IOException()).when(chain).doFilter(webRequest, webResponse); notFoundHandler.couldntFind(chain, webRequest, webResponse); } - @Test(expected=InterceptionException.class) + @Test public void shouldThrowInterceptionExceptionIfServletExceptionOccurs() throws Exception { + exception.expect(InterceptionException.class); doThrow(new ServletException()).when(chain).doFilter(webRequest, webResponse); notFoundHandler.couldntFind(chain, webRequest, webResponse); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/DefaultMethodNotAllowedHandlerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/DefaultMethodNotAllowedHandlerTest.java index d640eb7be..49e9d7f1f 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/DefaultMethodNotAllowedHandlerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/DefaultMethodNotAllowedHandlerTest.java @@ -28,7 +28,9 @@ import javax.servlet.http.HttpServletResponse; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.InterceptionException; import br.com.caelum.vraptor.http.MutableRequest; @@ -36,6 +38,9 @@ public class DefaultMethodNotAllowedHandlerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private DefaultMethodNotAllowedHandler handler; private MutableResponse response; private MutableRequest request; @@ -71,10 +76,11 @@ public void shouldNotSendMethodNotAllowedIfTheRequestMethodIsOptions() throws Ex verify(response, never()).sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } - @Test(expected=InterceptionException.class) + @Test public void shouldThrowInterceptionExceptionIfAnIOExceptionOccurs() throws Exception { - doThrow(new IOException()).when(response).sendError(anyInt()); + exception.expect(InterceptionException.class); + doThrow(new IOException()).when(response).sendError(anyInt()); this.handler.deny(request, response, EnumSet.of(HttpMethod.GET, HttpMethod.POST)); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/HttpMethodTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/HttpMethodTest.java index 0f9dc4fb2..4179e510b 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/HttpMethodTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/controller/HttpMethodTest.java @@ -15,19 +15,25 @@ */ package br.com.caelum.vraptor.controller; +import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; import javax.servlet.http.HttpServletRequest; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; public class HttpMethodTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private @Mock HttpServletRequest request; @Before @@ -39,20 +45,25 @@ public void setup() { public void shouldConvertGETStringToGetMethodForRequestParameter() throws Exception { when(request.getParameter("_method")).thenReturn("gEt"); when(request.getMethod()).thenReturn("POST"); - + assertEquals(HttpMethod.GET, HttpMethod.of(request)); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldThrowExceptionForNotKnowHttpMethodsForRequestParameter() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage(containsString("HTTP Method not known")); + when(request.getParameter("_method")).thenReturn("JUMP!"); when(request.getMethod()).thenReturn("POST"); HttpMethod.of(request); } - - @Test(expected = InvalidInputException.class) + + @Test public void shouldThrowInvalidInputExceptionIf_methodIsUsedInGETRequests() throws Exception { + exception.expect(InvalidInputException.class); + when(request.getParameter("_method")).thenReturn("DELETE"); when(request.getMethod()).thenReturn("GET"); HttpMethod.of(request); @@ -66,8 +77,11 @@ public void shouldConvertGETStringToGetMethod() throws Exception { assertEquals(HttpMethod.GET, HttpMethod.of(request)); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldThrowExceptionForNotKnowHttpMethods() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage(containsString("HTTP Method not known")); + when(request.getParameter("_method")).thenReturn(null); when(request.getMethod()).thenReturn("JUMP!"); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/core/DefaultConvertersTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/core/DefaultConvertersTest.java index 977822273..675bff7cf 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/core/DefaultConvertersTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/core/DefaultConvertersTest.java @@ -23,7 +23,9 @@ import static org.mockito.Mockito.when; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -35,6 +37,9 @@ public class DefaultConvertersTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + @Mock private Container container; private DefaultConverters converters; @@ -45,13 +50,19 @@ public void setup() { this.converters = new DefaultConverters(container, cache); } - @Test(expected = IllegalStateException.class) + @Test public void complainsIfNoConverterFound() { + exception.expect(IllegalStateException.class); + exception.expectMessage("Unable to find converter for " + getClass().getName()); + converters.to(DefaultConvertersTest.class); } - @Test(expected = IllegalStateException.class) + @Test public void convertingANonAnnotatedConverterEndsUpComplaining() { + exception.expect(IllegalStateException.class); + exception.expectMessage("The converter type " + WrongConverter.class.getName() + " should have the Convert annotation"); + converters.register(WrongConverter.class); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/core/ToInstantiateInterceptorHandlerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/core/ToInstantiateInterceptorHandlerTest.java index 2a5d24f97..54d7b4e9c 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/core/ToInstantiateInterceptorHandlerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/core/ToInstantiateInterceptorHandlerTest.java @@ -16,6 +16,7 @@ */ package br.com.caelum.vraptor.core; +import static org.hamcrest.CoreMatchers.containsString; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -23,7 +24,9 @@ import java.io.IOException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -34,6 +37,9 @@ public class ToInstantiateInterceptorHandlerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private @Mock Container container; private @Mock Interceptor interceptor; private @Mock InterceptorStack stack; @@ -63,10 +69,13 @@ public static class Dependency { } - @Test(expected = InterceptionException.class) + @Test public void shouldComplainWhenUnableToInstantiateAnInterceptor() throws InterceptionException, IOException { + exception.expect(InterceptionException.class); + exception.expectMessage(containsString("Unable to instantiate interceptor for")); + when(container.instanceFor(MyWeirdInterceptor.class)).thenReturn(null); - + ToInstantiateInterceptorHandler handler = new ToInstantiateInterceptorHandler(container, MyWeirdInterceptor.class); handler.execute(null, null, null); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/DefaultEnvironmentTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/DefaultEnvironmentTest.java index 13bd5a5a0..129e4201a 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/DefaultEnvironmentTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/DefaultEnvironmentTest.java @@ -28,10 +28,15 @@ import javax.servlet.ServletContext; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class DefaultEnvironmentTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + @Test public void shouldUseTheCurrentEnvironmentFileIfFound() throws IOException { ServletContext context = mock(ServletContext.class); @@ -67,8 +72,10 @@ public void shouldUseFalseIfFeatureIsNotPresent() throws IOException { assertThat(env.supports("feature_that_doesnt_exists"), equalTo(false)); } - @Test(expected = NoSuchElementException.class) + @Test public void shouldThrowExceptionIfKeyDoesNotExist() throws Exception { + exception.expect(NoSuchElementException.class); + ServletContext context = mock(ServletContext.class); ServletBasedEnvironment env = new ServletBasedEnvironment(context); env.get("key_that_doesnt_exist"); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/EnvironmentPropertyProducerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/EnvironmentPropertyProducerTest.java index cf8c86bcd..532ee35d4 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/EnvironmentPropertyProducerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/EnvironmentPropertyProducerTest.java @@ -22,7 +22,9 @@ import javax.enterprise.inject.Instance; import javax.inject.Inject; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import br.com.caelum.vraptor.WeldJunitRunner; @@ -30,6 +32,9 @@ @RunWith(WeldJunitRunner.class) public class EnvironmentPropertyProducerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + @Inject @Property("email.server.host") private String mailHost; @@ -54,8 +59,9 @@ public void shouldInferKeyFromFieldName() throws Exception { assertEquals(itWorks, "It Works!"); } - @Test(expected=NoSuchElementException.class) + @Test public void shouldNotResolveUnexistentKeys() throws Exception { + exception.expect(NoSuchElementException.class); nonExistent.get(); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/ServletBasedEnvironmentTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/ServletBasedEnvironmentTest.java index 5de44b587..cc0a75fe2 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/ServletBasedEnvironmentTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/environment/ServletBasedEnvironmentTest.java @@ -28,10 +28,15 @@ import javax.servlet.ServletContext; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class ServletBasedEnvironmentTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + @Test public void shouldUseTheCurrentEnvironmentFileIfFound() throws IOException { ServletContext context = mock(ServletContext.class); @@ -60,8 +65,10 @@ public void shouldNotUseAnyPropertiesIfItDoesntExist() throws IOException { assertFalse(env.has("unexistant_key")); } - @Test(expected = NoSuchElementException.class) + @Test public void shouldThrowExceptionIfKeyDoesNotExist() throws Exception { + exception.expect(NoSuchElementException.class); + ServletContext context = mock(ServletContext.class); ServletBasedEnvironment env = new ServletBasedEnvironment(context); env.get("key_that_doesnt_exist"); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/DefaultControllerTranslatorTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/DefaultControllerTranslatorTest.java index 8b9fe08af..855fe3810 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/DefaultControllerTranslatorTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/DefaultControllerTranslatorTest.java @@ -26,10 +26,14 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.when; +import java.util.EnumSet; + import javax.servlet.http.HttpServletRequest; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -40,6 +44,9 @@ public class DefaultControllerTranslatorTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private @Mock Router router; private @Mock HttpServletRequest request; @@ -104,11 +111,15 @@ public void shouldAcceptCaseInsensitiveGetRequestUsingThe_methodParameter() { } - @Test(expected=MethodNotAllowedException.class) + @Test public void shouldThrowExceptionWhenRequestANotKnownMethod() { + exception.expect(MethodNotAllowedException.class); + exception.expectMessage("Method COOK is not allowed for requested URI. Allowed Methods are [GET, POST]"); + when(request.getRequestURI()).thenReturn("/url"); when(request.getMethod()).thenReturn("COOK"); when(router.parse(anyString(), any(HttpMethod.class), any(MutableRequest.class))).thenReturn(method); + when(router.allowedMethodsFor("/url")).thenReturn(EnumSet.of(HttpMethod.GET, HttpMethod.POST)); translator.translate(webRequest); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/ParametersProviderTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/ParametersProviderTest.java index 2e821515a..5377b3166 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/ParametersProviderTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/ParametersProviderTest.java @@ -15,6 +15,7 @@ */ package br.com.caelum.vraptor.http; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -40,7 +41,9 @@ import javax.servlet.http.HttpServletRequest; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -60,6 +63,8 @@ public abstract class ParametersProviderTest { + @Rule + public ExpectedException exception = ExpectedException.none(); protected @Mock Converters converters; protected ParameterNameProvider nameProvider; @@ -264,8 +269,11 @@ public void addsValidationMessageWhenSetterFailsWithAValidationException() throw assertThat(errors.size(), is(greaterThan(0))); } - @Test(expected=InvalidParameterException.class) + @Test public void throwsExceptionWhenSetterFailsWithOtherException() throws Exception { + exception.expect(InvalidParameterException.class); + exception.expectMessage(containsString("Exception when trying to instantiate")); + requestParameterIs(error, "wrongCat.id", "guilherme"); getParameters(error); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java index 8f07e00bb..c6dc7175b 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java @@ -33,7 +33,9 @@ import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; @@ -58,6 +60,9 @@ public class PathAnnotationRoutesParserTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private Proxifier proxifier; private @Mock Converters converters; private NoTypeFinder typeFinder; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/RulesTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/RulesTest.java index f5e0cdd91..809d069bd 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/RulesTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/RulesTest.java @@ -20,7 +20,9 @@ import static org.mockito.Mockito.when; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -29,6 +31,9 @@ public class RulesTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private @Mock Router router; private @Mock Proxifier proxifier; private DefaultRouteBuilder routeBuilder; @@ -42,8 +47,10 @@ public void setup() { when(router.builderFor("")).thenReturn(routeBuilder); } - @Test(expected=IllegalRouteException.class) + @Test public void allowsAdditionOfRouteBuildersByDefaultWithNoStrategy() { + exception.expect(IllegalRouteException.class); + new Rules(router) { @Override public void routes() { diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java index 523729105..535c736c9 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java @@ -21,7 +21,9 @@ import javax.enterprise.inject.Vetoed; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.Accepts; import br.com.caelum.vraptor.InterceptionException; @@ -29,6 +31,9 @@ public class AcceptsNeedReturnBooleanValidationRuleTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private AcceptsNeedReturnBooleanValidationRule validationRule; private StepInvoker stepInvoker; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java index a5497c9c0..9b3d17cfc 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java @@ -19,13 +19,18 @@ import java.util.List; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.Accepts; import br.com.caelum.vraptor.interceptor.example.NotLogged; public class CustomAndInternalAcceptsValidationRuleTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private CustomAndInternalAcceptsValidationRule validationRule; private StepInvoker stepInvoker; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java index a82c72fe8..824d81477 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java @@ -19,7 +19,9 @@ import java.util.List; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.AfterCall; import br.com.caelum.vraptor.InterceptionException; @@ -27,6 +29,9 @@ public class NoInterceptMethodsValidationRuleTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private StepInvoker stepInvoker; @Intercepts diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java index 2548922ae..db6b9aedf 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java @@ -16,7 +16,9 @@ package br.com.caelum.vraptor.interceptor; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.Accepts; import br.com.caelum.vraptor.AroundCall; @@ -27,6 +29,9 @@ public class NoStackParamValidationRuleTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private NoStackParamValidationRule validationRule; private StepInvoker invoker; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java index fe3cd6960..23e7d566d 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java @@ -23,7 +23,9 @@ import java.lang.reflect.Method; import java.util.List; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.AroundCall; import br.com.caelum.vraptor.BeforeCall; @@ -33,6 +35,9 @@ public class StepInvokerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private StepInvoker stepInvoker = new StepInvoker(); @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java index d6ad99311..1ec0d72de 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java @@ -23,12 +23,17 @@ import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.Intercepts; public class TopologicalSortedInterceptorRegistryTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + @Intercepts static interface A {} diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java index f08d35177..6ba41b036 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java @@ -50,6 +50,9 @@ public class ExecuteMethodTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + @Mock private MethodInfo methodInfo; @Mock private Messages messages; @Mock private Validator validator; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ParametersInstantiatorTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ParametersInstantiatorTest.java index 1e2725912..ca66bc4df 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ParametersInstantiatorTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ParametersInstantiatorTest.java @@ -34,7 +34,9 @@ import net.vidageek.mirror.dsl.Mirror; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; @@ -55,6 +57,9 @@ public class ParametersInstantiatorTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private MethodInfo methodInfo = new MethodInfo(new ParanamerNameProvider()); private @Mock ParametersProvider parametersProvider; private @Mock Validator validator; @@ -132,8 +137,10 @@ public void shouldConvertArrayParametersToIndexParameters() throws Exception { /** * Bug related */ - @Test(expected=IllegalArgumentException.class) + @Test public void shouldThrowExceptionWhenThereIsAParameterContainingDotClass() throws Exception { + exception.expect(IllegalArgumentException.class); + methodInfo.setControllerMethod(otherMethod); when(request.getParameterNames()).thenReturn(enumeration(asList("someParam.class.id", "unrelatedParam"))); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserverTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserverTest.java index 41559a7c3..fae897bff 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserverTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/upload/CommonsUploadMultipartObserverTest.java @@ -39,7 +39,9 @@ import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -60,6 +62,9 @@ */ public class CommonsUploadMultipartObserverTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + @Mock private InterceptorStack stack; @Mock private ControllerFound event; @Mock private MutableRequest request; @@ -170,11 +175,14 @@ public void emptyFiles() throws Exception { observer.upload(event, request, config, validator); } - @Test(expected = InvalidParameterException.class) + @Test public void throwsInvalidParameterExceptionIfIOExceptionOccurs() throws Exception { + exception.expect(InvalidParameterException.class); + exception.expectMessage("Can't parse uploaded file myfile.txt"); + when(event.getMethod()).thenReturn(uploadMethodController); - FileItem item = new MockFileItem("thefile0", "file.txt", new byte[0]); + FileItem item = new MockFileItem("thefile0", "myfile.txt", new byte[0]); item = spy(item); doThrow(new IOException()).when(item).getInputStream(); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java index 26f7ea9d2..3f1e37cec 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java @@ -20,7 +20,9 @@ import static org.mockito.Mockito.verify; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -32,6 +34,8 @@ public class DefaultDeserializersTest { + @Rule + public ExpectedException exception = ExpectedException.none(); private Deserializers deserializers; @Mock private Container container; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java index c269fef00..81f2fc490 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java @@ -19,7 +19,9 @@ import static org.mockito.Mockito.verify; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.controller.DefaultBeanClass; import br.com.caelum.vraptor.serialization.Deserializer; @@ -28,6 +30,9 @@ public class DeserializesHandlerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private DeserializesHandler handler; private Deserializers deserializers; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/gson/GsonDeserializerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/gson/GsonDeserializerTest.java index c3e793043..fa8052060 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/gson/GsonDeserializerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/gson/GsonDeserializerTest.java @@ -43,7 +43,9 @@ import net.vidageek.mirror.dsl.Mirror; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -68,6 +70,9 @@ public class GsonDeserializerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private GsonDeserializerBuilder builder; private GsonDeserialization deserializer; private ParameterNameProvider provider; @@ -203,8 +208,11 @@ public void shouldDeserializerParseArraysWithRoot(){ assertThat(dog.age, is(1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldNotAcceptMethodsWithoutArguments() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("Methods that consumes representations must receive just one argument"); + deserializer.deserialize(emptyStream(), noParameter); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java index 2c6f8d09a..443eed259 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java @@ -41,7 +41,9 @@ import javax.servlet.http.HttpServletResponse; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.environment.Environment; @@ -50,6 +52,9 @@ public class XStreamXMLSerializationTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + protected XStreamXMLSerialization serialization; protected ByteArrayOutputStream stream; protected Environment environment; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXmlDeserializerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXmlDeserializerTest.java index 74c2e9cf8..4ac79b5ff 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXmlDeserializerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXmlDeserializerTest.java @@ -27,7 +27,9 @@ import java.util.TimeZone; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.controller.BeanClass; import br.com.caelum.vraptor.controller.ControllerMethod; @@ -40,6 +42,9 @@ public class XStreamXmlDeserializerTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private XStreamXMLDeserializer deserializer; private ControllerMethod bark; private ParameterNameProvider provider; @@ -107,10 +112,14 @@ public void annotated(DogWithAnnotations dog){ } - @Test(expected=IllegalArgumentException.class) + @Test public void shouldNotAcceptMethodsWithoutArguments() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("Methods that consumes xml must receive just one argument"); + deserializer.deserialize(new ByteArrayInputStream(new byte[0]), woof); } + @Test public void shouldBeAbleToDeserializeADog() throws Exception { InputStream stream = new ByteArrayInputStream("Brutus7".getBytes()); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/validator/MessagesTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/validator/MessagesTest.java index a7ee7aced..c0d47014a 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/validator/MessagesTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/validator/MessagesTest.java @@ -1,5 +1,6 @@ package br.com.caelum.vraptor.validator; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @@ -15,10 +16,15 @@ import javax.el.ELProcessor; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class MessagesTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private Messages messages; @Before @@ -26,8 +32,11 @@ public void setUp() { messages = new Messages(); } - @Test(expected = IllegalStateException.class) + @Test public void shouldThrowExceptionIfMessagesHasUnhandledErrors() { + exception.expect(IllegalStateException.class); + exception.expectMessage(containsString("There are validation errors and you forgot to specify where to go.")); + messages.add(new SimpleMessage("Test", "Test message")); messages.assertAbsenceOfErrors(); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultLogicResultTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultLogicResultTest.java index 231703d40..beda1272f 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultLogicResultTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultLogicResultTest.java @@ -39,7 +39,9 @@ import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -62,6 +64,9 @@ public class DefaultLogicResultTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private LogicResult logicResult; private @Mock Router router; @@ -220,8 +225,10 @@ public void cannotRedirectWhenLogicMethodIsAnnotatedWithAnyHttpMethodButGet() th } } - @Test(expected=ValidationException.class) + @Test public void shouldNotWrapValidationExceptionWhenForwarding() throws Exception { + exception.expect(ValidationException.class); + givenDispatcherWillBeReturnedWhenRequested(); when(response.isCommitted()).thenReturn(true); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java index 3ce3dc754..b02691e4b 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java @@ -31,7 +31,9 @@ import javax.servlet.ServletException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -48,6 +50,9 @@ public class DefaultPageResultTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private @Mock MutableRequest request; private @Mock MutableResponse response; private @Mock RequestDispatcher dispatcher; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java index 2629c3f9b..a226e04e2 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java @@ -26,7 +26,9 @@ import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -42,6 +44,8 @@ public class DefaultValidationViewsFactoryTest { + @Rule + public ExpectedException exception = ExpectedException.none(); private Result result; private Proxifier proxifier; From 9c0ecc39bbb899dddce7794ee975152f6d71e1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Tue, 23 Sep 2014 00:15:03 -0300 Subject: [PATCH 3/7] Improving exception tests with JUnit rules --- .../route/PathAnnotationRoutesParserTest.java | 16 ++- .../DefaultDeserializersTest.java | 9 +- .../DeserializesHandlerTest.java | 8 +- .../xstream/XStreamXMLSerializationTest.java | 15 ++- .../vraptor/view/DefaultPageResultTest.java | 35 ++++-- .../DefaultValidationViewsFactoryTest.java | 115 ++++++++++++------ 6 files changed, 133 insertions(+), 65 deletions(-) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java index c6dc7175b..189a536c0 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/http/route/PathAnnotationRoutesParserTest.java @@ -17,6 +17,7 @@ package br.com.caelum.vraptor.http.route; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; @@ -164,8 +165,11 @@ public void noSlashPath() { } } - @Test(expected = IllegalArgumentException.class) + @Test public void addsAPrefixToMethodsWhenTheControllerHasMoreThanOneAnnotatedPath() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("You must specify exactly one path on @Path at class " + MoreThanOnePathAnnotatedController.class.getName()); + parser.rulesFor(new DefaultBeanClass(MoreThanOnePathAnnotatedController.class)); } @@ -350,9 +354,12 @@ public void toInherit() { } } - @Test(expected=IllegalArgumentException.class) + @Test public void shouldThrowExceptionIfPathAnnotationHasEmptyArray() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage(containsString("You must specify at least one path on @Path at")); + parser.rulesFor(new DefaultBeanClass(NoPath.class)); } @@ -544,8 +551,11 @@ public void addsAPrefixToMethodsWhenTheGetControllerIsAnnotatedWithPath() throws assertThat(route, canHandle(GetAnnotatedController.class, "withoutPath")); } - @Test(expected=IllegalArgumentException.class) + @Test public void throwsExceptionWhenTheGetControllerHasAmbiguousDeclaration() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("You should specify paths either in @Path(\"/path\") or @Get(\"/path\") (or @Post, @Put, @Delete), not both at"); + parser.rulesFor(new DefaultBeanClass(WrongGetAnnotatedController.class)); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java index 3f1e37cec..67d914872 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DefaultDeserializersTest.java @@ -27,10 +27,6 @@ import org.mockito.MockitoAnnotations; import br.com.caelum.vraptor.ioc.Container; -import br.com.caelum.vraptor.serialization.DefaultDeserializers; -import br.com.caelum.vraptor.serialization.Deserializer; -import br.com.caelum.vraptor.serialization.Deserializers; -import br.com.caelum.vraptor.serialization.Deserializes; public class DefaultDeserializersTest { @@ -53,8 +49,11 @@ public void shouldThrowExceptionWhenThereIsNoDeserializerRegisteredForGivenConte static interface NotAnnotatedDeserializer extends Deserializer {} - @Test(expected=IllegalArgumentException.class) + @Test public void allDeserializersMustBeAnnotatedWithDeserializes() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("You must annotate your deserializers with @Deserializes"); + deserializers.register(NotAnnotatedDeserializer.class); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java index 81f2fc490..ace926c59 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/DeserializesHandlerTest.java @@ -15,6 +15,7 @@ */ package br.com.caelum.vraptor.serialization; +import static org.hamcrest.CoreMatchers.containsString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -24,9 +25,6 @@ import org.junit.rules.ExpectedException; import br.com.caelum.vraptor.controller.DefaultBeanClass; -import br.com.caelum.vraptor.serialization.Deserializer; -import br.com.caelum.vraptor.serialization.Deserializers; -import br.com.caelum.vraptor.serialization.DeserializesHandler; public class DeserializesHandlerTest { @@ -45,8 +43,10 @@ public void setUp() throws Exception { static interface MyDeserializer extends Deserializer{} static interface NotADeserializer{} - @Test(expected=IllegalArgumentException.class) + @Test public void shouldThrowExceptionWhenTypeIsNotADeserializer() throws Exception { + exception.expect(IllegalArgumentException.class); + exception.expectMessage(containsString("must implement Deserializer")); handler.handle(new DefaultBeanClass(NotADeserializer.class)); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java index 443eed259..677f59523 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/serialization/xstream/XStreamXMLSerializationTest.java @@ -312,22 +312,31 @@ public void shouldExcludeFieldsFromACollection() { assertThat(result(), not(containsString(""))); } - @Test(expected=IllegalArgumentException.class) + @Test public void shouldThrowAnExceptionWhenYouIncludeANonExistantField() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("Field path 'wrongFieldName' doesn't exists in class"); + Order order = new Order(new Client("guilherme silveira"), 15.0, "pack it nicely, please", new Item("name", 12.99)); serialization.from(order).include("wrongFieldName").serialize(); } - @Test(expected=IllegalArgumentException.class) + @Test public void shouldThrowAnExceptionWhenYouIncludeANonExistantFieldInsideOther() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("Field path 'wrongFieldName.client' doesn't exists in class"); + Order order = new Order(new Client("guilherme silveira"), 15.0, "pack it nicely, please", new Item("name", 12.99)); serialization.from(order).include("wrongFieldName.client").serialize(); } - @Test(expected=IllegalArgumentException.class) + @Test public void shouldThrowAnExceptionWhenYouIncludeANonExistantFieldInsideOtherNonExistantField() { + exception.expect(IllegalArgumentException.class); + exception.expectMessage("Field path 'wrongFieldName.another' doesn't exists in class"); + Order order = new Order(new Client("guilherme silveira"), 15.0, "pack it nicely, please", new Item("name", 12.99)); serialization.from(order).include("wrongFieldName.another").serialize(); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java index b02691e4b..009085d19 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultPageResultTest.java @@ -100,10 +100,11 @@ public void shouldNotIncludeContextPathIfURIIsAbsolute() throws Exception { verify(response, only()).sendRedirect("http://vraptor.caelum.com.br"); } - @Test(expected=ResultException.class) + @Test public void shouldThrowResultExceptionIfIOExceptionOccursWhileRedirect() throws Exception { - doThrow(new IOException()).when(response).sendRedirect(anyString()); + exception.expect(ResultException.class); + doThrow(new IOException()).when(response).sendRedirect(anyString()); view.redirectTo("/any/url"); } @@ -116,16 +117,20 @@ public void shouldForwardToGivenURI() throws Exception { } - @Test(expected=ResultException.class) + @Test public void shouldThrowResultExceptionIfServletExceptionOccursWhileForwarding() throws Exception { + exception.expect(ResultException.class); + when(request.getRequestDispatcher(anyString())).thenReturn(dispatcher); doThrow(new ServletException()).when(dispatcher).forward(request, response); view.forwardTo("/any/url"); } - @Test(expected=ResultException.class) + @Test public void shouldThrowResultExceptionIfIOExceptionOccursWhileForwarding() throws Exception { + exception.expect(ResultException.class); + when(request.getRequestDispatcher(anyString())).thenReturn(dispatcher); doThrow(new IOException()).when(dispatcher).forward(request, response); @@ -141,16 +146,20 @@ public void shouldAllowCustomPathResolverWhileForwardingView() throws ServletExc verify(dispatcher, only()).forward(request, response); } - @Test(expected=ApplicationLogicException.class) - public void shouldThrowResultExceptionIfServletExceptionOccursWhileForwardingView() throws Exception { + @Test + public void shouldThrowApplicationLogicExceptionIfServletExceptionOccursWhileForwardingView() throws Exception { + exception.expect(ApplicationLogicException.class); + when(request.getRequestDispatcher(anyString())).thenReturn(dispatcher); doThrow(new ServletException()).when(dispatcher).forward(request, response); view.defaultView(); } - @Test(expected=ResultException.class) + @Test public void shouldThrowResultExceptionIfIOExceptionOccursWhileForwardingView() throws Exception { + exception.expect(ResultException.class); + when(request.getRequestDispatcher(anyString())).thenReturn(dispatcher); doThrow(new IOException()).when(dispatcher).forward(request, response); @@ -166,16 +175,20 @@ public void shouldAllowCustomPathResolverWhileIncluding() throws ServletExceptio verify(dispatcher, only()).include(request, response); } - @Test(expected=ResultException.class) + @Test public void shouldThrowResultExceptionIfServletExceptionOccursWhileIncluding() throws Exception { + exception.expect(ResultException.class); + when(request.getRequestDispatcher(anyString())).thenReturn(dispatcher); doThrow(new ServletException()).when(dispatcher).include(request, response); view.include(); } - @Test(expected=ResultException.class) + @Test public void shouldThrowResultExceptionIfIOExceptionOccursWhileIncluding() throws Exception { + exception.expect(ResultException.class); + when(request.getRequestDispatcher(anyString())).thenReturn(dispatcher); doThrow(new IOException()).when(dispatcher).include(request, response); @@ -192,8 +205,10 @@ public void shoudNotExecuteLogicWhenUsingResultOf() { } } - @Test(expected = ProxyInvocationException.class) + @Test public void shoudThrowProxyInvocationExceptionIfAndExceptionOccursWhenUsingResultOf() { + exception.expect(ProxyInvocationException.class); + doThrow(new NullPointerException()).when(request).getRequestDispatcher(anyString()); view.of(SimpleController.class).notAllowedMethod(); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java index a226e04e2..62d8509f6 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/view/DefaultValidationViewsFactoryTest.java @@ -69,13 +69,15 @@ public void random() { } } - @Test(expected=ValidationException.class) + + @Test public void shouldUseValidationVersionOfLogicResult() throws Exception { + exception.expect(ValidationException.class); when(result.use(LogicResult.class)).thenReturn(new MockedLogic()); - factory.instanceFor(LogicResult.class, errors).forwardTo(RandomComponent.class).random(); } + @Test public void shouldThrowExceptionOnlyAtTheEndOfValidationCall() throws Exception { @@ -87,16 +89,20 @@ public void shouldThrowExceptionOnlyAtTheEndOfValidationCall() throws Exception factory.instanceFor(PageResult.class, errors); factory.instanceFor(PageResult.class, errors).of(RandomComponent.class); } - @Test(expected=ValidationException.class) + + @Test public void shouldUseValidationVersionOfPageResult() throws Exception { - when(result.use(PageResult.class)).thenReturn(new MockedPage()); + exception.expect(ValidationException.class); + when(result.use(PageResult.class)).thenReturn(new MockedPage()); factory.instanceFor(PageResult.class, errors).forwardTo("any uri"); } - @Test(expected=ValidationException.class) + + @Test public void shouldUseValidationVersionOfEmptyResult() throws Exception { - when(result.use(EmptyResult.class)).thenReturn(new EmptyResult()); + exception.expect(ValidationException.class); + when(result.use(EmptyResult.class)).thenReturn(new EmptyResult()); factory.instanceFor(EmptyResult.class, errors); } @@ -113,30 +119,36 @@ public void onHttpResultShouldNotThrowExceptionsOnHeaders() throws Exception { factory.instanceFor(HttpResult.class, errors).addIntHeader("jkl", 456); } - @Test(expected=ValidationException.class) + @Test public void onHttpResultShouldThrowExceptionsOnSendError() throws Exception { - HttpResult httpResult = mock(HttpResult.class); + exception.expect(ValidationException.class); + HttpResult httpResult = mock(HttpResult.class); when(result.use(HttpResult.class)).thenReturn(httpResult); factory.instanceFor(HttpResult.class, errors).sendError(404); } - @Test(expected=ValidationException.class) + + @Test public void onHttpResultShouldThrowExceptionsOnSendErrorWithMessage() throws Exception { - HttpResult httpResult = mock(HttpResult.class); + exception.expect(ValidationException.class); + HttpResult httpResult = mock(HttpResult.class); when(result.use(HttpResult.class)).thenReturn(httpResult); factory.instanceFor(HttpResult.class, errors).sendError(404, "Not Found"); } - @Test(expected=ValidationException.class) + + @Test public void onHttpResultShouldThrowExceptionsOnSetStatus() throws Exception { - HttpResult httpResult = mock(HttpResult.class); + exception.expect(ValidationException.class); + HttpResult httpResult = mock(HttpResult.class); when(result.use(HttpResult.class)).thenReturn(httpResult); factory.instanceFor(HttpResult.class, errors).setStatusCode(200); } + @Test public void shouldBeAbleToChainMethodsOnHttpResult() throws Exception { HttpResult httpResult = mock(HttpResult.class); @@ -146,10 +158,11 @@ public void shouldBeAbleToChainMethodsOnHttpResult() throws Exception { factory.instanceFor(HttpResult.class, errors).addDateHeader("abc", 123l).addHeader("def", "ghi").addIntHeader("jkl", 234); } - @Test(expected=ValidationException.class) + @Test public void onStatusResultShouldThrowExceptionsOnMoved() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); when(status.movedPermanentlyTo(RandomComponent.class)).thenReturn(new RandomComponent()); @@ -161,103 +174,121 @@ public void onStatusResultShouldThrowExceptionsOnMoved() throws Exception { factory.instanceFor(Status.class, errors).movedPermanentlyTo(RandomComponent.class).random(); } - @Test(expected=ValidationException.class) + @Test public void onStatusResultShouldThrowExceptionsOnMovedToLogic() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).movedPermanentlyTo("anywhere"); } - @Test(expected=ValidationException.class) + @Test public void onRefererResultShouldThrowExceptionsOnForward() throws Exception { - RefererResult referer = mock(RefererResult.class); + exception.expect(ValidationException.class); + RefererResult referer = mock(RefererResult.class); when(result.use(RefererResult.class)).thenReturn(referer); factory.instanceFor(RefererResult.class, errors).forward(); } - @Test(expected=ValidationException.class) + @Test public void onRefererResultShouldThrowExceptionsOnRedirect() throws Exception { - RefererResult referer = mock(RefererResult.class); + exception.expect(ValidationException.class); + RefererResult referer = mock(RefererResult.class); when(result.use(RefererResult.class)).thenReturn(referer); factory.instanceFor(RefererResult.class, errors).redirect(); } - @Test(expected=ValidationException.class) + @Test public void onStatusResultShouldThrowExceptionsOnNotFound() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).notFound(); } - @Test(expected=ValidationException.class) + + @Test public void onStatusResultShouldThrowExceptionsOnHeader() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).header("abc", "def"); } - @Test(expected=ValidationException.class) + @Test public void onStatusResultShouldThrowExceptionsOnCreated() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).created(); } - @Test(expected=ValidationException.class) + + @Test public void onStatusResultShouldThrowExceptionsOnCreatedWithLocation() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).created("/newLocation"); } - @Test(expected=ValidationException.class) + @Test public void onStatusResultShouldThrowExceptionsOnOk() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).ok(); } - @Test(expected=ValidationException.class) + @Test public void onStatusResultShouldThrowExceptionsOnConflict() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).conflict(); } - @Test(expected=ValidationException.class) + + @Test public void onStatusResultShouldThrowExceptionsOnMethodNotAllowed() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).methodNotAllowed(EnumSet.allOf(HttpMethod.class)); } - @Test(expected=ValidationException.class) + + @Test public void onStatusResultShouldThrowExceptionsOnMovedPermanentlyTo() throws Exception { - Status status = mock(Status.class); + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); factory.instanceFor(Status.class, errors).movedPermanentlyTo("/newUri"); } - @Test(expected=ValidationException.class) + + @Test public void onStatusResultShouldThrowExceptionsOnMovedPermanentlyToLogic() throws Exception { + exception.expect(ValidationException.class); + Status status = mock(Status.class); when(result.use(Status.class)).thenReturn(status); @@ -270,8 +301,11 @@ public void onStatusResultShouldThrowExceptionsOnMovedPermanentlyToLogic() throw } factory.instanceFor(Status.class, errors).movedPermanentlyTo(RandomComponent.class).random(); } - @Test(expected=ValidationException.class) + + @Test public void onXMLSerializationResultShouldThrowExceptionOnlyOnSerializeMethod() throws Exception { + exception.expect(ValidationException.class); + JSONSerialization serialization = mock(JSONSerialization.class); serializerBuilder = mock(SerializerBuilder.class, new Answer() { @@ -329,11 +363,12 @@ public RandomSerializer recursive() { @Override public void serialize() { } - } - @Test(expected=ValidationException.class) + @Test public void onSerializerResultsShouldBeAbleToCreateValidationInstancesEvenIfChildClassesUsesCovariantType() throws Exception { + exception.expect(ValidationException.class); + JSONSerialization serialization = mock(JSONSerialization.class); serializerBuilder = new RandomSerializer(); From 3713d6ae0c69366733e99d8d4bbd6f436d2bb0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Tue, 23 Sep 2014 00:38:21 -0300 Subject: [PATCH 4/7] Improving exception tests with JUnit rules --- ...cceptsNeedReturnBooleanValidationRuleTest.java | 10 ++++++++-- ...ustomAndInternalAcceptsValidationRuleTest.java | 5 ++++- .../NoInterceptMethodsValidationRuleTest.java | 5 ++++- .../NoStackParamValidationRuleTest.java | 15 ++++++++++++--- .../vraptor/interceptor/StepInvokerTest.java | 5 ++++- .../TopologicalSortedInterceptorRegistryTest.java | 6 +++++- .../vraptor/observer/ExecuteMethodTest.java | 5 ++++- 7 files changed, 41 insertions(+), 10 deletions(-) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java index 535c736c9..474dbeeeb 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/AcceptsNeedReturnBooleanValidationRuleTest.java @@ -43,15 +43,21 @@ public void setUp() { validationRule = new AcceptsNeedReturnBooleanValidationRule(stepInvoker); } - @Test(expected = InterceptionException.class) + @Test public void shouldVerifyIfAcceptsMethodReturnsVoid() { + exception.expect(InterceptionException.class); + exception.expectMessage("@Accepts method must return boolean"); + Class type = VoidAcceptsInterceptor.class; List allMethods = stepInvoker.findAllMethods(type); validationRule.validate(type, allMethods); } - @Test(expected = InterceptionException.class) + @Test public void shouldVerifyIfAcceptsMethodReturnsNonBooleanType() { + exception.expect(InterceptionException.class); + exception.expectMessage("@Accepts method must return boolean"); + Class type = NonBooleanAcceptsInterceptor.class; List allMethods = stepInvoker.findAllMethods(type); validationRule.validate(type, allMethods); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java index 9b3d17cfc..0da066983 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/CustomAndInternalAcceptsValidationRuleTest.java @@ -40,8 +40,11 @@ public void setUp() { validationRule = new CustomAndInternalAcceptsValidationRule(stepInvoker); } - @Test(expected = IllegalStateException.class) + @Test public void mustNotUseInternalAcceptsAndCustomAccepts(){ + exception.expect(IllegalStateException.class); + exception.expectMessage("Interceptor class " + InternalAndCustomAcceptsInterceptor.class.getName() + " must declare internal accepts or custom, not both"); + Class type = InternalAndCustomAcceptsInterceptor.class; List methods = stepInvoker.findAllMethods(type); validationRule.validate(type, methods); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java index 824d81477..5ab441dd8 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoInterceptMethodsValidationRuleTest.java @@ -49,8 +49,11 @@ public void setUp() { this.stepInvoker = new StepInvoker(); } - @Test(expected=InterceptionException.class) + @Test public void shoulThrowExceptionIfInterceptorDontHaveAnyCallableMethod() { + exception.expect(InterceptionException.class); + exception.expectMessage("Interceptor " + SimpleInterceptor.class.getCanonicalName() +" must declare at least one method whith @AfterCall, @AroundCall or @BeforeCall annotation"); + Class type = SimpleInterceptor.class; List allMethods = stepInvoker.findAllMethods(type); new NoInterceptMethodsValidationRule(stepInvoker).validate(type, allMethods); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java index db6b9aedf..d0280b061 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/NoStackParamValidationRuleTest.java @@ -41,21 +41,30 @@ public void setUp() { validationRule = new NoStackParamValidationRule(invoker); } - @Test(expected = IllegalStateException.class) + @Test public void mustReceiveStackAsParameterForAroundCall() { + exception.expect(IllegalStateException.class); + exception.expectMessage("@AroundCall method must receive br.com.caelum.vraptor.core.InterceptorStack or br.com.caelum.vraptor.interceptor.SimpleInterceptorStack"); + Class type = AroundInterceptorWithoutSimpleStackParameter.class; validationRule.validate(type, invoker.findAllMethods(type)); } - @Test(expected = IllegalStateException.class) + @Test public void mustNotReceiveStackAsParameterForAcceptsCall() { + exception.expect(IllegalStateException.class); + exception.expectMessage("Non @AroundCall method must not receive br.com.caelum.vraptor.core.InterceptorStack or br.com.caelum.vraptor.interceptor.SimpleInterceptorStack"); + Class type = AcceptsInterceptorWithStackAsParameter.class; validationRule.validate(type, invoker.findAllMethods(type)); } - @Test(expected = IllegalStateException.class) + @Test public void mustNotReceiveStackAsParameterForBeforeAfterCall() { + exception.expect(IllegalStateException.class); + exception.expectMessage("Non @AroundCall method must not receive br.com.caelum.vraptor.core.InterceptorStack or br.com.caelum.vraptor.interceptor.SimpleInterceptorStack"); + Class type = BeforeAfterInterceptorWithStackAsParameter.class; validationRule.validate(type, invoker.findAllMethods(type)); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java index 23e7d566d..2a7f5c260 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/StepInvokerTest.java @@ -47,8 +47,11 @@ public void shouldNotReadInheritedMethods() throws Exception { assertEquals(method, interceptorClass.getDeclaredMethod("begin")); } - @Test(expected=IllegalStateException.class) + @Test public void shouldThrowsExceptionWhenInterceptorHasMoreThanOneAnnotatedMethod() { + exception.expect(IllegalStateException.class); + exception.expectMessage(InterceptorWithMoreThanOneBeforeCallMethod.class.getName() + " - You should not have more than one @BeforeCall annotated method"); + Class interceptorClass = InterceptorWithMoreThanOneBeforeCallMethod.class; findMethod(interceptorClass, BeforeCall.class); } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java index 1ec0d72de..800b46b12 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/interceptor/TopologicalSortedInterceptorRegistryTest.java @@ -15,6 +15,7 @@ */ package br.com.caelum.vraptor.interceptor; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.hasItems; import static org.junit.Assert.assertThat; @@ -91,8 +92,11 @@ public void respectsBeforeAndAfterAttribute() throws Exception { } - @Test(expected=IllegalStateException.class) + @Test public void failsOnCycles() throws Exception { + exception.expect(IllegalStateException.class); + exception.expectMessage(containsString("There is a cycle on the interceptor sequence")); + TopologicalSortedInterceptorRegistry set = new TopologicalSortedInterceptorRegistry(); set.register(A.class); set.register(C.class); diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java index 6ba41b036..272fc5616 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/observer/ExecuteMethodTest.java @@ -124,13 +124,16 @@ public void shouldBeOkIfThereIsValidationErrorsAndYouSpecifiedWhereToGo() throws observer.execute(new InterceptorsExecuted(method, controller)); } - @Test(expected=InterceptionException.class) + @Test public void shouldThrowExceptionIfYouHaventSpecifiedWhereToGoOnValidationError() throws Exception { + exception.expect(InterceptionException.class); + Method didntSpecifyWhereToGo = AnyController.class.getMethod("didntSpecifyWhereToGo"); final ControllerMethod method = DefaultControllerMethod.instanceFor(AnyController.class, didntSpecifyWhereToGo); final AnyController controller = new AnyController(validator); doThrow(new IllegalStateException()).when(messages).assertAbsenceOfErrors(); when(methodInfo.getParametersValues()).thenReturn(new Object[0]); + observer.execute(new InterceptorsExecuted(method, controller)); } From 13480cd7334780430205d08dd1ec9a7c19439974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Tue, 23 Sep 2014 03:06:41 -0300 Subject: [PATCH 5/7] Adding exception rules to converter tests --- .../com/caelum/vraptor/VRaptorMatchers.java | 23 +++++++++++++ .../converter/BigDecimalConverterTest.java | 19 +++++------ .../converter/BigIntegerConverterTest.java | 24 ++++++------- .../converter/BooleanConverterTest.java | 17 +++++----- .../vraptor/converter/ByteConverterTest.java | 17 +++++----- .../converter/CalendarConverterTest.java | 16 ++++----- .../converter/CharacterConverterTest.java | 17 +++++----- .../vraptor/converter/DateConverterTest.java | 16 ++++----- .../converter/DoubleConverterTest.java | 18 +++++----- .../vraptor/converter/EnumConverterTest.java | 34 +++++++------------ .../vraptor/converter/FloatConverterTest.java | 18 +++++----- .../converter/IntegerConverterTest.java | 17 +++++----- .../vraptor/converter/LongConverterTest.java | 16 ++++----- .../PrimitiveBooleanConverterTest.java | 18 +++++----- .../converter/PrimitiveByteConverterTest.java | 16 ++++----- .../converter/PrimitiveCharConverterTest.java | 16 ++++----- .../PrimitiveDoubleConverterTest.java | 18 +++++----- .../PrimitiveFloatConverterTest.java | 18 +++++----- .../converter/PrimitiveIntConverterTest.java | 17 +++++----- .../converter/PrimitiveLongConverterTest.java | 16 ++++----- .../PrimitiveShortConverterTest.java | 17 +++++----- .../vraptor/converter/ShortConverterTest.java | 16 ++++----- 22 files changed, 199 insertions(+), 205 deletions(-) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorMatchers.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorMatchers.java index dcfa88ec1..38d2a45ca 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorMatchers.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/VRaptorMatchers.java @@ -27,6 +27,8 @@ import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; +import br.com.caelum.vraptor.converter.ConversionException; +import br.com.caelum.vraptor.converter.ConversionMessage; import br.com.caelum.vraptor.http.route.Route; import br.com.caelum.vraptor.validator.Message; @@ -92,4 +94,25 @@ protected boolean matchesSafely(Message message) { } }; } + + public static TypeSafeMatcher hasConversionException(String message) { + final Matcher delegate = equalTo(message); + return new TypeSafeMatcher() { + @Override + protected boolean matchesSafely(Exception item) { + if (item instanceof ConversionException) { + ConversionMessage message = ((ConversionException) item).getValidationMessage(); + message.setBundle(ResourceBundle.getBundle("messages")); + return delegate.matches(message.getMessage()); + } + + return false; + } + + @Override + public void describeTo(Description description) { + delegate.describeTo(description); + } + }; + } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java index bd361cf02..decbba590 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java @@ -17,12 +17,11 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.math.BigDecimal; @@ -32,16 +31,19 @@ import javax.servlet.http.HttpSession; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import br.com.caelum.vraptor.converter.ConversionException; -import br.com.caelum.vraptor.converter.BigDecimalConverter; import br.com.caelum.vraptor.http.MutableRequest; public class BigDecimalConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; private BigDecimalConverter converter; @@ -83,11 +85,8 @@ public void shouldBeAbleToConvertNull() { @Test public void shouldThrowExceptionWhenUnableToParse() { - try { - converter.convert("vr3.9", BigDecimal.class); - fail("Should throw exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("vr3.9 is not a valid number.")); - } + exception.expect(hasConversionException("vr3.9 is not a valid number.")); + + converter.convert("vr3.9", BigDecimal.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java index df9ee4898..1141fecfa 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java @@ -17,18 +17,18 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import java.math.BigInteger; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - +import org.junit.rules.ExpectedException; /** * VRaptor's BigInteger converter test. @@ -37,6 +37,9 @@ */ public class BigIntegerConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private BigIntegerConverter converter; @Before @@ -51,21 +54,14 @@ public void shouldBeAbleToConvertIntegerNumbers() { @Test public void shouldComplainAboutNonIntegerNumbers() { - try { - converter.convert("2.3", BigInteger.class); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("2.3 is not a valid number.")); - } + exception.expect(hasConversionException("2.3 is not a valid number.")); + converter.convert("2.3", BigInteger.class); } @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", BigInteger.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", BigInteger.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java index 25b4fa015..1406c80b2 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java @@ -17,19 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - +import org.junit.rules.ExpectedException; public class BooleanConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private BooleanConverter converter; @Before @@ -79,11 +82,7 @@ public void shouldConvertIgnoringCase() { @Test public void shouldThrowExceptionForInvalidString() { - try { - converter.convert("not a boolean!", Boolean.class); - fail("should throw an exception"); - } catch(ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("NOT A BOOLEAN! is not a valid boolean. Please use true/false, yes/no, y/n or on/off")); - } + exception.expect(hasConversionException("NOT A BOOLEAN! is not a valid boolean. Please use true/false, yes/no, y/n or on/off")); + converter.convert("not a boolean!", Boolean.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java index 84b19a410..d33d3569a 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java @@ -17,19 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - +import org.junit.rules.ExpectedException; public class ByteConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private ByteConverter converter; @Before @@ -44,12 +47,8 @@ public void shouldBeAbleToConvertNumbers() { @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", Byte.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", Byte.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java index 5d5da1fee..ca405182d 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java @@ -17,12 +17,11 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.util.Calendar; @@ -32,7 +31,9 @@ import javax.servlet.http.HttpSession; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -40,6 +41,9 @@ public class CalendarConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; private CalendarConverter converter; @@ -78,11 +82,7 @@ public void shouldBeAbleToConvertNull() { @Test public void shouldThrowExceptionWhenUnableToParse() { - try { - converter.convert("a,10/06/2008/a/b/c", Calendar.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("a,10/06/2008/a/b/c is not a valid date.")); - } + exception.expect(hasConversionException("a,10/06/2008/a/b/c is not a valid date.")); + converter.convert("a,10/06/2008/a/b/c", Calendar.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java index a8c35a5e7..f412f5dec 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java @@ -17,19 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - +import org.junit.rules.ExpectedException; public class CharacterConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private CharacterConverter converter; @Before @@ -44,12 +47,8 @@ public void shouldBeAbleToConvertCharacters() { @Test public void shouldComplainAboutStringTooBig() { - try { - converter.convert("---", Character.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid character.")); - } + exception.expect(hasConversionException("--- is not a valid character.")); + converter.convert("---", Character.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java index 9b2d6b699..d7782efdd 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java @@ -17,12 +17,11 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.text.ParseException; @@ -34,7 +33,9 @@ import javax.servlet.http.HttpSession; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -42,6 +43,9 @@ public class DateConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; private DateConverter converter; @@ -76,11 +80,7 @@ public void shouldBeAbleToConvertNull() { @Test public void shouldThrowExceptionWhenUnableToParse() { - try { - converter.convert("a,10/06/2008/a/b/c", Date.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("a,10/06/2008/a/b/c is not a valid date.")); - } + exception.expect(hasConversionException("a,10/06/2008/a/b/c is not a valid date.")); + converter.convert("a,10/06/2008/a/b/c", Date.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java index 1f50ec13d..0dd50d48b 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java @@ -17,12 +17,11 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.util.Locale; @@ -31,16 +30,19 @@ import javax.servlet.http.HttpSession; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import br.com.caelum.vraptor.converter.ConversionException; -import br.com.caelum.vraptor.converter.DoubleConverter; import br.com.caelum.vraptor.http.MutableRequest; public class DoubleConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; private DoubleConverter converter; @@ -82,11 +84,7 @@ public void shouldBeAbleToConvertNull() { @Test public void shouldThrowExceptionWhenUnableToParse() { - try { - converter.convert("vr3.9", Double.class); - fail("Should throw exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("vr3.9 is not a valid number.")); - } + exception.expect(hasConversionException("vr3.9 is not a valid number.")); + converter.convert("vr3.9", Double.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java index 65118d7d0..d81d63d67 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java @@ -17,18 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertEquals; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class EnumConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private Converter converter; @Before @@ -58,32 +62,20 @@ public void shouldConvertEmptyToNull() { @Test public void shouldComplainAboutInvalidIndex() { - try { - converter.convert("3200", MyCustomEnum.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("3200 is not a valid option.")); - } + exception.expect(hasConversionException("3200 is not a valid option.")); + converter.convert("3200", MyCustomEnum.class); } @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("32a00", MyCustomEnum.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("32a00 is not a valid option.")); - } + exception.expect(hasConversionException("32a00 is not a valid option.")); + converter.convert("32a00", MyCustomEnum.class); } @Test public void shouldComplainAboutInvalidOrdinal() { - try { - converter.convert("THIRD", MyCustomEnum.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("THIRD is not a valid option.")); - } + exception.expect(hasConversionException("THIRD is not a valid option.")); + converter.convert("THIRD", MyCustomEnum.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java index 205eeb280..75a58e635 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java @@ -17,12 +17,11 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.util.Locale; @@ -31,16 +30,19 @@ import javax.servlet.http.HttpSession; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import br.com.caelum.vraptor.converter.ConversionException; -import br.com.caelum.vraptor.converter.FloatConverter; import br.com.caelum.vraptor.http.MutableRequest; public class FloatConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; private FloatConverter converter; @@ -82,11 +84,7 @@ public void shouldBeAbleToConvertNull() { @Test public void shouldThrowExceptionWhenUnableToParse() { - try { - converter.convert("vr3.9", Float.class); - fail("Should throw exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("vr3.9 is not a valid number.")); - } + exception.expect(hasConversionException("vr3.9 is not a valid number.")); + converter.convert("vr3.9", Float.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java index 6bc9657ab..d9b03444a 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java @@ -17,19 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - +import org.junit.rules.ExpectedException; public class IntegerConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private IntegerConverter converter; @Before @@ -44,12 +47,8 @@ public void shouldBeAbleToConvertNumbers() { @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", Integer.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", Integer.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java index e7cb7ef8f..2e233c771 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java @@ -17,19 +17,23 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class LongConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private LongConverter converter; @Before @@ -44,12 +48,8 @@ public void shouldBeAbleToConvertNumbers(){ @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", long.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", long.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java index 14e2c2f83..858bad535 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java @@ -17,19 +17,22 @@ package br.com.caelum.vraptor.converter; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - -import br.com.caelum.vraptor.VRaptorMatchers; +import org.junit.rules.ExpectedException; public class PrimitiveBooleanConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private PrimitiveBooleanConverter converter; @Before @@ -83,12 +86,7 @@ public void shouldConvertIgnoringCase() { @Test public void shouldThrowExceptionForInvalidString() { - try { - converter.convert("not a boolean!", boolean.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), - VRaptorMatchers.hasMessage("NOT A BOOLEAN! is not a valid boolean. Please use true/false, yes/no, y/n or on/off")); - } + exception.expect(hasConversionException("NOT A BOOLEAN! is not a valid boolean. Please use true/false, yes/no, y/n or on/off")); + converter.convert("not a boolean!", boolean.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java index 3c684fb0a..e51d01819 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java @@ -17,18 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class PrimitiveByteConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private PrimitiveByteConverter converter; @Before @@ -43,12 +47,8 @@ public void shouldBeAbleToConvertNumbers() { @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", byte.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", byte.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java index 9b8a1336a..a857f58b6 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java @@ -17,18 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class PrimitiveCharConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private PrimitiveCharConverter converter; @Before @@ -43,12 +47,8 @@ public void shouldBeAbleToConvertNumbers() { @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", char.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid character.")); - } + exception.expect(hasConversionException("--- is not a valid character.")); + converter.convert("---", char.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java index 53a8d1ee9..dc8f5e308 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java @@ -17,11 +17,10 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.util.Locale; @@ -30,16 +29,19 @@ import javax.servlet.http.HttpSession; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import br.com.caelum.vraptor.converter.ConversionException; -import br.com.caelum.vraptor.converter.PrimitiveDoubleConverter; import br.com.caelum.vraptor.http.MutableRequest; public class PrimitiveDoubleConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; private PrimitiveDoubleConverter converter; @@ -81,11 +83,7 @@ public void shouldBeAbleToConvertNull() { @Test public void shouldThrowExceptionWhenUnableToParse() { - try { - converter.convert("vr3.9", double.class); - fail("Should throw exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("vr3.9 is not a valid number.")); - } + exception.expect(hasConversionException("vr3.9 is not a valid number.")); + converter.convert("vr3.9", double.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java index ab00095cd..8ae4727ac 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java @@ -16,11 +16,10 @@ */ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import java.util.Locale; @@ -29,16 +28,19 @@ import javax.servlet.http.HttpSession; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import br.com.caelum.vraptor.converter.ConversionException; -import br.com.caelum.vraptor.converter.PrimitiveFloatConverter; import br.com.caelum.vraptor.http.MutableRequest; public class PrimitiveFloatConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private PrimitiveFloatConverter converter; private @Mock MutableRequest request; private @Mock HttpSession session; @@ -78,11 +80,7 @@ public void shouldBeAbleToConvertNull() { @Test public void shouldThrowExceptionWhenUnableToParse() { - try { - converter.convert("vr3.9", float.class); - fail("Should throw exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("vr3.9 is not a valid number.")); - } + exception.expect(hasConversionException("vr3.9 is not a valid number.")); + converter.convert("vr3.9", float.class); } } diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java index f447616e8..1f6685787 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java @@ -17,18 +17,21 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - +import org.junit.rules.ExpectedException; public class PrimitiveIntConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private PrimitiveIntConverter converter; @Before @@ -43,12 +46,8 @@ public void shouldBeAbleToConvertNumbers() { @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", int.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", int.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java index f258eb45e..c293f5219 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java @@ -17,18 +17,22 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class PrimitiveLongConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private PrimitiveLongConverter converter; @Before @@ -43,12 +47,8 @@ public void shouldBeAbleToConvertNumbers() { @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", long.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", long.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java index c0660c5df..5534b05c5 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java @@ -17,19 +17,22 @@ package br.com.caelum.vraptor.converter; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - -import br.com.caelum.vraptor.VRaptorMatchers; +import org.junit.rules.ExpectedException; public class PrimitiveShortConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private PrimitiveShortConverter converter; @Before @@ -44,12 +47,8 @@ public void shouldBeAbleToConvertNumbers(){ @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", short.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), VRaptorMatchers.hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", short.class); } @Test diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java index 1ffcc826f..47ca6db1b 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java @@ -17,19 +17,23 @@ package br.com.caelum.vraptor.converter; -import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; +import static br.com.caelum.vraptor.VRaptorMatchers.hasConversionException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; public class ShortConverterTest { + @Rule + public ExpectedException exception = ExpectedException.none(); + private ShortConverter converter; @Before @@ -44,12 +48,8 @@ public void shouldBeAbleToConvertNumbers() { @Test public void shouldComplainAboutInvalidNumber() { - try { - converter.convert("---", Short.class); - fail("should throw an exception"); - } catch (ConversionException e) { - assertThat(e.getValidationMessage(), hasMessage("--- is not a valid number.")); - } + exception.expect(hasConversionException("--- is not a valid number.")); + converter.convert("---", Short.class); } @Test From 0785a842c1cbf896803bf9e39b1df6173b9a29f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Wed, 24 Sep 2014 00:58:48 -0300 Subject: [PATCH 6/7] Fixing code indentation --- .../converter/BigDecimalConverterTest.java | 3 +-- .../converter/BigIntegerConverterTest.java | 3 +-- .../converter/BooleanConverterTest.java | 4 +++- .../vraptor/converter/ByteConverterTest.java | 3 +-- .../converter/CalendarConverterTest.java | 3 +-- .../converter/CharacterConverterTest.java | 3 +-- .../vraptor/converter/DateConverterTest.java | 3 +-- .../converter/DoubleConverterTest.java | 19 +++++++++---------- .../vraptor/converter/EnumConverterTest.java | 3 +-- .../vraptor/converter/FloatConverterTest.java | 3 +-- .../converter/IntegerConverterTest.java | 2 +- .../vraptor/converter/LongConverterTest.java | 4 +--- .../PrimitiveBooleanConverterTest.java | 3 +-- .../converter/PrimitiveByteConverterTest.java | 4 +--- .../converter/PrimitiveCharConverterTest.java | 4 +--- .../PrimitiveDoubleConverterTest.java | 19 +++++++++---------- .../PrimitiveFloatConverterTest.java | 19 +++++++++---------- .../converter/PrimitiveIntConverterTest.java | 3 +-- .../converter/PrimitiveLongConverterTest.java | 4 +--- .../PrimitiveShortConverterTest.java | 4 +--- .../vraptor/converter/ShortConverterTest.java | 4 +--- 21 files changed, 47 insertions(+), 70 deletions(-) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java index decbba590..6fcc8f37b 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java @@ -54,7 +54,6 @@ public class BigDecimalConverterTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - when(request.getServletContext()).thenReturn(context); converter = new BigDecimalConverter(new Locale("pt", "BR")); @@ -89,4 +88,4 @@ public void shouldThrowExceptionWhenUnableToParse() { converter.convert("vr3.9", BigDecimal.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java index 1141fecfa..277b61beb 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigIntegerConverterTest.java @@ -73,5 +73,4 @@ public void shouldNotComplainAboutNull() { public void shouldNotComplainAboutEmpty() { assertThat(converter.convert("", BigInteger.class), is(nullValue())); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java index 1406c80b2..3e838e0c8 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BooleanConverterTest.java @@ -61,11 +61,13 @@ public void shouldConvertYesNo() { assertThat(converter.convert("yes", Boolean.class), is(equalTo(true))); assertThat(converter.convert("no", Boolean.class), is(equalTo(false))); } + @Test public void shouldConvertYN() { assertThat(converter.convert("y", Boolean.class), is(equalTo(true))); assertThat(converter.convert("n", Boolean.class), is(equalTo(false))); } + @Test public void shouldConvertOnOff() { assertThat(converter.convert("on", Boolean.class), is(equalTo(true))); @@ -85,4 +87,4 @@ public void shouldThrowExceptionForInvalidString() { exception.expect(hasConversionException("NOT A BOOLEAN! is not a valid boolean. Please use true/false, yes/no, y/n or on/off")); converter.convert("not a boolean!", Boolean.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java index d33d3569a..c9465e0e3 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ByteConverterTest.java @@ -60,5 +60,4 @@ public void shouldNotComplainAboutNull() { public void shouldNotComplainAboutEmpty() { assertThat(converter.convert("", Byte.class), is(nullValue())); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java index ca405182d..3fe9958f0 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java @@ -54,7 +54,6 @@ public class CalendarConverterTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - when(request.getServletContext()).thenReturn(context); converter = new CalendarConverter(new Locale("pt", "BR")); @@ -85,4 +84,4 @@ public void shouldThrowExceptionWhenUnableToParse() { exception.expect(hasConversionException("a,10/06/2008/a/b/c is not a valid date.")); converter.convert("a,10/06/2008/a/b/c", Calendar.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java index f412f5dec..81e70399e 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CharacterConverterTest.java @@ -56,5 +56,4 @@ public void shouldNotComplainAboutNullAndEmpty() { assertThat(converter.convert(null, Character.class), is(nullValue())); assertThat(converter.convert("", Character.class), is(nullValue())); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java index d7782efdd..b8c25f00c 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java @@ -56,7 +56,6 @@ public class DateConverterTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - when(request.getServletContext()).thenReturn(context); converter = new DateConverter(new Locale("pt", "BR")); @@ -83,4 +82,4 @@ public void shouldThrowExceptionWhenUnableToParse() { exception.expect(hasConversionException("a,10/06/2008/a/b/c is not a valid date.")); converter.convert("a,10/06/2008/a/b/c", Date.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java index 0dd50d48b..630575ea4 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java @@ -53,7 +53,6 @@ public class DoubleConverterTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - when(request.getServletContext()).thenReturn(context); converter = new DoubleConverter(new Locale("pt", "BR")); @@ -72,19 +71,19 @@ public void shouldBeAbleToConvertWithENUS() { assertThat(converter.convert("10.01", Double.class), is(equalTo(new Double("10.01")))); } - @Test - public void shouldBeAbleToConvertEmpty() { - assertThat(converter.convert("", Double.class), is(nullValue())); - } + @Test + public void shouldBeAbleToConvertEmpty() { + assertThat(converter.convert("", Double.class), is(nullValue())); + } - @Test - public void shouldBeAbleToConvertNull() { - assertThat(converter.convert(null, Double.class), is(nullValue())); - } + @Test + public void shouldBeAbleToConvertNull() { + assertThat(converter.convert(null, Double.class), is(nullValue())); + } @Test public void shouldThrowExceptionWhenUnableToParse() { exception.expect(hasConversionException("vr3.9 is not a valid number.")); converter.convert("vr3.9", Double.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java index d81d63d67..72f64910c 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/EnumConverterTest.java @@ -49,7 +49,6 @@ public void shouldBeAbleToConvertByOrdinal() { @Test public void shouldBeAbleToConvertByName() { - Enum value = converter.convert("FIRST", MyCustomEnum.class); MyCustomEnum first = MyCustomEnum.FIRST; assertEquals(value, first); @@ -86,4 +85,4 @@ public void shouldAcceptNull() { enum MyCustomEnum { FIRST, SECOND } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java index 75a58e635..27d3b57f9 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java @@ -53,7 +53,6 @@ public class FloatConverterTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - when(request.getServletContext()).thenReturn(context); converter = new FloatConverter(new Locale("pt", "BR")); @@ -87,4 +86,4 @@ public void shouldThrowExceptionWhenUnableToParse() { exception.expect(hasConversionException("vr3.9 is not a valid number.")); converter.convert("vr3.9", Float.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java index d9b03444a..982d130d9 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/IntegerConverterTest.java @@ -60,4 +60,4 @@ public void shouldNotComplainAboutNull() { public void shouldNotComplainAboutEmpty() { assertThat(converter.convert("", Integer.class), is(nullValue())); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java index 2e233c771..1e51d0e09 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/LongConverterTest.java @@ -28,7 +28,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; - public class LongConverterTest { @Rule @@ -61,5 +60,4 @@ public void shouldNotComplainAboutNull() { public void shouldNotComplainAboutEmpty() { assertThat(converter.convert("", long.class), is(nullValue())); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java index 858bad535..a270e52f2 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveBooleanConverterTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; - public class PrimitiveBooleanConverterTest { @Rule @@ -89,4 +88,4 @@ public void shouldThrowExceptionForInvalidString() { exception.expect(hasConversionException("NOT A BOOLEAN! is not a valid boolean. Please use true/false, yes/no, y/n or on/off")); converter.convert("not a boolean!", boolean.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java index e51d01819..d2627c30f 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveByteConverterTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; - public class PrimitiveByteConverterTest { @Rule @@ -60,5 +59,4 @@ public void shouldConvertToZeroWhenNull() { public void shouldConvertToZeroWhenEmpty() { assertThat(converter.convert("", byte.class), is(equalTo((byte) 0))); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java index a857f58b6..91b6b49a5 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveCharConverterTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; - public class PrimitiveCharConverterTest { @Rule @@ -60,5 +59,4 @@ public void shouldConvertToZeroWhenNull() { public void shouldConvertToZeroWhenEmpty() { assertThat(converter.convert("", char.class), is(equalTo('\u0000'))); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java index dc8f5e308..466cbcd58 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java @@ -52,7 +52,6 @@ public class PrimitiveDoubleConverterTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - when(request.getServletContext()).thenReturn(context); converter = new PrimitiveDoubleConverter(new Locale("pt", "BR")); @@ -71,19 +70,19 @@ public void shouldBeAbleToConvertWithENUS() { assertThat(converter.convert("10.01", double.class), is(equalTo(Double.parseDouble("10.01")))); } - @Test - public void shouldBeAbleToConvertEmpty() { - assertThat(converter.convert("", double.class), is(equalTo(0d))); - } + @Test + public void shouldBeAbleToConvertEmpty() { + assertThat(converter.convert("", double.class), is(equalTo(0d))); + } - @Test - public void shouldBeAbleToConvertNull() { - assertThat(converter.convert(null, double.class), is(equalTo(0d))); - } + @Test + public void shouldBeAbleToConvertNull() { + assertThat(converter.convert(null, double.class), is(equalTo(0d))); + } @Test public void shouldThrowExceptionWhenUnableToParse() { exception.expect(hasConversionException("vr3.9 is not a valid number.")); converter.convert("vr3.9", double.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java index 8ae4727ac..b35814b4c 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveFloatConverterTest.java @@ -49,7 +49,6 @@ public class PrimitiveFloatConverterTest { @Before public void setup() { MockitoAnnotations.initMocks(this); - when(request.getServletContext()).thenReturn(context); converter = new PrimitiveFloatConverter(new Locale("pt", "BR")); @@ -68,19 +67,19 @@ public void shouldBeAbleToConvertWithENUS() { assertThat(converter.convert("10.01", float.class), is(equalTo(Float.parseFloat("10.01")))); } - @Test - public void shouldBeAbleToConvertEmpty() { - assertThat(converter.convert("", float.class), is(equalTo(0f))); - } + @Test + public void shouldBeAbleToConvertEmpty() { + assertThat(converter.convert("", float.class), is(equalTo(0f))); + } - @Test - public void shouldBeAbleToConvertNull() { - assertThat(converter.convert(null, float.class), is(equalTo(0f))); - } + @Test + public void shouldBeAbleToConvertNull() { + assertThat(converter.convert(null, float.class), is(equalTo(0f))); + } @Test public void shouldThrowExceptionWhenUnableToParse() { exception.expect(hasConversionException("vr3.9 is not a valid number.")); converter.convert("vr3.9", float.class); } -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java index 1f6685787..0bfd5a0bd 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveIntConverterTest.java @@ -59,5 +59,4 @@ public void shouldConvertToZeroWhenNull() { public void shouldConvertToZeroWhenEmpty() { assertThat(converter.convert("", int.class), is(equalTo(0))); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java index c293f5219..2ec9d9391 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveLongConverterTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; - public class PrimitiveLongConverterTest { @Rule @@ -60,5 +59,4 @@ public void shouldConvertToZeroWhenNull() { public void shouldConvertToZeroWhenEmpty() { assertThat(converter.convert("", long.class), is(equalTo(0L))); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java index 5534b05c5..79825fbfb 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveShortConverterTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; - public class PrimitiveShortConverterTest { @Rule @@ -60,5 +59,4 @@ public void shouldConvertToZeroWhenNull() { public void shouldConvertToZeroWhenEmpty() { assertThat(converter.convert("", short.class), is(equalTo((short) 0))); } - -} +} \ No newline at end of file diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java index 47ca6db1b..b391c84fe 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/ShortConverterTest.java @@ -28,7 +28,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; - public class ShortConverterTest { @Rule @@ -61,5 +60,4 @@ public void shouldComplainAboutNull() { public void shouldComplainAboutEmpty() { assertThat(converter.convert("", Short.class), is(nullValue())); } - -} +} \ No newline at end of file From daba79450c96af82e5a29d3299072e0cb66eb163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Wed, 24 Sep 2014 01:02:11 -0300 Subject: [PATCH 7/7] Unused code --- .../com/caelum/vraptor/converter/BigDecimalConverterTest.java | 2 -- .../br/com/caelum/vraptor/converter/CalendarConverterTest.java | 2 -- .../java/br/com/caelum/vraptor/converter/DateConverterTest.java | 2 -- .../br/com/caelum/vraptor/converter/DoubleConverterTest.java | 2 -- .../br/com/caelum/vraptor/converter/FloatConverterTest.java | 2 -- .../caelum/vraptor/converter/PrimitiveDoubleConverterTest.java | 2 -- 6 files changed, 12 deletions(-) diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java index 6fcc8f37b..34bd67cb0 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/BigDecimalConverterTest.java @@ -44,8 +44,6 @@ public class BigDecimalConverterTest { @Rule public ExpectedException exception = ExpectedException.none(); - static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; - private BigDecimalConverter converter; private @Mock MutableRequest request; private @Mock HttpSession session; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java index 3fe9958f0..3af02da30 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/CalendarConverterTest.java @@ -44,8 +44,6 @@ public class CalendarConverterTest { @Rule public ExpectedException exception = ExpectedException.none(); - static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; - private CalendarConverter converter; private @Mock MutableRequest request; private @Mock HttpSession session; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java index b8c25f00c..9a9fe8bef 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DateConverterTest.java @@ -46,8 +46,6 @@ public class DateConverterTest { @Rule public ExpectedException exception = ExpectedException.none(); - static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; - private DateConverter converter; private @Mock MutableRequest request; private @Mock HttpSession session; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java index 630575ea4..61ba64174 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/DoubleConverterTest.java @@ -43,8 +43,6 @@ public class DoubleConverterTest { @Rule public ExpectedException exception = ExpectedException.none(); - static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; - private DoubleConverter converter; private @Mock MutableRequest request; private @Mock HttpSession session; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java index 27d3b57f9..b5b28e17a 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/FloatConverterTest.java @@ -43,8 +43,6 @@ public class FloatConverterTest { @Rule public ExpectedException exception = ExpectedException.none(); - static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; - private FloatConverter converter; private @Mock MutableRequest request; private @Mock HttpSession session; diff --git a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java index 466cbcd58..45d202126 100644 --- a/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java +++ b/vraptor-core/src/test/java/br/com/caelum/vraptor/converter/PrimitiveDoubleConverterTest.java @@ -42,8 +42,6 @@ public class PrimitiveDoubleConverterTest { @Rule public ExpectedException exception = ExpectedException.none(); - static final String LOCALE_KEY = "javax.servlet.jsp.jstl.fmt.locale"; - private PrimitiveDoubleConverter converter; private @Mock MutableRequest request; private @Mock HttpSession session;