/** * AwsBucket can find and return ockets. * * @throws Exception If fails */ @Test public void findsAndReturnsOckets() throws Exception { final Region region = Mockito.mock(Region.class); final Bucket bucket = new AwsBucket(region, "example.com"); final Ocket ocket = bucket.ocket("test"); MatcherAssert.assertThat(ocket, Matchers.notNullValue()); }
/** * AwsBucket can throw a proper exception. * * @throws IOException If succeeds */ @Test(expected = IOException.class) public void existsThrowsIOException() throws IOException { final Region region = Mockito.mock(Region.class); final AmazonS3 aws = Mockito.mock(AmazonS3.class); Mockito.when(region.aws()).thenReturn(aws); final String name = "throwing.bucket.com"; Mockito.when(aws.doesBucketExist(name)).thenThrow(new AmazonServiceException("Test exception")); final Bucket bucket = new AwsBucket(region, name); bucket.exists(); }
/** * AwsBucket can correctly check the existence of the non-existing bucket. * * @throws IOException If fails */ @Test public void existsNonExistingBucket() throws IOException { final Region region = Mockito.mock(Region.class); final AmazonS3 aws = Mockito.mock(AmazonS3.class); Mockito.when(region.aws()).thenReturn(aws); final String name = "non.existing.bucket.com"; Mockito.when(aws.doesBucketExist(name)).thenReturn(false); final Bucket bucket = new AwsBucket(region, name); Assert.assertFalse(bucket.exists()); }
/** * AwsBucket supports listing large buckets. * * @throws Exception if test fails */ @Test public void supportsListingLargeBuckets() throws Exception { final String name = "large.bucket"; final String prefix = "prefix"; final String first = "first"; final String second = "second"; final Region region = Mockito.mock(Region.class); final RegionExpectations expectations = new RegionExpectations(region); expectations .expectResponse(first, null, second) .expectResponse(second, second, null) .apply(name, prefix); final Bucket bucket = new AwsBucket(region, name); final Iterator<String> actual = bucket.list(prefix).iterator(); MatcherAssert.assertThat(actual.hasNext(), Matchers.equalTo(true)); MatcherAssert.assertThat(first, Matchers.equalTo(actual.next())); MatcherAssert.assertThat(actual.hasNext(), Matchers.equalTo(true)); MatcherAssert.assertThat(second, Matchers.equalTo(actual.next())); MatcherAssert.assertThat(actual.hasNext(), Matchers.equalTo(false)); expectations.verify(name, prefix); }