### Question:
AccessRequestService { public AccessRequest storeAccessRequest(AccessRequestWrapper request) throws GatekeeperException { GatekeeperUserEntry requestor = gatekeeperRoleService.getUserProfile(); for(AWSInstance instance : request.getInstances()){ if(!instance.getPlatform().equals(request.getPlatform())){ throw new GatekeeperException("Instance platform doesn't match requested platform. Instance: " + instance.getPlatform() + " Requested: " +request.getPlatform()); } } request.getUsers().forEach(u -> u.setUserId("gk-" + u.getUserId())); AccessRequest accessRequest = new AccessRequest() .setAccount(request.getAccount().toUpperCase()) .setRegion(request.getRegion()) .setHours(request.getHours()) .setRequestorId(requestor.getUserId()) .setRequestorName(requestor.getName()) .setRequestorEmail(requestor.getEmail()) .setUsers(request.getUsers()) .setInstances(request.getInstances()) .setTicketId(request.getTicketId()) .setRequestReason(request.getRequestReason()) .setPlatform(request.getPlatform()); logger.info("Storing Access Request"); accessRequestRepository.save(accessRequest); logger.info("Access Request stored with ID: " + accessRequest.getId()); Map<String, Object> variables = new HashMap<>(); variables.put("accessRequest", accessRequest); runtimeService.startProcessInstanceByKey("gatekeeperAccessRequest", variables); logger.info("Number of process instances: " + runtimeService.createProcessInstanceQuery().count()); return accessRequest; } @Autowired  AccessRequestService(TaskService taskService,
                                AccessRequestRepository accessRequestRepository,
                                GatekeeperRoleService gatekeeperRoleService,
                                RuntimeService runtimeService,
                                HistoryService historyService,
                                AccountInformationService accountInformationService,
                                SsmService ssmService,
                                GatekeeperApprovalProperties gatekeeperApprovalProperties,
                                EntityManager entityManager); AccessRequest storeAccessRequest(AccessRequestWrapper request); boolean isApprovalNeeded(AccessRequest request); List<ActiveAccessRequestWrapper> getActiveRequests(); List<CompletedAccessRequestWrapper> getRequest(Long id); List<CompletedAccessRequestWrapper> getCompletedRequests(); RequestEventDTO getLiveRequestsForUsersInRequest(EventType eventType, AccessRequest request); AccessRequest updateInstanceStatus(AccessRequest accessRequest); @PreAuthorize("@gatekeeperRoleService.isApprover()") List<ActiveAccessRequestWrapper> approveRequest(String taskId, Long requestId, String approverComments ); @PreAuthorize("@gatekeeperRoleService.isApprover()") List<ActiveAccessRequestWrapper> rejectRequest(String taskId, Long requestId, String approverComments); List<ActiveAccessRequestWrapper> cancelRequest(String taskId, Long requestId);  }### Answer:
@Test public void testStoreAccessRequest() throws GatekeeperException { List<User> users = new ArrayList<>(); users.add(user); List<AWSInstance> instances = new ArrayList<>(); instances.add(awsInstance); AccessRequest result = accessRequestService.storeAccessRequest(ownerRequestWrapper); Assert.assertEquals(result.getRequestorEmail(), "testEmail@finra.org"); Assert.assertEquals(result.getRequestorId(), "testUserId"); Assert.assertEquals(result.getRequestorName(), "testName"); Assert.assertEquals(result.getRegion(), "testRegion"); Assert.assertEquals(result.getAccount(), "TESTACCOUNT"); Assert.assertEquals((long) result.getHours(), 1L); Assert.assertEquals(result.getUsers(), users); Assert.assertEquals(result.getInstances(), instances); verify(accessRequestRepository, times(1)).save(result); }
@Test(expected = GatekeeperException.class) public void testRequestError() throws GatekeeperException{ when(ownerRequestWrapper.getPlatform()).thenReturn("differentPlatform"); accessRequestService.storeAccessRequest(ownerRequestWrapper); }