made blobmetadata parser name accessible for testing

This commit is contained in:
Adrian Cole 2011-02-26 21:48:51 -08:00
parent 00d172ce2f
commit 897dc000d5
1 changed files with 9 additions and 9 deletions

View File

@ -53,7 +53,7 @@ public class ParseSystemAndUserMetadataFromHeaders implements Function<HttpRespo
private final DateService dateParser; private final DateService dateParser;
private final Provider<MutableBlobMetadata> metadataFactory; private final Provider<MutableBlobMetadata> metadataFactory;
private String key; private String name;
@Inject @Inject
public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory, DateService dateParser, public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory, DateService dateParser,
@ -65,10 +65,11 @@ public class ParseSystemAndUserMetadataFromHeaders implements Function<HttpRespo
public MutableBlobMetadata apply(HttpResponse from) { public MutableBlobMetadata apply(HttpResponse from) {
checkNotNull(from, "request"); checkNotNull(from, "request");
checkState(key != null, "key must be initialized by now"); checkState(name != null, "name must be initialized by now");
MutableBlobMetadata to = metadataFactory.get(); MutableBlobMetadata to = metadataFactory.get();
to.setName(key); to.setName(name);
if (from.getPayload() != null)
HttpUtils.copy(from.getPayload().getContentMetadata(), to.getContentMetadata()); HttpUtils.copy(from.getPayload().getContentMetadata(), to.getContentMetadata());
addETagTo(from, to); addETagTo(from, to);
parseLastModifiedOrThrowException(from, to); parseLastModifiedOrThrowException(from, to);
@ -115,12 +116,11 @@ public class ParseSystemAndUserMetadataFromHeaders implements Function<HttpRespo
public ParseSystemAndUserMetadataFromHeaders setContext(HttpRequest request) { public ParseSystemAndUserMetadataFromHeaders setContext(HttpRequest request) {
checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest"); checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest");
setName(getNameFor(GeneratedHttpRequest.class.cast(request))); return setName(getNameFor(GeneratedHttpRequest.class.cast(request)));
return this;
} }
@VisibleForTesting public ParseSystemAndUserMetadataFromHeaders setName(String name) {
void setName(String key) { this.name = checkNotNull(name, "name");
this.key = checkNotNull(key, "key"); return this;
} }
} }