title: How to get the best code coverage in Java?
body: <p>Several tools exists that allow to calculate path coverage for a set of tests, but is there a tool (or an algorithm) that could suggest values to get the best path coverage with the smallest number of tests possible?</p>
  
  <p>For example with the following classes:</p>
  
  <pre><code>public class User {
  
      private boolean isAdmin = false;
      private String name;
      private String password;
  
      public User(String name, String password, boolean isAdmin) {
          this.name = name;
          this.password = password;
          this.isAdmin = isAdmin;
      }
  
      public boolean isAdmin() {
          return isAdmin;
      }
  
      public boolean authenticate(String name, String password) {
          if (name.equals(this.name) &amp;&amp; password.equals(this.password)) {
          return true;
          } else {
              return false;
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class DataRepository {
  
      List&lt;String&gt; data = new ArrayList&lt;String&gt;();
  
      public void add(String dataPiece) {
          data.add(dataPiece);
      }
  
      public void clearAll(User userAuthenticated) {
          if (userAuthenticated.isAdmin()) {
              data.clear();
          }
      }
  
      public void addAll(User userAuthenticated, List&lt;String&gt; collection) {
          if (userAuthenticated.isAdmin()) {
              data.addAll(collection);
          }
      }
  }
  </code></pre>
  
  <p>I will get a better test coverage if i create a test which is using a <strong>User</strong> with <strong>isAdmin</strong> at <em>true</em>.</p>
  
  <p>Is there a tool that could mention: if you create a test with <strong>User</strong> with <strong>isAdmin</strong> at <em>true</em> you will get the best test coverage.</p>
  
  <p>Something like that but for more complicated cases, and that checks all the branches of code.</p>