MainService { public String doSomething() { if (restService.executeServerCall()) { return "Hello world"; } else { throw new RuntimeException("Error!"); } } @Inject  MainService(RestService restService); String doSomething();  }
@Test public void testDoSomething() { when(restService.executeServerCall()).thenReturn(true); String s = mainService.doSomething(); assertThat(s).isEqualTo("Hello world"); }
@Test(expected = RuntimeException.class) public void testErrorOnDoSomething() { when(restService.executeServerCall()).thenReturn(false); mainService.doSomething(); }