You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by gh...@apache.org on 2020/09/21 08:59:21 UTC
[sling-org-apache-sling-auth-core] branch bugfix/cleanup-unit-test
created (now c03b9a8)
This is an automated email from the ASF dual-hosted git repository.
ghenzler pushed a change to branch bugfix/cleanup-unit-test
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git.
at c03b9a8 Cleanup unit test
This branch includes the following new commits:
new c03b9a8 Cleanup unit test
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[sling-org-apache-sling-auth-core] 01/01: Cleanup unit test
Posted by gh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ghenzler pushed a commit to branch bugfix/cleanup-unit-test
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git
commit c03b9a89a2c364c2eebca3543a1863b519a893f2
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Mon Sep 21 10:58:25 2020 +0200
Cleanup unit test
request.getAttribute("path") is not used anymore in main code and should
not be mocked
---
.../auth/core/impl/SlingAuthenticatorTest.java | 25 ++++++++++------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
index d6b5c3c..d3654cf 100644
--- a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
+++ b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
@@ -116,7 +116,7 @@ public class SlingAuthenticatorTest {
PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
+ buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo",
new Class[]{HttpServletRequest.class, HttpServletResponse.class}, new Object[]{request, Mockito.mock(HttpServletResponse.class)});
@@ -143,7 +143,7 @@ public class SlingAuthenticatorTest {
PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
+ buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo",
new Class[]{HttpServletRequest.class, HttpServletResponse.class}, new Object[]{request, Mockito.mock(HttpServletResponse.class)});
@@ -170,7 +170,7 @@ public class SlingAuthenticatorTest {
PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
+ buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo",
new Class[]{HttpServletRequest.class, HttpServletResponse.class}, new Object[]{request, Mockito.mock(HttpServletResponse.class)});
@@ -197,7 +197,7 @@ public class SlingAuthenticatorTest {
PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
+ buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo",
new Class[]{HttpServletRequest.class, HttpServletResponse.class}, new Object[]{request, Mockito.mock(HttpServletResponse.class)});
@@ -220,7 +220,7 @@ public class SlingAuthenticatorTest {
PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
+ buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo",
new Class[]{HttpServletRequest.class, HttpServletResponse.class}, new Object[]{request, Mockito.mock(HttpServletResponse.class)});
@@ -246,7 +246,7 @@ public class SlingAuthenticatorTest {
PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- buildExpectationsForRequestPathAndAuthPath(request, REQUEST_CHILD_NODE, PROTECTED_PATH);
+ buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo",
new Class[]{HttpServletRequest.class, HttpServletResponse.class}, new Object[]{request, Mockito.mock(HttpServletResponse.class)});
@@ -286,7 +286,7 @@ public class SlingAuthenticatorTest {
PrivateAccessor.setField(slingAuthenticator, "authHandlerCache", authRequiredCache);
final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
- buildExpectationsForRequestPathAndAuthPath(request, REQUEST_NOT_PROTECTED_PATH, PROTECTED_PATH);
+ buildExpectationsForRequest(request, REQUEST_NOT_PROTECTED_PATH);
AuthenticationInfo authInfo = (AuthenticationInfo) PrivateAccessor.invoke(slingAuthenticator, "getAuthenticationInfo",
new Class[]{HttpServletRequest.class, HttpServletResponse.class}, new Object[]{request, Mockito.mock(HttpServletResponse.class)});
@@ -373,19 +373,16 @@ public class SlingAuthenticatorTest {
/**
* Mocks the request to accept method calls on path;
*
- * @param request http request
- * @param requestPath path in the http request
- * @param authProtectedPath path protected by the auth handler
+ * @param request http request
+ * @param requestPath request path
*/
- private void buildExpectationsForRequestPathAndAuthPath(final HttpServletRequest request,
- final String requestPath,
- final String authProtectedPath) {
+ private void buildExpectationsForRequest(final HttpServletRequest request,
+ final String requestPath) {
{
Mockito.when(request.getServletPath()).thenReturn(requestPath);
Mockito.when(request.getServerName()).thenReturn("localhost");
Mockito.when(request.getServerPort()).thenReturn(80);
Mockito.when(request.getScheme()).thenReturn("http");
- Mockito.when(request.getAttribute("path")).thenReturn(requestPath);
}
}