title: Spring Framework controller integration test NullPointer Java
body: <p>I wrote this integration test and i have nullpointer exception but i can not fix it. I will copy the stack trace. I think that the problem comes from this line - <code>.andExpect(view().name("/login"))</code> but i do not find information in spring docs. </p>
  
  <pre><code>public class IntegratonTest {
  
      private MockMvc mockMvc;
  
      @Before
      public void setup() throws Exception {
  
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setPrefix("/WebContent/j/");
          viewResolver.setSuffix(".jsp");
          this.mockMvc = standaloneSetup(new LoginController()).setViewResolvers(viewResolver).build();
      }
  
      @Test
      public void testShowForm() throws Exception {
          this.mockMvc.perform(get("/login"))
                      .andExpect(status().isOk())
                      .andExpect(view().name("/login"))
                      .andExpect(model().attribute("login", hasProperty("email", isEmptyOrNullString())))
                      .andExpect(model().attribute("login", hasProperty("password", isEmptyOrNullString())));
      }
  
      @Test
      public void testOnSubmitLogin() throws Exception {
          this.mockMvc.perform(post("/login")
                      .param("email", "email@email.com")
                      .param("password", "password"))
                      .andExpect(status().isOk()).andExpect(redirectedUrl(null));
      }
  
  }
  </code></pre>
  
  <p><strong>Stack Trace</strong></p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:65)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
      at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:167)
      at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:134)
      at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:144)
      at test.loginController.IntegratonTest.testShowForm(IntegratonTest.java:38)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  Caused by: java.lang.NullPointerException
      at bg.profiles.controller.LoginController.showForm(LoginController.java:71)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
      ... 33 more
  </code></pre>
  
  <p><strong>EDIT:</strong>
  @Simze i do not ask what is a nullpointer. I asked how to fix the nullpointer that i have because it may be cause from a incorrect path or error in the controller class etc.</p>
  
  <p><strong>EDIT1:</strong></p>
  
  <pre><code>@Mock
      private LoginController logController;
  
      @Before
      public void setup() throws Exception {
          logController = new LoginController();
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setPrefix("/WebContent/j/");
          viewResolver.setSuffix(".jsp");
          this.mockMvc = standaloneSetup(logController).setViewResolvers(viewResolver).build();
      }
  </code></pre>