Always use 'this.' when accessing fields
Apply an Eclipse cleanup rules to ensure that fields are always accessed using `this.`. This aligns with the style used by Spring Framework and helps users quickly see the difference between a local and member variable. Issue gh-8945
This commit is contained in:
@@ -45,64 +45,65 @@ public class JndiDnsResolverTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
contextFactory = mock(InitialContextFactory.class);
|
||||
context = mock(DirContext.class);
|
||||
dnsResolver = new JndiDnsResolver();
|
||||
dnsResolver.setCtxFactory(contextFactory);
|
||||
when(contextFactory.getCtx()).thenReturn(context);
|
||||
this.contextFactory = mock(InitialContextFactory.class);
|
||||
this.context = mock(DirContext.class);
|
||||
this.dnsResolver = new JndiDnsResolver();
|
||||
this.dnsResolver.setCtxFactory(this.contextFactory);
|
||||
when(this.contextFactory.getCtx()).thenReturn(this.context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveIpAddress() throws Exception {
|
||||
Attributes records = new BasicAttributes("A", "63.246.7.80");
|
||||
|
||||
when(context.getAttributes("www.springsource.com", new String[] { "A" })).thenReturn(records);
|
||||
when(this.context.getAttributes("www.springsource.com", new String[] { "A" })).thenReturn(records);
|
||||
|
||||
String ipAddress = dnsResolver.resolveIpAddress("www.springsource.com");
|
||||
String ipAddress = this.dnsResolver.resolveIpAddress("www.springsource.com");
|
||||
assertThat(ipAddress).isEqualTo("63.246.7.80");
|
||||
}
|
||||
|
||||
@Test(expected = DnsEntryNotFoundException.class)
|
||||
public void testResolveIpAddressNotExisting() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class)))
|
||||
when(this.context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NameNotFoundException("not found"));
|
||||
|
||||
dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
|
||||
this.dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveServiceEntry() throws Exception {
|
||||
BasicAttributes records = createSrvRecords();
|
||||
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(records);
|
||||
when(this.context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(records);
|
||||
|
||||
String hostname = dnsResolver.resolveServiceEntry("ldap", "springsource.com");
|
||||
String hostname = this.dnsResolver.resolveServiceEntry("ldap", "springsource.com");
|
||||
assertThat(hostname).isEqualTo("kdc.springsource.com");
|
||||
}
|
||||
|
||||
@Test(expected = DnsEntryNotFoundException.class)
|
||||
public void testResolveServiceEntryNotExisting() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class)))
|
||||
when(this.context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NameNotFoundException("not found"));
|
||||
|
||||
dnsResolver.resolveServiceEntry("wrong", "secpod.de");
|
||||
this.dnsResolver.resolveServiceEntry("wrong", "secpod.de");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveServiceIpAddress() throws Exception {
|
||||
BasicAttributes srvRecords = createSrvRecords();
|
||||
BasicAttributes aRecords = new BasicAttributes("A", "63.246.7.80");
|
||||
when(context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(srvRecords);
|
||||
when(context.getAttributes("kdc.springsource.com", new String[] { "A" })).thenReturn(aRecords);
|
||||
when(this.context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).thenReturn(srvRecords);
|
||||
when(this.context.getAttributes("kdc.springsource.com", new String[] { "A" })).thenReturn(aRecords);
|
||||
|
||||
String ipAddress = dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
|
||||
String ipAddress = this.dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
|
||||
assertThat(ipAddress).isEqualTo("63.246.7.80");
|
||||
}
|
||||
|
||||
@Test(expected = DnsLookupException.class)
|
||||
public void testUnknowError() throws Exception {
|
||||
when(context.getAttributes(any(String.class), any(String[].class))).thenThrow(new NamingException("error"));
|
||||
dnsResolver.resolveIpAddress("");
|
||||
when(this.context.getAttributes(any(String.class), any(String[].class)))
|
||||
.thenThrow(new NamingException("error"));
|
||||
this.dnsResolver.resolveIpAddress("");
|
||||
}
|
||||
|
||||
private BasicAttributes createSrvRecords() {
|
||||
|
||||
@@ -111,11 +111,11 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
|
||||
}
|
||||
|
||||
public String getRequestProperty(String key) {
|
||||
return requestProperties.get(key);
|
||||
return this.requestProperties.get(key);
|
||||
}
|
||||
|
||||
public void setRequestProperty(String key, String value) {
|
||||
requestProperties.put(key, value);
|
||||
this.requestProperties.put(key, value);
|
||||
}
|
||||
|
||||
public boolean usingProxy() {
|
||||
|
||||
Reference in New Issue
Block a user