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

Various fixes of warnings in tests #5149

Merged
merged 5 commits into from
Jul 27, 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
8 changes: 4 additions & 4 deletions impl/src/test/java/com/sun/faces/mock/MockApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public Converter createConverter(String converterId) {
}

@Override
public Converter createConverter(Class targetClass) {
public Converter createConverter(Class<?> targetClass) {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -941,15 +941,15 @@ private Constructor<? extends SystemEvent> getEventConstructor(Class<?> source)
try {
return systemEvent.getDeclaredConstructor(source);
} catch (NoSuchMethodException ignored) {
Constructor[] ctors = systemEvent.getConstructors();
Constructor<?>[] ctors = systemEvent.getConstructors();
if (ctors != null) {
for (Constructor c : ctors) {
for (Constructor<?> c : ctors) {
Class<?>[] params = c.getParameterTypes();
if (params.length != 1) {
continue;
}
if (params[0].isAssignableFrom(source)) {
return c;
return (Constructor<? extends SystemEvent>) c;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Object put(String key, Object value) {
}

@Override
public void putAll(Map map) {
public void putAll(Map<? extends String, ? extends Object> map) {
Iterator<?> keys = map.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,31 @@

public class MockFacesContextFactory extends FacesContextFactory {
public MockFacesContextFactory(FacesContextFactory oldImpl) {
System.setProperty(FactoryFinder.FACES_CONTEXT_FACTORY,
this.getClass().getName());
super(oldImpl);
System.setProperty(FactoryFinder.FACES_CONTEXT_FACTORY, this.getClass().getName());
}
public MockFacesContextFactory() {}


@Override
public FacesContext getFacesContext(Object context, Object request,
Object response,
Object response,
Lifecycle lifecycle) throws FacesException {
MockFacesContext result = new MockFacesContext();

ExternalContext externalContext =
new MockExternalContext((ServletContext) context,
new MockExternalContext((ServletContext) context,
(ServletRequest) request, (ServletResponse) response);
result.setExternalContext(externalContext);
ApplicationFactory applicationFactory = (ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = (MockApplication) applicationFactory.getApplication();
Application application = applicationFactory.getApplication();
result.setApplication(application);

ELContext elContext = new MockELContext(new MockELResolver());
elContext.putContext(FacesContext.class, result);
result.setELContext(elContext);

return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public MockHttpServletRequest(String contextPath, String servletPath,
setHttpSession(session);
}

protected HashMap attributes = new HashMap();
protected HashMap<String, Object> attributes = new HashMap<>();
protected String contextPath = null;
protected Locale locale = null;
protected HashMap<String, String[]> parameters = new HashMap<>();
Expand Down Expand Up @@ -271,8 +271,8 @@ public Object getAttribute(String name) {
}

@Override
public Enumeration getAttributeNames() {
return (new MockEnumeration(attributes.keySet().iterator()));
public Enumeration<String> getAttributeNames() {
return (new MockEnumeration<>(attributes.keySet().iterator()));
}

@Override
Expand Down Expand Up @@ -324,7 +324,7 @@ public int getLocalPort() {
}

@Override
public Enumeration getLocales() {
public Enumeration<Locale> getLocales() {
throw new UnsupportedOperationException();
}

Expand All @@ -339,13 +339,13 @@ public String getParameter(String name) {
}

@Override
public Map getParameterMap() {
public Map<String, String[]> getParameterMap() {
return (parameters);
}

@Override
public Enumeration getParameterNames() {
return (new MockEnumeration(parameters.keySet().iterator()));
public Enumeration<String> getParameterNames() {
return (new MockEnumeration<>(parameters.keySet().iterator()));
}

@Override
Expand Down
25 changes: 9 additions & 16 deletions impl/src/test/java/com/sun/faces/mock/MockRenderKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.sun.faces.mock;

import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -31,15 +34,11 @@
import jakarta.faces.render.Renderer;
import jakarta.faces.render.ResponseStateManager;

import java.io.Writer;
import java.io.OutputStream;
import java.io.IOException;

public class MockRenderKit extends RenderKit {

public MockRenderKit() {
addRenderer(UIData.COMPONENT_FAMILY,
"jakarta.faces.Table", new TestRenderer(true));
"jakarta.faces.Table", new TestRenderer());
addRenderer(UIInput.COMPONENT_FAMILY,
"TestRenderer", new TestRenderer());
addRenderer(UIInput.COMPONENT_FAMILY,
Expand All @@ -49,11 +48,11 @@ public MockRenderKit() {
addRenderer(UIOutput.COMPONENT_FAMILY,
"jakarta.faces.Text", new TestRenderer());
addRenderer(UIPanel.COMPONENT_FAMILY,
"jakarta.faces.Grid", new TestRenderer(true));
"jakarta.faces.Grid", new TestRenderer());
responseStateManager = new MockResponseStateManager();
}

private Map renderers = new HashMap();
private Map<String, Renderer> renderers = new HashMap<>();
private ResponseStateManager responseStateManager = null;

@Override
Expand All @@ -70,7 +69,7 @@ public Renderer getRenderer(String family, String rendererType) {
if ((family == null) || (rendererType == null)) {
throw new NullPointerException();
}
return ((Renderer) renderers.get(family + "|" + rendererType));
return (renderers.get(family + "|" + rendererType));
}

@Override
Expand Down Expand Up @@ -116,17 +115,11 @@ public ResponseStateManager getResponseStateManager() {
return responseStateManager;
}

class TestRenderer extends Renderer {

private boolean rendersChildren = false;
class TestRenderer extends Renderer<UIComponent> {

public TestRenderer() {
}

public TestRenderer(boolean rendersChildren) {
this.rendersChildren = rendersChildren;
}

@Override
public void decode(FacesContext context, UIComponent component) {

Expand All @@ -142,7 +135,7 @@ public void decode(FacesContext context, UIComponent component) {
// System.err.println("decode(" + clientId + ")");

// Decode incoming request parameters
Map params = context.getExternalContext().getRequestParameterMap();
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
if (params.containsKey(clientId)) {
// System.err.println(" '" + input.currentValue(context) +
// "' --> '" + params.get(clientId) + "'");
Expand Down
26 changes: 17 additions & 9 deletions impl/src/test/java/com/sun/faces/mock/MockResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@

import java.io.InputStream;
import java.io.Reader;
import java.sql.NClob;
import java.sql.RowId;
import java.sql.SQLXML;
import java.util.Calendar;
import java.util.Map;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import com.sun.faces.mock.model.BeanTestImpl;
import java.util.Calendar;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;

import com.sun.faces.mock.model.BeanTestImpl;

/**
* <p>
* Mock object that implements enough of <code>java.sql.ResultSet</code> to
Expand Down Expand Up @@ -241,6 +243,7 @@ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
/**
* @deprecated
*/
@Deprecated
@Override
public BigDecimal getBigDecimal(int columnIndex, int scale)
throws SQLException {
Expand All @@ -256,6 +259,7 @@ public BigDecimal getBigDecimal(String columnName) throws SQLException {
* @param columnName
* @deprecated
*/
@Deprecated
@Override
public BigDecimal getBigDecimal(String columnName, int scale)
throws SQLException {
Expand Down Expand Up @@ -409,12 +413,12 @@ public long getLong(String columnName) throws SQLException {
}

@Override
public Object getObject(int columnIndex, Map map) throws SQLException {
public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException();
}

@Override
public Object getObject(String columnName, Map map) throws SQLException {
public Object getObject(String columnName, Map<String, Class<?>> map) throws SQLException {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -498,6 +502,7 @@ public Timestamp getTimestamp(String columnName, Calendar cal)
/**
* @deprecated
*/
@Deprecated
@Override
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
throw new UnsupportedOperationException();
Expand All @@ -507,6 +512,7 @@ public InputStream getUnicodeStream(int columnIndex) throws SQLException {
* @param columnName
* @deprecated
*/
@Deprecated
@Override
public InputStream getUnicodeStream(String columnName) throws SQLException {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -1131,11 +1137,13 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
throw new UnsupportedOperationException("Not supported yet.");
}
}
6 changes: 3 additions & 3 deletions impl/src/test/java/com/sun/faces/mock/MockSessionMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public boolean containsValue(Object value) {

@Override
public Set entrySet() {
Set set = new HashSet();
Enumeration keys = session.getAttributeNames();
Set<Object> set = new HashSet<>();
Enumeration<String> keys = session.getAttributeNames();
while (keys.hasMoreElements()) {
set.add(session.getAttribute((String) keys.nextElement()));
set.add(session.getAttribute(keys.nextElement()));
}
return set;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void testCDATAWithXHTML() throws Exception {
responseWriter.endElement("script");
responseWriter.flush();
assertEquals(expected, stringWriter.toString());
responseWriter.close();

// Case 2 start is // end is /* */
stringWriter = new StringWriter();
Expand All @@ -116,6 +117,7 @@ public void testCDATAWithXHTML() throws Exception {
responseWriter.endElement("script");
responseWriter.flush();
assertEquals(expected, stringWriter.toString());
responseWriter.close();

// Case 3 start is /* */ end is /* */
stringWriter = new StringWriter();
Expand All @@ -125,6 +127,7 @@ public void testCDATAWithXHTML() throws Exception {
responseWriter.endElement("script");
responseWriter.flush();
assertEquals(expected, stringWriter.toString());
responseWriter.close();

// Case 4 start is /* */ end is //
stringWriter = new StringWriter();
Expand All @@ -134,6 +137,7 @@ public void testCDATAWithXHTML() throws Exception {
responseWriter.endElement("script");
responseWriter.flush();
assertEquals(expected, stringWriter.toString());
responseWriter.close();

// Case 5 start is /* */ end is //
stringWriter = new StringWriter();
Expand All @@ -143,6 +147,7 @@ public void testCDATAWithXHTML() throws Exception {
responseWriter.endElement("script");
responseWriter.flush();
assertEquals(expected, stringWriter.toString());
responseWriter.close();
}

/**
Expand All @@ -163,6 +168,7 @@ public void testUnescapedCDATA() throws Exception {
responseWriter.endElement("style");
responseWriter.flush();
assertEquals(expectedStart + "]]]><![CDATA[" + expectedEnd, stringWriter.toString());
responseWriter.close();

// two chars
stringWriter = new StringWriter();
Expand All @@ -174,6 +180,7 @@ public void testUnescapedCDATA() throws Exception {
responseWriter.endElement("style");
responseWriter.flush();
assertEquals(expectedStart + "]]]><![CDATA[]]]><![CDATA[" + expectedEnd, stringWriter.toString());
responseWriter.close();

// long string
stringWriter = new StringWriter();
Expand All @@ -185,6 +192,7 @@ public void testUnescapedCDATA() throws Exception {
responseWriter.endElement("style");
responseWriter.flush();
assertEquals(expectedStart + "abc]]]><![CDATA[]>abc" + expectedEnd, stringWriter.toString());
responseWriter.close();
}

/**
Expand All @@ -206,6 +214,6 @@ public void testUnescapedCDataWithZeroLengthContent() throws Exception {
responseWriter.endElement("style");
responseWriter.flush();
assertEquals(expectedStart + expectedEnd, stringWriter.toString());

responseWriter.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Test implementation of {@link Validator}.
* </p>
*/
public class InputValidatorTestImpl implements Validator {
public class InputValidatorTestImpl implements Validator<Object> {

protected String validatorId = null;

Expand Down
Loading