@Test (dataProvider = "generateTestCases")
public void testActionPerformed(final boolean confirmed, int housings) throws Exception {
// Verifies that performing a QuitAction closes all windows, stops OSGI
// (except where user input indicates otherwise)
MCTAbstractHousing[] mockHousings = initializeRegistry(housings);
ContextAwareAction quit = new QuitAction();
Mockito.reset(mockRuntime);
// Set up window manager to support dialog call
// Act as though the user clicked "OK" or "Cancel" (depending on argument "confirmed")
WindowManager mockWindowManager = Mockito.mock(WindowManager.class);
Mockito.when(mockPlatform.getWindowManager()).thenReturn(mockWindowManager);
Mockito.when(mockWindowManager.showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] options = (Object[]) invocation.getArguments()[2];
return confirmed ? options[0] : options[1]; // options[0] presumed to mean "OK"
}
});
// Already tested in testQuitEnabled, but also need to obey action's life cycle
Assert.assertEquals(quit.canHandle(mockActionContext), housings > 0);
// Trigger the action - this is the method we are testing
quit.actionPerformed(mockEvent);
// A dialog should have been requested
Mockito.verify(mockWindowManager, Mockito.times(1)).showInputDialog(Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.<Map<String,Object>>any());
// All housings should be closed, iff dialog was confirmed