Source:
public void before() throws IOException { documentString = IOUtils.toString(new FileInputStream("conf/study-defaults/consent-page.xhtml")); consentService = new ConsentService(); consentService.setAccountDao(accountDao); consentService.setSendMailService(sendMailService); consentService.setActivityEventService(activityEventService); consentService.setStudyConsentService(studyConsentService); consentService.setSubpopulationService(subpopService); consentService.setS3Helper(s3Helper); consentService.setUrlShortenerService(urlShortenerService); consentService.setNotificationsService(notificationsService); consentService.setConsentTemplate(new ByteArrayResource((documentString).getBytes())); Study study = TestUtils.getValidStudy(ConsentServiceMockTest.class); STUDY.setConsentNotificationEmail(study.getConsentNotificationEmail()); STUDY.setConsentNotificationEmailVerified(study.isConsentNotificationEmailVerified()); STUDY.setSignedConsentTemplate(study.getSignedConsentTemplate()); STUDY.setSignedConsentSmsTemplate(study.getSignedConsentSmsTemplate()); account.setId(ID); when(accountDao.getAccount(any(AccountId.class))).thenReturn(account); when(s3Helper.generatePresignedUrl(eq(ConsentService.USERSIGNED_CONSENTS_BUCKET), any(), any(), eq(HttpMethod.GET))).thenReturn(new URL(LONG_URL)); when(urlShortenerService.shortenUrl(LONG_URL, BridgeConstants.SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS)) .thenReturn(SHORT_URL); when(studyConsentView.getCreatedOn()).thenReturn(CONSENT_CREATED_ON); when(studyConsentView.getDocumentContent()).thenReturn("<p>This is content of the final HTML document we assemble.</p>"); when(studyConsentService.getActiveConsent(subpopulation)).thenReturn(studyConsentView); when(subpopService.getSubpopulation(STUDY.getStudyIdentifier(), SUBPOP_GUID)).thenReturn(subpopulation); }

Target:
public void before() throws IOException { documentString = IOUtils.toString(new FileInputStream("conf/study-defaults/consent-page.xhtml")); consentService = new ConsentService(); consentService.setAccountDao(accountDao); consentService.setSendMailService(sendMailService); consentService.setActivityEventService(activityEventService); consentService.setStudyConsentService(studyConsentService); consentService.setSubpopulationService(subpopService); consentService.setS3Helper(s3Helper); consentService.setUrlShortenerService(urlShortenerService); consentService.setNotificationsService(notificationsService); consentService.setConsentTemplate(new ByteArrayResource((documentString).getBytes())); study = TestUtils.getValidStudy(ConsentServiceMockTest.class); account = Account.create(); account.setId(ID); when(accountDao.getAccount(any(AccountId.class))).thenReturn(account); when(s3Helper.generatePresignedUrl(eq(ConsentService.USERSIGNED_CONSENTS_BUCKET), any(), any(), eq(HttpMethod.GET))).thenReturn(new URL(LONG_URL)); when(urlShortenerService.shortenUrl(LONG_URL, BridgeConstants.SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS)) .thenReturn(SHORT_URL); when(studyConsentView.getCreatedOn()).thenReturn(CONSENT_CREATED_ON); when(studyConsentView.getDocumentContent()).thenReturn("<p>This is content of the final HTML document we assemble.</p>"); when(studyConsentService.getActiveConsent(subpopulation)).thenReturn(studyConsentView); when(subpopService.getSubpopulation(study.getStudyIdentifier(), SUBPOP_GUID)).thenReturn(subpopulation); }