title: How to test a Controller and Model in a JSF Project with jUnit?
body: <p>i don't know exactly how to write tests for these following Classes especially for the Controller and Model. Is it to possible to test with jUnit ?
  I heard from Selenium but first i would test with jUnit. Thanks for ur help and best regards.</p>
  
  <p>Controller.class:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import factory.InfoMessageFactory;
  import entity.Product;
  import java.io.Serializable;
  import java.util.List;
  import javax.annotation.PostConstruct;
  import javax.enterprise.context.SessionScoped;
  import javax.faces.application.FacesMessage;
  import javax.faces.context.FacesContext;
  import javax.inject.Inject;
  import javax.inject.Named;
  import model.ProductModel;
  import project.Konstanten;
  
  @Named(value = "ProductController")
  @SessionScoped
  public class ProductController implements Serializable {
     
      private Product product;
      
      @Inject
      private ProductModel model;
  
      @PostConstruct
      public void init() {
          this.product = new Product();
      }
      
     
      public String addProduct() {
         this.model.newProduct(this.product);
      }
  
      public Product getProduct() {
          return product;
      }
  
      public void setProdukt(Product product) {
          this.product = product;
      }
      
      public List&lt;Product&gt; getProducts() {
          return this.model.getProducts();
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Model.class</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>package model;
  
  import ejb.DB;
  import entity.Product;
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.List;
  import javax.enterprise.context.Dependent;
  import javax.inject.Inject;
  
  @Dependent
  public class ProductModel implements Serializable{
      
      @Inject
      private DB db;
      
      public boolean addProduct(Product p){
          try{
              db.persist(p);
          }catch(Exception e){
              System.out.println("Blablabla");
              return false;                
          }
          return true;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>And DB.class</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Stateless
  public class DB {
  
      @Inject
      @RealClass
      private EntityManager em;
      
      public void persist(Object object) {
          em.persist(object);
      }</code></pre>
  </div>
  </div>
  </p>