title: Testing if an Array is empty JUNIT
body: <p>I wanna write a Method displaying a deck from a Game.
  I initialized an <code>Array</code> with 98 Elements<br/></p>
  
  <pre><code>private int [] cards = new int[98];
  </code></pre>
  
  <p>I also created a get and a set method<br/></p>
  
  <pre><code>public int[] getCards() {
      return cards;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public void setCards(final int... cards) {
      this.cards = cards;
  }
  </code></pre>
  
  <p>The Method I wrote is called <code>drawCard</code>. If I use this method it should remove the first element out of the <code>Array</code> and return it.</p>
  
  <pre><code>public int drawCard() throws IndexOutOfBoundsException {
      if (getCards().length == 0) {
          throw new IndexOutOfBoundsException("No Cards Left!");
      }
      setCards(ArrayUtils.removeElement(getCards(), 0));
      return getCards()[0];
  }
  </code></pre>
  
  <p>And then I wrote the JUnit Test.
  The test should remove all the 98 elements and then the array should be empty <code>== 0</code>.
  But the test always stops at 1.</p>
  
  <pre><code>@Test
  public void testDrawCard() {
      Deck deck = new Deck();
      assertThat(deck.getCards().length).isEqualTo(98);
  
      for(int x = 98; x &gt;= 0; x--){
          deck.drawCard();
      }
      assertThat(deck.getCards().length).isEqualTo(0);
  }
  </code></pre>
  
  <p><strong>Error message:</strong></p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 0
  at edu.hm.hafner.java2.thegame.Deck.drawCard(Deck.java:35) 
  </code></pre>
  
  <blockquote>
    <p>35=Return Line</p>
  </blockquote>
  
  <pre><code>at edu.hm.hafner.java2.thegame.DeckTest.testDrawCard(DeckTest.java:40)
  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:498)
  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.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.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
  at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
  at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  </code></pre>
  
  <p>Does somebody know what's wrong?</p>