Skip to content

Commit

Permalink
Merge pull request #5206 from Emkas/warnings-in-others
Browse files Browse the repository at this point in the history
Fix various warnings in tests
  • Loading branch information
BalusC authored Jan 26, 2023
2 parents 74eec7f + 60065b4 commit 056dde4
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public class DefaultActionMappingMatcher implements ActionMappingMatcher {
* @param bean the bean.
* @return the action mapping match, or null if not found.
*/
@SuppressWarnings("rawtypes")
private ActionMappingMatch determineActionMappingMatch(FacesContext facesContext, Bean<?> bean) {
ActionMappingMatch result = null;
Class<?> clazz = bean.getBeanClass();
AnnotatedType annotatedType = CDI.current().getBeanManager().createAnnotatedType(clazz);
@SuppressWarnings("unchecked")
Set<AnnotatedMethod> annotatedMethodSet = annotatedType.getMethods();
for (AnnotatedMethod method : annotatedMethodSet) {
if (method.isAnnotationPresent(ActionMapping.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class DefaultActionMethodExecutor implements ActionMethodExecutor {
*/
@Override
public void execute(FacesContext facesContext, ActionMappingMatch actionMappingMatch) {
Instance instance = CDI.current().select(
Instance<?> instance = CDI.current().select(
actionMappingMatch.getBean().getBeanClass(), Any.Literal.INSTANCE);
String viewId;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.sun.faces.application;

import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
Expand All @@ -26,8 +28,6 @@

import jakarta.faces.application.FacesMessage;

import static org.junit.Assert.*;

public class FacesMessageTest {

// Case 0 (nothing)
Expand Down Expand Up @@ -69,7 +69,6 @@ private void persistAndCheck(FacesMessage message) {
String mDetail, mDetail1 = null;
String severity, severity1 = null;
ByteArrayOutputStream bos = null;
ByteArrayInputStream bis = null;

mSummary = message.getSummary();
mDetail = message.getDetail();
Expand Down
17 changes: 10 additions & 7 deletions impl/src/test/java/com/sun/faces/config/DigesterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package com.sun.faces.config;

import javax.xml.parsers.ParserConfigurationException;
import java.net.URL;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.digester.Digester;
import org.apache.commons.logging.impl.NoOpLog;
import org.xml.sax.ErrorHandler;
Expand All @@ -30,6 +32,7 @@
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

import com.sun.faces.util.ToolsUtil;

/**
Expand Down Expand Up @@ -88,9 +91,9 @@ public class DigesterFactory {
* The <code>ThreadLocal</code> variable used to record the VersionListener
* instance for each processing thread.</p>
*/
private static ThreadLocal versionListener = new ThreadLocal() {
private static ThreadLocal<VersionListener> versionListener = new ThreadLocal<>() {
@Override
protected Object initialValue() {
protected VersionListener initialValue() {
return (null);
}
};
Expand Down Expand Up @@ -165,7 +168,7 @@ public static DigesterFactory newInstance(boolean isValidating,
} // END newInstance

public static VersionListener getVersionListener() {
return ((VersionListener) versionListener.get());
return (versionListener.get());
}

public static void releaseDigester(Digester toRelease) {
Expand Down Expand Up @@ -200,7 +203,7 @@ public interface VersionListener {
* Called from the EntityResolver when we know one of the XML Grammar
* elements to which this config file conforms.</p>
* @param grammar */
public void takeActionOnGrammar(String grammar);
void takeActionOnGrammar(String grammar);

/**
* <p>
Expand All @@ -209,7 +212,7 @@ public interface VersionListener {
* parsed.</p>
* @param artifactName
*/
public void takeActionOnArtifact(String artifactName);
void takeActionOnArtifact(String artifactName);
}

// --------------------------------------------------------- Private Methods
Expand Down Expand Up @@ -337,7 +340,7 @@ private static class JsfEntityResolver extends DefaultHandler {
* Contains mapping between grammar name and the local URL to the
* physical resource.</p>
*/
private HashMap<String, String> entities = new HashMap<String, String>();
private HashMap<String, String> entities = new HashMap<>();

// -------------------------------------------------------- Constructors
public JsfEntityResolver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@

package com.sun.faces.context;

import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.junit.Test;
import org.powermock.api.easymock.PowerMock;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import org.junit.Test;
import org.powermock.api.easymock.PowerMock;

/**
* The JUnit tests for the ExternalContextImpl class.
Expand Down Expand Up @@ -128,13 +131,6 @@ public void testGetRequestCookieMap3() {
assertTrue(e instanceof UnsupportedOperationException);
}

try {
requestCookieMap.entrySet().remove("test");
fail();
} catch (Exception e) {
assertTrue(e instanceof UnsupportedOperationException);
}

try {
requestCookieMap.keySet().remove("test");
fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@

package com.sun.faces.el;

import com.sun.faces.facelets.tag.composite.CompositeComponentBeanInfo;

import jakarta.faces.application.Resource;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIPanel;
import jakarta.faces.context.FacesContext;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.beans.BeanDescriptor;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import jakarta.el.ELContext;

import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.easymock.EasyMock.*;

import com.sun.faces.facelets.tag.composite.CompositeComponentBeanInfo;

import jakarta.el.ELContext;
import jakarta.faces.application.Resource;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIPanel;
import jakarta.faces.context.FacesContext;

/**
* The JUnit tests for the CompositeComponentAttributesELResolver class.
Expand All @@ -50,8 +54,8 @@ public void testGetValue() throws Exception {
FacesContext facesContext1 = EasyMock.createNiceMock(FacesContext.class);
ELContext elContext2 = EasyMock.createNiceMock(ELContext.class);
FacesContext facesContext2 = EasyMock.createNiceMock(FacesContext.class);
HashMap<Object, Object> ctxAttributes1 = new HashMap<Object, Object>();

HashMap<Object, Object> ctxAttributes1 = new HashMap<>();
UIPanel composite = new UIPanel();
CompositeComponentBeanInfo compositeBeanInfo = new CompositeComponentBeanInfo();
BeanDescriptor beanDescriptor = new BeanDescriptor(composite.getClass());
Expand All @@ -65,15 +69,17 @@ public void testGetValue() throws Exception {
expect(elContext2.getContext(FacesContext.class)).andReturn(facesContext2);
expect(facesContext2.getAttributes()).andReturn(ctxAttributes1);
replay(elContext1, facesContext1, elContext2, facesContext2);

CompositeComponentAttributesELResolver elResolver = new CompositeComponentAttributesELResolver();
@SuppressWarnings("unchecked")
Map<String, Object> evalMap1 = (Map<String, Object>) elResolver.getValue(elContext1, composite, property);
assertNotNull(evalMap1);
@SuppressWarnings("unchecked")
Map<String, Object> evalMap2 = (Map<String, Object>) elResolver.getValue(elContext2, composite, property);
assertNotNull(evalMap2);

Field ctxField1 = evalMap1.getClass().getDeclaredField("ctx");
ctxField1.setAccessible(true);
ctxField1.setAccessible(true);
Field ctxField2 = evalMap2.getClass().getDeclaredField("ctx");
ctxField2.setAccessible(true);

Expand All @@ -82,7 +88,7 @@ public void testGetValue() throws Exception {
assertTrue(facesContext2 == ctxField1.get(evalMap1));
assertTrue(facesContext1 != ctxField2.get(evalMap2));
assertTrue(facesContext2 == ctxField2.get(evalMap2));

verify(elContext1, facesContext1, elContext2, facesContext2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package com.sun.faces.junit;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import com.sun.faces.mock.MockApplication;
import com.sun.faces.mock.MockExternalContext;
import com.sun.faces.mock.MockFacesContext;
Expand All @@ -30,11 +34,6 @@
import jakarta.faces.application.ApplicationFactory;
import jakarta.faces.context.FacesContextFactory;
import jakarta.faces.lifecycle.LifecycleFactory;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

public class JUnitFacesTestCaseBase extends TestCase {
Expand Down Expand Up @@ -91,7 +90,7 @@ public void setUp() throws Exception {
lifecycle = (MockLifecycle) lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext = (MockFacesContext) fcFactory.getFacesContext(servletContext, request, response, lifecycle);
externalContext = (MockExternalContext) facesContext.getExternalContext();
Map map = new HashMap();
Map<String, String> map = new HashMap<>();
externalContext.setRequestParameterMap(map);

ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MockResultSetMetaData implements ResultSetMetaData {
*
* @param clazz Class whose properties we treat like columns
*/
public MockResultSetMetaData(Class clazz) throws SQLException {
public MockResultSetMetaData(Class<?> clazz) throws SQLException {
try {
descriptors
= Introspector.getBeanInfo(clazz).getPropertyDescriptors();
Expand Down
7 changes: 4 additions & 3 deletions impl/src/test/java/com/sun/faces/mock/MockServletConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Enumeration;
import java.util.Hashtable;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;

Expand All @@ -31,7 +32,7 @@ public MockServletConfig(ServletContext context) {
setServletContext(context);
}

private Hashtable parameters = new Hashtable();
private Hashtable<String, String> parameters = new Hashtable<>();
private ServletContext context;

// --------------------------------------------------------- Public Methods
Expand All @@ -46,11 +47,11 @@ public void setServletContext(ServletContext context) {
// -------------------------------------------------- ServletConfig Methods
@Override
public String getInitParameter(String name) {
return ((String) parameters.get(name));
return (parameters.get(name));
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package com.sun.faces.renderkit.html_basic;

import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.StringWriter;
import java.util.Collections;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.easymock.EasyMock.expect;
import org.junit.Test;
import org.powermock.api.easymock.PowerMock;

Expand Down Expand Up @@ -59,9 +60,9 @@ public void testEncodeBegin() throws Exception {
BodyRenderer bodyRenderer = new BodyRenderer();
HtmlBody htmlBody = new HtmlBody();
htmlBody.getAttributes().put("styleClass", "myclass");

expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes();

PowerMock.replay(facesContext);
bodyRenderer.encodeBegin(facesContext, htmlBody);
PowerMock.verify(facesContext);
Expand Down Expand Up @@ -101,14 +102,15 @@ public void testEncodeEnd() throws Exception {
Application application = PowerMock.createMock(Application.class);
BodyRenderer bodyRenderer = new BodyRenderer();
HtmlBody htmlBody = new HtmlBody();

expect(facesContext.getApplication()).andReturn(application).anyTimes();
expect(facesContext.getClientIdsWithMessages()).andReturn(Collections.EMPTY_LIST.iterator()).anyTimes();
expect(facesContext.getClientIdsWithMessages()).andReturn(Collections.<String>emptyList().iterator())
.anyTimes();
expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes();
expect(facesContext.getViewRoot()).andReturn(viewRoot).anyTimes();
expect(facesContext.isProjectStage(ProjectStage.Development)).andReturn(false).anyTimes();
expect(viewRoot.getComponentResources(facesContext, "body")).andReturn(Collections.EMPTY_LIST).anyTimes();
expect(viewRoot.getComponentResources(facesContext, "body")).andReturn(Collections.emptyList()).anyTimes();

PowerMock.replay(facesContext, viewRoot, application);
bodyRenderer.encodeEnd(facesContext, htmlBody);
PowerMock.verify(facesContext, viewRoot, application);
Expand Down
Loading

0 comments on commit 056dde4

Please sign in to comment.