PreferenceBeanStoreImpl implements PreferenceBeanServerStore { @Override public <U extends BasePreference<U>, T extends BasePreferencePortable<U>> void save(final T portablePreference) { save(portablePreference, defaultScopeResolutionStrategy.getInfo()); } PreferenceBeanStoreImpl(); @Inject  PreferenceBeanStoreImpl(final PreferenceStore preferenceStore,
                                   @Customizable final PreferenceScopeResolutionStrategy defaultScopeResolutionStrategy,
                                   @PortablePreference final Instance<Preference> preferences); @Override T load(final T emptyPortablePreference); @Override T load(final T emptyPortablePreference,
                                                                                     final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo); @Override void load(final T emptyPortablePreference,
                                                                                        final ParameterizedCommand<T> successCallback,
                                                                                        final ParameterizedCommand<Throwable> errorCallback); @Override void load(final T emptyPortablePreference,
                                                                                        final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                                                                                        final ParameterizedCommand<T> successCallback,
                                                                                        final ParameterizedCommand<Throwable> errorCallback); @Override void save(final T portablePreference); @Override void save(final T portablePreference,
                                                                                        final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo); @Override void save(final T portablePreference,
                                                                                        final PreferenceScope scope); @Override void save(final T portablePreference,
                                                                                        final Command successCallback,
                                                                                        final ParameterizedCommand<Throwable> errorCallback); @Override void save(final T portablePreference,
                                                                                        final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                                                                                        final Command successCallback,
                                                                                        final ParameterizedCommand<Throwable> errorCallback); @Override void save(final T portablePreference,
                                                                                        final PreferenceScope scope,
                                                                                        final Command successCallback,
                                                                                        final ParameterizedCommand<Throwable> errorCallback); @Override void save(final Collection<BasePreferencePortable<? extends BasePreference<?>>> portablePreferences); @Override void save(final Collection<BasePreferencePortable<? extends BasePreference<?>>> portablePreferences,
                     final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo); @Override void save(final Collection<BasePreferencePortable<? extends BasePreference<?>>> portablePreferences,
                     final PreferenceScope scope); @Override void save(final Collection<BasePreferencePortable<? extends BasePreference<?>>> portablePreferences,
                     final Command successCallback,
                     final ParameterizedCommand<Throwable> errorCallback); @Override void save(final Collection<BasePreferencePortable<? extends BasePreference<?>>> portablePreferences,
                     final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo,
                     final Command successCallback,
                     final ParameterizedCommand<Throwable> errorCallback); @Override void save(final Collection<BasePreferencePortable<? extends BasePreference<?>>> portablePreferences,
                     final PreferenceScope scope,
                     final Command successCallback,
                     final ParameterizedCommand<Throwable> errorCallback); @Override PreferenceHierarchyElement<?> buildHierarchyStructureForPreference(final String identifier); @Override PreferenceHierarchyElement<?> buildHierarchyStructureForPreference(final String identifier,
                                                                              final PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo);  }
@Test public void saveTest() { final MyPreferencePortableGeneratedImpl myPreference = preferenceBeanStoreImpl.load(new MyPreferencePortableGeneratedImpl()); preferenceBeanStoreImpl.save(myPreference); verify(preferenceStore, times(2)).put(any(PreferenceScope.class), anyString(), any(Object.class)); verify(preferenceStore).put(eq(scopeInfo.defaultScope()), eq(MyPreference.class.getSimpleName()), eq(myPreference)); verify(preferenceStore).put(eq(scopeInfo.defaultScope()), eq(MySharedPreference.class.getSimpleName()), eq(myPreference.mySharedPreference)); }
@Test public void saveCollectionTest() { final List<BasePreferencePortable<? extends BasePreference<?>>> preferencesToSave = getRootPortablePreferences(); final MyPreference myPreference = (MyPreference) preferencesToSave.get(0); final MySharedPreference2 mySharedPreference2 = (MySharedPreference2) preferencesToSave.get(1); preferenceBeanStoreImpl.save(preferencesToSave); verify(preferenceStore, times(2)).put(eq(scopeInfo.defaultScope()), anyString(), any(Object.class)); verify(preferenceStore).put(scopeInfo.defaultScope(), MyPreference.class.getSimpleName(), myPreference); verify(preferenceStore).put(scopeInfo.defaultScope(), MySharedPreference.class.getSimpleName(), myPreference.mySharedPreference); verify(preferenceStore, never()).put(eq(scopeInfo.defaultScope()), eq(MySharedPreference2.class.getSimpleName()), same(mySharedPreference2)); }
@Test public void saveCollectionWithCustomResolutionStrategyScopeTest() { PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo = new PreferenceScopeResolutionStrategyInfo(new ArrayList<>(), mock(PreferenceScope.class)); final List<BasePreferencePortable<? extends BasePreference<?>>> preferencesToSave = getRootPortablePreferences(); final MyPreference myPreference = (MyPreference) preferencesToSave.get(0); final MySharedPreference2 mySharedPreference2 = (MySharedPreference2) preferencesToSave.get(1); preferenceBeanStoreImpl.save(preferencesToSave, scopeResolutionStrategyInfo); verify(preferenceStore, times(2)).put(eq(scopeResolutionStrategyInfo.defaultScope()), anyString(), any(Object.class)); verify(preferenceStore).put(scopeResolutionStrategyInfo.defaultScope(), MyPreference.class.getSimpleName(), myPreference); verify(preferenceStore).put(scopeResolutionStrategyInfo.defaultScope(), MySharedPreference.class.getSimpleName(), myPreference.mySharedPreference); verify(preferenceStore, never()).put(eq(scopeResolutionStrategyInfo.defaultScope()), eq(MySharedPreference2.class.getSimpleName()), same(mySharedPreference2)); }
@Test public void saveCollectionWithCustomScopeTest() { final PreferenceScope scope = mock(PreferenceScope.class); PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo = new PreferenceScopeResolutionStrategyInfo(new ArrayList<>(), mock(PreferenceScope.class)); final List<BasePreferencePortable<? extends BasePreference<?>>> preferencesToSave = getRootPortablePreferences(); final MyPreference myPreference = (MyPreference) preferencesToSave.get(0); final MySharedPreference2 mySharedPreference2 = (MySharedPreference2) preferencesToSave.get(1); preferenceBeanStoreImpl.save(preferencesToSave, scope); verify(preferenceStore, times(2)).put(same(scope), anyString(), any(Object.class)); verify(preferenceStore).put(same(scope), eq(MyPreference.class.getSimpleName()), eq(myPreference)); verify(preferenceStore).put(same(scope), eq(MySharedPreference.class.getSimpleName()), eq(myPreference.mySharedPreference)); verify(preferenceStore, never()).put(same(scope), eq(MySharedPreference2.class.getSimpleName()), same(mySharedPreference2)); }