FilterSettingsManagerImpl implements FilterSettingsManager { protected void removeSavedFilter(final MultiGridPreferencesStore store, String key) { store.removeTab(key); if (key.equals(store.getDefaultGridId())) { if (store.getGridsId().size() > 0) { store.setDefaultGridId(store.getGridsId().get(0)); } else { store.setDefaultGridId(null); } } }  @Inject void setMarshaller(final FilterSettingsJSONMarshaller marshaller); @Inject void setPreferencesService(final Caller<UserPreferencesService> preferencesService); @Override void loadSavedFilters(final Consumer<List<SavedFilter>> savedFiltersConsumer); @Override FilterSettings createDefaultFilterSettingsPrototype(); @Override void saveFilterIntoPreferences(final FilterSettings filterSettings,
                                          final Consumer<Boolean> callback); void loadSavedFiltersFromPreferences(final MultiGridPreferencesStore store,
                                                final Consumer<List<SavedFilter>> savedFiltersConsumer); @Override void getFilterSettings(final String key,
                                  final Consumer<FilterSettings> filterSettingsConsumer); @Override void resetDefaultSavedFilters(final Consumer<List<SavedFilter>> savedFiltersConsumer); @Override void removeSavedFilterFromPreferences(final String key, Command command); void defaultActiveFilterInit(final Consumer<FilterSettings> callback); @Override void saveDefaultActiveFilter(String filterKey, final Command callback); static final String FILTER_TABLE_SETTINGS; static final String DEFAULT_FILTER_SETTINGS_KEY; }
@Test public void testRemoveDefaultSavedFilter() { String defaultFilterKey = "key"; String nextSavedFilterKey = "next"; ArrayList<String> savedFiltersIds = new ArrayList<>(); savedFiltersIds.addAll(Arrays.asList(nextSavedFilterKey, "filter2", "filter3")); when(multiGridPreferencesStore.getDefaultGridId()).thenReturn(defaultFilterKey); when(multiGridPreferencesStore.getGridsId()).thenReturn(savedFiltersIds); filterSettingsManagerImpl.removeSavedFilter(multiGridPreferencesStore, defaultFilterKey); verify(multiGridPreferencesStore).removeTab(defaultFilterKey); verify(multiGridPreferencesStore).setDefaultGridId(nextSavedFilterKey); }
@Test public void testRemoveLastSavedFilter() { String defaultFilterKey = "key"; ArrayList<String> savedFiltersIds = new ArrayList<>(); when(multiGridPreferencesStore.getDefaultGridId()).thenReturn(defaultFilterKey); when(multiGridPreferencesStore.getGridsId()).thenReturn(savedFiltersIds); filterSettingsManagerImpl.removeSavedFilter(multiGridPreferencesStore, defaultFilterKey); verify(multiGridPreferencesStore).removeTab(defaultFilterKey); verify(multiGridPreferencesStore).setDefaultGridId(null); }
@Test public void testRemoveNotDefaultSavedFilter() { String defaultFilterKey = "defaultKey"; String key = "key"; ArrayList<String> savedFiltersIds = new ArrayList<>(); savedFiltersIds.addAll(Arrays.asList("filter1", "filter2", defaultFilterKey)); when(multiGridPreferencesStore.getDefaultGridId()).thenReturn(defaultFilterKey); when(multiGridPreferencesStore.getGridsId()).thenReturn(savedFiltersIds); filterSettingsManagerImpl.removeSavedFilter(multiGridPreferencesStore, key); verify(multiGridPreferencesStore).removeTab(key); verify(multiGridPreferencesStore, never()).setDefaultGridId(anyString()); }