title: java.util.NoSuchElementException: No value present - Error - Optional.get in JUNIT Testing with Spring
body: <p>I have a test where an Optional was used. In the method, its stating no value was present.  Here is the code, I have. How can I make this pass without NoSuchElementException. </p>
  
  <pre><code> public jobs theID(Integer id) {  
          if( id == null) {
              throw new IllegalArgumentException("Its missing.");
          }
  
  
          return jobTitleMapper.entityToModel(this.jobTitleRepository.findById(id).get());
  }
  </code></pre>
  
  <p>It is fussing about the get() from Java 8. </p>
  
  <p>How do I use an Optional with isPresent correctly in this sense?</p>
  
  <p>The test is:</p>
  
  <pre><code>public void findIdTest() {
      Jobs jt = this.Service.theID(Entities.thisID);
      Assert.assertNotNull(jt);
      Assert.assertEquals(Entities.thisID, .getId());
  }
  </code></pre>
  
  <p>Thanks for the help.</p>