1
0
mirror of synced 2026-05-22 13:23:17 +00:00

Remove blank lines from all tests

Remove all blank lines from test code so that test methods are
visually grouped together. This generally helps to make the test
classes easer to scan, however, the "given" / "when" / "then"
blocks used by some tests are now not as easy to discern.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-08-01 19:33:21 -07:00
committed by Rob Winch
parent 5bdd757108
commit a5aa6b3d7f
787 changed files with 9 additions and 10241 deletions
@@ -55,9 +55,7 @@ public class JndiDnsResolverTests {
@Test
public void testResolveIpAddress() throws Exception {
Attributes records = new BasicAttributes("A", "63.246.7.80");
given(this.context.getAttributes("www.springsource.com", new String[] { "A" })).willReturn(records);
String ipAddress = this.dnsResolver.resolveIpAddress("www.springsource.com");
assertThat(ipAddress).isEqualTo("63.246.7.80");
}
@@ -66,16 +64,13 @@ public class JndiDnsResolverTests {
public void testResolveIpAddressNotExisting() throws Exception {
given(this.context.getAttributes(any(String.class), any(String[].class)))
.willThrow(new NameNotFoundException("not found"));
this.dnsResolver.resolveIpAddress("notexisting.ansdansdugiuzgguzgioansdiandwq.foo");
}
@Test
public void testResolveServiceEntry() throws Exception {
BasicAttributes records = createSrvRecords();
given(this.context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).willReturn(records);
String hostname = this.dnsResolver.resolveServiceEntry("ldap", "springsource.com");
assertThat(hostname).isEqualTo("kdc.springsource.com");
}
@@ -84,7 +79,6 @@ public class JndiDnsResolverTests {
public void testResolveServiceEntryNotExisting() throws Exception {
given(this.context.getAttributes(any(String.class), any(String[].class)))
.willThrow(new NameNotFoundException("not found"));
this.dnsResolver.resolveServiceEntry("wrong", "secpod.de");
}
@@ -94,7 +88,6 @@ public class JndiDnsResolverTests {
BasicAttributes aRecords = new BasicAttributes("A", "63.246.7.80");
given(this.context.getAttributes("_ldap._tcp.springsource.com", new String[] { "SRV" })).willReturn(srvRecords);
given(this.context.getAttributes("kdc.springsource.com", new String[] { "A" })).willReturn(aRecords);
String ipAddress = this.dnsResolver.resolveServiceIpAddress("ldap", "springsource.com");
assertThat(ipAddress).isEqualTo("63.246.7.80");
}
@@ -50,13 +50,11 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("Aladdin", "open sesame");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
// Create a connection and ensure our executor sets its
// properties correctly
AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
HttpURLConnection conn = new MockHttpURLConnection(new URL("https://localhost/"));
executor.prepareConnection(conn, 10);
// Check connection properties
// See https://tools.ietf.org/html/rfc1945 section 11.1 for example
// we are comparing against
@@ -66,13 +64,11 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
@Test
public void testNullContextHolderIsNull() throws Exception {
SecurityContextHolder.getContext().setAuthentication(null);
// Create a connection and ensure our executor sets its
// properties correctly
AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
HttpURLConnection conn = new MockHttpURLConnection(new URL("https://localhost/"));
executor.prepareConnection(conn, 10);
// Check connection properties (shouldn't be an Authorization header)
assertThat(conn.getRequestProperty("Authorization")).isNull();
}
@@ -83,13 +79,11 @@ public class AuthenticationSimpleHttpInvokerRequestExecutorTests {
AnonymousAuthenticationToken anonymous = new AnonymousAuthenticationToken("key", "principal",
AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
SecurityContextHolder.getContext().setAuthentication(anonymous);
// Create a connection and ensure our executor sets its
// properties correctly
AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
HttpURLConnection conn = new MockHttpURLConnection(new URL("https://localhost/"));
executor.prepareConnection(conn, 10);
// Check connection properties (shouldn't be an Authorization header)
assertThat(conn.getRequestProperty("Authorization")).isNull();
}
@@ -49,9 +49,7 @@ public class ContextPropagatingRemoteInvocationTests {
Class<TargetObject> clazz = TargetObject.class;
Method method = clazz.getMethod("makeLowerCase", new Class[] { String.class });
MethodInvocation mi = new SimpleMethodInvocation(new TargetObject(), method, "SOME_STRING");
ContextPropagatingRemoteInvocationFactory factory = new ContextPropagatingRemoteInvocationFactory();
return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
}
@@ -60,9 +58,7 @@ public class ContextPropagatingRemoteInvocationTests {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
try {
// Set up the wrong arguments.
remoteInvocation.setArguments(new Object[] {});
@@ -72,7 +68,6 @@ public class ContextPropagatingRemoteInvocationTests {
catch (IllegalArgumentException ex) {
// expected
}
assertThat(SecurityContextHolder.getContext().getAuthentication())
.withFailMessage("Authentication must be null").isNull();
}
@@ -82,14 +77,11 @@ public class ContextPropagatingRemoteInvocationTests {
// Setup client-side context
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
// Set to null, as ContextPropagatingRemoteInvocation already obtained
// a copy and nulling is necessary to ensure the Context delivered by
// ContextPropagatingRemoteInvocation is used on server-side
SecurityContextHolder.clearContext();
// The result from invoking the TargetObject should contain the
// Authentication class delivered via the SecurityContextHolder
assertThat(remoteInvocation.invoke(new TargetObject())).isEqualTo(
@@ -99,11 +91,9 @@ public class ContextPropagatingRemoteInvocationTests {
@Test
public void testNullContextHolderDoesNotCauseInvocationProblems() throws Exception {
SecurityContextHolder.clearContext(); // just to be explicit
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
SecurityContextHolder.clearContext(); // unnecessary, but for
// explicitness
assertThat(remoteInvocation.invoke(new TargetObject())).isEqualTo("some_string Authentication empty");
}
@@ -112,7 +102,6 @@ public class ContextPropagatingRemoteInvocationTests {
public void testNullCredentials() throws Exception {
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", null);
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
assertThat(ReflectionTestUtils.getField(remoteInvocation, "credentials")).isNull();
}