title: Safely turn of BucketVersioning in S3 using Java
body: <p>I am new to S3 , I have a unit test where I turn on the versioning do a few operations and then suspend the versioning. But I want to always Suspend the versioning even if the test case fails.
  Here is my implementation :-</p>
  
  <pre><code>            @Test
              public void checkVersion() {
              AWSCredentials creds = new BasicAWSCredentials("","");
              AmazonS3 s3 = new AmazonS3Client(creds);
              BucketVersioningConfiguration configuration = 
                              new BucketVersioningConfiguration().withStatus("Enabled");
  
  
      SetBucketVersioningConfigurationRequest setBucketVersioningConfigurationRequest = new SetBucketVersioningConfigurationRequest(bucketName,configuration);
       s3Client.setBucketVersioningConfiguration(setBucketVersioningConfigurationRequest);
  
  //PUt object
  //Delete object
  //Put object
  
  
          }
  </code></pre>
  
  <p>Now I want to turn off the bucketversioning everytime even if the operations fail. For this is there any other better way other than using </p>
  
  <pre><code>try-catch-finally block 
  </code></pre>
  
  <p>Also , is it possible to implement Enable and Suspend versions using <code>try-with-resource</code> ?</p>