title: JUnit test for JSF validator
body: <p>I have this simple Java method which I use to test input from JSF page.</p>
  
  <pre><code>public void validateDC(FacesContext context, UIComponent component, Object value) throws ValidatorException, SQLException
      {
  
          Double d;
          String s = value.toString().trim();
  
          if (s.length() &gt; 10)
          {
                  throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                          "  Value is too long! (18 digits max)", null));
          }
  
          try
          {
              d = Double.parseDouble(s);
              if (d &lt; 0)
              {
                  throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                          "  '" + d + "' must be positive number!", null));
              }
          }
          catch(NumberFormatException nfe) { d = null; }
  
  
          if (d != null)
          {
  
  
          }
          else
          {
              throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                          s.isEmpty() ? "  This field cannot be empty!" : "  '" + s + "' is not a number!", null));
          }
  
      }
  </code></pre>
  
  <p>I'm interested how I can write JUnit test for this validator? I can simply call it and pass argument but there is no return value. What are the possible solutions?</p>