PreferenceBeanStoreImpl implements PreferenceBeanServerStore { @Override public <U extends BasePreference<U>, T extends BasePreferencePortable<U>> T load(final T emptyPortablePreference) { return load(emptyPortablePreference, 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 loadTest() { MyPreference myPreference = new MyPreferencePortableGeneratedImpl(); MySharedPreference mySharedPreference = new MySharedPreferencePortableGeneratedImpl(); MySharedPreference2 mySharedPreference2 = new MySharedPreference2PortableGeneratedImpl(); doReturn(myPreference).when(preferenceStore).get(any(PreferenceScopeResolutionStrategyInfo.class), eq(MyPreference.class.getSimpleName())); doReturn(mySharedPreference).when(preferenceStore).get(any(PreferenceScopeResolutionStrategyInfo.class), eq(MySharedPreference.class.getSimpleName())); doReturn(mySharedPreference2).when(preferenceStore).get(any(PreferenceScopeResolutionStrategyInfo.class), eq(MySharedPreference2.class.getSimpleName())); final MyPreferencePortableGeneratedImpl loadedMyPreference = preferenceBeanStoreImpl.load(new MyPreferencePortableGeneratedImpl()); final MySharedPreference2PortableGeneratedImpl loadedMySharedPreference2 = preferenceBeanStoreImpl.load(new MySharedPreference2PortableGeneratedImpl()); verify(preferenceStore, times(3)).get(eq(scopeInfo), anyString()); verify(preferenceStore).get(scopeInfo, MyPreference.class.getSimpleName()); verify(preferenceStore).get(scopeInfo, MySharedPreference.class.getSimpleName()); verify(preferenceStore).get(scopeInfo, MySharedPreference2.class.getSimpleName()); assertEquals(myPreference, loadedMyPreference); assertEquals(mySharedPreference, loadedMyPreference.mySharedPreference); assertEquals(mySharedPreference2, loadedMySharedPreference2); }
@Test public void loadDefaultValueTest() { MyPreference myPreference = new MyPreferencePortableGeneratedImpl(); myPreference = myPreference.defaultValue(myPreference); MySharedPreference mySharedPreference = new MySharedPreferencePortableGeneratedImpl(); MySharedPreference2 mySharedPreference2 = new MySharedPreference2PortableGeneratedImpl(); final MyPreferencePortableGeneratedImpl loadedMyPreference = preferenceBeanStoreImpl.load(new MyPreferencePortableGeneratedImpl()); final MySharedPreference2PortableGeneratedImpl loadedMySharedPreference2 = preferenceBeanStoreImpl.load(new MySharedPreference2PortableGeneratedImpl()); verify(preferenceStore, times(3)).get(eq(scopeInfo), anyString()); verify(preferenceStore).get(scopeInfo, MyPreference.class.getSimpleName()); verify(preferenceStore).get(scopeInfo, MySharedPreference.class.getSimpleName()); verify(preferenceStore).get(scopeInfo, MySharedPreference2.class.getSimpleName()); assertEquals(myPreference, loadedMyPreference); assertEquals(mySharedPreference, loadedMyPreference.mySharedPreference); assertEquals(mySharedPreference2, loadedMySharedPreference2); }
@Test public void loadWithCustomResolutionStrategyScopeTest() { MyPreference myPreference = new MyPreferencePortableGeneratedImpl(); MySharedPreference mySharedPreference = new MySharedPreferencePortableGeneratedImpl(); MySharedPreference2 mySharedPreference2 = new MySharedPreference2PortableGeneratedImpl(); doReturn(myPreference).when(preferenceStore).get(any(PreferenceScopeResolutionStrategyInfo.class), eq(MyPreference.class.getSimpleName())); doReturn(mySharedPreference).when(preferenceStore).get(any(PreferenceScopeResolutionStrategyInfo.class), eq(MySharedPreference.class.getSimpleName())); doReturn(mySharedPreference2).when(preferenceStore).get(any(PreferenceScopeResolutionStrategyInfo.class), eq(MySharedPreference2.class.getSimpleName())); PreferenceScopeResolutionStrategyInfo scopeResolutionStrategyInfo = new PreferenceScopeResolutionStrategyInfo(new ArrayList<>(), mock(PreferenceScope.class)); final MyPreferencePortableGeneratedImpl loadedMyPreference = preferenceBeanStoreImpl.load(new MyPreferencePortableGeneratedImpl(), scopeResolutionStrategyInfo); final MySharedPreference2PortableGeneratedImpl loadedMySharedPreference2 = preferenceBeanStoreImpl.load(new MySharedPreference2PortableGeneratedImpl(), scopeResolutionStrategyInfo); verify(preferenceStore, times(3)).get(eq(scopeResolutionStrategyInfo), anyString()); verify(preferenceStore).get(scopeResolutionStrategyInfo, MyPreference.class.getSimpleName()); verify(preferenceStore).get(scopeResolutionStrategyInfo, MySharedPreference.class.getSimpleName()); verify(preferenceStore).get(scopeResolutionStrategyInfo, MySharedPreference2.class.getSimpleName()); assertEquals(myPreference, loadedMyPreference); assertEquals(mySharedPreference, loadedMyPreference.mySharedPreference); assertEquals(mySharedPreference2, loadedMySharedPreference2); }