@Override
    public AppResponse process(Flow flow, RsPollAppApplicationResultRequest request) throws SharedServiceClientException {

        checkSwitchesEnabled();

        final String activationStatus = appSession.getActivationStatus();
        final Long accountId = appSession.getAccountId();
        final String userAppId = appSession.getUserAppId();
        final boolean removeOldApp = request.getRemoveOldApp().equals("true");
        String status;

        int maxAppsPerUser = sharedServiceClient.getSSConfigInt("Maximum_aantal_DigiD_apps_eindgebruiker");

        appSession.setRemoveOldApp(removeOldApp);

        if (TOO_MANY_APPS.equals(activationStatus) && !removeOldApp) {
            AppAuthenticator leastRecentApp = appAuthenticatorService.findLeastRecentApp(accountId);
            return new TooManyAppsResponse("too_many_active", maxAppsPerUser, leastRecentApp.getDeviceName(),
                leastRecentApp.getLastSignInOrActivatedAtOrCreatedAt().toLocalDate().format(DateTimeFormatter.ofPattern("dd-MM-yyyy")));
        }

        status = TOO_MANY_APPS.equals(activationStatus) && removeOldApp ? OK : activationStatus;

        if (!status.equals(OK)) {
            setValid(false);
        }

        return new RsPollAppApplicationResultResponse(status, userAppId);
    }
@Test
    public void processRsPollAppApplicationResultPendingTest() throws SharedServiceClientException {
        when(sharedServiceClient.getSSConfigInt("Maximum_aantal_DigiD_apps_eindgebruiker")).thenReturn(5);
        when(switchService.digidAppSwitchEnabled()).thenReturn(true);
        when(switchService.digidRequestStationEnabled()).thenReturn(true);

        rsPollAppApplicationResult.setAppSession(createAppSession(ApplyForAppAtRequestStationFlow.NAME, State.RS_APP_APPLICATION_STARTED, "PENDING"));

        mockedRsPollAppApplicationResultRequest = new RsPollAppApplicationResultRequest();
        mockedRsPollAppApplicationResultRequest.setActivationCode(APP_ACTIVATION_CODE);
        mockedRsPollAppApplicationResultRequest.setRemoveOldApp("true");

        AppResponse appResponse = rsPollAppApplicationResult.process(mockedApplyForAppAtRequestStationFlow, mockedRsPollAppApplicationResultRequest);

        assertEquals(true, rsPollAppApplicationResult.getAppSession().isRemoveOldApp());
        assertEquals(PENDING, rsPollAppApplicationResult.getAppSession().getActivationStatus());
        assertTrue(appResponse instanceof RsPollAppApplicationResultResponse);
        assertEquals(PENDING,((RsPollAppApplicationResultResponse) appResponse).getStatus());
        assertEquals(USER_APP_ID,((RsPollAppApplicationResultResponse) appResponse).getUserAppId());
    }