title: How to test Servlet on Mockito?
body: <p>I'm new to mokito, I'm trying to test my servlet who is responsible for registering the user. I'm trying to lock up the HttpRequestServlet but I always get ClassFormException. I can not understand why. How can this be fixed, can you tell? How it is possible to properly test a servlet and to mock HttpServletRequest?</p>
  
  <pre><code>@Mock
      private HttpServletRequest request = mock(HttpServletRequest.class); ;
  
      @After
      public void verifyRequest(){
          verify(request).getParameter(ConstantApp.RegistrationConstantField.GET_FIRST_NAME);
          verify(request).getParameter(ConstantApp.RegistrationConstantField.GET_LAST_NAME);
          verify(request).getParameter(ConstantApp.RegistrationConstantField.GET_LOGIN);
          verify(request).getParameter(ConstantApp.RegistrationConstantField.GET_EMAIL);
          verify(request, Mockito.atLeast(2)).getParameter(ConstantApp.RegistrationConstantField.GET_PASSWORD);
          verify(request).getParameter(ConstantApp.RegistrationConstantField.GET_CONFIRM_PASSWORD);
      }
  
      @Test
      public void shouldReturnTrue_WhenWeGetValidField() throws Exception{
          when(request.getParameter(ConstantApp.RegistrationConstantField.GET_FIRST_NAME)).thenReturn("Aloha");
          when(request.getParameter(ConstantApp.RegistrationConstantField.GET_LAST_NAME)).thenReturn("Dance");
          when(request.getParameter(ConstantApp.RegistrationConstantField.GET_LOGIN)).thenReturn("AlohaDance123");
          when(request.getParameter(ConstantApp.RegistrationConstantField.GET_EMAIL)).thenReturn("aloha.dance@gmail.com");
          when(request.getParameter(ConstantApp.RegistrationConstantField.GET_PASSWORD)).thenReturn("12345678Aa$");
          when(request.getParameter(ConstantApp.RegistrationConstantField.GET_CONFIRM_PASSWORD)).thenReturn("12345678Aa$");
  
          Validation validation = new Validation();
          Map&lt;String, String&gt; errorMap = validation.validate(new RegistrationInfoImpl(request));
  
          assertTrue(errorMap.isEmpty());
      }
  </code></pre>
  
  <p>My Exception:</p>
  
  <pre><code>   java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
  
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
      at java.lang.Class.getDeclaredMethods(Class.java:1975)
      at org.mockito.cglib.core.ReflectUtils.addAllMethods(ReflectUtils.java:349)
      at org.mockito.cglib.proxy.Enhancer.getMethods(Enhancer.java:427)
      at org.mockito.cglib.proxy.Enhancer.generateClass(Enhancer.java:457)
      at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
      at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217)
      at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378)
      at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318)
      at org.mockito.internal.creation.cglib.ClassImposterizer.createProxyClass(ClassImposterizer.java:123)
      at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:57)
      at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:49)
      at org.mockito.internal.creation.cglib.CglibMockMaker.createMock(CglibMockMaker.java:24)
      at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
      at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
      at org.mockito.Mockito.mock(Mockito.java:1285)
      at org.mockito.Mockito.mock(Mockito.java:1163)
      at servlet.RegistrationServletTest.&lt;init&gt;(RegistrationServletTest.java:25)
  </code></pre>