title: JUnit testing for assertEqual NullPointerException
body: <p>I am not sure why the test case doesn't have an output of <code>true</code>. Both cases should give a <code>NullPointerException</code>.</p>
  
  <p>I've tried doing this (Not exactly the same but it gives and output of <code>true</code>) :</p>
  
  <pre><code>    String nullStr = null;
  
  //@Test
  public int NullOutput1() {
      nullStr.indexOf(3);
      return 0;
  }
  
  //@Test(expected=NullPointerException.class)
  public int NullOutput2() {
      nullStr.indexOf(2);
      return 0;
  }
  
  @Test(expected=NullPointerException.class)
  public void testboth() {
      assertEquals(NullOutput1(), NullOutput2());
  }
  </code></pre>
  
  <p>Runner:</p>
  
  <pre><code>import org.junit.runner.JUnitCore;
  import org.junit.runner.Result;
  import org.junit.runner.notification.Failure;
  
  public class TestRunnerStringMethods {
      public static void main(String[] args) {
          Result result = JUnitCore.runClasses(TestJunitMyIndexOf.class);
          for (Failure failure : result.getFailures()) {
              System.out.println(failure.toString());
          }
          System.out.println(result.wasSuccessful());
      }
  }
  </code></pre>
  
  <p>Method:</p>
  
  <pre><code>public static int myIndexOf(char[] str, int ch, int index) {
          if (str == null) {
              throw new NullPointerException();
          }
          // increase efficiency
          if (str.length &lt;= index || index &lt; 0) {
              return -1;
          }
          for (int i = index; i &lt; str.length; i++) {
              if (index == str[i]) {
                  return i;
              }
          }
          // if not found
          return -1;
      }
  </code></pre>
  
  <p>Test Case:</p>
  
  <pre><code>@Test(expected=NullPointerException.class)
  public void testNullInput() {
      assertEquals(nullString.indexOf(3), StringMethods.myIndexOf(null, 'd',3));
  }
  </code></pre>