Skip to content

Commit

Permalink
Merge #5404, #5408 and #5409 from 4.0 into 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BalusC committed Mar 9, 2024
2 parents 939b2d9 + ac4719d commit 6397374
Show file tree
Hide file tree
Showing 86 changed files with 1,274 additions and 1,683 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void setViewRoot(UIViewRoot root) {
if (viewRoot != null && !viewRoot.equals(root)) {
Map<String, Object> viewMap = viewRoot.getViewMap(false);
if (viewMap != null) {
viewRoot.getViewMap().clear();
viewMap.clear();
}
RequestStateManager.clearAttributesOnChangeOfView(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void execute(FacesContext facesContext) throws FacesException {
} catch (RuntimeException re) {
String exceptionMessage = re.getMessage();
if (null != exceptionMessage) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING, exceptionMessage, re);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, exceptionMessage, re);
}
}
throw new FacesException(exceptionMessage, re);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void execute(FacesContext facesContext) throws FacesException {
} catch (RuntimeException re) {
String exceptionMessage = re.getMessage();
if (null != exceptionMessage) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING, exceptionMessage, re);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, exceptionMessage, re);
}
}
throw new FacesException(exceptionMessage, re);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void execute(FacesContext facesContext) throws FacesException {
} catch (RuntimeException re) {
String exceptionMessage = re.getMessage();
if (null != exceptionMessage) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING, exceptionMessage, re);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, exceptionMessage, re);
}
}
throw new FacesException(exceptionMessage, re);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void execute(FacesContext facesContext) {
} catch (RuntimeException re) {
String exceptionMessage = re.getMessage();
if (null != exceptionMessage) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING, exceptionMessage, re);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, exceptionMessage, re);
}
}
throw new FacesException(exceptionMessage, re);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package com.sun.faces.application;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import jakarta.faces.application.FacesMessage;

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

package com.sun.faces.application.resource;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.jupiter.api.Test;

public class ResourceCacheTest {

Expand All @@ -36,7 +35,7 @@ public void noMemoryLeakWithContracts() {
// now we clear the contracts list, which was used to create the cache entry.
contracts.clear();
ResourceInfo cachedResourceInfo = cache.get("bar.gif", null, null, Arrays.asList("foo", "baz"));
assertThat(cachedResourceInfo, is(resourceInfo));
assertEquals(resourceInfo, cachedResourceInfo);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.sun.faces.config.processor;

import static com.sun.faces.util.Util.createLocalDocumentBuilderFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -28,7 +28,7 @@
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

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 static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;

import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -30,8 +28,8 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.junit.Test;
import org.powermock.api.easymock.PowerMock;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.Cookie;
Expand All @@ -48,14 +46,12 @@ public class ExternalContextImplTest {
*/
@Test
public void testGetRequestCookieMap() {
ServletContext servletContext = PowerMock.createNiceMock(ServletContext.class);
HttpServletRequest request = PowerMock.createNiceMock(HttpServletRequest.class);
HttpServletResponse response = PowerMock.createNiceMock(HttpServletResponse.class);
replay(servletContext, request, response);

ServletContext servletContext = Mockito.mock(ServletContext.class);
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);

ExternalContextImpl externalContext = new ExternalContextImpl(servletContext, request, response);
verify(servletContext, request, response);


assertNotNull(externalContext.getRequestCookieMap());
}

Expand All @@ -64,19 +60,17 @@ public void testGetRequestCookieMap() {
*/
@Test
public void testGetRequestCookieMap2() {
ServletContext servletContext = PowerMock.createNiceMock(ServletContext.class);
HttpServletRequest request = PowerMock.createNiceMock(HttpServletRequest.class);
HttpServletResponse response = PowerMock.createNiceMock(HttpServletResponse.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Cookie cookie = new Cookie("foo", "bar");
expect(request.getCookies()).andReturn(new Cookie[]{cookie}).anyTimes();
replay(servletContext, request, response);

when(request.getCookies()).thenReturn(new Cookie[]{cookie});

ExternalContextImpl externalContext = new ExternalContextImpl(servletContext, request, response);
verify(servletContext, request, response);
Map<String, Object> requestCookieMap = externalContext.getRequestCookieMap();
assertTrue(requestCookieMap.get("foo") instanceof Cookie);
Cookie value = (Cookie) requestCookieMap.get("foo");

assertTrue(value.getValue().equals("bar"));
assertTrue(requestCookieMap.containsKey("foo"));
assertTrue(requestCookieMap.containsValue(requestCookieMap.get("foo")));
Expand All @@ -93,15 +87,13 @@ public void testGetRequestCookieMap2() {
*/
@Test
public void testGetRequestCookieMap3() {
ServletContext servletContext = PowerMock.createNiceMock(ServletContext.class);
HttpServletRequest request = PowerMock.createNiceMock(HttpServletRequest.class);
HttpServletResponse response = PowerMock.createNiceMock(HttpServletResponse.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Cookie cookie = new Cookie("foo", "bar");
expect(request.getCookies()).andReturn(new Cookie[]{cookie}).anyTimes();
replay(servletContext, request, response);

when(request.getCookies()).thenReturn(new Cookie[]{cookie});

ExternalContextImpl externalContext = new ExternalContextImpl(servletContext, request, response);
verify(servletContext, request, response);
Map<String, Object> requestCookieMap = externalContext.getRequestCookieMap();

Iterator<Entry<String, Object>> entryIterator = requestCookieMap.entrySet().iterator();
Expand Down Expand Up @@ -153,23 +145,21 @@ public void testGetRequestCookieMap3() {
@SuppressWarnings("unchecked")
@Test
public void testGetRequestCookieMap4() {
ServletContext servletContext = PowerMock.createNiceMock(ServletContext.class);
HttpServletRequest request = PowerMock.createNiceMock(HttpServletRequest.class);
HttpServletResponse response = PowerMock.createNiceMock(HttpServletResponse.class);
ServletContext servletContext = Mockito.mock(ServletContext.class);
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Cookie cookie = new Cookie("foo", "bar");
expect(request.getCookies()).andReturn(new Cookie[]{cookie}).anyTimes();
replay(servletContext, request, response);

when(request.getCookies()).thenReturn(new Cookie[]{cookie});

ExternalContextImpl externalContext = new ExternalContextImpl(servletContext, request, response);
verify(servletContext, request, response);
Map<String, Object> requestCookieMap = externalContext.getRequestCookieMap();
boolean exceptionThrown = false;
try {
requestCookieMap.clear();
} catch (UnsupportedOperationException e) {
exceptionThrown = true;
}

assertTrue(exceptionThrown);
verifySupplier(() -> requestCookieMap.put("foot", "bar"));
verifyConsumer(m -> requestCookieMap.putAll((Map<? extends String, ? extends Object>) m), new HashMap<>());
Expand All @@ -184,13 +174,13 @@ public void testGetRequestCookieMap4() {
*/
private void verifyConsumer(Consumer<Object> consumer, Object argument) {
boolean exceptionThrown = false;

try {
consumer.accept(argument);
} catch (UnsupportedOperationException e) {
exceptionThrown = true;
}

assertTrue(exceptionThrown);
}

Expand All @@ -201,13 +191,13 @@ private void verifyConsumer(Consumer<Object> consumer, Object argument) {
*/
private void verifySupplier(Supplier<?> supplier) {
boolean exceptionThrown = false;

try {
supplier.get();
} catch (UnsupportedOperationException e) {
exceptionThrown = true;
}

assertTrue(exceptionThrown);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@

package com.sun.faces.el;

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.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

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

import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

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

Expand All @@ -50,12 +48,12 @@ public class CompositeComponentAttributesELResolverTest {
*/
@Test
public void testGetValue() throws Exception {
ELContext elContext1 = EasyMock.createNiceMock(ELContext.class);
FacesContext facesContext1 = EasyMock.createNiceMock(FacesContext.class);
ELContext elContext2 = EasyMock.createNiceMock(ELContext.class);
FacesContext facesContext2 = EasyMock.createNiceMock(FacesContext.class);
ELContext elContext1 = Mockito.mock(ELContext.class);
FacesContext facesContext1 = Mockito.mock(FacesContext.class);
ELContext elContext2 = Mockito.mock(ELContext.class);
FacesContext facesContext2 = Mockito.mock(FacesContext.class);

HashMap<Object, Object> ctxAttributes1 = new HashMap<>();
HashMap<Object, Object> ctxAttributes1 = new HashMap<Object, Object>();
UIPanel composite = new UIPanel();
CompositeComponentBeanInfo compositeBeanInfo = new CompositeComponentBeanInfo();
BeanDescriptor beanDescriptor = new BeanDescriptor(composite.getClass());
Expand All @@ -64,17 +62,14 @@ public void testGetValue() throws Exception {
composite.getAttributes().put(UIComponent.BEANINFO_KEY, compositeBeanInfo);
String property = "attrs";

expect(elContext1.getContext(FacesContext.class)).andReturn(facesContext1);
expect(facesContext1.getAttributes()).andReturn(ctxAttributes1);
expect(elContext2.getContext(FacesContext.class)).andReturn(facesContext2);
expect(facesContext2.getAttributes()).andReturn(ctxAttributes1);
replay(elContext1, facesContext1, elContext2, facesContext2);
when(elContext1.getContext(FacesContext.class)).thenReturn(facesContext1);
when(facesContext1.getAttributes()).thenReturn(ctxAttributes1);
when(elContext2.getContext(FacesContext.class)).thenReturn(facesContext2);
when(facesContext2.getAttributes()).thenReturn(ctxAttributes1);

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);

Expand All @@ -88,7 +83,5 @@ 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);
}
}
8 changes: 4 additions & 4 deletions impl/src/test/java/com/sun/faces/el/ELUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.net.URL;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.sun.el.ExpressionFactoryImpl;
import com.sun.faces.RIConstants;
Expand All @@ -25,7 +25,7 @@ public class ELUtilsTest {

private ApplicationAssociate applicationAssociate;

@Before
@BeforeEach
public void setUp() {
MockServletContext mockServletContext = new MockServletContext() {
@Override
Expand All @@ -50,7 +50,7 @@ public URL getResource(String path) {

applicationAssociate = (ApplicationAssociate) externalContext.getApplicationMap()
.get(RIConstants.FACES_PREFIX + "ApplicationAssociate");

FacesContext.getCurrentInstance().getAttributes().put(RIConstants.CDI_BEAN_MANAGER, new MockBeanManager());
}

Expand Down
Loading

0 comments on commit 6397374

Please sign in to comment.