Source:
<code>public void testCopyObject() throws Exception { for (String regionId : regions) { String sourceContainer = "src" + containerName; String sourceObjectName = "original.txt"; String badSource = "badSource"; String destinationContainer = "dest" + containerName; String destinationObject = "copy.txt"; String destinationPath = "/" + destinationContainer + "/" + destinationObject; ContainerApi containerApi = api.getContainerApi(regionId); containerApi.create(sourceContainer); containerApi.create(destinationContainer); ObjectApi srcApi = api.getObjectApi(regionId, sourceContainer); ObjectApi destApi = api.getObjectApi(regionId, destinationContainer); assertNotNull(srcApi.put(sourceObjectName, PAYLOAD)); SwiftObject sourceObject = srcApi.get(sourceObjectName); checkObject(sourceObject); assertNotNull(destApi.put(destinationObject, PAYLOAD)); SwiftObject object = destApi.get(destinationObject); checkObject(object); assertTrue(destApi.copy(destinationObject, sourceContainer, sourceObjectName)); assertNotNull(destApi.get(destinationObject)); SwiftObject destSwiftObject = destApi.get(destinationObject); assertEquals(toStringAndClose(destSwiftObject.getPayload().openStream()), "swifty"); try { <START> destApi.copy(destinationObject, badSource, sourceObjectName); <END> } finally { deleteAllObjectsInContainer(regionId, sourceContainer); containerApi.deleteIfEmpty(sourceContainer); deleteAllObjectsInContainer(regionId, destinationContainer); containerApi.deleteIfEmpty(destinationContainer); } } }</code><technical_language>try .. catch instead of expectedExceptions? This narrows exception handling scope: <LINK_0> (also for loop complete this change)</technical_language>

Target:
public void testCopyObject() throws Exception { for (String regionId : regions) { String sourceContainer = "src" + containerName; String sourceObjectName = "original.txt"; String badSource = "badSource"; String destinationContainer = "dest" + containerName; String destinationObject = "copy.txt"; String destinationPath = "/" + destinationContainer + "/" + destinationObject; ContainerApi containerApi = api.getContainerApi(regionId); containerApi.create(sourceContainer); containerApi.create(destinationContainer); ObjectApi srcApi = api.getObjectApi(regionId, sourceContainer); ObjectApi destApi = api.getObjectApi(regionId, destinationContainer); assertNotNull(srcApi.put(sourceObjectName, PAYLOAD)); SwiftObject sourceObject = srcApi.get(sourceObjectName); checkObject(sourceObject); assertNotNull(destApi.put(destinationObject, PAYLOAD)); SwiftObject object = destApi.get(destinationObject); checkObject(object); assertTrue(destApi.copy(destinationObject, sourceContainer, sourceObjectName)); assertNotNull(destApi.get(destinationObject)); SwiftObject destSwiftObject = destApi.get(destinationObject); assertEquals(toStringAndClose(destSwiftObject.getPayload().openStream()), "swifty"); try { destApi.copy(destinationObject, badSource, sourceObjectName); } catch (KeyNotFoundException e) { continue; } finally { deleteAllObjectsInContainer(regionId, sourceContainer); containerApi.deleteIfEmpty(sourceContainer); deleteAllObjectsInContainer(regionId, destinationContainer); containerApi.deleteIfEmpty(destinationContainer); } fail("Expected KeyNotFoundException"); } }