@Test public void whenCalculateFactorialOfNegativeNumberFiveThenResultZeroAndPrintOutMessage() { Factorial factorial = new Factorial(-5); String result = null; PrintStream outConsole = System.out; try { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); PrintStream printStream = new PrintStream(outStream); System.setOut(printStream); assertThat(factorial.calculate(), is(0L)); printStream.flush(); result = outStream.toString(); } finally { System.setOut(outConsole); } assertThat(result, is(String.format("Non positive number%s",System.getProperty("line.separator")))); }
public long calculate() { long result = 1; if (this.n >= 0) { for (int i = 1; i <= this.n; i++) { result *= i; } } else { System.out.println("Non positive number"); result = 0; } return result; }
Factorial { public long calculate() { long result = 1; if (this.n >= 0) { for (int i = 1; i <= this.n; i++) { result *= i; } } else { System.out.println("Non positive number"); result = 0; } return result; } }
Factorial { public long calculate() { long result = 1; if (this.n >= 0) { for (int i = 1; i <= this.n; i++) { result *= i; } } else { System.out.println("Non positive number"); result = 0; } return result; } Factorial(int n); }
Factorial { public long calculate() { long result = 1; if (this.n >= 0) { for (int i = 1; i <= this.n; i++) { result *= i; } } else { System.out.println("Non positive number"); result = 0; } return result; } Factorial(int n); long calculate(); }
Factorial { public long calculate() { long result = 1; if (this.n >= 0) { for (int i = 1; i <= this.n; i++) { result *= i; } } else { System.out.println("Non positive number"); result = 0; } return result; } Factorial(int n); long calculate();  }