title: Junit Test for method with random number
body: <p>I'm trying to create a Junit test for a method which is using a simple random number for calling another simple method which returns rock, paper, or scissor depending on the value of the parameter.</p>
  
  <p>I don't know how to do this.</p>
  
  <pre><code>public class Play {
  
      public String player2Choice() {
  
          // Create a Random object.
          Random random = new Random();
  
          // Ramdon number between 1-3
          int numberChoice = random.nextInt(3) + 1;
  
          // Return the player random choice
          return getItem(numberChoice);
      }
  
      public String getItem(int numberChoice) {
  
          String item;
  
          switch (numberChoice) {
          case 1:
              item = "rock";
              break;
          case 2:
              item = "scissors";
              break;
          case 3:
              item = "paper";
              break;
          default:
              item = null;
          }
  
          return item;
      }
  }
  </code></pre>
  
  <p>Right now I have this test:</p>
  
  <pre><code>Play play;
  
  @Before
  public void setup() {
  
      play = new Play();
  }
  
  @Test
  public void testPlayer2Choice() {
  
      int param = 1;
      Play play2 = Mockito.mock(Play.class);
  
  
      play2.getItem(param);
      Mockito.verify(play2).getItem(param);
  
      String result = play.player2Choice();
  
      assertEquals("rock", result);
  
  
  }
  </code></pre>