title: Why do i get NullPointerException when i try to create object by POST method?
body: <p>I`ve been coding some REST API tests, and i dont know either i wrote my test wrong or my POST method is invalid. 
  Im getting this error when i perform the test: </p>
  
  <blockquote>
    <p>ERROR [2015-12-14 21:37:00,309] org.glassfish.grizzly.servlet.ServletHandler: service exception:
    ! java.lang.NullPointerException: null
    ! at resources.ActorResource.postActor(ActorResource.java:31) ...etc</p>
  </blockquote>
  
  <p>and i have no idea where it came from. Actor object in the tests is properly initialized, it all should have worked fine.</p>
  
  <p>Here is the post method : </p>
  
  <pre><code>    @POST
      @UnitOfWork
      public Saying postActor(@HeaderParam("actorName") String name, @HeaderParam("actorBirthDate") String birthDate) {
          Actor actor = dao.create(new Actor(name,birthDate));
          return new Saying("Added : " + actor.toString());
      }
  </code></pre>
  
  <p>And here is the test i wrote</p>
  
  <pre><code>    @Test
      public void postActor() {
          when(movieDAO.create(actor)).thenReturn(actor);
          final Response response = RULE.getJerseyTest().target("/actors").request().post(Entity.text(""));
  
          assertThat(response.getStatusInfo().getStatusCode()).isEqualTo(Response.Status.OK.getStatusCode());
          verify(movieDAO).create(actor);
      }
  </code></pre>
  
  <p><strong>EDIT</strong>
  Here`s Actor  initialization method</p>
  
  <pre><code>    @Before
      public void setup() {
          actor = new Actor();
          actor.setId(1L);
          actor.setBirthDate("12-03-2014");
          actor.setName("Karol Marks");
      }
  </code></pre>
  
  <p>And Actor class </p>
  
  <pre><code>@Entity
  @Table(name="Actors")
  public class Actor {
      private long id;
      private String name;
      private String birthDate;
      private Movie movie;
  
      public Actor() {
      }
  
      public Actor(String name, String birthDate) {
          this.name = name;
          this.birthDate = birthDate;
      }
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      public long getId() {
          return id;
      }
  
      public void setId(long id) {
          this.id = id;
      }
  
      @Column(name = "name", nullable = false)
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      @Column(name = "birthDate", nullable = false)
      public String getBirthDate() {
          return birthDate;
      }
  
      public void setBirthDate(String birthDate) {
          this.birthDate = birthDate;
      }
  
      @ManyToOne(cascade = CascadeType.ALL)
      public Movie getMovie() {
          return movie;
      }
  
      public void setMovie(Movie movie) {
          this.movie = movie;
      }
  
      @Override
      public String toString() {
          return "Actor{" +
                  "id=" + id +
                  ", name='" + name + '\'' +
                  ", birthDate='" + birthDate + '\'' +
                  '}';
      }
  </code></pre>