Start AssertJ Migration
Issue gh-3175
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.taglibs.authz;
|
||||
|
||||
import static org.fest.assertions.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
|
||||
+23
-23
@@ -12,7 +12,7 @@
|
||||
*/
|
||||
package org.springframework.security.taglibs.authz;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.*;
|
||||
@@ -77,11 +77,11 @@ public class AccessControlListTagTests {
|
||||
tag.setDomainObject(domainObject);
|
||||
tag.setHasPermission("READ");
|
||||
tag.setVar("allowed");
|
||||
assertSame(domainObject, tag.getDomainObject());
|
||||
assertEquals("READ", tag.getHasPermission());
|
||||
assertThat(tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(tag.getHasPermission()).isEqualTo("READ");
|
||||
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
|
||||
assertTrue((Boolean) pageContext.getAttribute("allowed"));
|
||||
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,11 +98,11 @@ public class AccessControlListTagTests {
|
||||
tag.setDomainObject(domainObject);
|
||||
tag.setHasPermission("READ");
|
||||
tag.setVar("allowed");
|
||||
assertSame(domainObject, tag.getDomainObject());
|
||||
assertEquals("READ", tag.getHasPermission());
|
||||
assertThat(tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(tag.getHasPermission()).isEqualTo("READ");
|
||||
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
|
||||
assertTrue((Boolean) pageContext.getAttribute("allowed"));
|
||||
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
|
||||
}
|
||||
|
||||
// SEC-2022
|
||||
@@ -115,11 +115,11 @@ public class AccessControlListTagTests {
|
||||
tag.setDomainObject(domainObject);
|
||||
tag.setHasPermission("READ,WRITE");
|
||||
tag.setVar("allowed");
|
||||
assertSame(domainObject, tag.getDomainObject());
|
||||
assertEquals("READ,WRITE", tag.getHasPermission());
|
||||
assertThat(tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(tag.getHasPermission()).isEqualTo("READ,WRITE");
|
||||
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
|
||||
assertTrue((Boolean) pageContext.getAttribute("allowed"));
|
||||
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
|
||||
verify(pe).hasPermission(bob, domainObject, "READ");
|
||||
verify(pe).hasPermission(bob, domainObject, "WRITE");
|
||||
verifyNoMoreInteractions(pe);
|
||||
@@ -135,11 +135,11 @@ public class AccessControlListTagTests {
|
||||
tag.setDomainObject(domainObject);
|
||||
tag.setHasPermission("1,2");
|
||||
tag.setVar("allowed");
|
||||
assertSame(domainObject, tag.getDomainObject());
|
||||
assertEquals("1,2", tag.getHasPermission());
|
||||
assertThat(tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(tag.getHasPermission()).isEqualTo("1,2");
|
||||
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
|
||||
assertTrue((Boolean) pageContext.getAttribute("allowed"));
|
||||
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
|
||||
verify(pe).hasPermission(bob, domainObject, 1);
|
||||
verify(pe).hasPermission(bob, domainObject, 2);
|
||||
verifyNoMoreInteractions(pe);
|
||||
@@ -154,11 +154,11 @@ public class AccessControlListTagTests {
|
||||
tag.setDomainObject(domainObject);
|
||||
tag.setHasPermission("1,WRITE");
|
||||
tag.setVar("allowed");
|
||||
assertSame(domainObject, tag.getDomainObject());
|
||||
assertEquals("1,WRITE", tag.getHasPermission());
|
||||
assertThat(tag.getDomainObject()).isSameAs(domainObject);
|
||||
assertThat(tag.getHasPermission()).isEqualTo("1,WRITE");
|
||||
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, tag.doStartTag());
|
||||
assertTrue((Boolean) pageContext.getAttribute("allowed"));
|
||||
assertThat(tag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
assertThat((Boolean) pageContext.getAttribute("allowed")).isTrue();
|
||||
verify(pe).hasPermission(bob, domainObject, 1);
|
||||
verify(pe).hasPermission(bob, domainObject, "WRITE");
|
||||
verifyNoMoreInteractions(pe);
|
||||
@@ -173,7 +173,7 @@ public class AccessControlListTagTests {
|
||||
tag.setHasPermission("READ");
|
||||
tag.setVar("allowed");
|
||||
|
||||
assertEquals(Tag.SKIP_BODY, tag.doStartTag());
|
||||
assertFalse((Boolean) pageContext.getAttribute("allowed"));
|
||||
assertThat(tag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat((Boolean) pageContext.getAttribute("allowed")).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
+19
-19
@@ -15,7 +15,7 @@
|
||||
|
||||
package org.springframework.security.taglibs.authz;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
@@ -55,9 +55,9 @@ public class AuthenticationTagTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
authenticationTag.setProperty("name");
|
||||
assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
|
||||
assertEquals(Tag.EVAL_PAGE, authenticationTag.doEndTag());
|
||||
assertEquals("rodUserDetails", authenticationTag.getLastMessage());
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
assertThat(authenticationTag.getLastMessage()).isEqualTo("rodUserDetails");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,9 +67,9 @@ public class AuthenticationTagTests {
|
||||
AuthorityUtils.NO_AUTHORITIES));
|
||||
|
||||
authenticationTag.setProperty("principal");
|
||||
assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
|
||||
assertEquals(Tag.EVAL_PAGE, authenticationTag.doEndTag());
|
||||
assertEquals("rodAsString", authenticationTag.getLastMessage());
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
assertThat(authenticationTag.getLastMessage()).isEqualTo("rodAsString");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,9 +77,9 @@ public class AuthenticationTagTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
authenticationTag.setProperty("principal.username");
|
||||
assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
|
||||
assertEquals(Tag.EVAL_PAGE, authenticationTag.doEndTag());
|
||||
assertEquals("rodUserDetails", authenticationTag.getLastMessage());
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
assertThat(authenticationTag.getLastMessage()).isEqualTo("rodUserDetails");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,8 +89,8 @@ public class AuthenticationTagTests {
|
||||
AuthorityUtils.NO_AUTHORITIES));
|
||||
|
||||
authenticationTag.setProperty("principal");
|
||||
assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
|
||||
assertEquals(Tag.EVAL_PAGE, authenticationTag.doEndTag());
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,16 +98,16 @@ public class AuthenticationTagTests {
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
|
||||
authenticationTag.setProperty("principal");
|
||||
assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
|
||||
assertEquals(Tag.EVAL_PAGE, authenticationTag.doEndTag());
|
||||
assertEquals(null, authenticationTag.getLastMessage());
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
assertThat(authenticationTag.getLastMessage()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipsBodyIfNullOrEmptyOperation() throws Exception {
|
||||
authenticationTag.setProperty("");
|
||||
assertEquals(Tag.SKIP_BODY, authenticationTag.doStartTag());
|
||||
assertEquals(Tag.EVAL_PAGE, authenticationTag.doEndTag());
|
||||
assertThat(authenticationTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
assertThat(authenticationTag.doEndTag()).isEqualTo(Tag.EVAL_PAGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,7 +131,7 @@ public class AuthenticationTagTests {
|
||||
authenticationTag.setProperty("name");
|
||||
authenticationTag.doStartTag();
|
||||
authenticationTag.doEndTag();
|
||||
assertEquals("<>& ", authenticationTag.getLastMessage());
|
||||
assertThat(authenticationTag.getLastMessage()).isEqualTo("<>& ");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,7 +142,7 @@ public class AuthenticationTagTests {
|
||||
authenticationTag.setHtmlEscape("false");
|
||||
authenticationTag.doStartTag();
|
||||
authenticationTag.doEndTag();
|
||||
assertEquals("<>& ", authenticationTag.getLastMessage());
|
||||
assertThat(authenticationTag.getLastMessage()).isEqualTo("<>& ");
|
||||
}
|
||||
|
||||
// ~ Inner Classes
|
||||
|
||||
+10
-10
@@ -16,7 +16,7 @@
|
||||
package org.springframework.security.taglibs.authz;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
@@ -96,33 +96,33 @@ public class AuthorizeTagTests {
|
||||
when(permissionEvaluator.hasPermission(eq(currentUser), eq(domain), anyString()))
|
||||
.thenReturn(true);
|
||||
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipsBodyIfNoAuthenticationPresent() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
authorizeTag.setAccess("permitAll");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipsBodyIfAccessExpressionDeniesAccess() throws Exception {
|
||||
authorizeTag.setAccess("denyAll");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void showsBodyIfAccessExpressionAllowsAccess() throws Exception {
|
||||
authorizeTag.setAccess("permitAll");
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestAttributeIsResolvedAsElVariable() throws JspException {
|
||||
request.setAttribute("blah", "blah");
|
||||
authorizeTag.setAccess("#blah == 'blah'");
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
}
|
||||
|
||||
// url attribute tests
|
||||
@@ -130,27 +130,27 @@ public class AuthorizeTagTests {
|
||||
public void skipsBodyWithUrlSetIfNoAuthenticationPresent() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
authorizeTag.setUrl("/something");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipsBodyIfUrlIsNotAllowed() throws Exception {
|
||||
authorizeTag.setUrl("/notallowed");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evaluatesBodyIfUrlIsAllowed() throws Exception {
|
||||
authorizeTag.setUrl("/allowed");
|
||||
authorizeTag.setMethod("GET");
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.EVAL_BODY_INCLUDE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skipsBodyIfMethodIsNotAllowed() throws Exception {
|
||||
authorizeTag.setUrl("/allowed");
|
||||
authorizeTag.setMethod("POST");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
assertThat(authorizeTag.doStartTag()).isEqualTo(Tag.SKIP_BODY);
|
||||
}
|
||||
|
||||
public static class MockWebInvocationPrivilegeEvaluator implements
|
||||
|
||||
+6
-6
@@ -14,7 +14,7 @@ import javax.servlet.jsp.tagext.TagSupport;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Nick Williams
|
||||
@@ -43,7 +43,7 @@ public class AbstractCsrfTagTests {
|
||||
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertEquals("The returned value is not correct.", TagSupport.EVAL_PAGE, returned);
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(TagSupport.EVAL_PAGE);
|
||||
assertEquals("The output value is not correct.", "",
|
||||
this.response.getContentAsString());
|
||||
}
|
||||
@@ -60,10 +60,10 @@ public class AbstractCsrfTagTests {
|
||||
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertEquals("The returned value is not correct.", TagSupport.EVAL_PAGE, returned);
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(TagSupport.EVAL_PAGE);
|
||||
assertEquals("The output value is not correct.", "fooBarBazQux",
|
||||
this.response.getContentAsString());
|
||||
assertSame("The token is not correct.", token, this.tag.token);
|
||||
assertThat(this.tag.token).as("The token is not correct.").isSameAs(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,10 +78,10 @@ public class AbstractCsrfTagTests {
|
||||
|
||||
int returned = this.tag.doEndTag();
|
||||
|
||||
assertEquals("The returned value is not correct.", TagSupport.EVAL_PAGE, returned);
|
||||
assertThat(returned).as("The returned value is not correct.").isEqualTo(TagSupport.EVAL_PAGE);
|
||||
assertEquals("The output value is not correct.", "<input type=\"hidden\" />",
|
||||
this.response.getContentAsString());
|
||||
assertSame("The token is not correct.", token, this.tag.token);
|
||||
assertThat(this.tag.token).as("The token is not correct.").isSameAs(token);
|
||||
}
|
||||
|
||||
private static class MockTag extends AbstractCsrfTag {
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import org.springframework.security.web.csrf.CsrfToken;
|
||||
import org.springframework.security.web.csrf.DefaultCsrfToken;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Nick Williams
|
||||
@@ -26,7 +26,7 @@ public class CsrfInputTagTests {
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertNotNull("The returned value should not be null.", value);
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertEquals("The output is not correct.",
|
||||
"<input type=\"hidden\" name=\"_csrf\" value=\"abc123def456ghi789\" />",
|
||||
value);
|
||||
@@ -39,7 +39,7 @@ public class CsrfInputTagTests {
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertNotNull("The returned value should not be null.", value);
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertEquals(
|
||||
"The output is not correct.",
|
||||
"<input type=\"hidden\" name=\"csrfParameter\" value=\"fooBarBazQux\" />",
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
import org.springframework.security.web.csrf.CsrfToken;
|
||||
import org.springframework.security.web.csrf.DefaultCsrfToken;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Nick Williams
|
||||
@@ -26,7 +26,7 @@ public class CsrfMetaTagsTagTests {
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertNotNull("The returned value should not be null.", value);
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertEquals("The output is not correct.",
|
||||
"<meta name=\"_csrf_parameter\" content=\"_csrf\" />"
|
||||
+ "<meta name=\"_csrf_header\" content=\"X-Csrf-Token\" />"
|
||||
@@ -40,7 +40,7 @@ public class CsrfMetaTagsTagTests {
|
||||
|
||||
String value = this.tag.handleToken(token);
|
||||
|
||||
assertNotNull("The returned value should not be null.", value);
|
||||
assertThat(value).as("The returned value should not be null.").isNotNull();
|
||||
assertEquals("The output is not correct.",
|
||||
"<meta name=\"_csrf_parameter\" content=\"csrfParameter\" />"
|
||||
+ "<meta name=\"_csrf_header\" content=\"csrfHeader\" />"
|
||||
|
||||
Reference in New Issue
Block a user