title: Nullpointer exception - JAVA Mockito
body: <p>Probably just me being blind, but why do i get a nullpointer exception at "when(sqldummy.getAllMembers()).thenReturn(mockedMemberList);"?
  Trying out Mockito for the first time, so i might have bad implementations. (I'm not quite sure).</p>
  
  <p>I've been staring myself blind for a while now. System-out debugging didn't yield any real information other than it's null.</p>
  
  <p>I tried moving the entire code from the @before into the actual method and it works there. But that is ugly and @Before is to handle duplicate code like this, that I would otherwise have to add to every other testmethod I create.</p>
  
  <p>Please help.</p>
  
  <pre><code>public class TestShipHandling extends TestCase{
  
  private static ShipHandling shipHandling;
  private static SQLDUMMY sqldummy;
  private static ArrayList&lt;Member&gt; mockedMemberList;
  private static ArrayList&lt;Ship&gt; mockedShipList;
  
  
  @Before
  public void before() {
      sqldummy = mock(SQLDUMMY.class);
      mockedMemberList = new ArrayList&lt;&gt;();
      mockedShipList = new ArrayList&lt;&gt;();
      shipHandling = new ShipHandling(sqldummy);  //Instance shiphandling class with mocked SQLDUMMY
  
      Member m1 = new Member();
      m1.setMemberFirstName("Max");
      m1.setMemberLastName("W0w");
      m1.setMemberID("MW222");
      mockedMemberList.add(m1);
  
      System.out.println(mockedMemberList);
      Member m2 = new Member();
      m2.setMemberFirstName("Andrew");
      m2.setMemberLastName("Gower");
      m2.setMemberID("AG222");
      mockedMemberList.add(m2);
  
      Member m3 = new Member();
      m3.setMemberFirstName("Maximum");
      m3.setMemberLastName("Crispness");
      m3.setMemberID("MC999");
      mockedMemberList.add(m3);
  
      Ship s = new Ship();
      s.setShipName("qweqwe");
      s.setShipClass("big");
      s.setShipGunCaliber(300);
      s.setShipLength(200);
      s.setShipNGuns(30);
      mockedShipList.add(s);
  
  }
  
  @After
  public void after() {
      System.out.println(mockedMemberList);
      mockedMemberList.clear();
      mockedShipList.clear();
  }
  
  @Test
  public void testAddShipReturnsTrue() throws Exception {
      when(sqldummy.getAllMembers()).thenReturn(mockedMemberList);
  
      Member tempMem = sqldummy.getAllMembers().get(0);
  
      String shipName = "Victorium";
      String shipClass = "Battleship";
      int shipGunCaliber = 305;
      int shipLength = 320;
      int shipNGuns = 10;
  
      assertTrue(shipHandling.addShip(tempMem, shipName, shipClass, shipGunCaliber, shipLength, shipNGuns));
  }
  </code></pre>