MainService { public void doSomething() { if (restService == null) { System.out.println("restService not allowed to be null"); } String s = restService.getSomething(); System.out.println(s); if (printer == null) { System.out.println("printer not allowed to be null"); } printer.print(s.toUpperCase()); } @Inject  MainService(RestService restService,  MyPrinter printer); void doSomething();  }
@Test public void testDoSomething() { when(restService.getSomething()).thenReturn("abc"); mainService.doSomething(); verify(myPrinter).print("ABC"); }