### Question:
S3ObjectsProvider { public String[] getS3ObjectsNames( String bucketName ) throws Exception { S3Bucket bucket = getBucket( bucketName ); if ( bucket == null ) { throw new Exception( Messages.getString( "S3DefaultService.Exception.UnableToFindBucket.Message", bucketName ) ); } return Arrays.stream( getS3Objects( bucket ) ).map( b -> b.getKey() ).toArray( String[]::new ); } S3ObjectsProvider( S3Service service ); String[] getBucketsNames(); S3Bucket getBucket( String bucketName ); String[] getS3ObjectsNames( String bucketName ); S3Object getS3Object( S3Bucket bucket, String objectKey, Long byteRangeStart, Long byteRangeEnd ); S3Object getS3Object( S3Bucket bucket, String objectKey ); long getS3ObjectContentLenght( S3Bucket bucket, String objectKey );  }### Answer:
@Test public void testGetObjectsNamesInBucketWithObjects() throws Exception { String[] actual = provider.getS3ObjectsNames( BUCKET2_NAME ); assertEquals( bucket2Objects.length, actual.length ); IntStream.rangeClosed( 0, actual.length - 1 ) .forEachOrdered( i -> assertEquals( bucket2Objects[i].getName(), actual[i] ) ); assertEquals( bucket2Objects.length, actual.length ); }
@Test public void testGetObjectsNamesInEmptyBucket() throws Exception { String[] actual = provider.getS3ObjectsNames( BUCKET3_NAME ); logArray( actual ); assertEquals( 0, actual.length ); }
@Test public void testGetObjectsNamesNoSuchBucket_ThrowsExeption() { try { provider.getS3ObjectsNames( "UnknownBucket" ); fail( "The Exception: Unable to find bucket 'UnknownBucket' should be thrown but it was not." ); } catch ( Exception e ) { assertTrue( e.getLocalizedMessage().contains( "Unable to find bucket 'UnknownBucket'" ) ); } }