Skip to content

Commit

Permalink
Replace test FilterRegistration with the one in testFixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jul 30, 2024
1 parent 24ab6f6 commit 5ac7e74
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Rossen Stoyanchev
* @since 6.2
*/
public class MockFilterRegistration implements FilterRegistration {
public class MockFilterRegistration implements FilterRegistration.Dynamic {

private final String name;

Expand All @@ -50,6 +50,8 @@ public class MockFilterRegistration implements FilterRegistration {

private final List<String> urlPatterns = new ArrayList<>();

private boolean asyncSupported;


public MockFilterRegistration(String className) {
this(className, "");
Expand Down Expand Up @@ -126,4 +128,13 @@ public Collection<String> getUrlPatternMappings() {
return Collections.unmodifiableCollection(this.urlPatterns);
}

@Override
public void setAsyncSupported(boolean asyncSupported) {
this.asyncSupported = asyncSupported;
}

public boolean isAsyncSupported() {
return this.asyncSupported;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Rossen Stoyanchev
* @since 6.2
*/
public class MockFilterRegistration implements FilterRegistration {
public class MockFilterRegistration implements FilterRegistration.Dynamic {

private final String name;

Expand All @@ -50,6 +50,8 @@ public class MockFilterRegistration implements FilterRegistration {

private final List<String> urlPatterns = new ArrayList<>();

private boolean asyncSupported;


public MockFilterRegistration(String className) {
this(className, "");
Expand Down Expand Up @@ -126,4 +128,13 @@ public Collection<String> getUrlPatternMappings() {
return Collections.unmodifiableCollection(this.urlPatterns);
}

@Override
public void setAsyncSupported(boolean asyncSupported) {
this.asyncSupported = asyncSupported;
}

public boolean isAsyncSupported() {
return this.asyncSupported;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
package org.springframework.web.servlet.support;

import java.util.Collections;
import java.util.EnumSet;
import java.util.EventListener;
import java.util.LinkedHashMap;
import java.util.Map;

import jakarta.servlet.DispatcherType;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterRegistration.Dynamic;
import jakarta.servlet.Servlet;
Expand All @@ -40,6 +38,7 @@
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.testfixture.servlet.MockFilterRegistration;
import org.springframework.web.testfixture.servlet.MockServletConfig;
import org.springframework.web.testfixture.servlet.MockServletContext;

Expand Down Expand Up @@ -112,11 +111,9 @@ void register() throws ServletException {
assertThat(filterRegistrations.get("delegatingFilterProxy#0")).isNotNull();
assertThat(filterRegistrations.get("delegatingFilterProxy#1")).isNotNull();

for (MockFilterRegistration filterRegistration : filterRegistrations.values()) {
assertThat(filterRegistration.isAsyncSupported()).isTrue();
EnumSet<DispatcherType> enumSet = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
DispatcherType.INCLUDE, DispatcherType.ASYNC);
assertThat(filterRegistration.getMappings().get(SERVLET_NAME)).isEqualTo(enumSet);
for (MockFilterRegistration registration : filterRegistrations.values()) {
assertThat(registration.isAsyncSupported()).isTrue();
assertThat(registration.getServletNameMappings().iterator().next()).isEqualTo(SERVLET_NAME);
}

}
Expand All @@ -135,9 +132,9 @@ protected boolean isAsyncSupported() {
MockServletRegistration servletRegistration = servletRegistrations.get(SERVLET_NAME);
assertThat(servletRegistration.isAsyncSupported()).isFalse();

for (MockFilterRegistration filterRegistration : filterRegistrations.values()) {
assertThat(filterRegistration.isAsyncSupported()).isFalse();
assertThat(filterRegistration.getMappings().get(SERVLET_NAME)).isEqualTo(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
for (MockFilterRegistration registration : filterRegistrations.values()) {
assertThat(registration.isAsyncSupported()).isFalse();
assertThat(registration.getServletNameMappings().iterator().next()).isEqualTo(SERVLET_NAME);
}
}

Expand Down Expand Up @@ -209,7 +206,7 @@ public Dynamic addFilter(String filterName, Filter filter) {
return null;
}
filters.put(filterName, filter);
MockFilterRegistration registration = new MockFilterRegistration();
MockFilterRegistration registration = new MockFilterRegistration(filter.getClass().getName(), filterName);
filterRegistrations.put(filterName, registration);
return registration;
}
Expand Down

This file was deleted.

0 comments on commit 5ac7e74

Please sign in to comment.