@Test
public void shouldReturnConflictIfCompareAndSetFailsBecauseAKeyAlreadyExistsExceptionIsThrown() {

    // we expect to be creating a new key
    final SetValue newKeyValue = new SetValue();
    newKeyValue.setExpectedValue(null);
    newKeyValue.setNewValue(NEW_VALUE);
    when(distributedStore.compareAndSet(KEY, newKeyValue)).thenReturn(Futures.<KeyValue>immediateFailedFuture(new KeyAlreadyExistsException(KEY)));
    assertThatResourceMethodReturnsStatus(
            client().resource(REQUEST_URI).type(MediaType.APPLICATION_JSON_TYPE).entity(newKeyValue),
            "PUT",
            ClientResponse.Status.CONFLICT
    );
}