### Question:
JCredStash { protected String getUpdatedBy() throws Exception { try { return awsSecurityTokenService.getCallerIdentity(new GetCallerIdentityRequest()).getArn(); } catch(Exception e){ throw new RuntimeException("Error getting user"); } } protected  JCredStash(); protected  JCredStash(AWSCredentialsProvider awsCredentialsProvider); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient); protected  JCredStash(AmazonDynamoDB amazonDynamoDBClient, AWSKMS awskmsClient, AWSSecurityTokenService awsSecurityTokenService);   }### Answer:
@Test public void getUpdatedByShouldReturnCurrentIAMUser() throws Exception{ JCredStash jCredStash = new JCredStash(); AWSSecurityTokenService awsSecurityTokenService = spy(AWSSecurityTokenService.class); GetCallerIdentityResult callerIdentityResult = new GetCallerIdentityResult(); callerIdentityResult.setArn("arn:aws:sts::123456789876:assumed-role/private_aws_application_dev/L25000"); jCredStash.awsSecurityTokenService = awsSecurityTokenService; doReturn(callerIdentityResult).when(awsSecurityTokenService).getCallerIdentity(anyObject()); String user = jCredStash.getUpdatedBy(); assert(user).equals("arn:aws:sts::123456789876:assumed-role/private_aws_application_dev/L25000"); }
@Test(expected = RuntimeException.class) public void returnErrorGettingUser() throws Exception{ JCredStash jCredStash = new JCredStash(); AWSSecurityTokenService awsSecurityTokenService = spy(AWSSecurityTokenService.class); GetCallerIdentityResult callerIdentityResult = new GetCallerIdentityResult(); callerIdentityResult.setArn("arn:aws:sts::123456789876:assumed-role/private_aws_application_dev/L25000"); doReturn(callerIdentityResult).when(awsSecurityTokenService).getCallerIdentity(anyObject()); String user = jCredStash.getUpdatedBy(); assert(user).equals("errorGettingUser"); }