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:
@@ -32,17 +32,12 @@ public class TldTests {
|
||||
@Test
|
||||
public void testTldVersionIsCorrect() throws Exception {
|
||||
String SPRING_SECURITY_VERSION = "springSecurityVersion";
|
||||
|
||||
String version = System.getProperty(SPRING_SECURITY_VERSION);
|
||||
|
||||
File securityTld = new File("src/main/resources/META-INF/security.tld");
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(securityTld);
|
||||
|
||||
String tlibVersion = document.getElementsByTagName("tlib-version").item(0).getTextContent();
|
||||
|
||||
assertThat(version).startsWith(tlibVersion);
|
||||
}
|
||||
|
||||
|
||||
-5
@@ -78,9 +78,7 @@ public class AbstractAuthorizeTagTests {
|
||||
WebInvocationPrivilegeEvaluator expected = mock(WebInvocationPrivilegeEvaluator.class);
|
||||
this.tag.setUrl(uri);
|
||||
this.request.setAttribute(WebAttributes.WEB_INVOCATION_PRIVILEGE_EVALUATOR_ATTRIBUTE, expected);
|
||||
|
||||
this.tag.authorizeUsingUrlCheck();
|
||||
|
||||
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any());
|
||||
}
|
||||
|
||||
@@ -93,9 +91,7 @@ public class AbstractAuthorizeTagTests {
|
||||
given(wac.getBeansOfType(WebInvocationPrivilegeEvaluator.class))
|
||||
.willReturn(Collections.singletonMap("wipe", expected));
|
||||
this.servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
|
||||
|
||||
this.tag.authorizeUsingUrlCheck();
|
||||
|
||||
verify(expected).isAllowed(eq(""), eq(uri), eq("GET"), any());
|
||||
}
|
||||
|
||||
@@ -109,7 +105,6 @@ public class AbstractAuthorizeTagTests {
|
||||
given(wac.getBeansOfType(SecurityExpressionHandler.class))
|
||||
.willReturn(Collections.<String, SecurityExpressionHandler>singletonMap("wipe", expected));
|
||||
this.servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
|
||||
|
||||
assertThat(this.tag.authorize()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
-16
@@ -64,13 +64,10 @@ public class AccessControlListTagTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.bob);
|
||||
this.tag = new AccessControlListTag();
|
||||
WebApplicationContext ctx = mock(WebApplicationContext.class);
|
||||
|
||||
this.pe = mock(PermissionEvaluator.class);
|
||||
|
||||
Map beanMap = new HashMap();
|
||||
beanMap.put("pe", this.pe);
|
||||
given(ctx.getBeansOfType(PermissionEvaluator.class)).willReturn(beanMap);
|
||||
|
||||
MockServletContext servletCtx = new MockServletContext();
|
||||
servletCtx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
|
||||
this.pageContext = new MockPageContext(servletCtx, new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||
@@ -86,13 +83,11 @@ public class AccessControlListTagTests {
|
||||
public void bodyIsEvaluatedIfAclGrantsAccess() throws Exception {
|
||||
Object domainObject = new Object();
|
||||
given(this.pe.hasPermission(this.bob, domainObject, "READ")).willReturn(true);
|
||||
|
||||
this.tag.setDomainObject(domainObject);
|
||||
this.tag.setHasPermission("READ");
|
||||
this.tag.setVar("allowed");
|
||||
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(this.tag.getHasPermission()).isEqualTo("READ");
|
||||
|
||||
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
|
||||
}
|
||||
@@ -104,16 +99,13 @@ public class AccessControlListTagTests {
|
||||
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||
servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||
servletContext.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
|
||||
|
||||
Object domainObject = new Object();
|
||||
given(this.pe.hasPermission(this.bob, domainObject, "READ")).willReturn(true);
|
||||
|
||||
this.tag.setDomainObject(domainObject);
|
||||
this.tag.setHasPermission("READ");
|
||||
this.tag.setVar("allowed");
|
||||
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(this.tag.getHasPermission()).isEqualTo("READ");
|
||||
|
||||
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
|
||||
}
|
||||
@@ -124,13 +116,11 @@ public class AccessControlListTagTests {
|
||||
Object domainObject = new Object();
|
||||
given(this.pe.hasPermission(this.bob, domainObject, "READ")).willReturn(true);
|
||||
given(this.pe.hasPermission(this.bob, domainObject, "WRITE")).willReturn(true);
|
||||
|
||||
this.tag.setDomainObject(domainObject);
|
||||
this.tag.setHasPermission("READ,WRITE");
|
||||
this.tag.setVar("allowed");
|
||||
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(this.tag.getHasPermission()).isEqualTo("READ,WRITE");
|
||||
|
||||
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
|
||||
verify(this.pe).hasPermission(this.bob, domainObject, "READ");
|
||||
@@ -144,13 +134,11 @@ public class AccessControlListTagTests {
|
||||
Object domainObject = new Object();
|
||||
given(this.pe.hasPermission(this.bob, domainObject, 1)).willReturn(true);
|
||||
given(this.pe.hasPermission(this.bob, domainObject, 2)).willReturn(true);
|
||||
|
||||
this.tag.setDomainObject(domainObject);
|
||||
this.tag.setHasPermission("1,2");
|
||||
this.tag.setVar("allowed");
|
||||
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(this.tag.getHasPermission()).isEqualTo("1,2");
|
||||
|
||||
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
|
||||
verify(this.pe).hasPermission(this.bob, domainObject, 1);
|
||||
@@ -163,13 +151,11 @@ public class AccessControlListTagTests {
|
||||
Object domainObject = new Object();
|
||||
given(this.pe.hasPermission(this.bob, domainObject, 1)).willReturn(true);
|
||||
given(this.pe.hasPermission(this.bob, domainObject, "WRITE")).willReturn(true);
|
||||
|
||||
this.tag.setDomainObject(domainObject);
|
||||
this.tag.setHasPermission("1,WRITE");
|
||||
this.tag.setVar("allowed");
|
||||
assertThat(this.tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(this.tag.getHasPermission()).isEqualTo("1,WRITE");
|
||||
|
||||
assertThat(this.tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isTrue();
|
||||
verify(this.pe).hasPermission(this.bob, domainObject, 1);
|
||||
@@ -181,11 +167,9 @@ public class AccessControlListTagTests {
|
||||
public void bodyIsSkippedIfAclDeniesAccess() throws Exception {
|
||||
Object domainObject = new Object();
|
||||
given(this.pe.hasPermission(this.bob, domainObject, "READ")).willReturn(false);
|
||||
|
||||
this.tag.setDomainObject(domainObject);
|
||||
this.tag.setHasPermission("READ");
|
||||
this.tag.setVar("allowed");
|
||||
|
||||
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat((Boolean) this.pageContext.getAttribute("allowed")).isFalse();
|
||||
}
|
||||
|
||||
-6
@@ -52,7 +52,6 @@ public class AuthenticationTagTests {
|
||||
@Test
|
||||
public void testOperationWhenPrincipalIsAUserDetailsInstance() throws JspException {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.auth);
|
||||
|
||||
this.authenticationTag.setProperty("name");
|
||||
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
@@ -63,7 +62,6 @@ public class AuthenticationTagTests {
|
||||
public void testOperationWhenPrincipalIsAString() throws JspException {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("rodAsString", "koala", AuthorityUtils.NO_AUTHORITIES));
|
||||
|
||||
this.authenticationTag.setProperty("principal");
|
||||
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
@@ -73,7 +71,6 @@ public class AuthenticationTagTests {
|
||||
@Test
|
||||
public void testNestedPropertyIsReadCorrectly() throws JspException {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.auth);
|
||||
|
||||
this.authenticationTag.setProperty("principal.username");
|
||||
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
@@ -84,7 +81,6 @@ public class AuthenticationTagTests {
|
||||
public void testOperationWhenPrincipalIsNull() throws JspException {
|
||||
SecurityContextHolder.getContext()
|
||||
.setAuthentication(new TestingAuthenticationToken(null, "koala", AuthorityUtils.NO_AUTHORITIES));
|
||||
|
||||
this.authenticationTag.setProperty("principal");
|
||||
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
@@ -93,7 +89,6 @@ public class AuthenticationTagTests {
|
||||
@Test
|
||||
public void testOperationWhenSecurityContextIsNull() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
|
||||
this.authenticationTag.setProperty("principal");
|
||||
assertThat(this.authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(this.authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
@@ -111,7 +106,6 @@ public class AuthenticationTagTests {
|
||||
public void testThrowsExceptionForUnrecognisedProperty() {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.auth);
|
||||
this.authenticationTag.setProperty("qsq");
|
||||
|
||||
try {
|
||||
this.authenticationTag.doStartTag();
|
||||
this.authenticationTag.doEndTag();
|
||||
|
||||
-4
@@ -66,11 +66,9 @@ public class AuthorizeTagTests {
|
||||
public void setUp() {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.currentUser);
|
||||
StaticWebApplicationContext ctx = new StaticWebApplicationContext();
|
||||
|
||||
BeanDefinitionBuilder webExpressionHandler = BeanDefinitionBuilder
|
||||
.rootBeanDefinition(DefaultWebSecurityExpressionHandler.class);
|
||||
webExpressionHandler.addPropertyValue("permissionEvaluator", this.permissionEvaluator);
|
||||
|
||||
ctx.registerBeanDefinition("expressionHandler", webExpressionHandler.getBeanDefinition());
|
||||
ctx.registerSingleton("wipe", MockWebInvocationPrivilegeEvaluator.class);
|
||||
MockServletContext servletCtx = new MockServletContext();
|
||||
@@ -85,14 +83,12 @@ public class AuthorizeTagTests {
|
||||
}
|
||||
|
||||
// access attribute tests
|
||||
|
||||
@Test
|
||||
public void taglibsDocumentationHasPermissionOr() throws Exception {
|
||||
Object domain = new Object();
|
||||
this.request.setAttribute("domain", domain);
|
||||
this.authorizeTag.setAccess("hasPermission(#domain,'read') or hasPermission(#domain,'write')");
|
||||
given(this.permissionEvaluator.hasPermission(eq(this.currentUser), eq(domain), anyString())).willReturn(true);
|
||||
|
||||
assertThat(this.authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
}
|
||||
|
||||
|
||||
-11
@@ -56,11 +56,8 @@ public class AbstractCsrfTagTests {
|
||||
|
||||
@Test
|
||||
public void noCsrfDoesNotRender() throws JspException, UnsupportedEncodingException {
|
||||
|
||||
this.tag.handleReturn = "shouldNotBeRendered";
|
||||
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(Tag.EVAL_PAGE);
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.")
|
||||
.isEqualTo("");
|
||||
@@ -68,14 +65,10 @@ public class AbstractCsrfTagTests {
|
||||
|
||||
@Test
|
||||
public void hasCsrfRendersReturnedValue() throws JspException, UnsupportedEncodingException {
|
||||
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
this.request.setAttribute(CsrfToken.class.getName(), token);
|
||||
|
||||
this.tag.handleReturn = "fooBarBazQux";
|
||||
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(Tag.EVAL_PAGE);
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.")
|
||||
.isEqualTo("fooBarBazQux");
|
||||
@@ -84,14 +77,10 @@ public class AbstractCsrfTagTests {
|
||||
|
||||
@Test
|
||||
public void hasCsrfRendersDifferentValue() throws JspException, UnsupportedEncodingException {
|
||||
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
this.request.setAttribute(CsrfToken.class.getName(), token);
|
||||
|
||||
this.tag.handleReturn = "<input type=\"hidden\" />";
|
||||
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(Tag.EVAL_PAGE);
|
||||
assertThat(this.response.getContentAsString()).withFailMessage("The output value is not correct.")
|
||||
.isEqualTo("<input type=\"hidden\" />");
|
||||
|
||||
@@ -39,9 +39,7 @@ public class CsrfInputTagTests {
|
||||
@Test
|
||||
public void handleTokenReturnsHiddenInput() {
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<input type=\"hidden\" name=\"_csrf\" value=\"abc123def456ghi789\" />");
|
||||
@@ -50,9 +48,7 @@ public class CsrfInputTagTests {
|
||||
@Test
|
||||
public void handleTokenReturnsHiddenInputDifferentTokenValue() {
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "csrfParameter", "fooBarBazQux");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<input type=\"hidden\" name=\"csrfParameter\" value=\"fooBarBazQux\" />");
|
||||
|
||||
-4
@@ -39,9 +39,7 @@ public class CsrfMetaTagsTagTests {
|
||||
@Test
|
||||
public void handleTokenRendersTags() {
|
||||
CsrfToken token = new DefaultCsrfToken("X-Csrf-Token", "_csrf", "abc123def456ghi789");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<meta name=\"_csrf_parameter\" content=\"_csrf\" />"
|
||||
@@ -52,9 +50,7 @@ public class CsrfMetaTagsTagTests {
|
||||
@Test
|
||||
public void handleTokenRendersTagsDifferentToken() {
|
||||
CsrfToken token = new DefaultCsrfToken("csrfHeader", "csrfParameter", "fooBarBazQux");
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertThat(value).withFailMessage("The output is not correct.")
|
||||
.isEqualTo("<meta name=\"_csrf_parameter\" content=\"csrfParameter\" />"
|
||||
|
||||
Reference in New Issue
Block a user