### Question:
ReloadCommand implements ExecutableCommand { @Override public void executeCommand(CommandSender sender, List<String> arguments) { try { settings.reload(); ConsoleLogger.setLoggingOptions(settings); settingsWarner.logWarningsForMisconfigurations(); if (!settings.getProperty(DatabaseSettings.BACKEND).equals(dataSource.getType())) { Utils.logAndSendMessage(sender, "Note: cannot change database type during /authme reload"); } performReloadOnServices(); commonService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); } catch (Exception e) { sender.sendMessage("Error occurred during reload of AuthMe: aborting"); ConsoleLogger.logException("Aborting! Encountered exception during reload of AuthMe:", e); plugin.stopOrUnload(); } }  @Override void executeCommand(CommandSender sender, List<String> arguments);  }### Answer:
@Test public void shouldReload() { CommandSender sender = mock(CommandSender.class); given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL); given(dataSource.getType()).willReturn(DataSourceType.MYSQL); List<Reloadable> reloadables = Arrays.asList( mock(Reloadable.class), mock(Reloadable.class), mock(Reloadable.class)); List<SettingsDependent> dependents = Arrays.asList( mock(SettingsDependent.class), mock(SettingsDependent.class)); given(reloadableStore.retrieveAllOfType()).willReturn(reloadables); given(settingsDependentStore.retrieveAllOfType()).willReturn(dependents); command.executeCommand(sender, Collections.emptyList()); verify(settings).reload(); verifyReloadingCalls(reloadables, dependents); verify(commandService).send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); verify(settingsWarner).logWarningsForMisconfigurations(); }
@Test public void shouldHandleReloadError() { CommandSender sender = mock(CommandSender.class); doThrow(IllegalStateException.class).when(reloadableStore).retrieveAllOfType(); given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL); given(dataSource.getType()).willReturn(DataSourceType.MYSQL); command.executeCommand(sender, Collections.emptyList()); verify(settings).reload(); verify(reloadableStore).retrieveAllOfType(); verify(sender).sendMessage(argThat(containsString("Error occurred"))); verify(authMe).stopOrUnload(); }
@SuppressWarnings("unchecked") @Test public void shouldIssueWarningForChangedDatasourceSetting() { CommandSender sender = mock(CommandSender.class); given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL); given(dataSource.getType()).willReturn(DataSourceType.SQLITE); given(reloadableStore.retrieveAllOfType()).willReturn(Collections.emptyList()); given(settingsDependentStore.retrieveAllOfType()).willReturn(Collections.emptyList()); command.executeCommand(sender, Collections.emptyList()); verify(settings).reload(); verify(reloadableStore).retrieveAllOfType(); verify(settingsDependentStore).retrieveAllOfType(); verify(sender).sendMessage(argThat(containsString("cannot change database type"))); }