### Question:
AwsRdsStatusLookupService { public ExternalDatabaseStatus getStatus(AuthenticatedContext ac, DatabaseStack dbStack) { AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential()); String regionName = ac.getCloudContext().getLocation().getRegion().value(); AmazonRDS rdsClient = awsClient.createRdsClient(credentialView, regionName); String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId(); DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier); DescribeDBInstancesResult describeDBInstancesResult; try { describeDBInstancesResult = rdsClient.describeDBInstances(describeDBInstancesRequest); } catch (DBInstanceNotFoundException ex) { return ExternalDatabaseStatus.DELETED; } catch (RuntimeException ex) { throw new CloudConnectorException(ex.getMessage(), ex); } return describeDBInstancesResult.getDBInstances() .stream() .map(i -> getExternalDatabaseStatus(i.getDBInstanceStatus())) .findFirst() .get(); }  ExternalDatabaseStatus getStatus(AuthenticatedContext ac, DatabaseStack dbStack); boolean isDeleteProtectionEnabled(AuthenticatedContext ac, DatabaseStack dbStack);  }### Answer:
@Test public void shouldLookupStartedExternalDatabaseStatus() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult); when(describeDBInstancesResult.getDBInstances()).thenReturn(Arrays.asList(dbInstance)); when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_STARTED); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.STARTED, result); }
@Test public void shouldLookupStoppedExternalDatabaseStatus() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult); when(describeDBInstancesResult.getDBInstances()).thenReturn(Arrays.asList(dbInstance)); when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_STOPPED); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.STOPPED, result); }
@Test public void shouldLookupUpdateInProgressExternalDatabaseStatus() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenReturn(describeDBInstancesResult); when(describeDBInstancesResult.getDBInstances()).thenReturn(Arrays.asList(dbInstance)); when(dbInstance.getDBInstanceStatus()).thenReturn(DB_INSTANCE_STATUS_ANY); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.UPDATE_IN_PROGRESS, result); }
@Test public void shouldReturnDeletedInCaseOfDBInstanceNotFoundException() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenThrow(DBInstanceNotFoundException.class); ExternalDatabaseStatus result = victim.getStatus(authenticatedContext, dbStack); assertEquals(ExternalDatabaseStatus.DELETED, result); }
@Test(expected = CloudConnectorException.class) public void shouldThrowCloudConnectorExceptionInCaseOfAnyRuntimeException() { when(amazonRDS.describeDBInstances(any(DescribeDBInstancesRequest.class))).thenThrow(RuntimeException.class); victim.getStatus(authenticatedContext, dbStack); }