Skip to content

Commit

Permalink
Merge pull request #5128 from Emkas/mock-servler-context-clean-up
Browse files Browse the repository at this point in the history
MockServletContext - clean-up
  • Loading branch information
BalusC authored Jun 25, 2022
2 parents 9290f7a + 272b06c commit 04d0074
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions impl/src/test/java/com/sun/faces/mock/MockServletContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import java.net.URL;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.Hashtable;
import java.util.Set;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;

import jakarta.servlet.Filter;
import jakarta.servlet.FilterRegistration;
import jakarta.servlet.RequestDispatcher;
Expand All @@ -39,111 +40,116 @@
// Mock Object for ServletContext (Version 4.0)
public class MockServletContext implements ServletContext {

private Hashtable attributes = new Hashtable();
private Hashtable parameters = new Hashtable();
private Hashtable<String, Object> attributes = new Hashtable<>();
private Hashtable<String, String> parameters = new Hashtable<>();

// --------------------------------------------------------- Public Methods
public void addInitParameter(String name, String value) {
parameters.put(name, value);
}

// ------------------------------------------------- ServletContext Methods
@Override
public Object getAttribute(String name) {
return (attributes.get(name));
return attributes.get(name);
}

public Enumeration getAttributeNames() {
return (attributes.keys());
@Override
public Enumeration<String> getAttributeNames() {
return attributes.keys();
}

@Override
public ServletContext getContext(String uripath) {
throw new UnsupportedOperationException();
}

@Override
public String getContextPath() {
return "test";
}

@Override
public String getInitParameter(String name) {
return ((String) parameters.get(name));
return parameters.get(name);
}

public Enumeration getInitParameterNames() {
return (parameters.keys());
@Override
public Enumeration<String> getInitParameterNames() {
return parameters.keys();
}

@Override
public int getMajorVersion() {
return (2);
return 2;
}

@Override
public String getMimeType(String path) {
throw new UnsupportedOperationException();
}

@Override
public int getMinorVersion() {
return (5);
return 5;
}

@Override
public RequestDispatcher getNamedDispatcher(String name) {
throw new UnsupportedOperationException();
}

@Override
public String getRealPath(String path) {
throw new UnsupportedOperationException();
}

@Override
public RequestDispatcher getRequestDispatcher(String path) {
throw new UnsupportedOperationException();
}

@Override
public URL getResource(String path) throws MalformedURLException {
throw new UnsupportedOperationException();
}

@Override
public InputStream getResourceAsStream(String path) {
throw new UnsupportedOperationException();
}

public Set getResourcePaths(String path) {
return new HashSet(0);
}

public Servlet getServlet(String name) throws ServletException {
throw new UnsupportedOperationException();
@Override
public Set<String> getResourcePaths(String path) {
return new HashSet<>(0);
}

@Override
public String getServletContextName() {
return ("MockServletContext");
return "MockServletContext";
}

@Override
public String getServerInfo() {
return ("MockServletContext");
}

public Enumeration getServlets() {
throw new UnsupportedOperationException();
}

public Enumeration getServletNames() {
throw new UnsupportedOperationException();
return "MockServletContext";
}

@Override
public void log(String message) {
throw new UnsupportedOperationException();
}

public void log(Exception exception, String message) {
throw new UnsupportedOperationException();
}

@Override
public void log(String message, Throwable exception) {
throw new UnsupportedOperationException();
}

@Override
public void removeAttribute(String name) {
attributes.remove(name);
}

@Override
public void setAttribute(String name, Object value) {
attributes.put(name, value);
}
Expand Down Expand Up @@ -282,9 +288,7 @@ public void declareRoles(String... strings) {
public String getVirtualServerName() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}



@Override
public ServletRegistration.Dynamic addJspFile(String string, String string1) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
Expand Down Expand Up @@ -320,5 +324,4 @@ public void setResponseCharacterEncoding(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}


}

0 comments on commit 04d0074

Please sign in to comment.