title: How to use Spring to unit test a portlet?
body: <p>I'm trying to use Spring to unit test a simple portlet.  The following is what I have so far...</p>
  
  <pre><code>import static org.hamcrest.core.IsEqual.equalTo;
  import static org.junit.Assert.assertThat;
  
  import java.io.IOException;
  
  import javax.portlet.GenericPortlet;
  import javax.portlet.PortletException;
  
  import org.junit.Test;
  import org.springframework.mock.web.portlet.MockPortletConfig;
  import org.springframework.mock.web.portlet.MockRenderRequest;
  import org.springframework.mock.web.portlet.MockRenderResponse;
  
  public class HelloWorldPortletTest {
  
     @Test
     public void testDoView() throws PortletException, IOException {              
        MockRenderResponse renderResponse = new MockRenderResponse();
  
        GenericPortlet portlet = new HelloWorldPortlet();     
        portlet.init(new MockPortletConfig());
        portlet.render(new MockRenderRequest(), renderResponse);
  
        assertThat(renderResponse.getContentType(), equalTo("text/html"));
        assertThat(renderResponse.getContentAsString(), equalTo("Hello Portlet" + System.getProperty("line.separator")));
     }
  }
  </code></pre>
  
  <p>Unfortunately when I run this, I get the following NullPointerException:</p>
  
  <pre><code>java.lang.NullPointerException
  at javax.portlet,GenericPortlet.getTitle(GenericPortlet.java:281)
  at stuff.HelloWorldPortlet.getTitle(HelloWorldPortlet.java:126)
  at javax.portlet.GenericPortlet.render(GenericPortlet.java:252)
  at stuff.HelloWorldPortlet.render(HelloWorldPortlet.java:94)
  at stuff.HelloWorldPortletTest.testDoView(HelloWorldPortletTest.java:24)
  </code></pre>
  
  <p>How do I get Spring to read in the portlet.xml file so that GenericPortlet's getTitle() method doesn't return a null?</p>