### Question:
AwsSessionService { public AmazonEC2 getEC2Session(AWSEnvironment environment){ return awsSessionFactory.createEc2Session(credentialCache.getUnchecked(environment), environment.getRegion()); } @Autowired  AwsSessionService(AccountInformationService accountInformationService,
                                               AWSSecurityTokenServiceClient awsSecurityTokenServiceClient,
                                               AwsSessionFactory awsSessionFactory,
                                               GatekeeperAwsProperties gatekeeperAwsProperties); AmazonEC2 getEC2Session(AWSEnvironment environment); AWSSimpleSystemsManagement getSsmSession(AWSEnvironment environment); AmazonSNS getSnsSession();  }### Answer:
@Test public void testGetEc2Session(){ AmazonEC2 client = awsSessionService.getEC2Session(awsEnvironment); Assert.assertNotNull("Verify EC2 Session is fetched", client ); Mockito.verify(awsSessionFactory, times(1)).createEc2Session(anyObject(), eq(awsEnvironment.getRegion())); }
@Test public void testExceptionThrown(){ String env = "Test"; awsEnvironment = new AWSEnvironment(env, "us-east-2"); when(accountInformationService.getAccountByAlias("Test")).thenReturn(null); try { awsSessionService.getEC2Session(awsEnvironment); }catch(Exception e){ Assert.assertEquals("Message with no alias is correct ", "org.finra.gatekeeper.exception.GatekeeperException: No account found with alias: " + env, e.getMessage()); } }