use of au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer in project constellation by constellation-app.
the class ButtonToolbarNGTest method manageFavourites_no_plugins_selected.
@Test
public void manageFavourites_no_plugins_selected() {
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of());
try (final MockedStatic<NotifyDisplayer> notifyDisplayerMockedStatic = Mockito.mockStatic(NotifyDisplayer.class)) {
buttonToolbar.manageFavourites();
notifyDisplayerMockedStatic.verify(() -> NotifyDisplayer.display("No plugins selected.", NotifyDescriptor.WARNING_MESSAGE));
}
}
use of au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer in project constellation by constellation-app.
the class JsonIONGTest method saveJsonPreferences_pref_dir_not_a_dir.
@Test
public void saveJsonPreferences_pref_dir_not_a_dir() throws URISyntaxException, FileNotFoundException, IOException {
final File outputFile = new File(System.getProperty("java.io.tmpdir") + "/my-preferences.json");
try (MockedStatic<JsonIO> jsonIoMockedStatic = Mockito.mockStatic(JsonIO.class);
MockedStatic<JsonIODialog> jsonIoDialogMockedStatic = Mockito.mockStatic(JsonIODialog.class);
MockedStatic<NotifyDisplayer> notifyDisplayerMockedStatic = Mockito.mockStatic(NotifyDisplayer.class)) {
final File preferenceDirectory = new File(System.getProperty("java.io.tmpdir") + "/samplefile");
jsonIoMockedStatic.when(() -> JsonIO.getPrefereceFileDirectory(SUB_DIRECTORY)).thenReturn(preferenceDirectory);
jsonIoMockedStatic.when(() -> JsonIO.saveJsonPreferences(any(Optional.class), any(Optional.class), any(), any(ObjectMapper.class))).thenCallRealMethod();
JsonIO.saveJsonPreferences(SUB_DIRECTORY, FILE_PREFIX, new Object(), new ObjectMapper());
// Verify no JSON IO dialogs were opened
jsonIoDialogMockedStatic.verifyNoInteractions();
// Verify the correct error dialog was presented
notifyDisplayerMockedStatic.verify(() -> NotifyDisplayer.display("Can't create preference directory '" + preferenceDirectory + "'.", NotifyDescriptor.ERROR_MESSAGE));
} finally {
Files.deleteIfExists(outputFile.toPath());
}
}
use of au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer in project constellation by constellation-app.
the class JsonIONGTest method deleteJsonPreferences_fails.
@Test
public void deleteJsonPreferences_fails() throws URISyntaxException, FileNotFoundException, IOException {
final File outputFile = new File(System.getProperty("java.io.tmpdir") + "/my-preferences.json");
try (MockedStatic<JsonIO> jsonIoMockedStatic = Mockito.mockStatic(JsonIO.class);
MockedStatic<NotifyDisplayer> notifyDisplayerMockedStatic = Mockito.mockStatic(NotifyDisplayer.class);
MockedStatic<Files> filesMockedStatic = Mockito.mockStatic(Files.class)) {
filesMockedStatic.when(() -> Files.deleteIfExists(outputFile.toPath())).thenThrow(new SecurityException("Some error"));
jsonIoMockedStatic.when(() -> JsonIO.getPrefereceFileDirectory(SUB_DIRECTORY)).thenReturn(new File(System.getProperty("java.io.tmpdir")));
jsonIoMockedStatic.when(() -> JsonIO.deleteJsonPreference(eq("preferences"), eq(SUB_DIRECTORY), eq(FILE_PREFIX))).thenCallRealMethod();
JsonIO.deleteJsonPreference("preferences", SUB_DIRECTORY, FILE_PREFIX);
assertFalse(outputFile.exists());
notifyDisplayerMockedStatic.verify(() -> NotifyDisplayer.display("Failed to delete file my-preferences.json from disk", NotifyDescriptor.ERROR_MESSAGE));
} finally {
Files.deleteIfExists(outputFile.toPath());
}
}
use of au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer in project constellation by constellation-app.
the class ButtonToolbarNGTest method verifyManageFavouritesWithUserInput.
/**
* Verifies that when manage favourites is called, depending on the user
* action against the dialog, different outcomes will occur.
*
* @param pluginTitle the plugin title of the only selected pane that is
* enabled
* @param selectedOption the option that the user selection in the dialog
* @param preferenceUtilsVerification the verification against
* {@link DataAccessPreferenceUtilities}
*/
private void verifyManageFavouritesWithUserInput(final String pluginTitle, final Object selectedOption, final Verification preferenceUtilsVerification) {
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final QueryPhasePane currentQueryPhasePane = mock(QueryPhasePane.class);
final DataSourceTitledPane dataSourceTitledPane1 = mock(DataSourceTitledPane.class);
final DataSourceTitledPane dataSourceTitledPane2 = mock(DataSourceTitledPane.class);
final Plugin plugin = mock(Plugin.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getQueryPhasePaneOfCurrentTab()).thenReturn(currentQueryPhasePane);
when(currentQueryPhasePane.getDataAccessPanes()).thenReturn(List.of(dataSourceTitledPane1, dataSourceTitledPane2));
when(dataSourceTitledPane1.isQueryEnabled()).thenReturn(false);
when(dataSourceTitledPane2.isQueryEnabled()).thenReturn(true);
when(dataSourceTitledPane2.getPlugin()).thenReturn(plugin);
when(plugin.getName()).thenReturn(pluginTitle);
try (final MockedStatic<NotifyDisplayer> notifyDisplayerMockedStatic = Mockito.mockStatic(NotifyDisplayer.class);
final MockedStatic<DataAccessPreferenceUtilities> prefUtilsMockedStatic = Mockito.mockStatic(DataAccessPreferenceUtilities.class)) {
notifyDisplayerMockedStatic.when(() -> NotifyDisplayer.displayAndWait(any(NotifyDescriptor.class))).thenAnswer(iom -> {
final NotifyDescriptor descriptor = iom.getArgument(0);
final String expectedMessage = "Add or remove plugins from your favourites category.\n\n" + "The following plugins were selected:\n" + pluginTitle + "\n" + "\nNote that you need to restart before changes take effect.";
assertEquals(descriptor.getMessage(), expectedMessage);
assertEquals(descriptor.getTitle(), "Manage Favourites");
assertEquals(descriptor.getOptionType(), NotifyDescriptor.DEFAULT_OPTION);
assertEquals(descriptor.getMessageType(), NotifyDescriptor.QUESTION_MESSAGE);
assertEquals(descriptor.getOptions(), new Object[] { "Add", "Remove", NotifyDescriptor.CANCEL_OPTION });
assertEquals(descriptor.getValue(), NotifyDescriptor.OK_OPTION);
// Simulating the value returned when the function is called on the FX thread
return CompletableFuture.completedFuture(CompletableFuture.completedFuture(selectedOption));
});
buttonToolbar.manageFavourites();
if (preferenceUtilsVerification != null) {
prefUtilsMockedStatic.verify(preferenceUtilsVerification);
} else {
prefUtilsMockedStatic.verifyNoInteractions();
}
}
}
Aggregations