EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.atmos.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ReturnEndpointIfAlreadyExists.java]

nameclass, %method, %block, %line, %
ReturnEndpointIfAlreadyExists.java100% (1/1)75%  (3/4)52%  (16/31)71%  (5/7)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ReturnEndpointIfAlreadyExists100% (1/1)75%  (3/4)52%  (16/31)71%  (5/7)
setContext (HttpRequest): ReturnEndpointIfAlreadyExists 0%   (0/1)0%   (0/9)0%   (0/1)
apply (Exception): URI 100% (1/1)57%  (8/14)67%  (2/3)
ReturnEndpointIfAlreadyExists (): void 100% (1/1)100% (3/3)100% (1/1)
setEndpoint (URI): ReturnEndpointIfAlreadyExists 100% (1/1)100% (5/5)100% (2/2)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.atmos.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.util.Throwables2.propagateOrNull;
23 
24import java.net.URI;
25 
26import javax.annotation.Nullable;
27 
28import org.jclouds.blobstore.KeyAlreadyExistsException;
29import org.jclouds.http.HttpRequest;
30import org.jclouds.rest.InvocationContext;
31 
32import com.google.common.annotations.VisibleForTesting;
33import com.google.common.base.Function;
34 
35/**
36 * 
37 * @author Adrian Cole
38 */
39public class ReturnEndpointIfAlreadyExists implements Function<Exception, URI>,
40      InvocationContext<ReturnEndpointIfAlreadyExists> {
41 
42   private URI endpoint;
43 
44   public URI apply(Exception from) {
45      if (checkNotNull(from, "exception") instanceof KeyAlreadyExistsException) {
46         return endpoint;
47      }
48      return URI.class.cast(propagateOrNull(from));
49   }
50 
51   @Override
52   public ReturnEndpointIfAlreadyExists setContext(HttpRequest request) {
53      return setEndpoint(request == null ? null : request.getEndpoint());
54   }
55 
56   @VisibleForTesting
57   ReturnEndpointIfAlreadyExists setEndpoint(@Nullable URI endpoint) {
58      this.endpoint = endpoint;
59      return this;
60   }
61 
62}

[all classes][org.jclouds.atmos.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov