### Question:
StunnerProfilePreferencesLoader { public void load(final Metadata metadata, final ParameterizedCommand<Profile> loadCompleteCallback, final ParameterizedCommand<Throwable> errorCallback) { profilePreferences .load(profilePreferences -> { final String profileName = profilePreferences.getProfile().getName(); loadCompleteCallback.execute(getProfileByPreference(metadata, profileName) .orElse(defaultProfile)); }, errorCallback); } @Inject  StunnerProfilePreferencesLoader(final ProfileManager profileManager,
                                           final ProfilePreferences profilePreferences,
                                           final FullProfile defaultProfile); void load(final Metadata metadata,
                     final ParameterizedCommand<Profile> loadCompleteCallback,
                     final ParameterizedCommand<Throwable> errorCallback);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testLoad() { ParameterizedCommand<Profile> loadCallback = mock(ParameterizedCommand.class); ParameterizedCommand<Throwable> errorCallback = mock(ParameterizedCommand.class); tested.load(metadata, loadCallback, errorCallback); verify(errorCallback, never()).execute(any(Throwable.class)); verify(loadCallback, times(1)).execute(eq(profile)); }
@Test @SuppressWarnings("unchecked") public void testLoadDefaultProfile() { when(profile.getProjectProfileName()).thenReturn(org.kie.workbench.common.profile.api.preferences.Profile.FULL.getName()); ParameterizedCommand<Profile> loadCallback = mock(ParameterizedCommand.class); ParameterizedCommand<Throwable> errorCallback = mock(ParameterizedCommand.class); tested.load(metadata, loadCallback, errorCallback); verify(errorCallback, never()).execute(any(Throwable.class)); verify(loadCallback, times(1)).execute(eq(DEFAULT_PROFILE)); }
@Test @SuppressWarnings("unchecked") public void testError() { final Throwable exception = mock(Throwable.class); doAnswer(invocation -> { ParameterizedCommand<Throwable> callback = (ParameterizedCommand<Throwable>) invocation.getArguments()[1]; callback.execute(exception); return null; }).when(profilePreferences).load(any(ParameterizedCommand.class), any(ParameterizedCommand.class)); ParameterizedCommand<Profile> loadCallback = mock(ParameterizedCommand.class); ParameterizedCommand<Throwable> errorCallback = mock(ParameterizedCommand.class); tested.load(metadata, loadCallback, errorCallback); verify(errorCallback, times(1)).execute(eq(exception)); verify(loadCallback, never()).execute(any(Profile.class)); }