HandlerManager { public String[] handle(String thingToHandle) { if (thingToHandle == null) { throw new IllegalArgumentException("thingToHandle must not be null"); } String[] strings = new String[handlers.size()]; int i = 0; for (Handler handler : handlers) { strings[i++] = handler.handle(thingToHandle); } return strings; }  String[] handle(String thingToHandle); void setHandlers(Set<Handler> handlers);  }
@Test public void shouldCallAllHandlers() { String thingToHandle = "Something"; given(handler1.handle(thingToHandle)).willReturn("value1"); given(handler2.handle(thingToHandle)).willReturn("value2"); String[] strings = manager.handle(thingToHandle); assertArrayEquals(new String[] { "value1", "value2" }, strings); }
@Test(expected = IllegalArgumentException.class) public void shouldFailToHandleGivenNull() { String thingToHandle = null; manager.handle(thingToHandle); }