Always use 'this.' when accessing fields

Ensure that `this.` is used consistently when accessing class
fields.

Issue: SPR-16968
This commit is contained in:
Phillip Webb
2018-06-25 11:37:17 -07:00
committed by Juergen Hoeller
parent eeebd51f57
commit 0b53c1096a
154 changed files with 374 additions and 373 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,14 +37,14 @@ public class MockEnvironment extends AbstractEnvironment {
* Create a new {@code MockEnvironment} with a single {@link MockPropertySource}.
*/
public MockEnvironment() {
getPropertySources().addLast(propertySource);
getPropertySources().addLast(this.propertySource);
}
/**
* Set a property on the underlying {@link MockPropertySource} for this environment.
*/
public void setProperty(String key, String value) {
propertySource.setProperty(key, value);
this.propertySource.setProperty(key, value);
}
/**

View File

@@ -120,7 +120,7 @@ public class MockClientHttpResponse implements ClientHttpResponse {
public Mono<String> getBodyAsString() {
Charset charset = getCharset();
return Flux.from(getBody())
.reduce(bufferFactory.allocateBuffer(), (previous, current) -> {
.reduce(this.bufferFactory.allocateBuffer(), (previous, current) -> {
previous.write(current);
DataBufferUtils.release(current);
return previous;

View File

@@ -226,7 +226,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
}
// Default case...
return environment1 -> new SimpleNamingContext("", boundObjects, (Hashtable<String, Object>) environment1);
return environment1 -> new SimpleNamingContext("", this.boundObjects, (Hashtable<String, Object>) environment1);
}
}

View File

@@ -116,7 +116,7 @@ public class MockAsyncContext implements AsyncContext {
@Override
public void complete() {
MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, MockHttpServletRequest.class);
MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(this.request, MockHttpServletRequest.class);
if (mockRequest != null) {
mockRequest.setAsyncStarted(false);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,12 +82,12 @@ public class MockFilterConfig implements FilterConfig {
@Override
public String getFilterName() {
return filterName;
return this.filterName;
}
@Override
public ServletContext getServletContext() {
return servletContext;
return this.servletContext;
}
public void addInitParameter(String name, String value) {

View File

@@ -1285,7 +1285,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
public String changeSessionId() {
Assert.isTrue(this.session != null, "The request does not have a session");
if (this.session instanceof MockHttpSession) {
return ((MockHttpSession) session).changeSessionId();
return ((MockHttpSession) this.session).changeSessionId();
}
return this.session.getId();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -177,7 +177,7 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
* @see JdbcTestUtils#deleteFromTableWhere
*/
protected int deleteFromTableWhere(String tableName, String whereClause, Object... args) {
return JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, tableName, whereClause, args);
return JdbcTestUtils.deleteFromTableWhere(this.jdbcTemplate, tableName, whereClause, args);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -227,10 +227,10 @@ public class SpringClassRule implements TestRule {
@Override
public void evaluate() throws Throwable {
try {
next.evaluate();
this.next.evaluate();
}
finally {
testContextManagerCache.remove(testClass);
testContextManagerCache.remove(this.testClass);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,7 +60,7 @@ public class RunPrepareTestInstanceCallbacks extends Statement {
*/
@Override
public void evaluate() throws Throwable {
this.testContextManager.prepareTestInstance(testInstance);
this.testContextManager.prepareTestInstance(this.testInstance);
this.next.evaluate();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,8 +68,8 @@ public class DefaultBootstrapContext implements BootstrapContext {
@Override
public String toString() {
return new ToStringCreator(this)//
.append("testClass", testClass.getName())//
.append("cacheAwareContextLoaderDelegate", cacheAwareContextLoaderDelegate.getClass().getName())//
.append("testClass", this.testClass.getName())//
.append("cacheAwareContextLoaderDelegate", this.cacheAwareContextLoaderDelegate.getClass().getName())//
.toString();
}

View File

@@ -110,7 +110,7 @@ public class DefaultTestContext implements TestContext {
@SuppressWarnings("resource")
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context;
Assert.state(cac.isActive(), () ->
"The ApplicationContext loaded for [" + mergedContextConfiguration +
"The ApplicationContext loaded for [" + this.mergedContextConfiguration +
"] is not active. This may be due to one of the following reasons: " +
"1) the context was closed programmatically by user code; " +
"2) the context was closed during parallel test execution either " +

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -141,11 +141,11 @@ class TestPropertySourceAttributes {
@Override
public String toString() {
return new ToStringCreator(this)//
.append("declaringClass", declaringClass.getName())//
.append("locations", ObjectUtils.nullSafeToString(locations))//
.append("inheritLocations", inheritLocations)//
.append("properties", ObjectUtils.nullSafeToString(properties))//
.append("inheritProperties", inheritProperties)//
.append("declaringClass", this.declaringClass.getName())//
.append("locations", ObjectUtils.nullSafeToString(this.locations))//
.append("inheritLocations", this.inheritLocations)//
.append("properties", ObjectUtils.nullSafeToString(this.properties))//
.append("inheritProperties", this.inheritProperties)//
.toString();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -161,7 +161,7 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst
* @see JdbcTestUtils#deleteFromTableWhere
*/
protected int deleteFromTableWhere(String tableName, String whereClause, Object... args) {
return JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, tableName, whereClause, args);
return JdbcTestUtils.deleteFromTableWhere(this.jdbcTemplate, tableName, whereClause, args);
}
/**

View File

@@ -106,7 +106,7 @@ class TransactionContext {
if (logger.isInfoEnabled()) {
logger.info(String.format(
"Began transaction (%s) for test context %s; transaction manager [%s]; rollback [%s]",
transactionsStarted, this.testContext, this.transactionManager, flaggedForRollback));
transactionsStarted, this.testContext, this.transactionManager, this.flaggedForRollback));
}
}

View File

@@ -104,12 +104,12 @@ public class XmlExpectationsHelper {
public boolean hasDifferences() {
return diff.hasDifferences();
return this.diff.hasDifferences();
}
@Override
public String toString() {
return diff.toString();
return this.diff.toString();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,7 +85,7 @@ public class MockMvcClientHttpRequestFactory
HttpMethod httpMethod, URI uri, HttpHeaders requestHeaders, byte[] requestBody) {
try {
MockHttpServletResponse servletResponse = mockMvc
MockHttpServletResponse servletResponse = this.mockMvc
.perform(request(httpMethod, uri).content(requestBody).headers(requestHeaders))
.andReturn()
.getResponse();

View File

@@ -231,7 +231,7 @@ public class ContentRequestMatchers {
return request -> {
try {
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
jsonHelper.assertJsonEqual(expectedJsonContent, mockRequest.getBodyAsString(), strict);
this.jsonHelper.assertJsonEqual(expectedJsonContent, mockRequest.getBodyAsString(), strict);
}
catch (Exception ex) {
throw new AssertionError("Failed to parse expected or actual JSON request content", ex);

View File

@@ -218,8 +218,8 @@ class WiretapConnector implements ClientHttpConnector {
@Override
public Flux<DataBuffer> getBody() {
return super.getBody()
.doOnNext(buffer::write)
.doOnError(body::onError)
.doOnNext(this.buffer::write)
.doOnError(this.body::onError)
.doOnCancel(this::handleOnComplete)
.doOnComplete(this::handleOnComplete);
}

View File

@@ -490,7 +490,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
synchronized (HtmlUnitRequestBuilder.this.sessions) {
HtmlUnitRequestBuilder.this.sessions.remove(getId());
}
removeSessionCookie(request, getId());
removeSessionCookie(this.request, getId());
}
}

View File

@@ -63,7 +63,7 @@ final class MockWebResponseBuilder {
public WebResponse build() throws IOException {
WebResponseData webResponseData = webResponseData();
long endTime = System.currentTimeMillis();
return new WebResponse(webResponseData, webRequest, endTime - startTime);
return new WebResponse(webResponseData, this.webRequest, endTime - this.startTime);
}
private WebResponseData webResponseData() throws IOException {

View File

@@ -156,7 +156,7 @@ public class ContentResultMatchers {
public ResultMatcher xml(final String xmlContent) {
return result -> {
String content = result.getResponse().getContentAsString();
xmlHelper.assertXmlEqual(xmlContent, content);
this.xmlHelper.assertXmlEqual(xmlContent, content);
};
}
@@ -167,7 +167,7 @@ public class ContentResultMatchers {
public ResultMatcher node(final Matcher<? super Node> matcher) {
return result -> {
String content = result.getResponse().getContentAsString();
xmlHelper.assertNode(content, matcher);
this.xmlHelper.assertNode(content, matcher);
};
}
@@ -179,7 +179,7 @@ public class ContentResultMatchers {
public ResultMatcher source(final Matcher<? super Source> matcher) {
return result -> {
String content = result.getResponse().getContentAsString();
xmlHelper.assertSource(content, matcher);
this.xmlHelper.assertSource(content, matcher);
};
}
@@ -212,7 +212,7 @@ public class ContentResultMatchers {
public ResultMatcher json(final String jsonContent, final boolean strict) {
return result -> {
String content = result.getResponse().getContentAsString();
jsonHelper.assertJsonEqual(jsonContent, content, strict);
this.jsonHelper.assertJsonEqual(jsonContent, content, strict);
};
}

View File

@@ -84,7 +84,7 @@ public class JsonPathResultMatchers {
* @see #value(Object)
*/
public <T> ResultMatcher value(Matcher<T> matcher) {
return result -> jsonPathHelper.assertValue(getContent(result), matcher);
return result -> this.jsonPathHelper.assertValue(getContent(result), matcher);
}
/**
@@ -98,7 +98,7 @@ public class JsonPathResultMatchers {
* @see #value(Object)
*/
public <T> ResultMatcher value(Matcher<T> matcher, Class<T> targetType) {
return result -> jsonPathHelper.assertValue(getContent(result), matcher, targetType);
return result -> this.jsonPathHelper.assertValue(getContent(result), matcher, targetType);
}
/**
@@ -108,7 +108,7 @@ public class JsonPathResultMatchers {
* @see #value(Matcher, Class)
*/
public ResultMatcher value(Object expectedValue) {
return result -> jsonPathHelper.assertValue(getContent(result), expectedValue);
return result -> this.jsonPathHelper.assertValue(getContent(result), expectedValue);
}
/**
@@ -120,7 +120,7 @@ public class JsonPathResultMatchers {
* <em>empty</em>.
*/
public ResultMatcher exists() {
return result -> jsonPathHelper.exists(getContent(result));
return result -> this.jsonPathHelper.exists(getContent(result));
}
/**
@@ -131,7 +131,7 @@ public class JsonPathResultMatchers {
* <em>empty</em>.
*/
public ResultMatcher doesNotExist() {
return result -> jsonPathHelper.doesNotExist(getContent(result));
return result -> this.jsonPathHelper.doesNotExist(getContent(result));
}
/**
@@ -145,7 +145,7 @@ public class JsonPathResultMatchers {
* @see #doesNotExist()
*/
public ResultMatcher isEmpty() {
return result -> jsonPathHelper.assertValueIsEmpty(getContent(result));
return result -> this.jsonPathHelper.assertValueIsEmpty(getContent(result));
}
/**
@@ -159,7 +159,7 @@ public class JsonPathResultMatchers {
* @see #doesNotExist()
*/
public ResultMatcher isNotEmpty() {
return result -> jsonPathHelper.assertValueIsNotEmpty(getContent(result));
return result -> this.jsonPathHelper.assertValueIsNotEmpty(getContent(result));
}
/**
@@ -173,7 +173,7 @@ public class JsonPathResultMatchers {
* @see #isNotEmpty()
*/
public ResultMatcher hasJsonPath() {
return result -> jsonPathHelper.hasJsonPath(getContent(result));
return result -> this.jsonPathHelper.hasJsonPath(getContent(result));
}
/**
@@ -188,7 +188,7 @@ public class JsonPathResultMatchers {
* @see #isEmpty()
*/
public ResultMatcher doesNotHaveJsonPath() {
return result -> jsonPathHelper.doesNotHaveJsonPath(getContent(result));
return result -> this.jsonPathHelper.doesNotHaveJsonPath(getContent(result));
}
/**
@@ -197,7 +197,7 @@ public class JsonPathResultMatchers {
* @since 4.2.1
*/
public ResultMatcher isString() {
return result -> jsonPathHelper.assertValueIsString(getContent(result));
return result -> this.jsonPathHelper.assertValueIsString(getContent(result));
}
/**
@@ -206,7 +206,7 @@ public class JsonPathResultMatchers {
* @since 4.2.1
*/
public ResultMatcher isBoolean() {
return result -> jsonPathHelper.assertValueIsBoolean(getContent(result));
return result -> this.jsonPathHelper.assertValueIsBoolean(getContent(result));
}
/**
@@ -215,7 +215,7 @@ public class JsonPathResultMatchers {
* @since 4.2.1
*/
public ResultMatcher isNumber() {
return result -> jsonPathHelper.assertValueIsNumber(getContent(result));
return result -> this.jsonPathHelper.assertValueIsNumber(getContent(result));
}
/**
@@ -223,7 +223,7 @@ public class JsonPathResultMatchers {
* assert that the result is an array.
*/
public ResultMatcher isArray() {
return result -> jsonPathHelper.assertValueIsArray(getContent(result));
return result -> this.jsonPathHelper.assertValueIsArray(getContent(result));
}
/**
@@ -232,7 +232,7 @@ public class JsonPathResultMatchers {
* @since 4.2.1
*/
public ResultMatcher isMap() {
return result -> jsonPathHelper.assertValueIsMap(getContent(result));
return result -> this.jsonPathHelper.assertValueIsMap(getContent(result));
}
private String getContent(MvcResult result) throws UnsupportedEncodingException {

View File

@@ -64,7 +64,7 @@ public class XpathResultMatchers {
public ResultMatcher node(final Matcher<? super Node> matcher) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNode(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
this.xpathHelper.assertNode(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
};
}
@@ -82,7 +82,7 @@ public class XpathResultMatchers {
public ResultMatcher exists() {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.exists(response.getContentAsByteArray(), getDefinedEncoding(response));
this.xpathHelper.exists(response.getContentAsByteArray(), getDefinedEncoding(response));
};
}
@@ -92,7 +92,7 @@ public class XpathResultMatchers {
public ResultMatcher doesNotExist() {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.doesNotExist(response.getContentAsByteArray(), getDefinedEncoding(response));
this.xpathHelper.doesNotExist(response.getContentAsByteArray(), getDefinedEncoding(response));
};
}
@@ -103,7 +103,7 @@ public class XpathResultMatchers {
public ResultMatcher nodeCount(final Matcher<Integer> matcher) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
this.xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
};
}
@@ -113,7 +113,7 @@ public class XpathResultMatchers {
public ResultMatcher nodeCount(final int expectedCount) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), expectedCount);
this.xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), expectedCount);
};
}
@@ -124,7 +124,7 @@ public class XpathResultMatchers {
public ResultMatcher string(final Matcher<? super String> matcher) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
this.xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
};
}
@@ -134,7 +134,7 @@ public class XpathResultMatchers {
public ResultMatcher string(final String expectedValue) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue);
this.xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue);
};
}
@@ -145,7 +145,7 @@ public class XpathResultMatchers {
public ResultMatcher number(final Matcher<? super Double> matcher) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
this.xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
};
}
@@ -155,7 +155,7 @@ public class XpathResultMatchers {
public ResultMatcher number(final Double expectedValue) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue);
this.xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue);
};
}
@@ -165,7 +165,7 @@ public class XpathResultMatchers {
public ResultMatcher booleanValue(final Boolean value) {
return result -> {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertBoolean(response.getContentAsByteArray(), getDefinedEncoding(response), value);
this.xpathHelper.assertBoolean(response.getContentAsByteArray(), getDefinedEncoding(response), value);
};
}