title: How to test a void method that prints on console in jUnit?
body: <p>I use a factory pattern. I have 3 currencies: dollars, RON and euro. In each of this classes i have the same function, print, with different output:</p>
  
  <pre><code>public void print() {
      System.out.println("I printed dollars!");
  
  }
  
       public void print() {
      System.out.println("I printed euro!");}
  </code></pre>
  
  <p>In my factory class, i have a method that return a new Object of currency type:</p>
  
  <pre><code>    public Valuta getValuta(String numeValuta){
      if(numeValuta == null){
          return null;
      }
      if(numeValuta.equalsIgnoreCase("dolar")){
          return new Dolar();
      }
      if(numeValuta.equalsIgnoreCase("euro")){
          return new Euro();
      }
      if(numeValuta.equalsIgnoreCase("lei")){
          return new Lei();
      }
      return null;
  }
  </code></pre>
  
  <p>Now, in my Test class, i tried testing this:</p>
  
  <pre><code>    FabricaBani fabrica = new FabricaBani();
      Valuta valuta = fabrica.getValuta("dolar");
      valuta.tipareste();
      assertEquals("I printed dollars!", valuta.print());
  </code></pre>
  
  <p>I get an error that says that i cannot test a String with a void. I tried putting .toString after valuta.print, but i am not allowed. </p>