Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocks clean up #5146

Merged
merged 7 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions impl/src/test/java/com/sun/faces/mock/MockApplicationMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,76 +24,87 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import jakarta.servlet.ServletContext;

final class MockApplicationMap implements Map {
final class MockApplicationMap implements Map<String, Object> {

public MockApplicationMap(ServletContext context) {
this.context = context;
}

private ServletContext context = null;

@Override
public void clear() {
Iterator keys = keySet().iterator();
Iterator<String> keys = keySet().iterator();
while (keys.hasNext()) {
context.removeAttribute((String) keys.next());
context.removeAttribute(keys.next());
}
}

@Override
public boolean containsKey(Object key) {
return (context.getAttribute(key(key)) != null);
}

@Override
public boolean containsValue(Object value) {
if (value == null) {
return (false);
}
Enumeration keys = context.getAttributeNames();
Enumeration<String> keys = context.getAttributeNames();
while (keys.hasMoreElements()) {
Object next = context.getAttribute((String) keys.nextElement());
Object next = context.getAttribute(keys.nextElement());
if (next == value) {
return (true);
}
}
return (false);
}

@Override
public Set entrySet() {
Set set = new HashSet();
Enumeration keys = context.getAttributeNames();
Set<Object> set = new HashSet<>();
Enumeration<String> keys = context.getAttributeNames();
while (keys.hasMoreElements()) {
set.add(context.getAttribute((String) keys.nextElement()));
set.add(context.getAttribute(keys.nextElement()));
}
return (set);
return set;
}

@Override
public boolean equals(Object o) {
return (context.equals(o));
}

@Override
public Object get(Object key) {
return (context.getAttribute(key(key)));
}

@Override
public int hashCode() {
return (context.hashCode());
}

@Override
public boolean isEmpty() {
return (size() < 1);
}

public Set keySet() {
Set set = new HashSet();
Enumeration keys = context.getAttributeNames();
@Override
public Set<String> keySet() {
Set<String> set = new HashSet<>();
Enumeration<String> keys = context.getAttributeNames();
while (keys.hasMoreElements()) {
set.add(keys.nextElement());
}
return (set);
}

public Object put(Object key, Object value) {
@Override
public Object put(String key, Object value) {
if (value == null) {
return (remove(key));
}
Expand All @@ -103,36 +114,40 @@ public Object put(Object key, Object value) {
return (previous);
}

@Override
public void putAll(Map map) {
Iterator keys = map.keySet().iterator();
Iterator<?> keys = map.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
context.setAttribute(key, map.get(key));
}
}

@Override
public Object remove(Object key) {
String skey = key(key);
Object previous = context.getAttribute(skey);
context.removeAttribute(skey);
return (previous);
}

@Override
public int size() {
int n = 0;
Enumeration keys = context.getAttributeNames();
Enumeration<String> keys = context.getAttributeNames();
while (keys.hasMoreElements()) {
keys.nextElement();
n++;
}
return (n);
}

public Collection values() {
List list = new ArrayList();
Enumeration keys = context.getAttributeNames();
@Override
public Collection<Object> values() {
List<Object> list = new ArrayList<>();
Enumeration<String> keys = context.getAttributeNames();
while (keys.hasMoreElements()) {
list.add(context.getAttribute((String) keys.nextElement()));
list.add(context.getAttribute(keys.nextElement()));
}
return (list);
}
Expand Down
12 changes: 5 additions & 7 deletions impl/src/test/java/com/sun/faces/mock/MockELResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Object getValue(Object base, Object property) {
String name = property.toString();
try {
if (base instanceof Map) {
Map map = (Map) base;
Map<?, ?> map = (Map<?, ?>) base;
if (map.containsKey(name)) {
return (map.get(name));
} else {
Expand All @@ -136,9 +136,8 @@ private ExternalContext econtext() {
}

@Override
public Class getType(ELContext context, Object base, Object property) throws ELException {
Class result = null;
return result;
public Class<?> getType(ELContext context, Object base, Object property) throws ELException {
return null;
}

@Override
Expand All @@ -157,8 +156,7 @@ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Obje
}

@Override
public Class getCommonPropertyType(ELContext context, Object base) {
Class result = null;
return result;
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return null;
}
}
8 changes: 4 additions & 4 deletions impl/src/test/java/com/sun/faces/mock/MockEnumeration.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
* General purpose <code>Enumeration</code> wrapper around an
* <code>Iterator</code> specified to our controller.</p>
*/
public class MockEnumeration implements Enumeration {
public class MockEnumeration<T> implements Enumeration<T> {

public MockEnumeration(Iterator iterator) {
public MockEnumeration(Iterator<T> iterator) {
this.iterator = iterator;
}

protected Iterator iterator;
protected Iterator<T> iterator;

@Override
public boolean hasMoreElements() {
return (iterator.hasNext());
}

@Override
public Object nextElement() {
public T nextElement() {
return (iterator.next());
}
}
Loading