kopia lustrzana https://github.com/gaul/s3proxy
Use ExpectedException to handle test failures
Also prefer matching AWS error code over the message.pull/53/head
rodzic
0709bb557d
commit
e0a1560cb2
|
@ -17,7 +17,7 @@
|
|||
<module name="AvoidNestedBlocks"/>
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="AvoidStaticImport">
|
||||
<property name="excludes" value="java.util.Objects.requireNonNull,com.google.common.base.Preconditions.checkArgument,com.google.common.base.Preconditions.checkState,org.assertj.core.api.Assertions.assertThat,org.assertj.core.api.Fail.failBecauseExceptionWasNotThrown"/>
|
||||
<property name="excludes" value="java.util.Objects.requireNonNull,com.google.common.base.Preconditions.checkArgument,com.google.common.base.Preconditions.checkState,org.assertj.core.api.Assertions.assertThat"/>
|
||||
</module>
|
||||
<module name="ClassTypeParameterName"/>
|
||||
<module name="CovariantEquals"/>
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.google.common.io.Resources;
|
|||
import com.google.inject.Module;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.hamcrest.CustomTypeSafeMatcher;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
|
@ -144,8 +145,13 @@ public final class S3AwsSdkTest {
|
|||
AmazonS3 client = new AmazonS3Client(awsCreds);
|
||||
client.setEndpoint(s3Endpoint.toString());
|
||||
|
||||
thrown.expect(AmazonS3Exception.class);
|
||||
thrown.expectMessage("Status Code: 400; Error Code: InvalidArgument");
|
||||
final String code = "InvalidArgument";
|
||||
thrown.expect(new CustomTypeSafeMatcher<AmazonS3Exception>(code) {
|
||||
@Override
|
||||
public boolean matchesSafely(AmazonS3Exception ase) {
|
||||
return ase.getErrorCode().equals(code);
|
||||
}
|
||||
});
|
||||
client.getObject(containerName, "foo");
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.gaul.s3proxy;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Fail.failBecauseExceptionWasNotThrown;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
@ -34,6 +33,7 @@ import com.google.common.io.Resources;
|
|||
import com.google.inject.Module;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.hamcrest.CustomTypeSafeMatcher;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.aws.AWSResponseException;
|
||||
|
@ -56,9 +56,14 @@ import org.jclouds.s3.S3Client;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public final class S3ProxyTest {
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private URI s3Endpoint;
|
||||
private S3Proxy s3Proxy;
|
||||
private BlobStoreContext context;
|
||||
|
@ -386,13 +391,15 @@ public final class S3ProxyTest {
|
|||
@Test
|
||||
public void testUnknownParameter() throws Exception {
|
||||
S3Client s3Client = s3Context.unwrapApi(S3Client.class);
|
||||
try {
|
||||
s3Client.disableBucketLogging(containerName);
|
||||
failBecauseExceptionWasNotThrown(AWSResponseException.class);
|
||||
} catch (AWSResponseException are) {
|
||||
assertThat(are.getError().getCode()).as("code").isEqualTo(
|
||||
"NotImplemented");
|
||||
}
|
||||
|
||||
final String code = "NotImplemented";
|
||||
thrown.expect(new CustomTypeSafeMatcher<AWSResponseException>(code) {
|
||||
@Override
|
||||
public boolean matchesSafely(AWSResponseException are) {
|
||||
return are.getError().getCode().equals(code);
|
||||
}
|
||||
});
|
||||
s3Client.disableBucketLogging(containerName);
|
||||
}
|
||||
|
||||
private static String createRandomContainerName() {
|
||||
|
|
Ładowanie…
Reference in New Issue