« HelloWorld v 2.0
November 8, 2008 • ☕️ 1 min read
Once upon a time we used to write:
public static void main(String[] args) {System.out.println("Hello World");}
Now I prefer:
@Testpublic void shouldSayHelloToTheGivenName() throws Exception {// givenPrintStream mockStream = mock(PrintStream.class);Greeter greeter = new Greeter(mockStream);// whengreeter.helloworld("toni");// thenverify(mockStream).println("Hello world, toni");}
The test is of course using the beautiful test double framework Mockito