### Question:
StunnerPreferencesRegistryLoader { public void load(final Metadata metadata, final ParameterizedCommand<StunnerPreferences> loadCompleteCallback, final ParameterizedCommand<Throwable> errorCallback) { final String definitionSetId = metadata.getDefinitionSetId(); final Annotation qualifier = definitionUtils.getQualifier(definitionSetId); final StunnerPreferencesRegistryHolder holder = InstanceUtils.lookup(preferencesHolders, qualifier); preferences.load(prefs -> { holder.set(prefs, StunnerPreferences.class); holder.set(textPreferences, StunnerTextPreferences.class); loadCompleteCallback.execute(prefs); }, errorCallback); } @Inject  StunnerPreferencesRegistryLoader(final DefinitionUtils definitionUtils,
                                            final @Any ManagedInstance<StunnerPreferencesRegistryHolder> preferencesHolders,
                                            final StunnerPreferences preferences,
                                            final StunnerTextPreferences textPreferences); void load(final Metadata metadata,
                     final ParameterizedCommand<StunnerPreferences> loadCompleteCallback,
                     final ParameterizedCommand<Throwable> errorCallback); @PreDestroy void destroy();  }### Answer:
@Test @SuppressWarnings("unchecked") public void testLoad() { final ParameterizedCommand<StunnerPreferences> loadCompleteCallback = mock(ParameterizedCommand.class); final ParameterizedCommand<Throwable> errorCallback = mock(ParameterizedCommand.class); final StunnerPreferences pre = mock(StunnerPreferences.class); doAnswer(invocation -> { ((ParameterizedCommand<StunnerPreferences>) invocation.getArguments()[0]).execute(pre); return null; }).when(preferences).load(any(ParameterizedCommand.class), any(ParameterizedCommand.class)); tested.load(metadata, loadCompleteCallback, errorCallback); verify(preferencesHolders, times(1)).select(eq(qualifier)); verify(loadCompleteCallback, times(1)).execute(eq(pre)); verify(errorCallback, never()).execute(any(Throwable.class)); verify(preferencesHolder, times(1)).set(eq(pre), eq(StunnerPreferences.class)); verify(preferencesHolder, times(1)).set(eq(textPreferences), eq(StunnerTextPreferences.class)); }
@Test @SuppressWarnings("unchecked") public void testLoadError() { final ParameterizedCommand<StunnerPreferences> loadCompleteCallback = mock(ParameterizedCommand.class); final ParameterizedCommand<Throwable> errorCallback = mock(ParameterizedCommand.class); final Throwable errorInstance = mock(Throwable.class); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((ParameterizedCommand<Throwable>) invocation.getArguments()[1]).execute(errorInstance); return null; } }).when(preferences).load(any(ParameterizedCommand.class), any(ParameterizedCommand.class)); tested.load(metadata, loadCompleteCallback, errorCallback); verify(preferencesHolders, times(1)).select(eq(qualifier)); verify(errorCallback, times(1)).execute(eq(errorInstance)); verify(loadCompleteCallback, never()).execute(any(StunnerPreferences.class)); verify(preferencesHolder, never()).set(any(StunnerPreferences.class), eq(StunnerPreferences.class)); verify(preferencesHolder, never()).set(any(StunnerTextPreferences.class), eq(StunnerTextPreferences.class)); }