@RunWith(PowerMockRunner.class)
@PrepareForTest(Service.class)
public class ServiceTest {
@Mock
private Support support;
@Before
public void setup() throws Exception {
PowerMockito.whenNew(Support.class).withNoArguments().thenReturn(support);
}
@Test
public void doSomethingNoThreads() throws Exception {
new Service().doSomething();
verify(support).say("hello");
}
@Test
public void doSomethingThreaded() throws Exception {
javax.swing.SwingUtilities.invokeAndWait(() -> {
new Service().doSomething();
});
verify(support).say("hello");
}
}