Consistent use of this when accessing fields in the core project

This commit is contained in:
Andy Wilkinson
2015-01-13 16:25:13 +00:00
parent 78736d6c50
commit b57eb002dc
11 changed files with 58 additions and 40 deletions

View File

@@ -20,7 +20,7 @@ import org.springframework.core.style.ToStringCreator;
/**
* Representation of a link used in a Hypermedia-based API
*
*
* @author Andy Wilkinson
*/
public class Link {
@@ -31,7 +31,7 @@ public class Link {
/**
* Creates a new {@code Link} with the given {@code rel} and {@code href}
*
*
* @param rel The link's rel
* @param href The link's href
*/
@@ -45,7 +45,7 @@ public class Link {
* @return the link's {@code rel}
*/
public String getRel() {
return rel;
return this.rel;
}
/**
@@ -53,15 +53,15 @@ public class Link {
* @return the link's {@code href}
*/
public String getHref() {
return href;
return this.href;
}
@Override
public int hashCode() {
int prime = 31;
int result = 1;
result = prime * result + href.hashCode();
result = prime * result + rel.hashCode();
result = prime * result + this.href.hashCode();
result = prime * result + this.rel.hashCode();
return result;
}
@@ -77,15 +77,16 @@ public class Link {
return false;
}
Link other = (Link) obj;
if (!href.equals(other.href)) {
if (!this.href.equals(other.href)) {
return false;
}
if (!rel.equals(other.rel)) {
if (!this.rel.equals(other.rel)) {
return false;
}
return true;
}
@Override
public String toString() {
return new ToStringCreator(this).append("rel", this.rel)
.append("href", this.href).toString();

View File

@@ -32,10 +32,10 @@ public class LinkDescriptor {
}
String getRel() {
return rel;
return this.rel;
}
String getDescription() {
return description;
return this.description;
}
}

View File

@@ -25,7 +25,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
/**
* A {@code LinkExtractor} is used to extract {@link Link links} from a JSON response. The
* expected format of the links in the response is determined by the implementation.
*
*
* @author Andy Wilkinson
*
*/
@@ -34,7 +34,7 @@ public interface LinkExtractor {
/**
* Extract the links from the given response, returning a {@code Map} of links where
* the keys are the link rels.
*
*
* @param response The response from which the links are to be extracted
* @return The extracted links, keyed by rel
* @throws IOException if link extraction fails

View File

@@ -31,7 +31,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Static factory methods provided a selection of {@link LinkExtractor link extractors}
* for use when documentating a hypermedia-based API.
*
*
* @author Andy Wilkinson
*
*/
@@ -41,7 +41,7 @@ public class LinkExtractors {
* Returns a {@code LinkExtractor} capable of extracting links in Hypermedia
* Application Language (HAL) format where the links are found in a map named
* {@code _links}.
*
*
* @return The extract for HAL-style links
*/
public static LinkExtractor halLinks() {
@@ -51,7 +51,7 @@ public class LinkExtractors {
/**
* Returns a {@code LinkExtractor} capable of extracting links in Atom format where
* the links are found in an array named {@code links}.
*
*
* @return The extractor for Atom-style links
*/
public static LinkExtractor atomLinks() {
@@ -62,6 +62,7 @@ public class LinkExtractors {
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
@SuppressWarnings("unchecked")
public Map<String, List<Link>> extractLinks(MockHttpServletResponse response)
throws IOException {
@@ -83,7 +84,7 @@ public class LinkExtractors {
if (possibleLinks instanceof Map) {
Map<String, Object> links = (Map<String, Object>) possibleLinks;
for (Entry<String, Object> entry : links.entrySet()) {
String rel = (String) entry.getKey();
String rel = entry.getKey();
extractedLinks.put(rel, convertToLinks(entry.getValue(), rel));
}
}

View File

@@ -53,10 +53,10 @@ public class RestDocumentationConfiguration extends MockMvcConfigurerAdapter {
@Override
public MockHttpServletRequest postProcessRequest(
MockHttpServletRequest request) {
request.setScheme(scheme);
request.setRemotePort(port);
request.setServerPort(port);
request.setRemoteHost(host);
request.setScheme(RestDocumentationConfiguration.this.scheme);
request.setRemotePort(RestDocumentationConfiguration.this.port);
request.setServerPort(RestDocumentationConfiguration.this.port);
request.setRemoteHost(RestDocumentationConfiguration.this.host);
return request;
}
};

View File

@@ -38,18 +38,20 @@ public class RestDocumentationResultHandler implements ResultHandler {
@Override
public void handle(MvcResult result) throws Exception {
documentCurlRequest(outputDir).includeResponseHeaders().handle(result);
documentCurlResponse(outputDir).includeResponseHeaders().handle(result);
documentCurlRequestAndResponse(outputDir).includeResponseHeaders().handle(result);
if (linkDocumentingResultHandler != null) {
linkDocumentingResultHandler.handle(result);
documentCurlRequest(this.outputDir).includeResponseHeaders().handle(result);
documentCurlResponse(this.outputDir).includeResponseHeaders().handle(result);
documentCurlRequestAndResponse(this.outputDir).includeResponseHeaders().handle(
result);
if (this.linkDocumentingResultHandler != null) {
this.linkDocumentingResultHandler.handle(result);
}
}
public RestDocumentationResultHandler withLinks(LinkExtractor linkExtractor,
LinkDescriptor... descriptors) {
linkDocumentingResultHandler = new LinkDocumentingResultHandler(outputDir,
linkExtractor, Arrays.asList(descriptors));
this.linkDocumentingResultHandler = new LinkDocumentingResultHandler(
this.outputDir, linkExtractor, Arrays.asList(descriptors));
return this;
}
}

View File

@@ -38,7 +38,7 @@ import org.springframework.util.FileCopyUtils;
/**
* Tests for {@link LinkExtractors}.
*
*
* @author Andy Wilkinson
*/
@RunWith(Parameterized.class)
@@ -118,7 +118,7 @@ public class LinkExtractorsTests {
}
private File getPayloadFile(String name) {
return new File("src/test/resources/link-payloads/" + linkType + "/" + name
return new File("src/test/resources/link-payloads/" + this.linkType + "/" + name
+ ".json");
}
}