diff --git a/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java b/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java index af05a58d83..44fb0996bc 100644 --- a/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java +++ b/impl/src/main/java/com/sun/faces/context/FacesContextImpl.java @@ -420,7 +420,7 @@ public void setViewRoot(UIViewRoot root) { if (viewRoot != null && !viewRoot.equals(root)) { Map viewMap = viewRoot.getViewMap(false); if (viewMap != null) { - viewRoot.getViewMap().clear(); + viewMap.clear(); } RequestStateManager.clearAttributesOnChangeOfView(this); } diff --git a/impl/src/main/java/com/sun/faces/lifecycle/ApplyRequestValuesPhase.java b/impl/src/main/java/com/sun/faces/lifecycle/ApplyRequestValuesPhase.java index a2dfb81fb7..29726ae126 100644 --- a/impl/src/main/java/com/sun/faces/lifecycle/ApplyRequestValuesPhase.java +++ b/impl/src/main/java/com/sun/faces/lifecycle/ApplyRequestValuesPhase.java @@ -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); diff --git a/impl/src/main/java/com/sun/faces/lifecycle/InvokeApplicationPhase.java b/impl/src/main/java/com/sun/faces/lifecycle/InvokeApplicationPhase.java index 1ccd7d919f..717714835d 100644 --- a/impl/src/main/java/com/sun/faces/lifecycle/InvokeApplicationPhase.java +++ b/impl/src/main/java/com/sun/faces/lifecycle/InvokeApplicationPhase.java @@ -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); diff --git a/impl/src/main/java/com/sun/faces/lifecycle/ProcessValidationsPhase.java b/impl/src/main/java/com/sun/faces/lifecycle/ProcessValidationsPhase.java index 9eb4a8cf1e..675a95754a 100644 --- a/impl/src/main/java/com/sun/faces/lifecycle/ProcessValidationsPhase.java +++ b/impl/src/main/java/com/sun/faces/lifecycle/ProcessValidationsPhase.java @@ -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); diff --git a/impl/src/main/java/com/sun/faces/lifecycle/UpdateModelValuesPhase.java b/impl/src/main/java/com/sun/faces/lifecycle/UpdateModelValuesPhase.java index b4cf5b56e9..adf3edb904 100644 --- a/impl/src/main/java/com/sun/faces/lifecycle/UpdateModelValuesPhase.java +++ b/impl/src/main/java/com/sun/faces/lifecycle/UpdateModelValuesPhase.java @@ -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); diff --git a/impl/src/test/java/com/sun/faces/application/FacesMessageTest.java b/impl/src/test/java/com/sun/faces/application/FacesMessageTest.java index 8b93675cf6..8ef9baef1d 100644 --- a/impl/src/test/java/com/sun/faces/application/FacesMessageTest.java +++ b/impl/src/test/java/com/sun/faces/application/FacesMessageTest.java @@ -16,7 +16,7 @@ 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; @@ -24,7 +24,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import jakarta.faces.application.FacesMessage; diff --git a/impl/src/test/java/com/sun/faces/application/resource/ResourceCacheTest.java b/impl/src/test/java/com/sun/faces/application/resource/ResourceCacheTest.java index c8223cb0ce..140a97740d 100644 --- a/impl/src/test/java/com/sun/faces/application/resource/ResourceCacheTest.java +++ b/impl/src/test/java/com/sun/faces/application/resource/ResourceCacheTest.java @@ -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 { @@ -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); } } diff --git a/impl/src/test/java/com/sun/faces/config/processor/FacesConfigNamespaceContextTest.java b/impl/src/test/java/com/sun/faces/config/processor/FacesConfigNamespaceContextTest.java index cb59988b72..b9f320d35f 100644 --- a/impl/src/test/java/com/sun/faces/config/processor/FacesConfigNamespaceContextTest.java +++ b/impl/src/test/java/com/sun/faces/config/processor/FacesConfigNamespaceContextTest.java @@ -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; @@ -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; diff --git a/impl/src/test/java/com/sun/faces/context/ExternalContextImplTest.java b/impl/src/test/java/com/sun/faces/context/ExternalContextImplTest.java index d83b72cd4b..e58f288399 100644 --- a/impl/src/test/java/com/sun/faces/context/ExternalContextImplTest.java +++ b/impl/src/test/java/com/sun/faces/context/ExternalContextImplTest.java @@ -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; @@ -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; @@ -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()); } @@ -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 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"))); @@ -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 requestCookieMap = externalContext.getRequestCookieMap(); Iterator> entryIterator = requestCookieMap.entrySet().iterator(); @@ -153,15 +145,13 @@ 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 requestCookieMap = externalContext.getRequestCookieMap(); boolean exceptionThrown = false; try { @@ -169,7 +159,7 @@ public void testGetRequestCookieMap4() { } catch (UnsupportedOperationException e) { exceptionThrown = true; } - + assertTrue(exceptionThrown); verifySupplier(() -> requestCookieMap.put("foot", "bar")); verifyConsumer(m -> requestCookieMap.putAll((Map) m), new HashMap<>()); @@ -184,13 +174,13 @@ public void testGetRequestCookieMap4() { */ private void verifyConsumer(Consumer consumer, Object argument) { boolean exceptionThrown = false; - + try { consumer.accept(argument); } catch (UnsupportedOperationException e) { exceptionThrown = true; } - + assertTrue(exceptionThrown); } @@ -201,13 +191,13 @@ private void verifyConsumer(Consumer consumer, Object argument) { */ private void verifySupplier(Supplier supplier) { boolean exceptionThrown = false; - + try { supplier.get(); } catch (UnsupportedOperationException e) { exceptionThrown = true; } - + assertTrue(exceptionThrown); } } diff --git a/impl/src/test/java/com/sun/faces/el/CompositeComponentAttributesELResolverTest.java b/impl/src/test/java/com/sun/faces/el/CompositeComponentAttributesELResolverTest.java index 32e1339b3c..4d0799b397 100644 --- a/impl/src/test/java/com/sun/faces/el/CompositeComponentAttributesELResolverTest.java +++ b/impl/src/test/java/com/sun/faces/el/CompositeComponentAttributesELResolverTest.java @@ -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; @@ -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 ctxAttributes1 = new HashMap<>(); + HashMap ctxAttributes1 = new HashMap(); UIPanel composite = new UIPanel(); CompositeComponentBeanInfo compositeBeanInfo = new CompositeComponentBeanInfo(); BeanDescriptor beanDescriptor = new BeanDescriptor(composite.getClass()); @@ -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 evalMap1 = (Map) elResolver.getValue(elContext1, composite, property); assertNotNull(evalMap1); - @SuppressWarnings("unchecked") Map evalMap2 = (Map) elResolver.getValue(elContext2, composite, property); assertNotNull(evalMap2); @@ -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); } } diff --git a/impl/src/test/java/com/sun/faces/el/ELUtilsTest.java b/impl/src/test/java/com/sun/faces/el/ELUtilsTest.java index 2eca310586..8bd05397e0 100644 --- a/impl/src/test/java/com/sun/faces/el/ELUtilsTest.java +++ b/impl/src/test/java/com/sun/faces/el/ELUtilsTest.java @@ -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; @@ -25,7 +25,7 @@ public class ELUtilsTest { private ApplicationAssociate applicationAssociate; - @Before + @BeforeEach public void setUp() { MockServletContext mockServletContext = new MockServletContext() { @Override @@ -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()); } diff --git a/impl/src/test/java/com/sun/faces/facelets/component/UIRepeatTest.java b/impl/src/test/java/com/sun/faces/facelets/component/UIRepeatTest.java index d6c44d2952..564c220d54 100644 --- a/impl/src/test/java/com/sun/faces/facelets/component/UIRepeatTest.java +++ b/impl/src/test/java/com/sun/faces/facelets/component/UIRepeatTest.java @@ -16,22 +16,21 @@ package com.sun.faces.facelets.component; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; import java.lang.reflect.Method; -import junit.framework.TestCase; - -import org.easymock.EasyMock; -import org.easymock.IAnswer; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import jakarta.faces.application.FacesMessage; import jakarta.faces.application.FacesMessage.Severity; import jakarta.faces.context.FacesContext; -public class UIRepeatTest extends TestCase { +public class UIRepeatTest { private FacesContext ctx; @@ -41,14 +40,13 @@ public class UIRepeatTest extends TestCase { @Test public void testHasErrorMessages() throws Exception { - ctx = EasyMock.createMock(FacesContext.class); - expect(ctx.getMaximumSeverity()).andAnswer(new IAnswer() { - @Override - public Severity answer() throws Throwable { - return maximumSeverity; - } - }).anyTimes(); - replay(ctx); + ctx = Mockito.mock(FacesContext.class); + when(ctx.getMaximumSeverity()).thenAnswer(new Answer() { + @Override + public Severity answer(InvocationOnMock invocation) throws Throwable { + return maximumSeverity; + } + }); maximumSeverity = FacesMessage.SEVERITY_WARN; assertEquals(false, hasErrorMessages(ctx)); diff --git a/impl/src/test/java/com/sun/faces/facelets/util/ClasspathTestCase.java b/impl/src/test/java/com/sun/faces/facelets/util/ClasspathTestCase.java index b37ead4d50..2f3761b609 100644 --- a/impl/src/test/java/com/sun/faces/facelets/util/ClasspathTestCase.java +++ b/impl/src/test/java/com/sun/faces/facelets/util/ClasspathTestCase.java @@ -16,17 +16,15 @@ package com.sun.faces.facelets.util; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.util.jar.JarFile; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -public class ClasspathTestCase extends TestCase { +import org.junit.jupiter.api.Test; - public static Test suite() { - return (new TestSuite(ClasspathTestCase.class)); - } +public class ClasspathTestCase { + @Test public void testGetAlternativeJarFile() throws Exception { String input = "rar:/scratch/fleme/fmwhome/AS11gR1SOA/soa/connectors/FileAdapter.rar!fileAdapter.jar!/META-INF/"; diff --git a/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java b/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java index ea2b0feaaa..e148807ba3 100644 --- a/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java +++ b/impl/src/test/java/com/sun/faces/junit/JUnitFacesTestCaseBase.java @@ -20,6 +20,9 @@ import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; + import com.sun.faces.mock.MockApplication; import com.sun.faces.mock.MockExternalContext; import com.sun.faces.mock.MockFacesContext; @@ -34,9 +37,8 @@ import jakarta.faces.application.ApplicationFactory; import jakarta.faces.context.FacesContextFactory; import jakarta.faces.lifecycle.LifecycleFactory; -import junit.framework.TestCase; -public class JUnitFacesTestCaseBase extends TestCase { +public class JUnitFacesTestCaseBase { protected MockApplication application = null; protected MockServletConfig config = null; @@ -48,14 +50,8 @@ public class JUnitFacesTestCaseBase extends TestCase { protected MockLifecycle lifecycle = null; protected MockHttpSession session = null; - public JUnitFacesTestCaseBase(String name) { - super(name); - } - - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); - // Set up Servlet API Objects servletContext = new MockServletContext(); servletContext.addInitParameter("appParamName", "appParamValue"); @@ -99,7 +95,7 @@ public void setUp() throws Exception { } - @Override + @AfterEach public void tearDown() throws Exception { FactoryFinder.releaseFactories(); Method reInitializeFactoryManager = FactoryFinder.class.getDeclaredMethod("reInitializeFactoryManager", (Class[]) null); @@ -115,7 +111,5 @@ public void tearDown() throws Exception { response = null; servletContext = null; session = null; - - super.tearDown(); } } diff --git a/impl/src/test/java/com/sun/faces/mock/MockExternalContextFactory.java b/impl/src/test/java/com/sun/faces/mock/MockExternalContextFactory.java index eb61af8874..662ed31b87 100644 --- a/impl/src/test/java/com/sun/faces/mock/MockExternalContextFactory.java +++ b/impl/src/test/java/com/sun/faces/mock/MockExternalContextFactory.java @@ -16,14 +16,13 @@ package com.sun.faces.mock; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; - import jakarta.faces.FacesException; import jakarta.faces.FactoryFinder; import jakarta.faces.context.ExternalContext; import jakarta.faces.context.ExternalContextFactory; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; public class MockExternalContextFactory extends ExternalContextFactory { diff --git a/impl/src/test/java/com/sun/faces/mock/MockFacesContextFactory.java b/impl/src/test/java/com/sun/faces/mock/MockFacesContextFactory.java index 6939db8d0b..59cdc6673e 100644 --- a/impl/src/test/java/com/sun/faces/mock/MockFacesContextFactory.java +++ b/impl/src/test/java/com/sun/faces/mock/MockFacesContextFactory.java @@ -17,10 +17,6 @@ package com.sun.faces.mock; import jakarta.el.ELContext; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; - import jakarta.faces.FacesException; import jakarta.faces.FactoryFinder; import jakarta.faces.application.Application; @@ -29,6 +25,9 @@ import jakarta.faces.context.FacesContext; import jakarta.faces.context.FacesContextFactory; import jakarta.faces.lifecycle.Lifecycle; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; public class MockFacesContextFactory extends FacesContextFactory { public MockFacesContextFactory(FacesContextFactory oldImpl) { diff --git a/impl/src/test/java/com/sun/faces/mock/MockLifecycle.java b/impl/src/test/java/com/sun/faces/mock/MockLifecycle.java index a463f65ab7..8977b8c90b 100644 --- a/impl/src/test/java/com/sun/faces/mock/MockLifecycle.java +++ b/impl/src/test/java/com/sun/faces/mock/MockLifecycle.java @@ -16,13 +16,12 @@ package com.sun.faces.mock; -import jakarta.servlet.http.HttpServletResponse; - import jakarta.faces.FacesException; import jakarta.faces.context.ExternalContext; import jakarta.faces.context.FacesContext; import jakarta.faces.event.PhaseListener; import jakarta.faces.lifecycle.Lifecycle; +import jakarta.servlet.http.HttpServletResponse; public class MockLifecycle extends Lifecycle { diff --git a/impl/src/test/java/com/sun/faces/mock/MockLifecycleFactory.java b/impl/src/test/java/com/sun/faces/mock/MockLifecycleFactory.java index e70a4a414e..4405d07d0d 100644 --- a/impl/src/test/java/com/sun/faces/mock/MockLifecycleFactory.java +++ b/impl/src/test/java/com/sun/faces/mock/MockLifecycleFactory.java @@ -16,14 +16,13 @@ package com.sun.faces.mock; +import java.util.ArrayList; import java.util.Iterator; import jakarta.faces.FactoryFinder; import jakarta.faces.lifecycle.Lifecycle; import jakarta.faces.lifecycle.LifecycleFactory; -import java.util.ArrayList; - public class MockLifecycleFactory extends LifecycleFactory { public MockLifecycleFactory(LifecycleFactory oldImpl) { diff --git a/impl/src/test/java/com/sun/faces/mock/MockServlet.java b/impl/src/test/java/com/sun/faces/mock/MockServlet.java index 6fb35a3267..d5264f2abf 100644 --- a/impl/src/test/java/com/sun/faces/mock/MockServlet.java +++ b/impl/src/test/java/com/sun/faces/mock/MockServlet.java @@ -17,6 +17,7 @@ package com.sun.faces.mock; import java.io.IOException; + import jakarta.servlet.Servlet; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletException; diff --git a/impl/src/test/java/com/sun/faces/renderkit/html_basic/BodyRendererTest.java b/impl/src/test/java/com/sun/faces/renderkit/html_basic/BodyRendererTest.java index 170cc90120..5d88c84add 100644 --- a/impl/src/test/java/com/sun/faces/renderkit/html_basic/BodyRendererTest.java +++ b/impl/src/test/java/com/sun/faces/renderkit/html_basic/BodyRendererTest.java @@ -16,16 +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 static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; import java.io.StringWriter; import java.util.Collections; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; - import jakarta.faces.application.Application; import jakarta.faces.application.ProjectStage; import jakarta.faces.component.Doctype; @@ -34,6 +31,9 @@ import jakarta.faces.context.FacesContext; import jakarta.faces.context.ResponseWriter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + /** * The JUnit tests for the BodyRenderer class. */ @@ -57,23 +57,21 @@ public void testDecode() { public void testEncodeBegin() throws Exception { StringWriter writer = new StringWriter(); ResponseWriter testResponseWriter = new TestResponseWriter(writer); - FacesContext facesContext = PowerMock.createPartialMock(FacesContext.class, "getResponseWriter"); - UIViewRoot viewRoot = PowerMock.createMock(UIViewRoot.class); - Doctype doctype = PowerMock.createMock(Doctype.class); + FacesContext facesContext = Mockito.mock(FacesContext.class); + UIViewRoot viewRoot = Mockito.mock(UIViewRoot.class); + Doctype doctype = Mockito.mock(Doctype.class); BodyRenderer bodyRenderer = new BodyRenderer(); HtmlBody htmlBody = new HtmlBody(); htmlBody.getAttributes().put("styleClass", "myclass"); - expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes(); - expect(facesContext.getViewRoot()).andReturn(viewRoot).anyTimes(); - expect(viewRoot.getDoctype()).andReturn(doctype).anyTimes(); - expect(doctype.getRootElement()).andReturn("html").anyTimes(); - expect(doctype.getPublic()).andReturn(null).anyTimes(); - expect(doctype.getSystem()).andReturn(null).anyTimes(); + when(facesContext.getResponseWriter()).thenReturn(testResponseWriter); + when(facesContext.getViewRoot()).thenReturn(viewRoot); + when(viewRoot.getDoctype()).thenReturn(doctype); + when(doctype.getRootElement()).thenReturn("html"); + when(doctype.getPublic()).thenReturn(null); + when(doctype.getSystem()).thenReturn(null); - PowerMock.replay(facesContext); bodyRenderer.encodeBegin(facesContext, htmlBody); - PowerMock.verify(facesContext); String html = writer.toString(); assertTrue(html.contains("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.emptyList()).anyTimes(); + when(facesContext.getApplication()).thenReturn(application); + when(facesContext.getClientIdsWithMessages()).thenReturn(Collections.emptyList().iterator()); + when(facesContext.getResponseWriter()).thenReturn(testResponseWriter); + when(facesContext.getViewRoot()).thenReturn(viewRoot); + when(facesContext.isProjectStage(ProjectStage.Development)).thenReturn(false); + when(viewRoot.getComponentResources(facesContext, "body")).thenReturn(Collections.emptyList()); - PowerMock.replay(facesContext, viewRoot, application); bodyRenderer.encodeEnd(facesContext, htmlBody); - PowerMock.verify(facesContext, viewRoot, application); String html = writer.toString(); assertTrue(html.contains("")); } diff --git a/impl/src/test/java/com/sun/faces/renderkit/html_basic/HeadRendererTest.java b/impl/src/test/java/com/sun/faces/renderkit/html_basic/HeadRendererTest.java index d47004c016..ccc36072a5 100644 --- a/impl/src/test/java/com/sun/faces/renderkit/html_basic/HeadRendererTest.java +++ b/impl/src/test/java/com/sun/faces/renderkit/html_basic/HeadRendererTest.java @@ -16,14 +16,14 @@ package com.sun.faces.renderkit.html_basic; -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; import java.io.StringWriter; import java.util.Collections; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.component.Doctype; import jakarta.faces.component.UIViewRoot; @@ -54,22 +54,20 @@ public void testDecode() { public void testEncodeBegin() throws Exception { StringWriter writer = new StringWriter(); ResponseWriter testResponseWriter = new TestResponseWriter(writer); - FacesContext facesContext = PowerMock.createPartialMock(FacesContext.class, "getResponseWriter"); - UIViewRoot viewRoot = PowerMock.createMock(UIViewRoot.class); - Doctype doctype = PowerMock.createMock(Doctype.class); + FacesContext facesContext = Mockito.mock(FacesContext.class, "getResponseWriter"); + UIViewRoot viewRoot = Mockito.mock(UIViewRoot.class); + Doctype doctype = Mockito.mock(Doctype.class); HeadRenderer headRenderer = new HeadRenderer(); HtmlHead htmlHead = new HtmlHead(); - expect(facesContext.getResponseWriter()).andReturn(testResponseWriter).anyTimes(); - expect(facesContext.getViewRoot()).andReturn(viewRoot).anyTimes(); - expect(viewRoot.getDoctype()).andReturn(doctype).anyTimes(); - expect(doctype.getRootElement()).andReturn("html").anyTimes(); - expect(doctype.getPublic()).andReturn(null).anyTimes(); - expect(doctype.getSystem()).andReturn(null).anyTimes(); + when(facesContext.getResponseWriter()).thenReturn(testResponseWriter); + when(facesContext.getViewRoot()).thenReturn(viewRoot); + when(viewRoot.getDoctype()).thenReturn(doctype); + when(doctype.getRootElement()).thenReturn("html"); + when(doctype.getPublic()).thenReturn(null); + when(doctype.getSystem()).thenReturn(null); - PowerMock.replay(facesContext); headRenderer.encodeBegin(facesContext, htmlHead); - PowerMock.verify(facesContext); String html = writer.toString(); assertTrue(html.contains("")); } diff --git a/impl/src/test/java/com/sun/faces/renderkit/html_basic/HtmlResponseWriterTest.java b/impl/src/test/java/com/sun/faces/renderkit/html_basic/HtmlResponseWriterTest.java index 83d1d22629..a768502b0b 100644 --- a/impl/src/test/java/com/sun/faces/renderkit/html_basic/HtmlResponseWriterTest.java +++ b/impl/src/test/java/com/sun/faces/renderkit/html_basic/HtmlResponseWriterTest.java @@ -16,19 +16,21 @@ package com.sun.faces.renderkit.html_basic; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.StringWriter; import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.Method; -import org.junit.Test; +import org.junit.jupiter.api.Test; import jakarta.faces.component.UIComponent; import jakarta.faces.component.UIOutput; import jakarta.faces.context.FacesContext; -import static org.junit.Assert.*; - public class HtmlResponseWriterTest { /** diff --git a/impl/src/test/java/com/sun/faces/spi/ConfigurationResourceProviderFactoryTest.java b/impl/src/test/java/com/sun/faces/spi/ConfigurationResourceProviderFactoryTest.java index fba1e9ac76..9f3ec3a0d3 100644 --- a/impl/src/test/java/com/sun/faces/spi/ConfigurationResourceProviderFactoryTest.java +++ b/impl/src/test/java/com/sun/faces/spi/ConfigurationResourceProviderFactoryTest.java @@ -1,13 +1,16 @@ package com.sun.faces.spi; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; +import org.junit.jupiter.api.Test; + import com.sun.faces.spi.ConfigurationResourceProviderFactory.ProviderType; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; /** * Tests {@link ConfigurationResourceProviderFactory}. @@ -52,7 +55,7 @@ public void testCreateProvidersSuccessful() throws FileNotFoundException { * @throws FileNotFoundException * Thrown when the test service file can't be written. */ - @Test(expected = IllegalStateException.class) + @Test public void testCreateProvidersWrongService() throws FileNotFoundException { ProviderType facesConfig = ProviderType.FacesConfig; @@ -65,7 +68,7 @@ public void testCreateProvidersWrongService() throws FileNotFoundException { } try { - ConfigurationResourceProviderFactory.createProviders(facesConfig); + assertThrows(IllegalStateException.class, () -> ConfigurationResourceProviderFactory.createProviders(facesConfig)); } finally { servicesFile.delete(); } diff --git a/impl/src/test/java/com/sun/faces/util/ByteArrayGuardAESCTRTest.java b/impl/src/test/java/com/sun/faces/util/ByteArrayGuardAESCTRTest.java index 50ccaf5de7..d4740f76b6 100644 --- a/impl/src/test/java/com/sun/faces/util/ByteArrayGuardAESCTRTest.java +++ b/impl/src/test/java/com/sun/faces/util/ByteArrayGuardAESCTRTest.java @@ -16,16 +16,19 @@ package com.sun.faces.util; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.security.InvalidKeyException; -import jakarta.xml.bind.DatatypeConverter; -import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.jupiter.api.Test; + +import jakarta.xml.bind.DatatypeConverter; public class ByteArrayGuardAESCTRTest { - + @Test public void testSmallerSizeBytes() throws Exception { ByteArrayGuardAESCTR guard = new ByteArrayGuardAESCTR(); @@ -34,22 +37,22 @@ public void testSmallerSizeBytes() throws Exception { String value = "1fX_2vX"; String encrypted = guard.encrypt(value); assertTrue(encrypted.length() < 33); - + String decryptedValue = guard.decrypt(encrypted); assertEquals(decryptedValue, value); - + } - - @Test(expected = InvalidKeyException.class) + + @Test public void testDecryptValueWithoutIvBytes() throws InvalidKeyException { ByteArrayGuardAESCTR sut = new ByteArrayGuardAESCTR(); - + String value = "noIV"; byte[] bytes = DatatypeConverter.parseBase64Binary(value); assertTrue(bytes.length < 16); - sut.decrypt(value); + assertThrows(InvalidKeyException.class, () -> sut.decrypt(value)); } } diff --git a/impl/src/test/java/com/sun/faces/util/FacesLoggerTest.java b/impl/src/test/java/com/sun/faces/util/FacesLoggerTest.java index b4d0830c71..badfa24957 100644 --- a/impl/src/test/java/com/sun/faces/util/FacesLoggerTest.java +++ b/impl/src/test/java/com/sun/faces/util/FacesLoggerTest.java @@ -1,14 +1,16 @@ package com.sun.faces.util; +import java.util.Locale; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + import com.sun.faces.mock.MockApplication; import com.sun.faces.mock.MockFacesContext; + import jakarta.el.ELContext; import jakarta.faces.component.UIViewRoot; -import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Locale; public class FacesLoggerTest { @@ -16,14 +18,14 @@ public class FacesLoggerTest { public void unresolvedNavigationUS() { MockFacesContext facesContext = new MockFacesContext(); facesContext.setApplication(new MockApplication()); - facesContext.setELContext(EasyMock.createMock(ELContext.class)); + facesContext.setELContext(Mockito.mock(ELContext.class)); UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); root.setLocale(Locale.US); facesContext.setViewRoot(root); final Object[] params = {"componentId1", "outcome.xhtml", "viewId.xhtml"}; Locale.setDefault(new Locale("en", "US")); final String result = FacesLogger.RENDERKIT.interpolateMessage(facesContext, "faces.outcometarget.navigation.case.not.resolved", params); - Assert.assertEquals("JSF1090: Navigation case outcome.xhtml not resolved for component componentId1 in viewId viewId.xhtml", result); + Assertions.assertEquals("JSF1090: Navigation case outcome.xhtml not resolved for component componentId1 in viewId viewId.xhtml", result); } @@ -31,13 +33,13 @@ public void unresolvedNavigationUS() { public void unresolvedNavigationGermany() { MockFacesContext facesContext = new MockFacesContext(); facesContext.setApplication(new MockApplication()); - facesContext.setELContext(EasyMock.createMock(ELContext.class)); + facesContext.setELContext(Mockito.mock(ELContext.class)); UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); root.setLocale(Locale.GERMANY); facesContext.setViewRoot(root); final Object[] params = {"componentId1", "outcome.xhtml", "viewId.xhtml"}; Locale.setDefault(new Locale("de", "DE")); final String result = FacesLogger.RENDERKIT.interpolateMessage(facesContext, "faces.outcometarget.navigation.case.not.resolved", params); - Assert.assertEquals("JSF1090: Navigations-Fall wurde für Komponente componentId1 nicht aufgelöst.", result); + Assertions.assertEquals("JSF1090: Navigations-Fall wurde für Komponente componentId1 nicht aufgelöst.", result); } } diff --git a/impl/src/test/java/com/sun/faces/util/MostlySingletonTest.java b/impl/src/test/java/com/sun/faces/util/MostlySingletonTest.java index 26ead141bf..310ea86ed9 100644 --- a/impl/src/test/java/com/sun/faces/util/MostlySingletonTest.java +++ b/impl/src/test/java/com/sun/faces/util/MostlySingletonTest.java @@ -16,10 +16,12 @@ package com.sun.faces.util; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.HashSet; import java.util.Set; -import org.junit.Test; -import static org.junit.Assert.*; + +import org.junit.jupiter.api.Test; public class MostlySingletonTest { diff --git a/impl/src/test/java/com/sun/faces/util/TestHtmlUtils.java b/impl/src/test/java/com/sun/faces/util/TestHtmlUtils.java index f585413391..55255644ae 100644 --- a/impl/src/test/java/com/sun/faces/util/TestHtmlUtils.java +++ b/impl/src/test/java/com/sun/faces/util/TestHtmlUtils.java @@ -16,17 +16,20 @@ // TestHtmlUtils.java package com.sun.faces.util; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.StringWriter; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * TestHtmlUtils is a class ... */ -public class TestHtmlUtils extends TestCase { +public class TestHtmlUtils { + @Test public void testWriteURL() throws IOException { //Test url with no params testURLEncoding("http://www.google.com", @@ -66,6 +69,7 @@ public void testWriteURL() throws IOException { "/index.jsf?greek=%CE%B5%CE%BB&cyrillic=%D0%BA%D0%B8&hebrew=%D7%99%D7%AA&arabic=%D9%8A%D8%A9%D9%8F%E2%80%8E%E2%80%8E&korean=%ED%95%9C%EA%B8%80"); } + @Test public void testControlCharacters() throws IOException { final char[] controlCharacters = new char[32]; diff --git a/impl/src/test/java/com/sun/faces/util/TestLRUMap_local.java b/impl/src/test/java/com/sun/faces/util/TestLRUMap_local.java index 4a4eaf1425..60e54e28c8 100644 --- a/impl/src/test/java/com/sun/faces/util/TestLRUMap_local.java +++ b/impl/src/test/java/com/sun/faces/util/TestLRUMap_local.java @@ -15,31 +15,24 @@ */ package com.sun.faces.util; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; -import java.util.List; import java.util.Collections; +import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; /** * Validate LRU functionality of LRUMap */ -public class TestLRUMap_local extends TestCase { - - // ------------------------------------------------------------ Constructors - public TestLRUMap_local() { - super("TestLRUMap_local"); - } - - public TestLRUMap_local(String name) { - super(name); - } +public class TestLRUMap_local { // ------------------------------------------------------------ Test Methods /** * Ensure that LRUMap works as advertised. */ + @Test public void testLRUMap() { LRUMap map = new LRUMap(5); diff --git a/impl/src/test/java/com/sun/faces/util/TestUtil_local.java b/impl/src/test/java/com/sun/faces/util/TestUtil_local.java index 8e6987494e..404bad4b68 100644 --- a/impl/src/test/java/com/sun/faces/util/TestUtil_local.java +++ b/impl/src/test/java/com/sun/faces/util/TestUtil_local.java @@ -17,46 +17,23 @@ // TestUtil_local.java package com.sun.faces.util; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.util.HashMap; +import org.junit.jupiter.api.Test; /** * TestUtil_local.java is a class ... - * + * * Lifetime And Scope *

* */ -public class TestUtil_local extends TestCase { - -// -// Protected Constants -// -// Class Variables -// -// -// Instance Variables -// -// Attribute Instance Variables -// Relationship Instance Variables -// -// Constructors and Initializers -// - public TestUtil_local() { - super("TestUtil_local.java"); - } +public class TestUtil_local { - public TestUtil_local(String name) { - super(name); - } - -// -// Class methods -// -// -// General Methods -// + @Test public void testGetLocaleFromString() { // positive tests assertNotNull(Util.getLocaleFromString("ps")); @@ -90,23 +67,25 @@ public void testGetLocaleFromString() { } catch (Exception exception) { } } - + + @Test public void testSplit() { String[] result = null; - + result = Util.split(new HashMap(), "fooBarKey=Zm9vQmFyVmFsdWU====", "=", 2); assertEquals(2, result.length); assertEquals(result[1], "Zm9vQmFyVmFsdWU===="); - + result = Util.split(new HashMap(), "fooBarKey=Zm9vQmFyVmFsdWU=", "=", 2); assertEquals(2, result.length); assertEquals(result[1], "Zm9vQmFyVmFsdWU="); - + result = Util.split(new HashMap(), "fooBarKey2=Zm9vQmFyVmFsdWUy", "=", 2); assertEquals(2, result.length); assertEquals(result[1], "Zm9vQmFyVmFsdWUy"); } + @Test public void testExtractFirstNumericSegment() { char separatorChar = ':'; @@ -132,5 +111,5 @@ public void testExtractFirstNumericSegment() { assertEquals("there is no numeric segment", e.getMessage()); } } - + } // end of class TestUtil_local diff --git a/impl/src/test/java/com/sun/faces/xml/ParseXMLTestCase.java b/impl/src/test/java/com/sun/faces/xml/ParseXMLTestCase.java index 1e5976421a..93a90d6f83 100644 --- a/impl/src/test/java/com/sun/faces/xml/ParseXMLTestCase.java +++ b/impl/src/test/java/com/sun/faces/xml/ParseXMLTestCase.java @@ -16,6 +16,8 @@ package com.sun.faces.xml; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; @@ -24,34 +26,19 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class ParseXMLTestCase extends TestCase { +public class ParseXMLTestCase { List list = new ArrayList<>(); private final static String xmlDir = "/conf/share"; - public ParseXMLTestCase(String name) { - super(name); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - } - - public static Test suite() { - return (new TestSuite(ParseXMLTestCase.class)); - } - // ------------------------------------------------------------ Test Methods /** * Added for issue 904. */ + @Test public void testParseXML() throws Exception { String curDir = System.getProperty("user.dir"); @@ -81,7 +68,7 @@ public void testParseXML() throws Exception { } // Process all files and directories under dir - public void visitAllDirsAndFiles(File dir) { + private void visitAllDirsAndFiles(File dir) { if (dir.isFile()) { if (isXML(dir)) { @@ -96,7 +83,7 @@ public void visitAllDirsAndFiles(File dir) { } } - public boolean isXML(File file) { + private boolean isXML(File file) { String name = file.getName(); return name.endsWith(".xml"); } diff --git a/impl/src/test/java/com/sun/faces/xml/XHTMLResolvingHandler.java b/impl/src/test/java/com/sun/faces/xml/XHTMLResolvingHandler.java index 766ca44be3..3fde265a21 100644 --- a/impl/src/test/java/com/sun/faces/xml/XHTMLResolvingHandler.java +++ b/impl/src/test/java/com/sun/faces/xml/XHTMLResolvingHandler.java @@ -24,6 +24,7 @@ import java.io.UnsupportedEncodingException; import java.util.Locale; import java.util.ResourceBundle; + import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; diff --git a/impl/src/test/java/jakarta/faces/FacesConfigOrderingTestCase.java b/impl/src/test/java/jakarta/faces/FacesConfigOrderingTestCase.java index c072c4fd98..32a0eab13a 100644 --- a/impl/src/test/java/jakarta/faces/FacesConfigOrderingTestCase.java +++ b/impl/src/test/java/jakarta/faces/FacesConfigOrderingTestCase.java @@ -17,6 +17,7 @@ package jakarta.faces; import static com.sun.faces.util.Util.createLocalDocumentBuilderFactory; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Method; import java.util.ArrayList; @@ -27,6 +28,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -34,29 +37,13 @@ import com.sun.faces.config.manager.documents.DocumentOrderingWrapper; import jakarta.faces.context.FacesContext; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -public class FacesConfigOrderingTestCase extends TestCase { - - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name - * Name of the test case - */ - public FacesConfigOrderingTestCase(String name) { - super(name); - } +public class FacesConfigOrderingTestCase { // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); - Method method = FacesContext.class.getDeclaredMethod( "setCurrentInstance", FacesContext.class); method.setAccessible(true); @@ -64,17 +51,6 @@ public void setUp() throws Exception { } - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(FacesConfigOrderingTestCase.class)); - } - - // Tear down instance variables required by ths test case - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - // ------------------------------------------------- Individual Test Methods /** *

@@ -84,6 +60,7 @@ public void tearDown() throws Exception { * * @throws java.lang.Exception */ + @Test public void testNoOrderingStartWithCab() throws Exception { DocumentInfo docC = createDocument("C", null, null); DocumentInfo doca = createDocument("a", null, null); @@ -113,10 +90,11 @@ public void testNoOrderingStartWithCab() throws Exception { boolean assertion = (actually.equals(possibility1)); String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n"; - assertTrue(message, assertion); + assertTrue(assertion, message); System.out.println("testNoOrderingStartWithCab: Passed" + message); } - + + @Test public void testCafteraStartWithCab() throws Exception { List docCAfterIds = new ArrayList(); Collections.addAll(docCAfterIds, "a"); @@ -150,10 +128,11 @@ public void testCafteraStartWithCab() throws Exception { boolean assertion = (actually.equals(possibility1)); String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n"; - assertTrue(message, assertion); + assertTrue(assertion, message); System.out.println("testCafteraStartWithCab: Passed" + message); } - + + @Test public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithABCD() throws Exception { List docAAfterIds = new ArrayList(); Collections.addAll(docAAfterIds, "D"); @@ -203,10 +182,11 @@ public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithABCD() throw ); String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n"; - assertTrue(message, assertion); + assertTrue(assertion, message); System.out.println("testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithABCD: Passed" + message); } - + + @Test public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithADBC() throws Exception { List docAAfterIds = new ArrayList(); @@ -257,11 +237,12 @@ public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithADBC() throw ); String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n"; - assertTrue(message, assertion); + assertTrue(assertion, message); System.out.println("testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithADBC: Passed" + message); } - + + @Test public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_shuffle() throws Exception { List docAAfterIds = new ArrayList(); @@ -294,38 +275,38 @@ public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_shuffle() throws Exce new DocumentOrderingWrapper(docD) ); //J+ - + int number = 100; for (int i = 0; i < number; i++) { - + Collections.shuffle(documents); - + DocumentOrderingWrapper[] wrappers = documents.toArray(new DocumentOrderingWrapper[documents.size()]); String[] originalOrder = extractNames(wrappers); DocumentOrderingWrapper.sort(wrappers); - + String[] orderedNames = extractNames(wrappers); - + // some solutions: // [D, C, B, A] // [D, A, C, B] List original = Arrays.asList(originalOrder); List actually = Arrays.asList(orderedNames); - + List possibility1 = Arrays.asList("D", "C", "B", "A"); List possibility2 = Arrays.asList("D", "A", "C", "B"); - + boolean assertion = (actually.equals(possibility1) || actually.equals(possibility2) ); - String message = "\n original: " + original + + String message = "\n original: " + original + "\n expected: " + possibility1 + "\n or: " + possibility2 + "\n actually: " + actually + "\n"; - assertTrue(message, assertion); - + assertTrue(assertion, message); + } - + System.out.println("testAafterD_BafterCbeforeOthers_CafterDbeforeB_shuffle: " + number + " shuffles passed."); } @@ -359,7 +340,7 @@ private DocumentInfo createDocument(String documentId, return new DocumentInfo(document, null); } - + public static String[] extractNames(DocumentOrderingWrapper[] documents) { String[] extractedNames = new String[documents.length]; int i = 0; diff --git a/impl/src/test/java/jakarta/faces/FacesWrapperTestCase.java b/impl/src/test/java/jakarta/faces/FacesWrapperTestCase.java index f456c07f65..f8c6c76daa 100644 --- a/impl/src/test/java/jakarta/faces/FacesWrapperTestCase.java +++ b/impl/src/test/java/jakarta/faces/FacesWrapperTestCase.java @@ -16,6 +16,9 @@ package jakarta.faces; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -23,7 +26,8 @@ import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -32,7 +36,7 @@ * should help to keep the wrapper classes in synch with the wrapped classes. *

*/ -public class FacesWrapperTestCase extends TestCase { +public class FacesWrapperTestCase { private static List> wrapperClasses; private static List> noWrapperClasses; @@ -44,8 +48,8 @@ public class FacesWrapperTestCase extends TestCase { * implementing FacesWrapper. * @throws java.lang.Exception */ - @Override - protected void setUp() throws Exception { + @BeforeEach + public void setUp() throws Exception { if (wrapperClasses == null) { loadWrapperClasses(); methodsToIgnore = new ArrayList(); @@ -56,22 +60,24 @@ protected void setUp() throws Exception { /** * Unit test to assert wrapperClasses list was loaded (see {@link #setUp()}. */ + @Test public void testWrapperClassesLoaded() { assertNotNull(wrapperClasses); - assertTrue("no wrapper classes found!", !wrapperClasses.isEmpty()); + assertTrue(!wrapperClasses.isEmpty()); } /** * Unit test to assert there are no *Wrapper classes not implementing * FacesWrapper. */ + @Test public void testWrapperClassesImplementFacesWrapper() { assertNotNull(noWrapperClasses); if (noWrapperClasses.size() > 0) { System.out.println("Wrapper classes not implementing jakarta.faces.FacesWrapper:"); System.out.println(noWrapperClasses.toString()); } - assertTrue("Found wrapper classes not implementing FacesWrapper!", noWrapperClasses + assertTrue(noWrapperClasses .isEmpty()); } @@ -80,6 +86,7 @@ public void testWrapperClassesImplementFacesWrapper() { * implementing FacesWrapper do wrap all public and protected methods of the * wrapped class. */ + @Test public void testWrapperClassWrapsPublicAndProtectedMethods() { for (Class wrapper : wrapperClasses) { if (wrapper.isInterface()) { @@ -95,7 +102,7 @@ public void testWrapperClassWrapsPublicAndProtectedMethods() { if (isMethodContained(m, methodsToIgnore)) { continue; } - assertTrue(msg + m.toString(), isMethodContained(m, wrapperMethods)); + assertTrue(isMethodContained(m, wrapperMethods), msg + m.toString()); } } } @@ -154,8 +161,8 @@ private void loadWrapperClasses() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { collectWrapperClasses( - classLoader, - JAVAX_FACES_PKG, + classLoader, + JAVAX_FACES_PKG, new File(classLoader.getResource("jakarta/faces/Messages.properties").getFile()) .getParentFile()); } catch (Exception e) { diff --git a/impl/src/test/java/jakarta/faces/FactoryFinderTestCase.java b/impl/src/test/java/jakarta/faces/FactoryFinderTestCase.java index 1956391ccc..0738dfd342 100644 --- a/impl/src/test/java/jakarta/faces/FactoryFinderTestCase.java +++ b/impl/src/test/java/jakarta/faces/FactoryFinderTestCase.java @@ -16,10 +16,17 @@ package jakarta.faces; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.io.PrintWriter; import java.lang.reflect.Method; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.mock.MockHttpServletRequest; import com.sun.faces.mock.MockHttpServletResponse; import com.sun.faces.mock.MockServletContext; @@ -30,21 +37,8 @@ import jakarta.faces.context.FacesContextFactory; import jakarta.faces.lifecycle.Lifecycle; import jakarta.faces.lifecycle.LifecycleFactory; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class FactoryFinderTestCase extends TestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public FactoryFinderTestCase(String name) { - super(name); - } +public class FactoryFinderTestCase { public static String FACTORIES[][] = { {FactoryFinder.APPLICATION_FACTORY, @@ -66,10 +60,8 @@ public FactoryFinderTestCase(String name) { // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); - Method method = FacesContext.class.getDeclaredMethod("setCurrentInstance", FacesContext.class); method.setAccessible(true); method.invoke(null, new Object[]{null}); @@ -79,15 +71,9 @@ public void setUp() throws Exception { } } - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(FactoryFinderTestCase.class)); - } - // Tear down instance variables required by ths test case - @Override + @AfterEach public void tearDown() throws Exception { - super.tearDown(); FactoryFinder.releaseFactories(); for (int i = 0, len = FACTORIES.length; i < len; i++) { System.getProperties().remove(FACTORIES[i][0]); @@ -102,6 +88,7 @@ public void tearDown() throws Exception { * * @throws java.lang.Exception */ + @Test public void testFacesConfigCase() throws Exception { Object factory = null; Class clazz = null; @@ -150,12 +137,12 @@ public void testFacesConfigCase() throws Exception { for (i = 0, len = FACTORIES.length; i < len; i++) { clazz = Class.forName(FACTORIES[i][0]); factory = FactoryFinder.getFactory(FACTORIES[i][0]); - assertTrue("Factory for " + clazz.getName() - + " not of expected type.", - clazz.isAssignableFrom(factory.getClass())); + assertTrue( + clazz.isAssignableFrom(factory.getClass()), "Factory for " + clazz.getName() + + " not of expected type."); clazz = Class.forName(FACTORIES[i][1]); - assertTrue("Factory " + FACTORIES[i][1] + " not of expected type", - clazz.isAssignableFrom(factory.getClass())); + assertTrue( + clazz.isAssignableFrom(factory.getClass()), "Factory " + FACTORIES[i][1] + " not of expected type"); } // verify that the delegation works @@ -181,6 +168,7 @@ public void testFacesConfigCase() throws Exception { } // TODO re-enable + @Test public void testNoFacesContext() throws Exception { // assertNull(FacesContext.getCurrentInstance()); // Object result = FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); @@ -195,6 +183,7 @@ public void testNoFacesContext() throws Exception { * * @throws java.lang.Exception */ + @Test public void testServicesCase() throws Exception { Object factory = null; Class clazz = null; @@ -242,12 +231,12 @@ public void testServicesCase() throws Exception { for (i = 0, len = FACTORIES.length; i < len; i++) { clazz = Class.forName(FACTORIES[i][0]); factory = FactoryFinder.getFactory(FACTORIES[i][0]); - assertTrue("Factory for " + clazz.getName() - + " not of expected type.", - clazz.isAssignableFrom(factory.getClass())); + assertTrue( + clazz.isAssignableFrom(factory.getClass()), "Factory for " + clazz.getName() + + " not of expected type."); clazz = Class.forName(FACTORIES[i][1]); - assertTrue("Factory " + FACTORIES[i][1] + " not of expected type", - clazz.isAssignableFrom(factory.getClass())); + assertTrue( + clazz.isAssignableFrom(factory.getClass()), "Factory " + FACTORIES[i][1] + " not of expected type"); } // verify that the delegation works @@ -258,6 +247,7 @@ public void testServicesCase() throws Exception { cServicesFile.delete(); } + @Test public void testNoFacesContextInitially() throws Exception { assertNull(FacesContext.getCurrentInstance()); diff --git a/impl/src/test/java/jakarta/faces/FactoryFinderTestCase2.java b/impl/src/test/java/jakarta/faces/FactoryFinderTestCase2.java index e28e84c25c..8b91e1f928 100644 --- a/impl/src/test/java/jakarta/faces/FactoryFinderTestCase2.java +++ b/impl/src/test/java/jakarta/faces/FactoryFinderTestCase2.java @@ -16,59 +16,44 @@ package jakarta.faces; -import junit.framework.TestCase; -import junit.framework.Test; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class FactoryFinderTestCase2 extends TestCase { +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class FactoryFinderTestCase2 { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public FactoryFinderTestCase2(String name) { - super(name); - } - public static String FACTORIES[][] = { - { FactoryFinder.APPLICATION_FACTORY, + { FactoryFinder.APPLICATION_FACTORY, "com.sun.faces.mock.MockApplicationFactory" }, - { FactoryFinder.EXTERNAL_CONTEXT_FACTORY, + { FactoryFinder.EXTERNAL_CONTEXT_FACTORY, "com.sun.faces.mock.MockExternalContextFactory" }, - { FactoryFinder.FACES_CONTEXT_FACTORY, + { FactoryFinder.FACES_CONTEXT_FACTORY, "com.sun.faces.mock.MockFacesContextFactory" }, - { FactoryFinder.LIFECYCLE_FACTORY, + { FactoryFinder.LIFECYCLE_FACTORY, "com.sun.faces.mock.MockLifecycleFactory" }, - { FactoryFinder.RENDER_KIT_FACTORY, + { FactoryFinder.RENDER_KIT_FACTORY, "com.sun.faces.mock.MockRenderKitFactory" } }; // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); for (int i = 0, len = FactoryFinderTestCase2.FACTORIES.length; i < len; i++) { System.getProperties().remove(FactoryFinderTestCase2.FACTORIES[i][0]); } } - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(FactoryFinderTestCase2.class)); - } - // Tear down instance variables required by ths test case - @Override + @AfterEach public void tearDown() throws Exception { - super.tearDown(); FactoryFinder.releaseFactories(); for (int i = 0, len = FactoryFinderTestCase2.FACTORIES.length; i < len; i++) { System.getProperties().remove(FactoryFinderTestCase2.FACTORIES[i][0]); @@ -83,6 +68,7 @@ public void tearDown() throws Exception { * precedence.

* @throws java.lang.Exception */ + @Test public void testJSFImplCase() throws Exception { Object factory = null; Class clazz = null; @@ -100,12 +86,12 @@ public void testJSFImplCase() throws Exception { for (i = 0, len = FactoryFinderTestCase2.FACTORIES.length; i < len; i++) { clazz = Class.forName(FactoryFinderTestCase2.FACTORIES[i][0]); factory = FactoryFinder.getFactory(FactoryFinderTestCase2.FACTORIES[i][0]); - assertTrue("Factory for " + clazz.getName() - + " not of expected type.", - clazz.isAssignableFrom(factory.getClass())); + assertTrue( + clazz.isAssignableFrom(factory.getClass()), "Factory for " + clazz.getName() + + " not of expected type."); clazz = Class.forName(FactoryFinderTestCase2.FACTORIES[i][1]); - assertTrue("Factory " + FactoryFinderTestCase2.FACTORIES[i][1] + " not of expected type", - clazz.isAssignableFrom(factory.getClass())); + assertTrue( + clazz.isAssignableFrom(factory.getClass()), "Factory " + FactoryFinderTestCase2.FACTORIES[i][1] + " not of expected type"); } } } diff --git a/impl/src/test/java/jakarta/faces/component/NamingContainerTestCase.java b/impl/src/test/java/jakarta/faces/component/NamingContainerTestCase.java index c83be918e7..716212a50c 100644 --- a/impl/src/test/java/jakarta/faces/component/NamingContainerTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/NamingContainerTestCase.java @@ -16,17 +16,23 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.junit.JUnitFacesTestCaseBase; import com.sun.faces.mock.MockRenderKit; import jakarta.faces.FactoryFinder; import jakarta.faces.render.RenderKit; import jakarta.faces.render.RenderKitFactory; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -39,15 +45,10 @@ public class NamingContainerTestCase extends JUnitFacesTestCaseBase { // The root of the component tree to be tested private UIViewRoot root = null; - // ------------------------------------------------------------ Constructors - // Construct a new instance of this test case. - public NamingContainerTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -67,15 +68,9 @@ public void setUp() throws Exception { } - // Return the tests included in this test case. - public static Test suite() { - - return new TestSuite(NamingContainerTestCase.class); - - } - // Tear down instance variables required by this test case. @Override + @AfterEach public void tearDown() throws Exception { root = null; @@ -84,6 +79,7 @@ public void tearDown() throws Exception { // ------------------------------------------------- Individual Test Methods // Test nested NamingContainer callbacks + @Test public void testNested() { NamingContainerTestImpl a = new NamingContainerTestImpl(); @@ -134,6 +130,7 @@ public void testNested() { } // Test nested NamingContainer callbacks + @Test public void testNested2() { NamingContainerTestImpl a = new NamingContainerTestImpl(); @@ -184,6 +181,7 @@ public void testNested2() { } // Test standard NamingContainer functionality + @Test public void testStandard() { // Set up a component hierarchy as follows (component ids in quotes): diff --git a/impl/src/test/java/jakarta/faces/component/SearchExpressionHandlerTest.java b/impl/src/test/java/jakarta/faces/component/SearchExpressionHandlerTest.java index c2f87d76e5..85062251bc 100644 --- a/impl/src/test/java/jakarta/faces/component/SearchExpressionHandlerTest.java +++ b/impl/src/test/java/jakarta/faces/component/SearchExpressionHandlerTest.java @@ -16,13 +16,22 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.Assert; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.sun.faces.component.search.CompositeSearchKeywordResolver; import com.sun.faces.component.search.SearchExpressionContextFactoryImpl; @@ -57,11 +66,8 @@ public class SearchExpressionHandlerTest extends JUnitFacesTestCaseBase { - public SearchExpressionHandlerTest(String name) { - super(name); - } - @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -99,6 +105,7 @@ public void setUp() throws Exception { } @Override + @AfterEach public void tearDown() throws Exception { super.tearDown(); } @@ -153,6 +160,7 @@ public void invokeContextCallback(FacesContext context, UIComponent target) { } } + @Test public void test_ResolveComponent_Parent() { UIComponent root = new UIPanel(); @@ -172,9 +180,10 @@ public void test_ResolveComponent_Parent() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", innerContainer, resolveComponent(source, "@parent")); + assertSame(innerContainer, resolveComponent(source, "@parent")); } + @Test public void test_ResolveComponent_ParentParent() { UIComponent root = new UIPanel(); @@ -194,9 +203,10 @@ public void test_ResolveComponent_ParentParent() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", outerContainer, resolveComponent(source, "@parent:@parent")); + assertSame(outerContainer, resolveComponent(source, "@parent:@parent")); } + @Test public void test_ResolveComponent_Form() { UIComponent root = new UIPanel(); @@ -216,9 +226,10 @@ public void test_ResolveComponent_Form() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", form, resolveComponent(source, "@form")); + assertSame(form, resolveComponent(source, "@form")); } + @Test public void test_ResolveComponent_FormParent() { UIComponent root = new UIPanel(); @@ -238,9 +249,10 @@ public void test_ResolveComponent_FormParent() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", root, resolveComponent(source, "@form:@parent")); + assertSame(root, resolveComponent(source, "@form:@parent")); } + @Test public void test_ResolveComponent_All() { UIComponent root = new UIPanel(); @@ -260,9 +272,10 @@ public void test_ResolveComponent_All() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", root, resolveComponent(source, "@all")); + assertSame(root, resolveComponent(source, "@all")); } + @Test public void test_ResolveComponent_This() { UIComponent root = new UIPanel(); @@ -282,9 +295,10 @@ public void test_ResolveComponent_This() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", source, resolveComponent(source, "@this")); + assertSame(source, resolveComponent(source, "@this")); } + @Test public void test_ResolveComponent_ThisParent() { UIComponent root = new UIPanel(); @@ -304,9 +318,10 @@ public void test_ResolveComponent_ThisParent() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", innerContainer, resolveComponent(source, "@this:@parent")); + assertSame(innerContainer, resolveComponent(source, "@this:@parent")); } + @Test public void test_ResolveComponent_Namingcontainer() { UIComponent root = new UIPanel(); @@ -326,9 +341,10 @@ public void test_ResolveComponent_Namingcontainer() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", innerContainer, resolveComponent(source, "@namingcontainer")); + assertSame(innerContainer, resolveComponent(source, "@namingcontainer")); } + @Test public void test_ResolveComponent_Absolute() { UIComponent root = new UIPanel(); @@ -353,9 +369,10 @@ public void test_ResolveComponent_Absolute() { source.setId("source"); innerContainer.getChildren().add(source); - assertSame("Failed", source, resolveComponent(source, " :form:outerContainer:innerContainer:source ")); + assertSame(source, resolveComponent(source, " :form:outerContainer:innerContainer:source ")); } + @Test public void test_ResolveComponent_Relative() { UIComponent root = new UIPanel(); @@ -380,9 +397,10 @@ public void test_ResolveComponent_Relative() { source.setId("source"); innerContainer.getChildren().add(source); - assertSame("Failed", component, resolveComponent(source, " other ")); + assertSame(component, resolveComponent(source, " other ")); } + @Test public void test_ResolveComponent_AbsoluteForm() { UIComponent root = new UIPanel(); @@ -408,9 +426,10 @@ public void test_ResolveComponent_AbsoluteForm() { source.setId("source"); innerContainer.getChildren().add(source); - assertSame("Failed", root, resolveComponent(source, " :form:@parent ")); + assertSame(root, resolveComponent(source, " :form:@parent ")); } + @Test public void test_ResolveComponent_ParentChild() { UIComponent root = new UIPanel(); @@ -436,10 +455,11 @@ public void test_ResolveComponent_ParentChild() { source.setId("source"); innerContainer.getChildren().add(source); - assertSame("Failed", component, resolveComponent(source, " @parent:@child(0) ")); - assertSame("Failed", source, resolveComponent(source, " @parent:@child(1) ")); + assertSame(component, resolveComponent(source, " @parent:@child(0) ")); + assertSame(source, resolveComponent(source, " @parent:@child(1) ")); } + @Test public void test_ResolveComponent_AbsoluteNamingcontainer() { UIComponent root = new UIPanel(); @@ -465,9 +485,10 @@ public void test_ResolveComponent_AbsoluteNamingcontainer() { source.setId("source"); innerContainer.getChildren().add(source); - assertSame("Failed", form, resolveComponent(source, " :form:outerContainer:@namingcontainer ")); + assertSame(form, resolveComponent(source, " :form:outerContainer:@namingcontainer ")); } + @Test public void test_ResolveClientId_This() { UIComponent root = new UIPanel(); @@ -491,9 +512,10 @@ public void test_ResolveClientId_This() { source.setId("source"); innerContainer.getChildren().add(source); - assertEquals("Failed", "form:outerContainer:innerContainer:source", resolveClientId(source, " @this ")); + assertEquals("form:outerContainer:innerContainer:source", resolveClientId(source, " @this ")); } + @Test public void test_ResolveClientId_Form() { UIComponent root = new UIPanel(); @@ -517,9 +539,10 @@ public void test_ResolveClientId_Form() { source.setId("source"); innerContainer.getChildren().add(source); - assertEquals("Failed", "form", resolveClientId(source, " @form ")); + assertEquals("form", resolveClientId(source, " @form ")); } + @Test public void test_ResolveClientId_AbsoluteId() { UIComponent root = new UIPanel(); @@ -543,9 +566,10 @@ public void test_ResolveClientId_AbsoluteId() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertEquals("Failed", "form", resolveClientId(source, " :form ")); + assertEquals("form", resolveClientId(source, " :form ")); } + @Test public void test_ResolveClientId_Relative() { UIComponent root = new UIPanel(); @@ -570,9 +594,10 @@ public void test_ResolveClientId_Relative() { source.setId("source"); innerContainer.getChildren().add(source); - assertEquals("Failed", "form:outerContainer:innerContainer:other", resolveClientId(source, " other ")); + assertEquals("form:outerContainer:innerContainer:other", resolveClientId(source, " other ")); } + @Test public void test_ResolveComponents_RelativeAndParentParent() { UIComponent root = new UIPanel(); @@ -598,11 +623,12 @@ public void test_ResolveComponents_RelativeAndParentParent() { innerContainer.getChildren().add(source); List resolvedComponents = resolveComponents(source, " other @parent:@parent "); - assertTrue("Failed", resolvedComponents.contains(component)); - assertTrue("Failed", resolvedComponents.contains(outerContainer)); - assertEquals("Failed", 2, resolvedComponents.size()); + assertTrue(resolvedComponents.contains(component)); + assertTrue(resolvedComponents.contains(outerContainer)); + assertEquals(2, resolvedComponents.size()); } + @Test public void test_ResolveComponents_RelativeAndThisParent() { UIComponent root = new UIPanel(); @@ -628,11 +654,12 @@ public void test_ResolveComponents_RelativeAndThisParent() { innerContainer.getChildren().add(source); List resolvedComponents = resolveComponents(source, " other,@this:@parent @none "); - assertTrue("Failed", resolvedComponents.contains(component)); - assertTrue("Failed", resolvedComponents.contains(innerContainer)); - assertEquals("Failed", 2, resolvedComponents.size()); + assertTrue(resolvedComponents.contains(component)); + assertTrue(resolvedComponents.contains(innerContainer)); + assertEquals(2, resolvedComponents.size()); } + @Test public void test_ResolveComponent_Next() { UIComponent root = new UIPanel(); @@ -650,8 +677,8 @@ public void test_ResolveComponent_Next() { command3.setId("command3"); root.getChildren().add(command3); - assertSame("Failed", command2, resolveComponent(command1, " @next ")); - assertSame("Failed", command3, resolveComponent(command2, " @next ")); + assertSame(command2, resolveComponent(command1, " @next ")); + assertSame(command3, resolveComponent(command2, " @next ")); try { resolveComponent(command3, " @next"); @@ -661,6 +688,7 @@ public void test_ResolveComponent_Next() { } } + @Test public void test_ResolveComponent_NextNext() { UIComponent root = new UIPanel(); @@ -678,7 +706,7 @@ public void test_ResolveComponent_NextNext() { command3.setId("command3"); root.getChildren().add(command3); - assertSame("Failed", command3, resolveComponent(command1, " @next:@next ")); + assertSame(command3, resolveComponent(command1, " @next:@next ")); try { resolveComponent(command2, " @next:@next"); @@ -695,6 +723,7 @@ public void test_ResolveComponent_NextNext() { } } + @Test public void test_ResolveComponent_Previous() { UIComponent root = new UIPanel(); @@ -712,8 +741,8 @@ public void test_ResolveComponent_Previous() { command3.setId("command3"); root.getChildren().add(command3); - assertSame("Failed", command1, resolveComponent(command2, " @previous ")); - assertSame("Failed", command2, resolveComponent(command3, " @previous ")); + assertSame(command1, resolveComponent(command2, " @previous ")); + assertSame(command2, resolveComponent(command3, " @previous ")); try { resolveComponent(command1, " @previous"); @@ -723,6 +752,7 @@ public void test_ResolveComponent_Previous() { } } + @Test public void test_ResolveComponent_Root() { UIComponent root = new UIPanel(); @@ -740,9 +770,10 @@ public void test_ResolveComponent_Root() { command3.setId("command3"); root.getChildren().add(command3); - assertSame("Failed", facesContext.getViewRoot(), resolveComponent(command2, " @root ")); + assertSame(facesContext.getViewRoot(), resolveComponent(command2, " @root ")); } + @Test public void test_ResolveComponent_FormChildNextNext() { UIForm root = new UIForm(); @@ -760,9 +791,10 @@ public void test_ResolveComponent_FormChildNextNext() { command3.setId("command3"); root.getChildren().add(command3); - assertSame("Failed", command3, resolveComponent(command1, " @form:@child(0):@next:@next ")); + assertSame(command3, resolveComponent(command1, " @form:@child(0):@next:@next ")); } + @Test public void test_ResolveComponent_IgnoreNoResult() { UIForm root = new UIForm(); root.setId("form"); @@ -775,9 +807,10 @@ public void test_ResolveComponent_IgnoreNoResult() { command2.setId("command2"); root.getChildren().add(command2); - assertSame("Failed", null, resolveComponent(command1, " command3 ", SearchExpressionHint.IGNORE_NO_RESULT)); + assertSame(null, resolveComponent(command1, " command3 ", SearchExpressionHint.IGNORE_NO_RESULT)); } + @Test public void test_ResolveClientId_AbsoluteWithFormPrependIdFalse() { UIComponent root = new UIPanel(); @@ -803,9 +836,10 @@ public void test_ResolveClientId_AbsoluteWithFormPrependIdFalse() { source.setId("source"); innerContainer.getChildren().add(source); - assertEquals("Failed", "outerContainer:innerContainer:source", resolveClientId(source, " :form:outerContainer:innerContainer:source ")); + assertEquals("outerContainer:innerContainer:source", resolveClientId(source, " :form:outerContainer:innerContainer:source ")); } + @Test public void test_ResolveClientId_AbsoluteWithFormPrependIdFalse_InvokeOnComponent() { UIComponent root = new UIPanel(); @@ -831,76 +865,79 @@ public void test_ResolveClientId_AbsoluteWithFormPrependIdFalse_InvokeOnComponen source.setId("source"); innerContainer.getChildren().add(source); - assertEquals("Failed", "outerContainer:innerContainer:source", resolveClientId(source, " outerContainer:innerContainer:source ")); + assertEquals("outerContainer:innerContainer:source", resolveClientId(source, " outerContainer:innerContainer:source ")); } + @Test public void test_Passthrough() { SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler(); SearchExpressionContext searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(facesContext, null); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:showName")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:nested:1:nestedText")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:baseText")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:0:baseText")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:nested:0:nestedText")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:nested")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:1:nested:0:nestedText")); - - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@this")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@this:@parent:showName")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@parent:showName:@parent:showName")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form:showName")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@namingcontainer:showName")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@previous")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@next")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@parent:@id(msgName)")); - - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@whoNows")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@parent:@whoNows")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:@whoNows")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "!whoNows")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:showName")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:nested:1:nestedText")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:baseText")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:0:baseText")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:nested:0:nestedText")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:3:nested")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:table:1:nested:0:nestedText")); + + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@this")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@this:@parent:showName")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@parent:showName:@parent:showName")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form:showName")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@namingcontainer:showName")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@previous")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@next")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@parent:@id(msgName)")); + + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@whoNows")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@parent:@whoNows")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "mainForm:@whoNows")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "!whoNows")); Set hints = new HashSet<>(); hints.add(SearchExpressionHint.RESOLVE_CLIENT_SIDE); searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(facesContext, null, hints, null); - Assert.assertTrue(handler.isPassthroughExpression(searchExpressionContext, "@form")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form:showName")); - Assert.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form:@child(0)")); + Assertions.assertTrue(handler.isPassthroughExpression(searchExpressionContext, "@form")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form:showName")); + Assertions.assertFalse(handler.isPassthroughExpression(searchExpressionContext, "@form:@child(0)")); } + @Test public void test_Valid() { SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler(); SearchExpressionContext searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(facesContext, null); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:showName")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:nested:1:nestedText")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:baseText")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:0:baseText")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:nested:0:nestedText")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:nested")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:1:nested:0:nestedText")); - - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@this")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@this:@parent:showName")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@parent:showName:@parent:showName")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@form:showName")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@namingcontainer:showName")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@previous")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@next")); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@parent:@id(msgName)")); - - Assert.assertFalse(handler.isValidExpression(searchExpressionContext, "@whoNows")); - Assert.assertFalse(handler.isValidExpression(searchExpressionContext, "@parent:@whoNows")); - Assert.assertFalse(handler.isValidExpression(searchExpressionContext, "mainForm:@whoNows")); - - Assert.assertFalse(handler.isValidExpression(searchExpressionContext, "@none:@parent")); - Assert.assertFalse(handler.isValidExpression(searchExpressionContext, "@all:@parent")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:showName")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:nested:1:nestedText")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:baseText")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:0:baseText")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:nested:0:nestedText")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:3:nested")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "mainForm:table:1:nested:0:nestedText")); + + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@this")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@this:@parent:showName")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@parent:showName:@parent:showName")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@form:showName")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@namingcontainer:showName")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@previous")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@next")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@parent:@id(msgName)")); + + Assertions.assertFalse(handler.isValidExpression(searchExpressionContext, "@whoNows")); + Assertions.assertFalse(handler.isValidExpression(searchExpressionContext, "@parent:@whoNows")); + Assertions.assertFalse(handler.isValidExpression(searchExpressionContext, "mainForm:@whoNows")); + + Assertions.assertFalse(handler.isValidExpression(searchExpressionContext, "@none:@parent")); + Assertions.assertFalse(handler.isValidExpression(searchExpressionContext, "@all:@parent")); } + @Test public void test_ResolveComponents_Id() { UIComponent root = new UIPanel(); FacesContext.getCurrentInstance().getViewRoot().getChildren().add(root); @@ -938,6 +975,7 @@ public void test_ResolveComponents_Id() { * The SearchExpression API was inspired by PrimeFaces. This test only tests, if PFS (PrimeFaces Selectors -> jQuery * like selectors; like @(#myId > .myStyle)) can be correctly handled by the API+IMPL as a passthrough expression. */ + @Test public void test_PFS() { CompositeSearchKeywordResolver s = (CompositeSearchKeywordResolver) application.getSearchKeywordResolver(); s.add(new SearchKeywordResolver() { @@ -970,10 +1008,11 @@ public boolean isLeaf(SearchExpressionContext searchExpressionContext, String ke SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler(); SearchExpressionContext searchExpressionContext = SearchExpressionContext.createSearchExpressionContext(facesContext, null); - Assert.assertTrue(handler.isValidExpression(searchExpressionContext, "@(.myPanel #id)")); - Assert.assertFalse(handler.isValidExpression(searchExpressionContext, "@(.myPanel #id):test")); + Assertions.assertTrue(handler.isValidExpression(searchExpressionContext, "@(.myPanel #id)")); + Assertions.assertFalse(handler.isValidExpression(searchExpressionContext, "@(.myPanel #id):test")); } + @Test public void test_chainOfResponsability() { CompositeSearchKeywordResolver s = (CompositeSearchKeywordResolver) application.getSearchKeywordResolver(); s.add(new CustomSearchKeywordResolverImplForm()); // drop in new @form resolver @@ -995,8 +1034,8 @@ public void test_chainOfResponsability() { UIComponent source = new UICommand(); innerContainer.getChildren().add(source); - assertSame("Failed", source, resolveComponent(source, "@form")); - assertNotSame("Failed", form, resolveComponent(source, "@form")); + assertSame(source, resolveComponent(source, "@form")); + assertNotSame(form, resolveComponent(source, "@form")); } class CustomSearchKeywordResolverImplForm extends SearchKeywordResolverImplForm { @@ -1006,6 +1045,7 @@ public void resolve(SearchKeywordContext searchKeywordContext, UIComponent curre } } + @Test public void test_ResolveComponent_LeafErrorHandling() { UIComponent root = new UIPanel(); diff --git a/impl/src/test/java/jakarta/faces/component/StateHolderSaverTestCase.java b/impl/src/test/java/jakarta/faces/component/StateHolderSaverTestCase.java index 803413d60a..721dce80c4 100644 --- a/impl/src/test/java/jakarta/faces/component/StateHolderSaverTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/StateHolderSaverTestCase.java @@ -16,42 +16,37 @@ package jakarta.faces.component; -import jakarta.faces.convert.IntegerConverter; -import junit.framework.Test; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -public class StateHolderSaverTestCase extends UIComponentBaseTestCase { +import org.junit.jupiter.api.Test; - // ------------------------------------------------------ Instance Variables - // ------------------------------------------------------------ Constructors - // Construct a new instance of this test case. - public StateHolderSaverTestCase(String name) { - super(name); - } +import jakarta.faces.convert.IntegerConverter; - // ---------------------------------------------------- Overall Test Methods - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(StateHolderSaverTestCase.class); - } +public class StateHolderSaverTestCase extends UIComponentBaseTestCase { // ------------------------------------------------- Individual Test Methods @Override + @Test public void testLifecycleManagement() { } @Override + @Test public void testChildrenRecursive() { } @Override + @Test public void testComponentReconnect() { } @Override + @Test public void testComponentRemoval() { } + @Test public void testImplementsStateHolder() throws Exception { StateHolderSaver saver = null; UIInput postSave, preSave = new UIInput(); @@ -63,6 +58,7 @@ public void testImplementsStateHolder() throws Exception { assertEquals(postSave.getId(), preSave.getId()); } + @Test public void testImplementsSerializable() throws Exception { StateHolderSaver saver = null; String preSave = "hello"; @@ -73,6 +69,7 @@ public void testImplementsSerializable() throws Exception { assertTrue(preSave.equals(postSave)); } + @Test public void testImplementsNeither() throws Exception { StateHolderSaver saver = null; IntegerConverter preSave = new IntegerConverter(), postSave = null; diff --git a/impl/src/test/java/jakarta/faces/component/UIColumnTestCase.java b/impl/src/test/java/jakarta/faces/component/UIColumnTestCase.java index 252331471b..e17feeb7cf 100644 --- a/impl/src/test/java/jakarta/faces/component/UIColumnTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIColumnTestCase.java @@ -16,8 +16,9 @@ package jakarta.faces.component; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -26,19 +27,10 @@ */ public class UIColumnTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIColumnTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UIColumn(); @@ -47,13 +39,9 @@ public void setUp() throws Exception { expectedRendererType = null; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIColumnTestCase.class); - } - // Tear down instance variables required by ths test case @Override + @AfterEach public void tearDown() throws Exception { super.tearDown(); } @@ -61,6 +49,7 @@ public void tearDown() throws Exception { // ------------------------------------------------- Individual Test Methods // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } diff --git a/impl/src/test/java/jakarta/faces/component/UICommandTestCase.java b/impl/src/test/java/jakarta/faces/component/UICommandTestCase.java index 40be6928ca..b6d12aea60 100644 --- a/impl/src/test/java/jakarta/faces/component/UICommandTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UICommandTestCase.java @@ -16,10 +16,16 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.mock.MockExternalContext; import jakarta.faces.FactoryFinder; @@ -30,8 +36,6 @@ import jakarta.faces.render.RenderKit; import jakarta.faces.render.RenderKitFactory; import jakarta.faces.render.Renderer; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -40,19 +44,10 @@ */ public class UICommandTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UICommandTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UICommand(); @@ -61,11 +56,6 @@ public void setUp() throws Exception { expectedRendererType = "jakarta.faces.Button"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UICommandTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test order of action listener calls with actionListener also public void PENDING_FIXME_testActionOrder() throws Exception { @@ -98,6 +88,7 @@ public void PENDING_FIXME_testActionOrder() throws Exception { } // Test event queuing and broadcasting (any phase listeners) + @Test public void testEventsGeneric() { UICommand command = (UICommand) component; @@ -122,6 +113,7 @@ public void testEventsGeneric() { } // Test event queuing and broadcasting (mixed phase listeners) + @Test public void testEventsMixed() { UICommand command = (UICommand) component; @@ -147,6 +139,7 @@ public void testEventsMixed() { // Test event queuing and broadcasting (mixed phase listeners), with // immediate set. + @Test public void testEventsMixedImmediate() { UICommand command = (UICommand) component; @@ -172,6 +165,7 @@ public void testEventsMixedImmediate() { } // Test listener registration and deregistration + @Test public void testListeners() { CommandTestImpl command = new CommandTestImpl(); @@ -191,6 +185,7 @@ public void testListeners() { } // Test empty listener list + @Test public void testEmptyListeners() { CommandTestImpl command = new CommandTestImpl(); @@ -203,9 +198,11 @@ public void testEmptyListeners() { // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } + @Test public void testNestedCommands() { UIViewRoot root = new UIViewRoot(); UICommand c1 = new UICommand(); @@ -229,6 +226,7 @@ public void testNestedCommands() { assertTrue(ae.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)); } + @Test public void testGetActionListeners() throws Exception { UICommand command = (UICommand) component; UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); diff --git a/impl/src/test/java/jakarta/faces/component/UIComponentBaseAttachedStateTestCase.java b/impl/src/test/java/jakarta/faces/component/UIComponentBaseAttachedStateTestCase.java index 12fd79a66f..37d97bc789 100644 --- a/impl/src/test/java/jakarta/faces/component/UIComponentBaseAttachedStateTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIComponentBaseAttachedStateTestCase.java @@ -16,6 +16,11 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.lang.reflect.Method; import java.util.HashMap; import java.util.HashSet; @@ -23,6 +28,10 @@ import java.util.Set; import java.util.Stack; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.mock.MockExternalContext; import com.sun.faces.mock.MockFacesContext; import com.sun.faces.mock.MockHttpServletRequest; @@ -34,29 +43,16 @@ import jakarta.faces.context.FacesContext; import jakarta.faces.event.FacesListener; import jakarta.faces.event.ValueChangeListener; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -public class UIComponentBaseAttachedStateTestCase extends TestCase { +public class UIComponentBaseAttachedStateTestCase { private MockFacesContext facesContext = null; private MockServletContext servletContext; private MockHttpServletRequest request; private MockHttpServletResponse response; - public UIComponentBaseAttachedStateTestCase(String arg0) { - super(arg0); - } - - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIComponentBaseAttachedStateTestCase.class); - } - - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); facesContext = new MockFacesContext(); servletContext = new MockServletContext(); @@ -71,9 +67,8 @@ public void setUp() throws Exception { } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @AfterEach + public void tearDown() throws Exception { FactoryFinder.releaseFactories(); Method reInitializeFactoryManager = FactoryFinder.class.getDeclaredMethod("reInitializeFactoryManager", (Class[]) null); reInitializeFactoryManager.setAccessible(true); @@ -81,6 +76,7 @@ protected void tearDown() throws Exception { } + @Test public void testAttachedObjectsSet() throws Exception { Set attachedObjects = new HashSet<>(); ValueChangeListener toAdd = new ValueChangeListenerTestImpl(); @@ -96,6 +92,7 @@ public void testAttachedObjectsSet() throws Exception { assertNotNull(returnedAttachedObjects); } + @Test public void testAttachedObjectsStack() throws Exception { Stack attachedObjects = new Stack<>(); ValueChangeListener toAdd = new ValueChangeListenerTestImpl(); @@ -111,6 +108,7 @@ public void testAttachedObjectsStack() throws Exception { assertNotNull(returnedAttachedObjects); } + @Test public void testAttachedObjectsMap() throws Exception { Map attachedObjects = new HashMap<>(); ValueChangeListener toAdd = new ValueChangeListenerTestImpl(); @@ -144,6 +142,7 @@ public void testAttachedObjectsCount() throws Exception { assertEquals(firstSize, secondSize); } + @Test public void testFacesListenerState() { UIComponent component = new UIOutput(); TestFacesListener listener = new TestFacesListener(); @@ -171,7 +170,7 @@ public void testFacesListenerState() { component.addFacesListener(listener); listener.setValue("newinitial"); component.restoreState(facesContext, state); - assertTrue("newvalue".equals(listener.getValue())); + assertEquals("newvalue", listener.getValue()); // verify listeners are overwritten when using full state saving component = new UIOutput(); @@ -185,9 +184,10 @@ public void testFacesListenerState() { component.restoreState(facesContext, state); TestFacesListener l = (TestFacesListener) component.getFacesListeners(TestFacesListener.class)[0]; assertTrue(l != listener); - assertTrue("initial".equals(l.getValue())); + assertEquals("initial", l.getValue()); } + @Test public void testTransientListenersState() { UIComponent output = new UIOutput(); output.markInitialState(); @@ -227,6 +227,7 @@ public void testTransientListenersState() { assertTrue(listeners.length == 0); } + @Test public void testTransientListenersState2() { UIComponent output = new UIOutput(); TestFacesListener l1 = new TestFacesListener(); diff --git a/impl/src/test/java/jakarta/faces/component/UIComponentBaseBehaviorTestCase.java b/impl/src/test/java/jakarta/faces/component/UIComponentBaseBehaviorTestCase.java index f5b070350e..8fe128cc07 100644 --- a/impl/src/test/java/jakarta/faces/component/UIComponentBaseBehaviorTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIComponentBaseBehaviorTestCase.java @@ -16,6 +16,10 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.Serializable; import java.util.Collection; import java.util.Collections; @@ -24,6 +28,8 @@ import java.util.Map; import java.util.Set; +import org.junit.jupiter.api.Test; + import jakarta.faces.component.behavior.ClientBehavior; import jakarta.faces.component.behavior.ClientBehaviorContext; import jakarta.faces.component.behavior.ClientBehaviorHint; @@ -138,13 +144,10 @@ public String toString() { } } - public UIComponentBaseBehaviorTestCase(String name) { - super(name); - } - /** * Test method for {@link jakarta.faces.component.UIComponentBase#saveState(jakarta.faces.context.FacesContext)}. */ + @Test public void testSaveState() { BehaviorComponent comp = new BehaviorComponent(); // Cast component to the interface, to be sure about method definition. @@ -173,6 +176,7 @@ public void testSaveState() { assertEquals(behavior2, behaviors.get(ONCLICK).get(1)); } + @Test public void testNonClientBehaviorHolder() throws Exception { UIInput input = new UIInput(); try { @@ -187,24 +191,25 @@ public void testNonClientBehaviorHolder() throws Exception { * Test method for * {@link jakarta.faces.component.UIComponentBase#addClientBehavior(java.lang.String, jakarta.faces.component.behavior.ClientBehavior)}. */ + @Test public void testAddBehavior() { BehaviorComponent comp = new BehaviorComponent(); // Cast component to the interface, to be sure about method definition. ClientBehaviorHolder holder = comp; holder.addClientBehavior(ONCLICK, new TestBehavior()); + assertTrue(holder.getClientBehaviors().containsKey(ONCLICK)); holder.addClientBehavior(ONCLICK, new TestBehavior()); + assertTrue(holder.getClientBehaviors().containsKey(ONCLICK)); holder.addClientBehavior(ONCHANGE, new TestBehavior()); - try { - holder.addClientBehavior("foo", new TestBehavior()); - } catch (IllegalArgumentException e) { - return; - } - assertFalse(true); + assertTrue(holder.getClientBehaviors().containsKey(ONCHANGE)); + holder.addClientBehavior("foo", new TestBehavior()); + assertFalse(holder.getClientBehaviors().containsKey("foo")); } /** * Test method for {@link jakarta.faces.component.UIComponentBase#getEventNames()}. */ + @Test public void testGetEventNames() { BehaviorComponent comp = new BehaviorComponent(); ClientBehaviorHolder holder = comp; @@ -214,6 +219,7 @@ public void testGetEventNames() { /** * Test method for {@link jakarta.faces.component.UIComponentBase#getClientBehaviors()}. */ + @Test public void testGetBehaviors() { BehaviorComponent comp = new BehaviorComponent(); // Cast component to the interface, to be sure about method definition. @@ -226,6 +232,7 @@ public void testGetBehaviors() { holder.addClientBehavior(ONCLICK, new TestBehavior()); holder.addClientBehavior(ONCLICK, new TestBehavior()); holder.addClientBehavior(ONCHANGE, new TestBehavior()); + behaviors = holder.getClientBehaviors(); assertFalse(behaviors.isEmpty()); assertTrue(behaviors.containsKey(ONCLICK)); assertTrue(behaviors.containsKey(ONCHANGE)); @@ -240,6 +247,7 @@ public void testGetBehaviors() { /** * Test method for {@link jakarta.faces.component.UIComponentBase#getDefaultEventName()}. */ + @Test public void testGetDefaultEventName() { BehaviorComponent comp = new BehaviorComponent(); // Cast component to the interface, to be sure about method definition. diff --git a/impl/src/test/java/jakarta/faces/component/UIComponentBaseTestCase.java b/impl/src/test/java/jakarta/faces/component/UIComponentBaseTestCase.java index 7881fc8f9f..b07172cd55 100644 --- a/impl/src/test/java/jakarta/faces/component/UIComponentBaseTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIComponentBaseTestCase.java @@ -16,6 +16,12 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -26,6 +32,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import jakarta.faces.FacesException; import jakarta.faces.context.FacesContext; import jakarta.faces.event.AbortProcessingException; @@ -36,8 +46,6 @@ import jakarta.faces.event.PreRenderComponentEvent; import jakarta.faces.event.SystemEvent; import jakarta.faces.event.SystemEventListener; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -46,21 +54,10 @@ */ public class UIComponentBaseTestCase extends UIComponentTestCase { - // ------------------------------------------------------ Instance Variables - // Mock object instances for our tests - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIComponentBaseTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { // Set up the component under test @@ -69,13 +66,9 @@ public void setUp() throws Exception { } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIComponentBaseTestCase.class); - } - // Tear down instance variables required by ths test case @Override + @AfterEach public void tearDown() throws Exception { externalContext.setRequestParameterMap(null); @@ -85,6 +78,7 @@ public void tearDown() throws Exception { // ------------------------------------------------- Individual Test Methods // Test lifecycle management methods + @Test public void testLifecycleManagement() { checkLifecycleParentRendered(); @@ -94,6 +88,7 @@ public void testLifecycleManagement() { } + @Test public void testComponentToFromEL2() throws Exception { final FacesContext ctx = facesContext; @@ -166,6 +161,7 @@ public void testComponentToFromEL2() throws Exception { } + @Test public void testEncodeChildren() throws Exception { ComponentTestImpl.trace(null); UIComponent comp1 = new ComponentTestImpl("one"); @@ -185,6 +181,7 @@ public void testEncodeChildren() throws Exception { } // Test recursive adding and removing child trees with ids + @Test public void testChildrenRecursive() { // Create the components we will need @@ -220,6 +217,7 @@ public void testChildrenRecursive() { } + @Test public void testChildrenAndFacetsWithNullGetParent() throws Exception { ComponentTestImpl child = new ComponentTestImpl() { @Override @@ -240,6 +238,7 @@ public UIComponent getParent() { } // Test reconnecting a child or facet to a different component + @Test public void testComponentReconnect() { UIComponent parent1 = new ComponentTestImpl(); @@ -293,6 +292,7 @@ public void testComponentReconnect() { } // Test removing components from our naming container. + @Test public void testComponentRemoval() { UIComponent testComponent = new ComponentTestImpl(); @@ -349,6 +349,7 @@ public void testComponentRemoval() { assertTrue(!kidItr.hasNext()); } + @Test public void testStateHolder2() throws Exception { UIComponent c = new UIComponentListener(); @@ -362,6 +363,7 @@ public void testStateHolder2() throws Exception { } + @Test public void testAttributesThatAreSetStateHolder() throws Exception { ComponentTestImpl c = new ComponentTestImpl(); c.getAttributes().put("attr1", "value1"); @@ -377,6 +379,7 @@ public void testAttributesThatAreSetStateHolder() throws Exception { assertEquals(Arrays.asList("attr1", "attr2"), c.getAttributes().get("jakarta.faces.component.UIComponentBase.attributesThatAreSet")); } + @Test public void testValueExpressions() throws Exception { UIComponentBase test = (UIComponentBase) component; @@ -505,17 +508,17 @@ private void checkLifecycleParentRendered() { // Test processDecodes() ComponentTestImpl.trace(null); component.processDecodes(facesContext); - assertEquals("processDecodes", lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); // Test processValidators() ComponentTestImpl.trace(null); component.processValidators(facesContext); - assertEquals("processValidators", lifecycleTrace("pV", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pV", null), ComponentTestImpl.trace()); // Test processUpdates() ComponentTestImpl.trace(null); component.processUpdates(facesContext); - assertEquals("processUpdates", lifecycleTrace("pU", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pU", null), ComponentTestImpl.trace()); } @@ -568,17 +571,17 @@ private void checkLifecycleParentUnrendered() { // Test processDecodes() ComponentTestImpl.trace(null); component.processDecodes(facesContext); - assertEquals("processDecodes", lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); // Test processValidators() ComponentTestImpl.trace(null); component.processValidators(facesContext); - assertEquals("processValidators", lifecycleTrace("pV", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pV", null), ComponentTestImpl.trace()); // Test processUpdates() ComponentTestImpl.trace(null); component.processUpdates(facesContext); - assertEquals("processUpdates", lifecycleTrace("pU", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pU", null), ComponentTestImpl.trace()); } @@ -628,17 +631,17 @@ private void checkLifecycleSelfRendered() { // Test processDecodes() ComponentTestImpl.trace(null); component.processDecodes(facesContext); - assertEquals("processDecodes", lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); // Test processValidators() ComponentTestImpl.trace(null); component.processValidators(facesContext); - assertEquals("processValidators", lifecycleTrace("pV", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pV", null), ComponentTestImpl.trace()); // Test processUpdates() ComponentTestImpl.trace(null); component.processUpdates(facesContext); - assertEquals("processUpdates", lifecycleTrace("pU", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pU", null), ComponentTestImpl.trace()); } @@ -688,17 +691,17 @@ private void checkLifecycleSelfUnrendered() { // Test processDecodes() ComponentTestImpl.trace(null); component.processDecodes(facesContext); - assertEquals("processDecodes", lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pD", "d"), ComponentTestImpl.trace()); // Test processValidators() ComponentTestImpl.trace(null); component.processValidators(facesContext); - assertEquals("processValidators", lifecycleTrace("pV", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pV", null), ComponentTestImpl.trace()); // Test processUpdates() ComponentTestImpl.trace(null); component.processUpdates(facesContext); - assertEquals("processUpdates", lifecycleTrace("pU", null), ComponentTestImpl.trace()); + assertEquals(lifecycleTrace("pU", null), ComponentTestImpl.trace()); } @@ -773,6 +776,7 @@ protected void lifecycleTrace(String lmethod, String cmethod, UIComponent compon } + @Test public void testGetFacetsAndChildren() { UIComponent testComponent = new ComponentTestImpl(); @@ -830,21 +834,21 @@ public void testGetFacetsAndChildren() { *

*
      * root: id: root
-     * 
+     *
      *   form1: id: form1
-     * 
+     *
      *     panel1: id: panel
-     * 
+     *
      *       input1: id: input1
-     * 
+     *
      *       input2: id: input2
-     * 
+     *
      *   form2: id: form2
-     * 
+     *
      *     panel2: id: panel
-     * 
+     *
      *       input3: id: input1
-     * 
+     *
      *       input4: id: input2
      * 
* @@ -896,6 +900,7 @@ private Map setupInvokeOnComponentTree() { return result; } + @Test public void testInvokeOnComponentPositive() throws Exception { Map tree = setupInvokeOnComponentTree(); @@ -911,8 +916,7 @@ public void testInvokeOnComponentPositive() throws Exception { result = root.invokeOnComponent(facesContext, input1.getClientId(facesContext), new ContextCallback() { @Override public void invokeContextCallback(FacesContext context, UIComponent component) { - assertEquals("getCurrentComponent does not return the current component during" + "invokeOnComponent", UIComponent.getCurrentComponent(context), - component); + assertEquals(UIComponent.getCurrentComponent(context), component); foundComponent = component; } }); @@ -922,6 +926,7 @@ public void invokeContextCallback(FacesContext context, UIComponent component) { } + @Test public void testInvokeOnComponentNegative() throws Exception { Map tree = setupInvokeOnComponentTree(); @@ -1013,6 +1018,7 @@ public void invokeContextCallback(FacesContext context, UIComponent component) { } + @Test public void testInvokeOnComponentWithPrependId() throws Exception { Map tree = setupInvokeOnComponentTree(); @@ -1161,6 +1167,7 @@ public void invokeContextCallback(FacesContext context, UIComponent component) { } + @Test public void testChildrenListAfterAddPublish() { Listener listener = new Listener(); @@ -1198,6 +1205,7 @@ public void testChildrenListAfterAddPublish() { } + @Test public void testFacetMapAfterAddViewPublish() { QueueingListener listener = new QueueingListener(); @@ -1210,11 +1218,11 @@ public void testFacetMapAfterAddViewPublish() { List e = listener.getEvents(); Map facets = c1.getFacets(); facets.put("c2", c2); - assertTrue("Expected Event queue size of 0, found: " + e.size(), e.isEmpty()); + assertEquals(0, e.size()); UIViewRoot root = new UIViewRoot(); root.getChildren().add(c1); - assertTrue("Expected Event queue size of 2, found: " + e.size(), e.size() == 2); + assertEquals(2, e.size()); assertTrue(e.get(0).getSource() == c1); assertTrue(e.get(1).getSource() == c2); @@ -1224,13 +1232,13 @@ public void testFacetMapAfterAddViewPublish() { root.getChildren().remove(c1); facets = c1.getFacets(); facets.put("c3", c3); - assertTrue("Expected Event queue size of 0, found: " + e.size(), e.isEmpty()); + assertEquals(0, e.size()); // reorganize the facet structure to ensure nested facets work facets.remove("c3"); c2.getFacets().put("c3", c3); root.getChildren().add(c1); - assertTrue("Expected Event queue size of 3, found: " + e.size(), e.size() == 3); + assertEquals(3, e.size()); assertTrue(e.get(0).getSource() == c1); assertTrue(e.get(1).getSource() == c2); assertTrue(e.get(2).getSource() == c3); @@ -1240,12 +1248,13 @@ public void testFacetMapAfterAddViewPublish() { facets.clear(); c2.getFacets().remove("c3"); c2.getFacets().put("c3", c3); - assertTrue("Expected Event queue size of 0, found: " + e.size(), e.isEmpty()); + assertEquals(0, e.size()); application.unsubscribeFromEvent(PostAddToViewEvent.class, listener); } + @Test public void testChildrenListAfterAddViewPublish() { QueueingListener listener = new QueueingListener(); @@ -1266,11 +1275,11 @@ public void testChildrenListAfterAddViewPublish() { // sub-tree has been added to the view. Ensure that subsequent additions // to that sub-tree cause the PostAddToViewEvent to fire. c2.getChildren().add(c4); - assertTrue("Expected Event queue size of 4, found: " + e.size(), e.size() == 4); + assertEquals(4, e.size()); UIComponent[] comps = { c1, c2, c3, c4 }; for (int i = 0; i < comps.length; i++) { - assertTrue("Index " + i + " invalid", e.get(i).getSource() == comps[i]); + assertTrue(e.get(i).getSource() == comps[i], "Index " + i + " invalid"); } // remove c1 and it's children from the subview, then remove and @@ -1280,18 +1289,18 @@ public void testChildrenListAfterAddViewPublish() { root.getChildren().remove(c1); c2.getChildren().remove(c4); c2.getChildren().add(c4); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); c2.getChildren().remove(c4); c1.getChildren().add(c4); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); // re-wire c1 as a child of root and ensure all children get re-notified root.getChildren().add(c1); - assertTrue("Expected Event queue size of 4, found: " + e.size(), e.size() == 4); + assertEquals(4, e.size()); for (int i = 0; i < comps.length; i++) { - assertTrue("Index " + i + " invalid", e.get(i).getSource() == comps[i]); + assertTrue(e.get(i).getSource() == comps[i], "Index " + i + " invalid"); } // validate clearing c1's children (effectively removing them from the view @@ -1303,24 +1312,24 @@ public void testChildrenListAfterAddViewPublish() { UIComponent temp = createComponent(); e.clear(); c2.getChildren().add(temp); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); c2.getChildren().remove(temp); c3.getChildren().add(temp); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); c3.getChildren().remove(temp); c4.getChildren().add(temp); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); c4.getChildren().remove(temp); // now add c2 and c4 as children of c1. This should cause three // events to fire c1.getChildren().add(c2); c1.getChildren().add(c4); - assertTrue("Expected Event queue size of 3, found: " + e.size(), e.size() == 3); + assertEquals(3, e.size()); UIComponent[] comps2 = { c2, c3, c4 }; for (int i = 0; i < comps2.length; i++) { - assertTrue("Index " + i + " invalid", e.get(i).getSource() == comps2[i]); + assertTrue(e.get(i).getSource() == comps2[i], "Index " + i + " invalid"); } // validate add(int, UIComponent) fires events @@ -1330,7 +1339,7 @@ public void testChildrenListAfterAddViewPublish() { assertTrue(c1.getChildren().get(0) == c4); assertTrue(c1.getChildren().get(1) == c2); - assertTrue("Expected Event queue size of 1, found: " + e.size(), e.size() == 1); + assertEquals(1, e.size()); assertTrue(e.get(0).getSource() == c4); // validate addAll(Collection) fires events @@ -1341,7 +1350,7 @@ public void testChildrenListAfterAddViewPublish() { c1.getChildren().addAll(children); assertTrue(c1.getChildren().get(0) == c2); assertTrue(c1.getChildren().get(1) == c4); - assertTrue("Expected Event queue size of 3, found: " + e.size(), e.size() == 3); + assertEquals(3, e.size()); assertTrue(e.get(0).getSource() == c2); assertTrue(e.get(2).getSource() == c4); @@ -1356,7 +1365,7 @@ public void testChildrenListAfterAddViewPublish() { assertTrue(c1.getChildren().get(1) == t2); assertTrue(c1.getChildren().get(2) == c2); assertTrue(c1.getChildren().get(3) == c4); - assertTrue("Expected Event queue size of 2, found: " + e.size(), e.size() == 2); + assertEquals(2, e.size()); assertTrue(e.get(0).getSource() == t1); assertTrue(e.get(1).getSource() == t2); @@ -1371,7 +1380,7 @@ public void testChildrenListAfterAddViewPublish() { assertTrue(c1.getChildren().get(0) == c2); assertTrue(c1.getChildren().get(1) == c4); t1.getChildren().add(t2); - assertTrue("Expected Event queue size of 0, found: " + e.size(), e.isEmpty()); + assertEquals(0, e.size()); // test set(int, UIComponent) properly fires an event if the parent // the component is being added to is wired to the view @@ -1380,7 +1389,7 @@ public void testChildrenListAfterAddViewPublish() { assertTrue(c1.getChildren().size() == 2); assertTrue(c1.getChildren().get(0) == t1); assertTrue(c1.getChildren().get(1) == c4); - assertTrue("Expected Event queue size of 2, found: " + e.size(), e.size() == 2); + assertEquals(2, e.size()); assertTrue(e.get(0).getSource() == t1); assertTrue(e.get(1).getSource() == t2); @@ -1389,7 +1398,7 @@ public void testChildrenListAfterAddViewPublish() { e.clear(); UIComponent t3 = createComponent(); c2.getChildren().add(t3); - assertTrue("Expected Event queue size of 0, found: " + e.size(), e.isEmpty()); + assertEquals(0, e.size()); application.unsubscribeFromEvent(PostAddToViewEvent.class, listener); @@ -1404,17 +1413,18 @@ public void testChildrenListAfterAddViewPublish() { // to t1, t2, or c4 should result in no events being fired e.clear(); t1.getChildren().add(temp); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); t1.getChildren().remove(temp); t2.getChildren().add(temp); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); t2.getChildren().remove(temp); c4.getChildren().add(temp); - assertTrue("AfterAddToView events queued after a sub-tree was removed from the view, and a child added to the sub-view", e.isEmpty()); + assertEquals(0, e.size()); c4.getChildren().remove(temp); } + @Test public void testEncodeBeginPublish() throws Exception { Listener listener = new Listener(); @@ -1538,7 +1548,6 @@ public static final class CustomAbortProcessingException extends AbortProcessing private static final long serialVersionUID = 1L; public CustomAbortProcessingException() { - super(); } public CustomAbortProcessingException(String message) { diff --git a/impl/src/test/java/jakarta/faces/component/UIComponentTestCase.java b/impl/src/test/java/jakarta/faces/component/UIComponentTestCase.java index 9143f7ae71..0e3eb7f9f9 100644 --- a/impl/src/test/java/jakarta/faces/component/UIComponentTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIComponentTestCase.java @@ -16,6 +16,12 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; @@ -27,6 +33,10 @@ import java.util.Map; import java.util.Set; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.junit.JUnitFacesTestCaseBase; import com.sun.faces.mock.MockRenderKit; @@ -41,8 +51,6 @@ import jakarta.faces.render.RenderKitFactory; import jakarta.faces.validator.Validator; import jakarta.faces.validator.ValidatorException; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -101,15 +109,10 @@ public UIComponent setValue(UIComponent value) { }; - // ------------------------------------------------------------ Constructors - // Construct a new instance of this test case. - public UIComponentTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -133,13 +136,9 @@ public void setUp() throws Exception { component = new ComponentTestImpl(expectedId); } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIComponentTestCase.class); - } - // Tear down instance variables required by this test case. @Override + @AfterEach public void tearDown() throws Exception { component = null; @@ -154,6 +153,7 @@ public void tearDown() throws Exception { } // ------------------------------------------------- Individual Test Methods + @Test public void testValidationEvents() { Listener prelistener = new Listener(); Listener postlistener = new Listener(); @@ -196,12 +196,13 @@ public void testValidationEvents() { ((UIInput) col.getChildren().get(0)).setSubmittedValue("hello"); data.setRowIndex(-1); root.processValidators(facesContext); - assertEquals("root/out/form/data/in/", "root/out/form/data/in/", prelistener.getResults()); - assertEquals("out/*/in/data/form/root/", "out/*/in/data/form/root/", postlistener.getResults()); + assertEquals("root/out/form/data/in/", prelistener.getResults()); + assertEquals("out/*/in/data/form/root/", postlistener.getResults()); } // Test behavior of Map returned by getAttributes() + @Test public void testAttributesMap() { // Initialize some attributes @@ -218,12 +219,12 @@ public void testAttributesMap() { assertTrue(!attributes.containsKey("parent")); // Property name // Test get() - assertEquals("bar", (String) attributes.get("foo")); - assertEquals("bop", (String) attributes.get("baz")); + assertEquals("bar", attributes.get("foo")); + assertEquals("bop", attributes.get("baz")); assertNull(attributes.get("bar")); assertNull(attributes.get("bop")); component.setId("oldvalue"); - assertEquals("oldvalue", (String) attributes.get("id")); // Property + assertEquals("oldvalue", attributes.get("id")); // Property component.setRendered(false); assertTrue(!((Boolean) attributes.get("rendered")).booleanValue()); component.setRendered(true); @@ -249,7 +250,7 @@ public void testAttributesMap() { // Expected result } attributes.put("id", "newvalue"); - assertEquals("newvalue", (String) attributes.get("id")); + assertEquals("newvalue", attributes.get("id")); assertEquals("newvalue", component.getId()); attributes.put("rendered", Boolean.TRUE); assertTrue(component.isRendered()); @@ -270,6 +271,7 @@ public void testAttributesMap() { } // Negative tests on attribute methods + @Test public void testAttributesNegative() { // getAttributes().get() - null @@ -291,6 +293,7 @@ public void testAttributesNegative() { } // Positive tests on attribute methods + @Test public void testAttributesPositive() { checkAttributeCount(component, expectedAttributes.length); @@ -320,13 +323,14 @@ public void testAttributesPositive() { } // Test attribute-property transparency + @Test public void testAttributesTransparency() { assertEquals(component.getChildren(), component.getAttributes().get("children")); assertEquals(component.getFacets(), component.getAttributes().get("facets")); - assertEquals(component.getId(), (String) component.getAttributes().get("id")); + assertEquals(component.getId(), component.getAttributes().get("id")); assertEquals(component.getParent(), component.getAttributes().get("parent")); @@ -341,7 +345,7 @@ public void testAttributesTransparency() { assertTrue(component.isRendered()); component.setRendererType("foo"); - assertEquals("foo", (String) component.getAttributes().get("rendererType")); + assertEquals("foo", component.getAttributes().get("rendererType")); component.setRendererType(null); assertNull(component.getAttributes().get("rendererType")); component.getAttributes().put("rendererType", "bar"); @@ -354,6 +358,7 @@ public void testAttributesTransparency() { } // Test getChildren().iterator() + @Test public void testChildrenIterator() { Iterator kids; @@ -407,6 +412,7 @@ public void testChildrenIterator() { } // Test getChildren().listIterator() + @Test public void testChildrenListIterator() { ListIterator kids; @@ -581,6 +587,7 @@ public void testChildrenListIterator() { } // Negative tests on children methods + @Test public void testChidrenNegative() { // Construct components we will need @@ -694,6 +701,7 @@ public void testChidrenNegative() { } // Positive tests on children methods + @Test public void testChildrenPositive() { // Construct components we will need @@ -861,6 +869,7 @@ public void testChildrenPositive() { } // Test replacing a child with a new one that has the same id + @Test public void testChidrenReplace() { ComponentTestImpl child1 = new ComponentTestImpl("child"); @@ -881,6 +890,7 @@ public void testChidrenReplace() { } // Test Set returned by getFacets().entrySet() + @Test public void testFacetsMapEntrySet() { Map facets; @@ -1067,6 +1077,7 @@ public void testFacetsMapEntrySet() { } // Test Set returned by getFacets().keySet() + @Test public void testFacetsMapKeySet() { Map facets; @@ -1220,6 +1231,7 @@ public void testFacetsMapKeySet() { } // Test Collection returned by getFacets().values() + @Test public void testFacetsMapValues() { Map facets; @@ -1398,6 +1410,7 @@ public void testFacetsMapValues() { } // Negative tests on facet methods + @Test public void testFacetsNegative() { // Construct components we will need @@ -1441,6 +1454,7 @@ public void testFacetsNegative() { } // Positive tests on facet methods + @Test public void testFacetsPositive() { // Construct components we will need @@ -1517,6 +1531,7 @@ public void testFacetsPositive() { } // Test a pristine UIComponent instance + @Test public void testPristine() { // Validate attributes @@ -1526,28 +1541,29 @@ public void testPristine() { } // Validate properties - assertEquals("expected family", expectedFamily, component.getFamily()); - assertEquals("expected id", expectedId, component.getId()); - assertNull("no parent", component.getParent()); - assertEquals("expected rendered", expectedRendered, component.isRendered()); - assertEquals("expected rendererType", expectedRendererType, component.getRendererType()); - assertEquals("expected rendersChildren", expectedRendersChildren, component.getRendersChildren()); + assertEquals(expectedFamily, component.getFamily()); + assertEquals(expectedId, component.getId()); + assertNull(component.getParent()); + assertEquals(expectedRendered, component.isRendered()); + assertEquals(expectedRendererType, component.getRendererType()); + assertEquals(expectedRendersChildren, component.getRendersChildren()); // Validate children and facets checkChildCount(component, 0); checkFacetCount(component, 0); int n = 0; Iterator items = component.getFacetsAndChildren(); - assertNotNull("iterator returned", items); + assertNotNull(items); while (items.hasNext()) { items.next(); n++; } - assertEquals("facets and children", 0, n); + assertEquals(0, n); } // Test setting properties to invalid values + @Test public void testPropertiesInvalid() throws Exception { // id - zero length @@ -1593,28 +1609,29 @@ public void testPropertiesInvalid() throws Exception { } // Test setting properties to valid values + @Test public void testPropertiesValid() throws Exception { // id - simple name component.setId("foo"); - assertEquals("expected id", "foo", component.getId()); + assertEquals("foo", component.getId()); // id - complex name component.setId("a123-bcd_e"); - assertEquals("expected id", "a123-bcd_e", component.getId()); + assertEquals("a123-bcd_e", component.getId()); // parent UIComponent parent = new ComponentTestImpl("parent"); component.setParent(parent); - assertEquals("expected parent", parent, component.getParent()); + assertEquals(parent, component.getParent()); // rendered component.setRendered(!expectedRendered); - assertEquals("expected rendered", !expectedRendered, component.isRendered()); + assertEquals(!expectedRendered, component.isRendered()); // rendererType component.setRendererType("foo"); - assertEquals("expected rendererType", "foo", component.getRendererType()); + assertEquals("foo", component.getRendererType()); } @@ -1627,12 +1644,12 @@ protected void checkAttributeCount(UIComponent component, int count) { names.next(); result++; } - assertEquals("attribute count", count, result); + assertEquals(count, result); } // Validate that the specified attribute name is not present protected void checkAttributeMissing(UIComponent component, String name) { - assertNull("Attribute " + name + " should be missing", component.getAttributes().get(name)); + assertNull(component.getAttributes().get(name), "Attribute " + name + " should be missing"); Iterator keys = component.getAttributes().keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); @@ -1645,16 +1662,16 @@ protected void checkAttributeMissing(UIComponent component, String name) { // Validate that the specified attribute name is present with the // specified value (if value is not null) protected void checkAttributePresent(UIComponent component, String name, Object value) { - assertNotNull("attribute " + name + " should be present", component.getAttributes().get(name)); + assertNotNull(component.getAttributes().get(name), "attribute " + name + " should be present"); if (value != null) { - assertEquals("attribute " + name + " value should be equal", value, component.getAttributes().get(name)); + assertEquals(value, component.getAttributes().get(name)); } Iterator keys = component.getAttributes().keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); if (name.equals(key)) { if (value != null) { - assertEquals("attribute " + name + " value should match", value, component.getAttributes().get(name)); + assertEquals(value, component.getAttributes().get(name)); } return; } @@ -1665,22 +1682,22 @@ protected void checkAttributePresent(UIComponent component, String name, Object // Validate that the specified number of children are present protected void checkChildCount(UIComponent component, int count) { - assertEquals("child count 1", count, component.getChildCount()); - assertEquals("child count 2", count, component.getChildren().size()); - assertEquals("child count 3", count, component.getChildCount()); + assertEquals(count, component.getChildCount()); + assertEquals(count, component.getChildren().size()); + assertEquals(count, component.getChildCount()); if (count == 0) { - assertTrue("children empty", component.getChildren().isEmpty()); + assertTrue(component.getChildren().isEmpty()); } else { - assertTrue("children not empty", !component.getChildren().isEmpty()); + assertTrue(!component.getChildren().isEmpty()); } } // Validate that the specified child is not present protected void checkChildMissing(UIComponent component, UIComponent child) { - assertNull("child " + child + " has no parent", child.getParent()); + assertNull(child.getParent(), "child " + child + " has no parent"); List children = component.getChildren(); - assertTrue("child " + child + " should not be contained", !children.contains(child)); - assertEquals("child " + child + " should not be found by indexOf", -1, children.indexOf(child)); + assertTrue(!children.contains(child), "child " + child + " should not be contained"); + assertEquals(-1, children.indexOf(child)); for (int i = 0; i < children.size(); i++) { if (child.equals(children.get(i))) { fail("child " + child + " should be missing"); @@ -1691,31 +1708,31 @@ protected void checkChildMissing(UIComponent component, UIComponent child) { // Validate that the specified child is present at the specified index protected void checkChildPresent(UIComponent component, UIComponent child, int index) { List children = component.getChildren(); - assertTrue("child " + child + " should be contained", children.contains(child)); - assertEquals("child " + child + " should be found by indexOf", index, children.indexOf(child)); + assertTrue(children.contains(child), "child " + child + " should be contained"); + assertEquals(index, children.indexOf(child)); UIComponent kid = children.get(index); - assertEquals("child " + child + " should be present", child, kid); - assertEquals("child " + child + " has correct parent", component, kid.getParent()); + assertEquals(child, kid); + assertEquals(component, kid.getParent()); } // Validate that the specified number of facets is present protected void checkFacetCount(UIComponent component, int count) { - assertEquals("facet count", count, component.getFacets().size()); + assertEquals(count, component.getFacets().size()); if (count == 0) { - assertTrue("facets empty", component.getFacets().isEmpty()); + assertTrue(component.getFacets().isEmpty()); } else { - assertTrue("facets not empty", !component.getFacets().isEmpty()); + assertTrue(!component.getFacets().isEmpty()); } } // Validate that the specified facet is not present protected void checkFacetMissing(UIComponent component, String name, UIComponent facet) { - assertNull("facet " + name + " has no parent", facet.getParent()); + assertNull(facet.getParent(), "facet " + name + " has no parent"); Map facets = component.getFacets(); - assertTrue("facet " + name + " key not present", !facets.containsKey(name)); - assertTrue("facet " + name + " value not present", !facets.containsValue(facet)); - assertNull("facet " + name + " key not found by get", facets.get(name)); - assertNull("facet " + name + " not returned by getFacet(String)", component.getFacet(name)); + assertTrue(!facets.containsKey(name), "facet " + name + " key not present"); + assertTrue(!facets.containsValue(facet), "facet " + name + " value not present"); + assertNull(facets.get(name), "facet " + name + " key not found by get"); + assertNull(component.getFacet(name), "facet " + name + " not returned by getFacet(String)"); Iterator keys = facets.keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); @@ -1735,12 +1752,12 @@ protected void checkFacetMissing(UIComponent component, String name, UIComponent // Validate that the specified facet is present protected void checkFacetPresent(UIComponent component, String name, UIComponent facet) { - assertEquals("facet " + name + " has correct parent", component, facet.getParent()); + assertEquals(component, facet.getParent()); Map facets = component.getFacets(); - assertTrue("facet " + name + " key is present", facets.containsKey(name)); - assertTrue("facet " + name + " value is present", facets.containsValue(facet)); - assertEquals("facet " + name + " has correct value", facet, facets.get(name)); - assertTrue("facet " + name + " returned by getFacet(String)", facet == component.getFacet(name)); + assertTrue(facets.containsKey(name), "facet " + name + " key is present"); + assertTrue(facets.containsValue(facet), "facet " + name + " value is present"); + assertEquals(facet, facets.get(name)); + assertTrue(facet == component.getFacet(name), "facet " + name + " returned by getFacet(String)"); boolean found = false; Iterator keys = facets.keySet().iterator(); while (keys.hasNext()) { diff --git a/impl/src/test/java/jakarta/faces/component/UIDataTest.java b/impl/src/test/java/jakarta/faces/component/UIDataTest.java index 392d89a727..5804801c20 100644 --- a/impl/src/test/java/jakarta/faces/component/UIDataTest.java +++ b/impl/src/test/java/jakarta/faces/component/UIDataTest.java @@ -18,20 +18,16 @@ import static jakarta.faces.component.NamingContainer.SEPARATOR_CHAR; import static jakarta.faces.component.UINamingContainer.SEPARATOR_CHAR_PARAM_NAME; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.powermock.api.easymock.PowerMock.createNicePartialMockAndInvokeDefaultConstructor; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -import org.junit.Test; -import org.powermock.reflect.Whitebox; +import org.junit.jupiter.api.Test; +import jakarta.faces.context.ExternalContext; import jakarta.faces.context.FacesContext; +import jakarta.faces.render.RenderKit; /** * @author Manfred Riem (manfred.riem@oracle.com) @@ -43,12 +39,10 @@ public class UIDataTest { */ @Test public void testSaveState() { - FacesContext context = createMock(FacesContext.class); + FacesContext context = mock(FacesContext.class); UIData data = new UIData(); data.markInitialState(); - replay(context); assertNull(data.saveState(context)); - verify(context); } /** @@ -56,11 +50,9 @@ public void testSaveState() { */ @Test public void testSaveState2() { - FacesContext context = createMock(FacesContext.class); + FacesContext context = mock(FacesContext.class); UIData data = new UIData(); - replay(context); assertNotNull(data.saveState(context)); - verify(context); } /** @@ -68,18 +60,20 @@ public void testSaveState2() { */ @Test public void testSaveState3() { - FacesContext context = createMock(FacesContext.class); + FacesContext context = mock(FacesContext.class); UIData data = new UIData(); data.markInitialState(); data.setRowIndex(4); - replay(context); assertNotNull(data.saveState(context)); - verify(context); } @Test public void testInvokeOnComponentMustNotCallSetRowIndexIfNotTouched() throws Exception { - FacesContext context = createNicePartialMockAndInvokeDefaultConstructor(FacesContext.class, "getRenderKit"); + FacesContext context = mock(FacesContext.class); + ExternalContext externalContext = mock(ExternalContext.class); + when(context.getExternalContext()).thenReturn(externalContext); + RenderKit renderKit = mock(RenderKit.class); + when(context.getRenderKit()).thenReturn(renderKit); context.getAttributes().put(SEPARATOR_CHAR_PARAM_NAME, SEPARATOR_CHAR); UIData data = new UIData() { @@ -90,12 +84,10 @@ public void setRowIndex(int rowIndex) { }; data.setId("data"); - // simple way. otherwise, we have to mock the renderkit and whatever. - Whitebox.setInternalState(data, "clientId", data.getId()); data.invokeOnComponent(context, "differentId", (contextInLambda, target) -> { }); - assertThat(context.getAttributes().get("setRowIndexCalled"), is(nullValue())); + assertNull(context.getAttributes().get("setRowIndexCalled")); } } diff --git a/impl/src/test/java/jakarta/faces/component/UIGraphicTestCase.java b/impl/src/test/java/jakarta/faces/component/UIGraphicTestCase.java index e3399e052f..01380c37da 100644 --- a/impl/src/test/java/jakarta/faces/component/UIGraphicTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIGraphicTestCase.java @@ -16,8 +16,11 @@ package jakarta.faces.component; -import junit.framework.Test; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -26,19 +29,10 @@ */ public class UIGraphicTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIGraphicTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UIGraphic(); @@ -47,14 +41,10 @@ public void setUp() throws Exception { expectedRendererType = "jakarta.faces.Image"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIGraphicTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test attribute-property transparency @Override + @Test public void testAttributesTransparency() { super.testAttributesTransparency(); @@ -62,7 +52,7 @@ public void testAttributesTransparency() { assertEquals(graphic.getValue(), component.getAttributes().get("value")); graphic.setValue("foo"); - assertEquals("foo", (String) component.getAttributes().get("value")); + assertEquals("foo", component.getAttributes().get("value")); graphic.setValue(null); assertNull(component.getAttributes().get("value")); component.getAttributes().put("value", "bar"); @@ -70,9 +60,9 @@ public void testAttributesTransparency() { component.getAttributes().put("value", null); assertNull(graphic.getValue()); - assertEquals(graphic.getUrl(), (String) graphic.getAttributes().get("url")); + assertEquals(graphic.getUrl(), graphic.getAttributes().get("url")); graphic.setUrl("foo"); - assertEquals("foo", (String) graphic.getAttributes().get("url")); + assertEquals("foo", graphic.getAttributes().get("url")); graphic.setUrl(null); assertNull(graphic.getAttributes().get("url")); graphic.getAttributes().put("url", "bar"); @@ -83,21 +73,24 @@ public void testAttributesTransparency() { // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } // Test a pristine UIGraphic instance @Override + @Test public void testPristine() { super.testPristine(); UIGraphic graphic = (UIGraphic) component; - assertNull("no value", graphic.getValue()); - assertNull("no url", graphic.getUrl()); + assertNull(graphic.getValue()); + assertNull(graphic.getUrl()); } // Test setting properties to invalid values @Override + @Test public void testPropertiesInvalid() throws Exception { super.testPropertiesInvalid(); } diff --git a/impl/src/test/java/jakarta/faces/component/UIInputTest.java b/impl/src/test/java/jakarta/faces/component/UIInputTest.java index 173c294502..9646a002d3 100644 --- a/impl/src/test/java/jakarta/faces/component/UIInputTest.java +++ b/impl/src/test/java/jakarta/faces/component/UIInputTest.java @@ -16,14 +16,13 @@ package jakarta.faces.component; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.easymock.EasyMock; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.context.FacesContext; import jakarta.faces.validator.LengthValidator; @@ -37,36 +36,31 @@ public class UIInputTest { @Test public void testSaveState() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); - replay(context); assertNotNull(input.saveState(context)); - verify(context); } - @Test(expected = NullPointerException.class) + @Test public void testSaveState2() { UIInput input = new UIInput(); - input.saveState(null); + assertThrows(NullPointerException.class, () -> input.saveState(null)); } @Test public void testSaveState3() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); - replay(context); input.markInitialState(); assertNull(input.saveState(context)); - verify(context); } @Test public void testSaveState4() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); LengthValidator l1 = new LengthValidator(); LengthValidator l2 = new LengthValidator(); - replay(context); input.addValidator(l1); input.addValidator(l2); l1.setMinimum(1); @@ -77,58 +71,48 @@ public void testSaveState4() { assertTrue(l2.initialStateMarked()); Object state = input.saveState(context); assertNull(state); - verify(context); } @Test public void testRestoreState() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); - replay(context); input.restoreState(context, null); - verify(context); } - @Test(expected = NullPointerException.class) + @Test public void testRestoreState2() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); - replay(context); - input.restoreState(null, null); - verify(context); + assertThrows(NullPointerException.class, () -> input.restoreState(null, null)); } @Test public void testRestoreState3() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); - replay(context); Object state = input.saveState(context); assertNotNull(state); input.restoreState(context, state); - verify(context); } @Test public void testRestoreState4() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); input.addValidator(new LongRangeValidator()); - replay(context); Object state = input.saveState(context); assertNotNull(state); input = new UIInput(); input.restoreState(context, state); - verify(context); } @Test public void testRestoreState5() { - FacesContext context = EasyMock.createMock(FacesContext.class); + FacesContext context = Mockito.mock(FacesContext.class); UIInput input = new UIInput(); LengthValidator l1 = new LengthValidator(); LengthValidator l2 = new LengthValidator(); - replay(context); input.addValidator(l1); input.addValidator(l2); l1.setMinimum(1); @@ -205,6 +189,5 @@ public void testRestoreState5() { assertTrue(v.getMinimum() == i + 1); } - verify(context); } } diff --git a/impl/src/test/java/jakarta/faces/component/UIInputTestCase.java b/impl/src/test/java/jakarta/faces/component/UIInputTestCase.java index 339ff2d173..1013cd5732 100644 --- a/impl/src/test/java/jakarta/faces/component/UIInputTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIInputTestCase.java @@ -16,16 +16,22 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Iterator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import jakarta.faces.application.FacesMessage; import jakarta.faces.context.FacesContext; import jakarta.faces.event.PhaseId; import jakarta.faces.event.ValueChangeEvent; import jakarta.faces.event.ValueChangeListener; import jakarta.faces.validator.Validator; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -34,19 +40,10 @@ */ public class UIInputTestCase extends UIOutputTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIInputTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UIInput(); @@ -54,21 +51,17 @@ public void setUp() throws Exception { expectedRendererType = "jakarta.faces.Text"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIInputTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test attribute-property transparency @Override + @Test public void testAttributesTransparency() { super.testAttributesTransparency(); UIInput input = (UIInput) component; assertEquals(input.getSubmittedValue(), input.getAttributes().get("submittedValue")); input.setSubmittedValue("foo"); - assertEquals("foo", (String) input.getAttributes().get("submittedValue")); + assertEquals("foo", input.getAttributes().get("submittedValue")); input.setSubmittedValue(null); assertNull(input.getAttributes().get("submittedValue")); input.getAttributes().put("submittedValue", "bar"); @@ -95,6 +88,7 @@ public void testAttributesTransparency() { } // Test the compareValues() method + @Test public void testCompareValues() { InputTestImpl input = new InputTestImpl(); Object value1a = "foo"; @@ -115,6 +109,7 @@ public void testCompareValues() { } // Test event queuing and broadcasting (any phase listeners) + @Test public void testEventsGeneric() { UIInput input = (UIInput) component; ValueChangeEvent event = new ValueChangeEvent(input, null, null); @@ -131,6 +126,7 @@ public void testEventsGeneric() { } // Test event queuing and broadcasting (mixed phase listeners) + @Test public void testEventsMixed() { UIInput input = (UIInput) component; input.setRendererType(null); @@ -164,6 +160,7 @@ public void testEventsMixed() { } // Test listener registration and deregistration + @Test public void testListeners() { InputTestImpl input = new InputTestImpl(); @@ -181,6 +178,7 @@ public void testListeners() { } // Test empty listener list + @Test public void testEmptyListeners() { InputTestImpl input = new InputTestImpl(); @@ -191,24 +189,27 @@ public void testEmptyListeners() { // Test a pristine UIInput instance @Override + @Test public void testPristine() { super.testPristine(); UIInput input = (UIInput) component; - assertNull("no submittedValue", input.getSubmittedValue()); - assertTrue("not required", !input.isRequired()); - assertTrue("is valid", input.isValid()); - assertTrue("is not immediate", !input.isImmediate()); + assertNull(input.getSubmittedValue()); + assertTrue(!input.isRequired()); + assertTrue(input.isValid()); + assertTrue(!input.isImmediate()); } // Test setting properties to invalid values @Override + @Test public void testPropertiesInvalid() throws Exception { super.testPropertiesInvalid(); UIInput input = (UIInput) component; } // Test validation of a required field + @Test public void testValidateRequired() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); root.getChildren().add(component); @@ -245,6 +246,7 @@ public void testValidateRequired() throws Exception { assertTrue(input.isValid()); } + @Test public void testGetValueChangeListeners() throws Exception { UIInput command = (UIInput) component; UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -269,11 +271,11 @@ protected void checkMessages(int expected) { Iterator messages = facesContext.getMessages(); while (messages.hasNext()) { FacesMessage message = messages.next(); - assertEquals("Severity == ERROR", FacesMessage.SEVERITY_ERROR, message.getSeverity()); + assertEquals(FacesMessage.SEVERITY_ERROR, message.getSeverity()); n++; // System.err.println(message.getSummary()); } - assertEquals("expected message count", expected, n); + assertEquals(expected, n); } // Create a pristine component of the type to be used in state holder tests diff --git a/impl/src/test/java/jakarta/faces/component/UIOutputAttachedObjectStateTestCase.java b/impl/src/test/java/jakarta/faces/component/UIOutputAttachedObjectStateTestCase.java index 4f99e07294..cabd4b5704 100644 --- a/impl/src/test/java/jakarta/faces/component/UIOutputAttachedObjectStateTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIOutputAttachedObjectStateTestCase.java @@ -16,8 +16,17 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.lang.reflect.Method; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.mock.MockExternalContext; import com.sun.faces.mock.MockFacesContext; import com.sun.faces.mock.MockHttpServletRequest; @@ -28,29 +37,16 @@ import jakarta.faces.FactoryFinder; import jakarta.faces.convert.Converter; import jakarta.faces.convert.DateTimeConverter; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -public class UIOutputAttachedObjectStateTestCase extends TestCase { +public class UIOutputAttachedObjectStateTestCase { private MockFacesContext facesContext = null; private MockServletContext servletContext; private MockHttpServletRequest request; private MockHttpServletResponse response; - public UIOutputAttachedObjectStateTestCase(String arg0) { - super(arg0); - } - - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIOutputAttachedObjectStateTestCase.class); - } - - @Override + @BeforeEach public void setUp() throws Exception { - super.setUp(); facesContext = new MockFacesContext(); facesContext = new MockFacesContext(); @@ -66,9 +62,8 @@ public void setUp() throws Exception { } - @Override + @AfterEach protected void tearDown() throws Exception { - super.tearDown(); FactoryFinder.releaseFactories(); Method reInitializeFactoryManager = FactoryFinder.class.getDeclaredMethod("reInitializeFactoryManager", (Class[]) null); reInitializeFactoryManager.setAccessible(true); @@ -76,6 +71,8 @@ protected void tearDown() throws Exception { } // ------------------------------------------------------------ Test Methods + + @Test public void testConverterState() { UIOutput output = new UIOutput(); DateTimeConverter converter = new DateTimeConverter(); @@ -124,7 +121,7 @@ public void testConverterState() { // for the component. output.restoreState(facesContext, state); assertTrue(output.getConverter() != null); - assertTrue("dd-MM-yy".equals(converter.getPattern())); + assertEquals("dd-MM-yy", converter.getPattern()); // now validate the case where UIOutput has some event // that adds a converter *after* initial state has been @@ -154,6 +151,6 @@ public void testConverterState() { assertNotNull(c); assertTrue(c instanceof DateTimeConverter); converter = (DateTimeConverter) c; - assertTrue("dd-MM-yy".equals(converter.getPattern())); + assertEquals("dd-MM-yy", converter.getPattern()); } } diff --git a/impl/src/test/java/jakarta/faces/component/UIOutputTestCase.java b/impl/src/test/java/jakarta/faces/component/UIOutputTestCase.java index e8520ade88..c5a620a011 100644 --- a/impl/src/test/java/jakarta/faces/component/UIOutputTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIOutputTestCase.java @@ -16,8 +16,8 @@ package jakarta.faces.component; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -26,19 +26,10 @@ */ public class UIOutputTestCase extends ValueHolderTestCaseBase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIOutputTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UIOutput(); @@ -47,14 +38,10 @@ public void setUp() throws Exception { expectedRendererType = "jakarta.faces.Text"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIOutputTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } diff --git a/impl/src/test/java/jakarta/faces/component/UIPanelTestCase.java b/impl/src/test/java/jakarta/faces/component/UIPanelTestCase.java index e79b15d395..d551eaaa97 100644 --- a/impl/src/test/java/jakarta/faces/component/UIPanelTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIPanelTestCase.java @@ -16,8 +16,8 @@ package jakarta.faces.component; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -26,19 +26,10 @@ */ public class UIPanelTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIPanelTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UIPanel(); @@ -48,14 +39,10 @@ public void setUp() throws Exception { expectedRendersChildren = false; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIPanelTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } diff --git a/impl/src/test/java/jakarta/faces/component/UIParameterTest.java b/impl/src/test/java/jakarta/faces/component/UIParameterTest.java index 9b53117b78..e5f4c5f8c4 100644 --- a/impl/src/test/java/jakarta/faces/component/UIParameterTest.java +++ b/impl/src/test/java/jakarta/faces/component/UIParameterTest.java @@ -16,15 +16,13 @@ package jakarta.faces.component; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; import java.lang.reflect.Method; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.el.ELContext; import jakarta.el.ValueExpression; @@ -37,7 +35,7 @@ public class UIParameterTest { */ @Test public void testIsDisable() throws Exception { - FacesContext facesContext = PowerMock.createNicePartialMockForAllMethodsExcept(FacesContext.class, "getCurrentInstance", "setCurrentInstance"); + FacesContext facesContext = Mockito.mock(FacesContext.class); Method method = FacesContext.class.getDeclaredMethod("setCurrentInstance", FacesContext.class); method.setAccessible(true); method.invoke(null, facesContext); @@ -52,21 +50,19 @@ public void testIsDisable() throws Exception { */ @Test public void testIsDisable2() throws Exception { - ELContext elContext = PowerMock.createMock(ELContext.class); - FacesContext facesContext = PowerMock.createPartialMockForAllMethodsExcept(FacesContext.class, "getCurrentInstance", "setCurrentInstance"); - ValueExpression valueExpression = PowerMock.createMock(ValueExpression.class); + ELContext elContext = Mockito.mock(ELContext.class); + FacesContext facesContext = Mockito.mock(FacesContext.class); + ValueExpression valueExpression = Mockito.mock(ValueExpression.class); Method method = FacesContext.class.getDeclaredMethod("setCurrentInstance", FacesContext.class); method.setAccessible(true); method.invoke(null, facesContext); - expect(facesContext.getExternalContext()).andReturn(null).anyTimes(); - expect(valueExpression.isLiteralText()).andReturn(false).anyTimes(); - expect(facesContext.getELContext()).andReturn(elContext); - expect(valueExpression.getValue(elContext)).andReturn(true); - replay(elContext, facesContext, valueExpression); + when(facesContext.getExternalContext()).thenReturn(null); + when(valueExpression.isLiteralText()).thenReturn(false); + when(facesContext.getELContext()).thenReturn(elContext); + when(valueExpression.getValue(elContext)).thenReturn(true); UIParameter parameter = new UIParameter(); parameter.setValueExpression("disable", valueExpression); assertTrue(parameter.isDisable()); - verify(elContext, facesContext, valueExpression); method.invoke(null, (FacesContext) null); } } diff --git a/impl/src/test/java/jakarta/faces/component/UIParameterTestCase.java b/impl/src/test/java/jakarta/faces/component/UIParameterTestCase.java index d720720e29..a8b312a8cb 100644 --- a/impl/src/test/java/jakarta/faces/component/UIParameterTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIParameterTestCase.java @@ -16,8 +16,11 @@ package jakarta.faces.component; -import junit.framework.Test; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -26,19 +29,10 @@ */ public class UIParameterTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIParameterTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UIParameter(); @@ -47,21 +41,17 @@ public void setUp() throws Exception { expectedRendererType = null; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UIParameterTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test attribute-property transparency @Override + @Test public void testAttributesTransparency() { super.testAttributesTransparency(); UIParameter parameter = (UIParameter) component; assertEquals(parameter.getValue(), component.getAttributes().get("value")); parameter.setValue("foo"); - assertEquals("foo", (String) component.getAttributes().get("value")); + assertEquals("foo", component.getAttributes().get("value")); parameter.setValue(null); assertNull(component.getAttributes().get("value")); component.getAttributes().put("value", "bar"); @@ -69,9 +59,9 @@ public void testAttributesTransparency() { component.getAttributes().put("value", null); assertNull(parameter.getValue()); - assertEquals(parameter.getName(), (String) parameter.getAttributes().get("name")); + assertEquals(parameter.getName(), parameter.getAttributes().get("name")); parameter.setName("foo"); - assertEquals("foo", (String) parameter.getAttributes().get("name")); + assertEquals("foo", parameter.getAttributes().get("name")); parameter.setName(null); assertNull(parameter.getAttributes().get("name")); parameter.getAttributes().put("name", "bar"); @@ -82,30 +72,33 @@ public void testAttributesTransparency() { // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } // Test a pristine UIParameter instance @Override + @Test public void testPristine() { super.testPristine(); UIParameter parameter = (UIParameter) component; - assertNull("no value", parameter.getValue()); - assertNull("no name", parameter.getName()); + assertNull(parameter.getValue()); + assertNull(parameter.getName()); } // Test setting properties to valid values @Override + @Test public void testPropertiesValid() throws Exception { super.testPropertiesValid(); UIParameter parameter = (UIParameter) component; // value parameter.setValue("foo.bar"); - assertEquals("expected value", "foo.bar", parameter.getValue()); + assertEquals("foo.bar", parameter.getValue()); parameter.setValue(null); - assertNull("erased value", parameter.getValue()); + assertNull(parameter.getValue()); parameter.setName("foo"); assertEquals("foo", parameter.getName()); diff --git a/impl/src/test/java/jakarta/faces/component/UISelectBooleanTestCase.java b/impl/src/test/java/jakarta/faces/component/UISelectBooleanTestCase.java index 00e01b26bf..423bf4c708 100644 --- a/impl/src/test/java/jakarta/faces/component/UISelectBooleanTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UISelectBooleanTestCase.java @@ -16,8 +16,11 @@ package jakarta.faces.component; -import junit.framework.Test; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** *

@@ -26,19 +29,10 @@ */ public class UISelectBooleanTestCase extends UIInputTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UISelectBooleanTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UISelectBoolean(); @@ -46,14 +40,10 @@ public void setUp() throws Exception { expectedRendererType = "jakarta.faces.Checkbox"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UISelectBooleanTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test attribute-property transparency @Override + @Test public void testAttributesTransparency() { super.testAttributesTransparency(); UISelectBoolean selectBoolean = (UISelectBoolean) component; @@ -70,10 +60,11 @@ public void testAttributesTransparency() { // Test a pristine UISelectBoolean instance @Override + @Test public void testPristine() { super.testPristine(); UISelectBoolean selectBoolean = (UISelectBoolean) component; - assertTrue("not selected", !selectBoolean.isSelected()); + assertTrue(!selectBoolean.isSelected()); } // --------------------------------------------------------- Support Methods diff --git a/impl/src/test/java/jakarta/faces/component/UISelectItemSub.java b/impl/src/test/java/jakarta/faces/component/UISelectItemSub.java index fd58550a6d..bdb949ae80 100644 --- a/impl/src/test/java/jakarta/faces/component/UISelectItemSub.java +++ b/impl/src/test/java/jakarta/faces/component/UISelectItemSub.java @@ -19,7 +19,6 @@ public class UISelectItemSub extends UISelectItem { public UISelectItemSub(String value, String label, String description) { - super(); setItemValue(value); setItemLabel(label); setItemDescription(description); diff --git a/impl/src/test/java/jakarta/faces/component/UISelectItemTestCase.java b/impl/src/test/java/jakarta/faces/component/UISelectItemTestCase.java index ead566ec80..4cb3712e38 100644 --- a/impl/src/test/java/jakarta/faces/component/UISelectItemTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UISelectItemTestCase.java @@ -16,9 +16,15 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import jakarta.faces.model.SelectItem; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -27,19 +33,10 @@ */ public class UISelectItemTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UISelectItemTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UISelectItem(); @@ -48,19 +45,16 @@ public void setUp() throws Exception { expectedRendererType = null; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UISelectItemTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } // Test attribute-property transparency @Override + @Test public void testAttributesTransparency() { super.testAttributesTransparency(); UISelectItem selectItem = (UISelectItem) component; @@ -77,9 +71,9 @@ public void testAttributesTransparency() { component.getAttributes().put("value", null); assertNull(selectItem.getValue()); - assertEquals(selectItem.getItemDescription(), (String) selectItem.getAttributes().get("itemDescription")); + assertEquals(selectItem.getItemDescription(), selectItem.getAttributes().get("itemDescription")); selectItem.setItemDescription("foo"); - assertEquals("foo", (String) selectItem.getAttributes().get("itemDescription")); + assertEquals("foo", selectItem.getAttributes().get("itemDescription")); selectItem.setItemDescription(null); assertNull(selectItem.getAttributes().get("itemDescription")); selectItem.getAttributes().put("itemDescription", "bar"); @@ -97,9 +91,9 @@ public void testAttributesTransparency() { selectItem.getAttributes().put("itemDisabled", Boolean.TRUE); assertTrue(selectItem.isItemDisabled()); - assertEquals(selectItem.getItemLabel(), (String) selectItem.getAttributes().get("itemLabel")); + assertEquals(selectItem.getItemLabel(), selectItem.getAttributes().get("itemLabel")); selectItem.setItemLabel("foo"); - assertEquals("foo", (String) selectItem.getAttributes().get("itemLabel")); + assertEquals("foo", selectItem.getAttributes().get("itemLabel")); selectItem.setItemLabel(null); assertNull(selectItem.getAttributes().get("itemLabel")); selectItem.getAttributes().put("itemLabel", "bar"); @@ -109,7 +103,7 @@ public void testAttributesTransparency() { assertEquals(selectItem.getItemValue(), selectItem.getAttributes().get("itemValue")); selectItem.setItemValue("foo"); - assertEquals("foo", (String) selectItem.getAttributes().get("itemValue")); + assertEquals("foo", selectItem.getAttributes().get("itemValue")); selectItem.setItemValue(null); assertNull(selectItem.getAttributes().get("itemValue")); selectItem.getAttributes().put("itemValue", "bar"); @@ -120,19 +114,21 @@ public void testAttributesTransparency() { // Test a pristine UISelectItem instance @Override + @Test public void testPristine() { super.testPristine(); UISelectItem selectItem = (UISelectItem) component; - assertNull("no value", selectItem.getValue()); - assertNull("no itemDescription", selectItem.getItemDescription()); - assertFalse("no itemDisabled", selectItem.isItemDisabled()); - assertNull("no itemLabel", selectItem.getItemLabel()); - assertNull("no itemValue", selectItem.getItemValue()); + assertNull(selectItem.getValue()); + assertNull(selectItem.getItemDescription()); + assertFalse(selectItem.isItemDisabled()); + assertNull(selectItem.getItemLabel()); + assertNull(selectItem.getItemValue()); } // Test setting properties to valid values @Override + @Test public void testPropertiesValid() throws Exception { super.testPropertiesValid(); UISelectItem selectItem = (UISelectItem) component; @@ -140,9 +136,9 @@ public void testPropertiesValid() throws Exception { // value SelectItem item = new SelectItem("foo"); selectItem.setValue(item); - assertEquals("expected value", item, selectItem.getValue()); + assertEquals(item, selectItem.getValue()); selectItem.setValue(null); - assertNull("erased value", selectItem.getValue()); + assertNull(selectItem.getValue()); selectItem.setItemDescription("foo"); assertEquals("foo", selectItem.getItemDescription()); diff --git a/impl/src/test/java/jakarta/faces/component/UISelectItemsTestCase.java b/impl/src/test/java/jakarta/faces/component/UISelectItemsTestCase.java index a4a6bc9c36..cde6a1e6b1 100644 --- a/impl/src/test/java/jakarta/faces/component/UISelectItemsTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UISelectItemsTestCase.java @@ -16,9 +16,13 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import jakarta.faces.model.SelectItem; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -27,19 +31,10 @@ */ public class UISelectItemsTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UISelectItemsTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UISelectItems(); @@ -48,14 +43,10 @@ public void setUp() throws Exception { expectedRendererType = null; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UISelectItemsTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test attribute-property transparency @Override + @Test public void testAttributesTransparency() { super.testAttributesTransparency(); UISelectItems selectItems = (UISelectItems) component; @@ -74,19 +65,22 @@ public void testAttributesTransparency() { // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } // Test a pristine UISelectItems instance @Override + @Test public void testPristine() { super.testPristine(); UISelectItems selectItems = (UISelectItems) component; - assertNull("no value", selectItems.getValue()); + assertNull(selectItems.getValue()); } // Test setting properties to valid values @Override + @Test public void testPropertiesValid() throws Exception { super.testPropertiesValid(); UISelectItems selectItems = (UISelectItems) component; @@ -94,9 +88,9 @@ public void testPropertiesValid() throws Exception { // value SelectItem item = new SelectItem("foo"); selectItems.setValue(item); - assertEquals("expected value", item, selectItems.getValue()); + assertEquals(item, selectItems.getValue()); selectItems.setValue(null); - assertNull("erased value", selectItems.getValue()); + assertNull(selectItems.getValue()); } // --------------------------------------------------------- Support Methods diff --git a/impl/src/test/java/jakarta/faces/component/UISelectManyTestCase.java b/impl/src/test/java/jakarta/faces/component/UISelectManyTestCase.java index d7f6bec985..019f132a87 100644 --- a/impl/src/test/java/jakarta/faces/component/UISelectManyTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UISelectManyTestCase.java @@ -16,6 +16,12 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -27,14 +33,15 @@ import java.util.NoSuchElementException; import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.renderkit.SelectItemsIterator; import jakarta.faces.application.FacesMessage; import jakarta.faces.model.ListDataModel; import jakarta.faces.model.SelectItem; import jakarta.faces.model.SelectItemGroup; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -43,19 +50,10 @@ */ public class UISelectManyTestCase extends UIInputTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UISelectManyTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UISelectMany(); @@ -63,14 +61,10 @@ public void setUp() throws Exception { expectedRendererType = "jakarta.faces.Listbox"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UISelectManyTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test the compareValues() method @Override + @Test public void testCompareValues() { SelectManyTestImpl selectMany = new SelectManyTestImpl(); Object values1a[] = new Object[] { "foo", "bar", "baz" }; @@ -99,20 +93,23 @@ public void testCompareValues() { // Test a pristine UISelectMany instance @Override + @Test public void testPristine() { super.testPristine(); UISelectMany selectMany = (UISelectMany) component; - assertNull("no selectedValues", selectMany.getSelectedValues()); + assertNull(selectMany.getSelectedValues()); } // Test setting properties to invalid values @Override + @Test public void testPropertiesInvalid() throws Exception { super.testPropertiesInvalid(); } // Test validation of value against the valid list + @Test public void testValidation() throws Exception { // Put our component under test in a tree under a UIViewRoot UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -146,6 +143,7 @@ public void testValidation() throws Exception { } // Test validation of component with UISelectItems pointing to map + @Test public void testValidation2() throws Exception { // Put our component under test in a tree under a UIViewRoot UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -177,6 +175,7 @@ public void testValidation2() throws Exception { // Test validation of component with UISelectItems pointing to Set and the // value of the component is Set + @Test public void testValidation3() throws Exception { Set items = new HashSet<>(); items.add(new SelectItem("foo")); @@ -192,6 +191,7 @@ public void testValidation3() throws Exception { } // Test validation of component with UISelectItems pointing to List + @Test public void testValidation4() throws Exception { List items = new ArrayList<>(); items.add(new SelectItem("foo")); @@ -207,6 +207,7 @@ public void testValidation4() throws Exception { } // Test validation of component with UISelectItems pointing to an Array + @Test public void testValidation5() throws Exception { // Put our component under test in a tree under a UIViewRoot UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -260,6 +261,7 @@ private void testValidateWithCollection(Collection selectItems, Obje private String illegalValues[] = { "D1", "D2", "Group A", "Group B", "Group C" }; // Test validation against a nested list of available options + @Test public void testValidateNested() throws Exception { // Set up UISelectMany with nested UISelectItems UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -276,7 +278,7 @@ public void testValidateNested() throws Exception { selectMany.setValid(true); selectMany.setSubmittedValue(new Object[] { legalValues[0], legalValues[i] }); selectMany.validate(facesContext); - assertTrue("Value '" + legalValues[i] + "' found", selectMany.isValid()); + assertTrue(selectMany.isValid(), "Value '" + legalValues[i] + "' found"); checkMessages(0); } @@ -285,12 +287,13 @@ public void testValidateNested() throws Exception { selectMany.setValid(true); selectMany.setSubmittedValue(new Object[] { legalValues[0], illegalValues[i] }); selectMany.validate(facesContext); - assertTrue("Value '" + illegalValues[i] + "' not found", !selectMany.isValid()); + assertTrue(!selectMany.isValid(), "Value '" + illegalValues[i] + "' not found"); checkMessages(i + 1); } } // Test validation against a nested Set of available options + @Test public void testValidateNestedSet() throws Exception { // Set up UISelectMany with nested UISelectItems UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -307,7 +310,7 @@ public void testValidateNestedSet() throws Exception { selectMany.setValid(true); selectMany.setSubmittedValue(new Object[] { legalValues[0], legalValues[i] }); selectMany.validate(facesContext); - assertTrue("Value '" + legalValues[i] + "' found", selectMany.isValid()); + assertTrue(selectMany.isValid(), "Value '" + legalValues[i] + "' found"); checkMessages(0); } @@ -316,13 +319,14 @@ public void testValidateNestedSet() throws Exception { selectMany.setValid(true); selectMany.setSubmittedValue(new Object[] { legalValues[0], illegalValues[i] }); selectMany.validate(facesContext); - assertTrue("Value '" + illegalValues[i] + "' not found", !selectMany.isValid()); + assertTrue(!selectMany.isValid(), "Value '" + illegalValues[i] + "' not found"); checkMessages(i + 1); } } // Test validation of a required field @Override + @Test public void testValidateRequired() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); root.getChildren().add(component); @@ -361,6 +365,7 @@ public void testValidateRequired() throws Exception { assertTrue(selectMany.isValid()); } + @Test public void testSelectItemsIterator() { // sub test 1: non-selectitem at end UISelectMany selectMany = (UISelectMany) component; diff --git a/impl/src/test/java/jakarta/faces/component/UISelectOneTestCase.java b/impl/src/test/java/jakarta/faces/component/UISelectOneTestCase.java index 26f5e4f42a..dae1499e7f 100644 --- a/impl/src/test/java/jakarta/faces/component/UISelectOneTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UISelectOneTestCase.java @@ -16,6 +16,8 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -25,11 +27,12 @@ import java.util.Map; import java.util.Set; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import jakarta.faces.application.FacesMessage; import jakarta.faces.model.SelectItem; import jakarta.faces.model.SelectItemGroup; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -38,19 +41,10 @@ */ public class UISelectOneTestCase extends UIInputTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UISelectOneTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UISelectOne(); @@ -58,13 +52,9 @@ public void setUp() throws Exception { expectedRendererType = "jakarta.faces.Menu"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(UISelectOneTestCase.class); - } - // ------------------------------------------------- Individual Test Methods // Test validation of value against the valid list + @Test public void testValidation() throws Exception { // Put our component under test in a tree under a UIViewRoot UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -97,6 +87,7 @@ public void testValidation() throws Exception { } // Test validation of component with UISelectItems pointing to map + @Test public void testValidation2() throws Exception { // Put our component under test in a tree under a UIViewRoot UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -126,6 +117,7 @@ public void testValidation2() throws Exception { } // Test validation of component with UISelectItems pointing to Set + @Test public void testValidation3() throws Exception { Set items = new HashSet<>(); items.add(new SelectItem("foo")); @@ -136,6 +128,7 @@ public void testValidation3() throws Exception { } // Test validation of component with UISelectItems pointing to List + @Test public void testValidation4() throws Exception { List items = new ArrayList<>(); items.add(new SelectItem("foo")); @@ -146,6 +139,7 @@ public void testValidation4() throws Exception { } // Test validation of component with UISelectItems pointing to an Array + @Test public void testValidation5() throws Exception { // Put our component under test in a tree under a UIViewRoot UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -198,6 +192,7 @@ private void testValidateWithCollection(Collection selectItems, Stri private String illegalValues[] = { "D1", "D2", "Group A", "Group B", "Group C" }; // Test validation against a nested list of available options + @Test public void testValidateNested() throws Exception { // Set up UISelectOne with nested UISelectItems UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -214,7 +209,7 @@ public void testValidateNested() throws Exception { selectOne.setValid(true); selectOne.setSubmittedValue(legalValues[i]); selectOne.validate(facesContext); - assertTrue("Value '" + legalValues[i] + "' found", selectOne.isValid()); + assertTrue(selectOne.isValid(), "Value '" + legalValues[i] + "' found"); checkMessages(0); } @@ -223,13 +218,14 @@ public void testValidateNested() throws Exception { selectOne.setValid(true); selectOne.setSubmittedValue(illegalValues[i]); selectOne.validate(facesContext); - assertTrue("Value '" + illegalValues[i] + "' not found", !selectOne.isValid()); + assertTrue(!selectOne.isValid(), "Value '" + illegalValues[i] + "' not found"); checkMessages(i + 1); } } // Test validation of a required field @Override + @Test public void testValidateRequired() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); root.getChildren().add(component); @@ -260,6 +256,7 @@ public void testValidateRequired() throws Exception { assertTrue(selectOne.isValid()); } + @Test public void testSelectItemsIterator() { // sub test 1 : non-selectItem at end UISelectOne selectOne = (UISelectOne) component; diff --git a/impl/src/test/java/jakarta/faces/component/UIViewRootTest.java b/impl/src/test/java/jakarta/faces/component/UIViewRootTest.java index ff3fd11a97..e6b4d66545 100644 --- a/impl/src/test/java/jakarta/faces/component/UIViewRootTest.java +++ b/impl/src/test/java/jakarta/faces/component/UIViewRootTest.java @@ -16,19 +16,16 @@ package jakarta.faces.component; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reset; -import static org.easymock.EasyMock.verify; -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 static org.mockito.Mockito.when; import java.lang.reflect.Method; 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 jakarta.faces.application.Application; import jakarta.faces.application.ProjectStage; @@ -42,99 +39,82 @@ public class UIViewRootTest { @Test public void testViewMapPostConstructViewMapEvent() { - FacesContext facesContext = EasyMock.createMock(FacesContext.class); - Application application = EasyMock.createMock(Application.class); - ExternalContext externalContext = EasyMock.createMock(ExternalContext.class); - HttpSession httpSession = EasyMock.createMock(HttpSession.class); + FacesContext facesContext = Mockito.mock(FacesContext.class); + Application application = Mockito.mock(Application.class); + ExternalContext externalContext = Mockito.mock(ExternalContext.class); + HttpSession httpSession = Mockito.mock(HttpSession.class); setFacesContext(facesContext); - expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes(); - expect(externalContext.getApplicationMap()).andReturn(null).anyTimes(); - replay(facesContext, externalContext); + when(facesContext.getExternalContext()).thenReturn(externalContext); + when(externalContext.getApplicationMap()).thenReturn(null); UIViewRoot viewRoot = new UIViewRoot(); - verify(facesContext, externalContext); - reset(facesContext, externalContext); - expect(facesContext.getApplication()).andReturn(application).anyTimes(); - expect(application.getProjectStage()).andReturn(ProjectStage.UnitTest); + when(facesContext.getApplication()).thenReturn(application); + when(application.getProjectStage()).thenReturn(ProjectStage.UnitTest); application.publishEvent(facesContext, PostConstructViewMapEvent.class, UIViewRoot.class, viewRoot); - replay(facesContext, application, externalContext, httpSession); Map viewMap = viewRoot.getViewMap(); assertNotNull(viewMap); - verify(facesContext, application, externalContext, httpSession); setFacesContext(null); } @Test public void testViewMapPreDestroyViewMapEvent() { - FacesContext facesContext = EasyMock.createMock(FacesContext.class); - Application application = EasyMock.createMock(Application.class); - ExternalContext externalContext = EasyMock.createMock(ExternalContext.class); - HttpSession httpSession = EasyMock.createMock(HttpSession.class); + FacesContext facesContext = Mockito.mock(FacesContext.class); + Application application = Mockito.mock(Application.class); + ExternalContext externalContext = Mockito.mock(ExternalContext.class); + HttpSession httpSession = Mockito.mock(HttpSession.class); setFacesContext(facesContext); - expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes(); - expect(externalContext.getApplicationMap()).andReturn(null).anyTimes(); - replay(facesContext, externalContext); + when(facesContext.getExternalContext()).thenReturn(externalContext); + when(externalContext.getApplicationMap()).thenReturn(null); UIViewRoot viewRoot = new UIViewRoot(); - verify(facesContext, externalContext); - reset(facesContext, externalContext); - expect(facesContext.getApplication()).andReturn(application).anyTimes(); - expect(application.getProjectStage()).andReturn(ProjectStage.UnitTest); + when(facesContext.getApplication()).thenReturn(application); + when(application.getProjectStage()).thenReturn(ProjectStage.UnitTest); application.publishEvent(facesContext, PostConstructViewMapEvent.class, UIViewRoot.class, viewRoot); - expect(facesContext.getViewRoot()).andReturn(viewRoot); + when(facesContext.getViewRoot()).thenReturn(viewRoot); application.publishEvent(facesContext, PreDestroyViewMapEvent.class, UIViewRoot.class, viewRoot); - expect(facesContext.getViewRoot()).andReturn(viewRoot); + when(facesContext.getViewRoot()).thenReturn(viewRoot); application.publishEvent(facesContext, PreDestroyViewMapEvent.class, UIViewRoot.class, viewRoot); - replay(facesContext, application, externalContext, httpSession); Map viewMap = viewRoot.getViewMap(); assertNotNull(viewMap); viewRoot.getViewMap().clear(); viewRoot.getViewMap().clear(); - verify(facesContext, application, externalContext, httpSession); setFacesContext(null); } @Test public void testViewMapSaveAndRestoreState() { - FacesContext facesContext = EasyMock.createMock(FacesContext.class); - Application application = EasyMock.createMock(Application.class); - ExternalContext externalContext = EasyMock.createMock(ExternalContext.class); - HttpSession httpSession = EasyMock.createMock(HttpSession.class); + FacesContext facesContext = Mockito.mock(FacesContext.class); + Application application = Mockito.mock(Application.class); + ExternalContext externalContext = Mockito.mock(ExternalContext.class); + HttpSession httpSession = Mockito.mock(HttpSession.class); HashMap attributes = new HashMap<>(); HashMap sessionMap = new HashMap<>(); setFacesContext(facesContext); - expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes(); - expect(externalContext.getApplicationMap()).andReturn(null).anyTimes(); - replay(facesContext, externalContext); + when(facesContext.getExternalContext()).thenReturn(externalContext); + when(externalContext.getApplicationMap()).thenReturn(null); UIViewRoot viewRoot1 = new UIViewRoot(); - verify(facesContext, externalContext); - reset(facesContext, externalContext); - expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes(); - expect(externalContext.getApplicationMap()).andReturn(null).anyTimes(); - replay(facesContext, externalContext); + when(facesContext.getExternalContext()).thenReturn(externalContext); + when(externalContext.getApplicationMap()).thenReturn(null); UIViewRoot viewRoot2 = new UIViewRoot(); - verify(facesContext, externalContext); - reset(facesContext, externalContext); - - expect(facesContext.getAttributes()).andReturn(attributes).anyTimes(); - expect(facesContext.getApplication()).andReturn(application).anyTimes(); - expect(application.getProjectStage()).andReturn(ProjectStage.UnitTest).anyTimes(); - expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes(); - expect(externalContext.getSessionMap()).andReturn(sessionMap).anyTimes(); + + when(facesContext.getAttributes()).thenReturn(attributes); + when(facesContext.getApplication()).thenReturn(application); + when(application.getProjectStage()).thenReturn(ProjectStage.UnitTest); + when(facesContext.getExternalContext()).thenReturn(externalContext); + when(externalContext.getSessionMap()).thenReturn(sessionMap); application.publishEvent(facesContext, PostConstructViewMapEvent.class, UIViewRoot.class, viewRoot1); - replay(facesContext, application, externalContext, httpSession); Map viewMap = viewRoot1.getViewMap(); viewMap.put("one", "one"); Object saved = viewRoot1.saveState(facesContext); @@ -149,7 +129,6 @@ public void testViewMapSaveAndRestoreState() { viewRoot2.restoreState(facesContext, saved); viewMap = viewRoot2.getViewMap(); assertEquals("one", viewMap.get("one")); - verify(facesContext, application, externalContext, httpSession); setFacesContext(null); } diff --git a/impl/src/test/java/jakarta/faces/component/UIViewRootTestCase.java b/impl/src/test/java/jakarta/faces/component/UIViewRootTestCase.java index 8137f695e2..8f4b1b8972 100644 --- a/impl/src/test/java/jakarta/faces/component/UIViewRootTestCase.java +++ b/impl/src/test/java/jakarta/faces/component/UIViewRootTestCase.java @@ -16,11 +16,21 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import java.lang.reflect.Field; import java.util.List; import java.util.Locale; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.mock.MockRenderKit; import jakarta.el.MethodExpression; @@ -34,8 +44,6 @@ import jakarta.faces.event.PostRestoreStateEvent; import jakarta.faces.render.RenderKit; import jakarta.faces.render.RenderKitFactory; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -44,30 +52,13 @@ */ public class UIViewRootTestCase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public UIViewRootTestCase(String name) { - super(name); - } - - // ---------------------------------------------------- Overall Test Methods - /** - * Return the tests included in this test suite. - */ - public static Test suite() { - return new TestSuite(UIViewRootTestCase.class); - } - public static String FACTORIES[][] = { { FactoryFinder.APPLICATION_FACTORY, "com.sun.faces.mock.MockApplicationFactory" }, { FactoryFinder.FACES_CONTEXT_FACTORY, "com.sun.faces.mock.MockFacesContextFactory" }, { FactoryFinder.LIFECYCLE_FACTORY, "com.sun.faces.mock.MockLifecycleFactory" }, { FactoryFinder.RENDER_KIT_FACTORY, "com.sun.faces.mock.MockRenderKitFactory" } }; @Override + @BeforeEach public void setUp() throws Exception { FactoryFinder.releaseFactories(); super.setUp(); @@ -100,12 +91,14 @@ public void setUp() throws Exception { * @throws java.lang.Exception */ @Override + @AfterEach public void tearDown() throws Exception { component = null; super.tearDown(); } // ------------------------------------------------- Individual Test Methods + @Test public void testAddGetComponentResources() { application.addComponent("jakarta.faces.ComponentResourceContainer", Container.class.getName()); UIViewRoot root = new UIViewRoot(); @@ -147,6 +140,7 @@ public void testAddGetComponentResources() { } // Tests that the resources are rendered again if renderall, @all, is set + @Test public void testRenderAllComponentResources() { application.addComponent("jakarta.faces.ComponentResourceContainer", Container.class.getName()); UIViewRoot previousRoot = facesContext.getViewRoot(); @@ -169,13 +163,13 @@ public void testRenderAllComponentResources() { postRestoreStateEvent.setComponent(root); root.processEvent(postRestoreStateEvent); - assertFalse("Resource should not be marked as rendered", resourceHandler.isResourceRendered(facesContext, "scriptTest", "scriptLibrary")); + assertFalse(resourceHandler.isResourceRendered(facesContext, "scriptTest", "scriptLibrary")); // partial update i.e. @form facesContext.getPartialViewContext().setRenderAll(false); root.processEvent(postRestoreStateEvent); - assertTrue("Resource should be marked as rendered", resourceHandler.isResourceRendered(facesContext, "scriptTest", "scriptLibrary")); + assertTrue(resourceHandler.isResourceRendered(facesContext, "scriptTest", "scriptLibrary")); facesContext.getPartialViewContext().setPartialRequest(false); facesContext.getPartialViewContext().setRenderAll(false); @@ -184,6 +178,7 @@ public void testRenderAllComponentResources() { } // Test AbortProcessingException support + @Test public void testAbortProcessingException() { // Register three listeners, with the second one set to abort UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -205,6 +200,7 @@ public void testAbortProcessingException() { } // Test event queuing and dequeuing during broadcasting + @Test public void testEventBroadcasting() { // Register a listener that will conditionally queue a new event UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -233,6 +229,7 @@ public void testEventBroadcasting() { } // Test event queuing and broadcasting + @Test public void testEventQueuing() { // Check for correct ifecycle management processing of event broadcast checkEventQueueing(PhaseId.APPLY_REQUEST_VALUES); @@ -242,6 +239,7 @@ public void testEventQueuing() { checkEventQueueing(PhaseId.ANY_PHASE); } + @Test public void testLocaleFromVB() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); @@ -263,6 +261,7 @@ public void testLocaleFromVB() throws Exception { assertEquals(Locale.CANADA_FRENCH, root.getLocale()); } + @Test public void testUninitializedInstance() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); @@ -270,42 +269,49 @@ public void testUninitializedInstance() throws Exception { assertEquals(Locale.getDefault(), root.getLocale()); } + @Test public void testPhaseMethExpression() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); doTestPhaseMethodExpression(root, false); } + @Test public void testPhaseMethExpressionSkipping() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); doTestPhaseMethodExpression(root, true); } + @Test public void testPhaseListener() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); doTestPhaseListener(root, false); } + @Test public void testPhaseListenerSkipping() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); doTestPhaseListener(root, true); } + @Test public void testPhaseMethodExpressionAndListener() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); doTestPhaseMethodExpressionAndListener(root, false); } + @Test public void testPhaseMethodExpressionAndListenerSkipping() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); doTestPhaseMethodExpressionAndListener(root, true); } + @Test public void testPhaseMethExpressionState() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); @@ -317,6 +323,7 @@ public void testPhaseMethExpressionState() throws Exception { doTestPhaseMethodExpression(root, false); } + @Test public void testPhaseListenerState() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); @@ -328,6 +335,7 @@ public void testPhaseListenerState() throws Exception { doTestPhaseListener(root, false); } + @Test public void testPhaseMethodExpressionAndListenerState() throws Exception { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); @@ -339,6 +347,7 @@ public void testPhaseMethodExpressionAndListenerState() throws Exception { doTestPhaseMethodExpressionAndListener(root, false); } + @Test public void testPhaseListenerExceptions() throws Exception { PhaseId[] ids = { PhaseId.APPLY_REQUEST_VALUES, PhaseId.PROCESS_VALIDATIONS, PhaseId.UPDATE_MODEL_VALUES, PhaseId.INVOKE_APPLICATION, PhaseId.RENDER_RESPONSE }; @@ -518,16 +527,17 @@ public void doTestPhaseMethodExpressionAndListenerWithPhaseId(UIViewRoot root, P private void checkEventQueuesSizes(List events, int applyEventsSize, int valEventsSize, int updateEventsSize, int appEventsSize) { List applyEvents = events.get(PhaseId.APPLY_REQUEST_VALUES.getOrdinal()); - assertEquals("Apply-Request-Values Event Count", applyEventsSize, applyEvents.size()); + assertEquals(applyEventsSize, applyEvents.size()); List valEvents = events.get(PhaseId.PROCESS_VALIDATIONS.getOrdinal()); - assertEquals("Process-Validations Event Count", valEventsSize, valEvents.size()); + assertEquals(valEventsSize, valEvents.size()); List updateEvents = events.get(PhaseId.UPDATE_MODEL_VALUES.getOrdinal()); - assertEquals("Update-Model Event Count", updateEventsSize, updateEvents.size()); + assertEquals(updateEventsSize, updateEvents.size()); List appEvents = events.get(PhaseId.INVOKE_APPLICATION.getOrdinal()); - assertEquals("Invoke-Application Event Count", appEventsSize, appEvents.size()); + assertEquals(appEventsSize, appEvents.size()); } // Test Events List Clearing + @Test public void testEventsListClear() { UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); @@ -646,7 +656,7 @@ public void testEventsListClear() { } catch (Exception e) { assertTrue(false); } - assertNull("events", events); + assertNull(events); } private void callRightLifecycleMethodGivenPhaseId(UIViewRoot root, PhaseId phaseId) throws Exception { @@ -720,30 +730,35 @@ private void checkEventQueueing(PhaseId phaseId) { // These overrides are necessary because our normal setup // calls releaseFactories, which makes it impossible to get clientIds. @Override + @Test public void testInvokeOnComponentPositive() throws Exception { super.setUp(); super.testInvokeOnComponentPositive(); } @Override + @Test public void testInvokeOnComponentNegative() throws Exception { super.setUp(); super.testInvokeOnComponentNegative(); } @Override + @Test public void testInvokeOnComponentWithPrependId() throws Exception { super.setUp(); super.testInvokeOnComponentWithPrependId(); } @Override + @Test public void testChildrenListAfterAddViewPublish() { // overridding to do nothing. UIViewRoot is a special cases // and there should always only be on UIViewRoot in a tree } @Override + @Test public void testFacetMapAfterAddViewPublish() { // overridding to do nothing. UIViewRoot is a special cases // and there should always only be on UIViewRoot in a tree diff --git a/impl/src/test/java/jakarta/faces/component/ValueHolderTestCaseBase.java b/impl/src/test/java/jakarta/faces/component/ValueHolderTestCaseBase.java index 8b5db25fea..0e7bda4afc 100644 --- a/impl/src/test/java/jakarta/faces/component/ValueHolderTestCaseBase.java +++ b/impl/src/test/java/jakarta/faces/component/ValueHolderTestCaseBase.java @@ -16,12 +16,19 @@ package jakarta.faces.component; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import jakarta.faces.component.html.HtmlInputText; import jakarta.faces.convert.LongConverter; import jakarta.faces.convert.NumberConverter; import jakarta.faces.convert.ShortConverter; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -31,19 +38,10 @@ */ public abstract class ValueHolderTestCaseBase extends UIComponentBaseTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public ValueHolderTestCaseBase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); component = new UIOutput(); @@ -51,12 +49,8 @@ public void setUp() throws Exception { expectedRendererType = "Text"; } - // Return the tests included in this test case. - public static Test suite() { - return new TestSuite(ValueHolderTestCaseBase.class); - } - // ------------------------------------------------- Individual Test Methods + @Test public void testAttributesTransparencyNonDeterministic() throws Exception { final int numThreads = 30; final Boolean outcomes[] = new Boolean[numThreads]; @@ -130,6 +124,7 @@ public void run() { } @Override + @Test public void testAttributesTransparency() { super.testAttributesTransparency(); ValueHolder vh = (ValueHolder) component; @@ -140,7 +135,7 @@ public void testAttributesTransparency() { public boolean doTestAttributesTransparency(ValueHolder vh, UIComponent newComp) { assertEquals(vh.getValue(), newComp.getAttributes().get("value")); vh.setValue("foo"); - assertEquals("foo", (String) newComp.getAttributes().get("value")); + assertEquals("foo", newComp.getAttributes().get("value")); vh.setValue(null); assertNull(newComp.getAttributes().get("value")); newComp.getAttributes().put("value", "bar"); @@ -165,37 +160,40 @@ public boolean doTestAttributesTransparency(ValueHolder vh, UIComponent newComp) // Suppress lifecycle tests since we do not have a renderer @Override + @Test public void testLifecycleManagement() { } // Test a pristine ValueHolderBase instance @Override + @Test public void testPristine() { super.testPristine(); ValueHolder vh = (ValueHolder) component; // Validate properties - assertNull("no value", vh.getValue()); - assertNull("no converter", vh.getConverter()); + assertNull(vh.getValue()); + assertNull(vh.getConverter()); } // Test setting properties to valid values @Override + @Test public void testPropertiesValid() throws Exception { super.testPropertiesValid(); ValueHolder vh = (ValueHolder) component; // value vh.setValue("foo.bar"); - assertEquals("expected value", "foo.bar", vh.getValue()); + assertEquals("foo.bar", vh.getValue()); vh.setValue(null); - assertNull("erased value", vh.getValue()); + assertNull(vh.getValue()); // converter vh.setConverter(new LongConverter()); - assertTrue("expected converter", vh.getConverter() instanceof LongConverter); + assertTrue(vh.getConverter() instanceof LongConverter); vh.setConverter(null); - assertNull("erased converter", vh.getConverter()); + assertNull(vh.getConverter()); } // --------------------------------------------------------- Support Methods diff --git a/impl/src/test/java/jakarta/faces/convert/BigIntegerConverterTest.java b/impl/src/test/java/jakarta/faces/convert/BigIntegerConverterTest.java index a6d919db2c..70f8a6c468 100644 --- a/impl/src/test/java/jakarta/faces/convert/BigIntegerConverterTest.java +++ b/impl/src/test/java/jakarta/faces/convert/BigIntegerConverterTest.java @@ -16,15 +16,14 @@ package jakarta.faces.convert; -import java.math.BigInteger; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import java.math.BigInteger; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.component.UIPanel; import jakarta.faces.context.FacesContext; @@ -37,10 +36,10 @@ public class BigIntegerConverterTest { /** * Test getAsObject method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsObject() { BigIntegerConverter converter = new BigIntegerConverter(); - converter.getAsObject(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsObject(null, null, null)); } /** @@ -49,10 +48,8 @@ public void testGetAsObject() { @Test public void testGetAsObject2() { BigIntegerConverter converter = new BigIntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -61,10 +58,8 @@ public void testGetAsObject2() { @Test public void testGetAsObject3() { BigIntegerConverter converter = new BigIntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), " ")); - verify(facesContext); } /** @@ -73,19 +68,17 @@ public void testGetAsObject3() { @Test public void testGetAsObject4() { BigIntegerConverter converter = new BigIntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals(BigInteger.valueOf(123), converter.getAsObject(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** * Test getAsString method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsString() { BigIntegerConverter converter = new BigIntegerConverter(); - converter.getAsString(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsString(null, null, null)); } /** @@ -94,10 +87,8 @@ public void testGetAsString() { @Test public void testGetAsString2() { BigIntegerConverter converter = new BigIntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("", converter.getAsString(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -106,10 +97,8 @@ public void testGetAsString2() { @Test public void testGetAsString3() { BigIntegerConverter converter = new BigIntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** @@ -118,9 +107,7 @@ public void testGetAsString3() { @Test public void testGetAsString4() { BigIntegerConverter converter = new BigIntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), BigInteger.valueOf(123))); - verify(facesContext); } } diff --git a/impl/src/test/java/jakarta/faces/convert/DoubleConverterTest.java b/impl/src/test/java/jakarta/faces/convert/DoubleConverterTest.java index b033eca4fe..976600b158 100644 --- a/impl/src/test/java/jakarta/faces/convert/DoubleConverterTest.java +++ b/impl/src/test/java/jakarta/faces/convert/DoubleConverterTest.java @@ -16,13 +16,12 @@ package jakarta.faces.convert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.component.UIPanel; import jakarta.faces.context.FacesContext; @@ -35,10 +34,10 @@ public class DoubleConverterTest { /** * Test getAsObject method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsObject() { DoubleConverter converter = new DoubleConverter(); - converter.getAsObject(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsObject(null, null, null)); } /** @@ -47,10 +46,8 @@ public void testGetAsObject() { @Test public void testGetAsObject2() { DoubleConverter converter = new DoubleConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -59,10 +56,8 @@ public void testGetAsObject2() { @Test public void testGetAsObject3() { DoubleConverter converter = new DoubleConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), " ")); - verify(facesContext); } /** @@ -71,19 +66,17 @@ public void testGetAsObject3() { @Test public void testGetAsObject4() { DoubleConverter converter = new DoubleConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals(Double.valueOf("12.3"), converter.getAsObject(facesContext, new UIPanel(), "12.3")); - verify(facesContext); } /** * Test getAsString method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsString() { DoubleConverter converter = new DoubleConverter(); - converter.getAsString(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsString(null, null, null)); } /** @@ -92,10 +85,8 @@ public void testGetAsString() { @Test public void testGetAsString2() { DoubleConverter converter = new DoubleConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("", converter.getAsString(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -104,10 +95,8 @@ public void testGetAsString2() { @Test public void testGetAsString3() { DoubleConverter converter = new DoubleConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("12.3", converter.getAsString(facesContext, new UIPanel(), "12.3")); - verify(facesContext); } /** @@ -116,9 +105,7 @@ public void testGetAsString3() { @Test public void testGetAsString4() { DoubleConverter converter = new DoubleConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("12.3", converter.getAsString(facesContext, new UIPanel(), Double.valueOf("12.3"))); - verify(facesContext); } } diff --git a/impl/src/test/java/jakarta/faces/convert/FloatConverterTest.java b/impl/src/test/java/jakarta/faces/convert/FloatConverterTest.java index e62c4bf86c..446940f431 100644 --- a/impl/src/test/java/jakarta/faces/convert/FloatConverterTest.java +++ b/impl/src/test/java/jakarta/faces/convert/FloatConverterTest.java @@ -16,13 +16,12 @@ package jakarta.faces.convert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.component.UIPanel; import jakarta.faces.context.FacesContext; @@ -35,10 +34,10 @@ public class FloatConverterTest { /** * Test getAsObject method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsObject() { FloatConverter converter = new FloatConverter(); - converter.getAsObject(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsObject(null, null, null)); } /** @@ -47,10 +46,8 @@ public void testGetAsObject() { @Test public void testGetAsObject2() { FloatConverter converter = new FloatConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -59,10 +56,8 @@ public void testGetAsObject2() { @Test public void testGetAsObject3() { FloatConverter converter = new FloatConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), " ")); - verify(facesContext); } /** @@ -71,19 +66,17 @@ public void testGetAsObject3() { @Test public void testGetAsObject4() { FloatConverter converter = new FloatConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals(Float.valueOf("12.3"), converter.getAsObject(facesContext, new UIPanel(), "12.3")); - verify(facesContext); } /** * Test getAsString method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsString() { FloatConverter converter = new FloatConverter(); - converter.getAsString(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsString(null, null, null)); } /** @@ -92,10 +85,8 @@ public void testGetAsString() { @Test public void testGetAsString2() { FloatConverter converter = new FloatConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("", converter.getAsString(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -104,10 +95,8 @@ public void testGetAsString2() { @Test public void testGetAsString3() { FloatConverter converter = new FloatConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("12.3", converter.getAsString(facesContext, new UIPanel(), "12.3")); - verify(facesContext); } /** @@ -116,9 +105,7 @@ public void testGetAsString3() { @Test public void testGetAsString4() { FloatConverter converter = new FloatConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("12.3", converter.getAsString(facesContext, new UIPanel(), Float.valueOf("12.3"))); - verify(facesContext); } } diff --git a/impl/src/test/java/jakarta/faces/convert/IntegerConverterTest.java b/impl/src/test/java/jakarta/faces/convert/IntegerConverterTest.java index a554dde147..4427b9441d 100644 --- a/impl/src/test/java/jakarta/faces/convert/IntegerConverterTest.java +++ b/impl/src/test/java/jakarta/faces/convert/IntegerConverterTest.java @@ -16,13 +16,12 @@ package jakarta.faces.convert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.component.UIPanel; import jakarta.faces.context.FacesContext; @@ -35,10 +34,10 @@ public class IntegerConverterTest { /** * Test getAsObject method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsObject() { IntegerConverter converter = new IntegerConverter(); - converter.getAsObject(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsObject(null, null, null)); } /** @@ -47,10 +46,8 @@ public void testGetAsObject() { @Test public void testGetAsObject2() { IntegerConverter converter = new IntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -59,10 +56,8 @@ public void testGetAsObject2() { @Test public void testGetAsObject3() { IntegerConverter converter = new IntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), " ")); - verify(facesContext); } /** @@ -71,19 +66,17 @@ public void testGetAsObject3() { @Test public void testGetAsObject4() { IntegerConverter converter = new IntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals(Integer.valueOf("123"), converter.getAsObject(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** * Test getAsString method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsString() { IntegerConverter converter = new IntegerConverter(); - converter.getAsString(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsString(null, null, null)); } /** @@ -92,10 +85,8 @@ public void testGetAsString() { @Test public void testGetAsString2() { IntegerConverter converter = new IntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("", converter.getAsString(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -104,10 +95,8 @@ public void testGetAsString2() { @Test public void testGetAsString3() { IntegerConverter converter = new IntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** @@ -116,9 +105,7 @@ public void testGetAsString3() { @Test public void testGetAsString4() { IntegerConverter converter = new IntegerConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), Integer.valueOf("123"))); - verify(facesContext); } } diff --git a/impl/src/test/java/jakarta/faces/convert/LongConverterTest.java b/impl/src/test/java/jakarta/faces/convert/LongConverterTest.java index 3e6f07afca..27e7f8fa6f 100644 --- a/impl/src/test/java/jakarta/faces/convert/LongConverterTest.java +++ b/impl/src/test/java/jakarta/faces/convert/LongConverterTest.java @@ -16,13 +16,12 @@ package jakarta.faces.convert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.component.UIPanel; import jakarta.faces.context.FacesContext; @@ -35,10 +34,10 @@ public class LongConverterTest { /** * Test getAsObject method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsObject() { LongConverter converter = new LongConverter(); - converter.getAsObject(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsObject(null, null, null)); } /** @@ -47,10 +46,8 @@ public void testGetAsObject() { @Test public void testGetAsObject2() { LongConverter converter = new LongConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -59,10 +56,8 @@ public void testGetAsObject2() { @Test public void testGetAsObject3() { LongConverter converter = new LongConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), " ")); - verify(facesContext); } /** @@ -71,19 +66,17 @@ public void testGetAsObject3() { @Test public void testGetAsObject4() { LongConverter converter = new LongConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals(Long.valueOf("123"), converter.getAsObject(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** * Test getAsString method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsString() { LongConverter converter = new LongConverter(); - converter.getAsString(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsString(null, null, null)); } /** @@ -92,10 +85,8 @@ public void testGetAsString() { @Test public void testGetAsString2() { LongConverter converter = new LongConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("", converter.getAsString(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -104,10 +95,8 @@ public void testGetAsString2() { @Test public void testGetAsString3() { LongConverter converter = new LongConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** @@ -116,9 +105,7 @@ public void testGetAsString3() { @Test public void testGetAsString4() { LongConverter converter = new LongConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), Long.valueOf("123"))); - verify(facesContext); } } diff --git a/impl/src/test/java/jakarta/faces/convert/ShortConverterTest.java b/impl/src/test/java/jakarta/faces/convert/ShortConverterTest.java index d7b23aa1a8..5223c7cb6d 100644 --- a/impl/src/test/java/jakarta/faces/convert/ShortConverterTest.java +++ b/impl/src/test/java/jakarta/faces/convert/ShortConverterTest.java @@ -16,13 +16,12 @@ package jakarta.faces.convert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; -import org.powermock.api.easymock.PowerMock; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import jakarta.faces.component.UIPanel; import jakarta.faces.context.FacesContext; @@ -35,10 +34,10 @@ public class ShortConverterTest { /** * Test getAsObject method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsObject() { ShortConverter converter = new ShortConverter(); - converter.getAsObject(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsObject(null, null, null)); } /** @@ -47,10 +46,8 @@ public void testGetAsObject() { @Test public void testGetAsObject2() { ShortConverter converter = new ShortConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -59,10 +56,8 @@ public void testGetAsObject2() { @Test public void testGetAsObject3() { ShortConverter converter = new ShortConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertNull(converter.getAsObject(facesContext, new UIPanel(), " ")); - verify(facesContext); } /** @@ -71,19 +66,17 @@ public void testGetAsObject3() { @Test public void testGetAsObject4() { ShortConverter converter = new ShortConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals(Short.valueOf("123"), converter.getAsObject(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** * Test getAsString method. */ - @Test(expected = NullPointerException.class) + @Test public void testGetAsString() { ShortConverter converter = new ShortConverter(); - converter.getAsString(null, null, null); + assertThrows(NullPointerException.class, () -> converter.getAsString(null, null, null)); } /** @@ -92,10 +85,8 @@ public void testGetAsString() { @Test public void testGetAsString2() { ShortConverter converter = new ShortConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("", converter.getAsString(facesContext, new UIPanel(), null)); - verify(facesContext); } /** @@ -104,10 +95,8 @@ public void testGetAsString2() { @Test public void testGetAsString3() { ShortConverter converter = new ShortConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), "123")); - verify(facesContext); } /** @@ -116,9 +105,7 @@ public void testGetAsString3() { @Test public void testGetAsString4() { ShortConverter converter = new ShortConverter(); - FacesContext facesContext = PowerMock.createMock(FacesContext.class); - replay(facesContext); + FacesContext facesContext = Mockito.mock(FacesContext.class); assertEquals("123", converter.getAsString(facesContext, new UIPanel(), Short.valueOf("123"))); - verify(facesContext); } } diff --git a/impl/src/test/java/jakarta/faces/event/PhaseIdTest.java b/impl/src/test/java/jakarta/faces/event/PhaseIdTest.java index cd37376a01..bbc23c5445 100644 --- a/impl/src/test/java/jakarta/faces/event/PhaseIdTest.java +++ b/impl/src/test/java/jakarta/faces/event/PhaseIdTest.java @@ -16,36 +16,15 @@ package jakarta.faces.event; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Iterator; -import junit.framework.TestCase; - -public class PhaseIdTest extends TestCase { -// -// Protected Constants -// - -// -// Class Variables -// -// -// Instance Variables -// -// Attribute Instance Variables -// Relationship Instance Variables -// -// Constructors and Initializers -// - public PhaseIdTest() { - super(); - } +import org.junit.jupiter.api.Test; + +public class PhaseIdTest { -// -// Class methods -// -// -// General Methods -// + @Test public void testToString() { Iterator valueIter = PhaseId.VALUES.iterator(); String cur = null; diff --git a/impl/src/test/java/jakarta/faces/model/ArrayDataModelTestCase.java b/impl/src/test/java/jakarta/faces/model/ArrayDataModelTestCase.java index 7a79e80404..2e179c117a 100644 --- a/impl/src/test/java/jakarta/faces/model/ArrayDataModelTestCase.java +++ b/impl/src/test/java/jakarta/faces/model/ArrayDataModelTestCase.java @@ -16,8 +16,7 @@ package jakarta.faces.model; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeEach; /** *

@@ -25,20 +24,10 @@ */ public class ArrayDataModelTestCase extends DataModelTestCaseBase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public ArrayDataModelTestCase(String name) { - super(name); - } - // ------------------------------------------------------ Instance Variables // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. - @Override + @BeforeEach public void setUp() throws Exception { beans = new BeanTestImpl[5]; for (int i = 0; i < beans.length; i++) { @@ -46,12 +35,6 @@ public void setUp() throws Exception { } configure(); model = new ArrayDataModel(beans); - super.setUp(); - } - - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(ArrayDataModelTestCase.class)); } // ------------------------------------------------- Individual Test Methods diff --git a/impl/src/test/java/jakarta/faces/model/CollectionDataModelTest.java b/impl/src/test/java/jakarta/faces/model/CollectionDataModelTest.java index 9a1e2f8497..bc33faa3f3 100644 --- a/impl/src/test/java/jakarta/faces/model/CollectionDataModelTest.java +++ b/impl/src/test/java/jakarta/faces/model/CollectionDataModelTest.java @@ -16,12 +16,12 @@ package jakarta.faces.model; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.ArrayList; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * The JUnit tests for CollectionDataModel. diff --git a/impl/src/test/java/jakarta/faces/model/DataModelTestCaseBase.java b/impl/src/test/java/jakarta/faces/model/DataModelTestCaseBase.java index dff859b3f8..c522afbe73 100644 --- a/impl/src/test/java/jakarta/faces/model/DataModelTestCaseBase.java +++ b/impl/src/test/java/jakarta/faces/model/DataModelTestCaseBase.java @@ -16,32 +16,24 @@ package jakarta.faces.model; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.lang.reflect.Method; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.jupiter.api.Test; /** *

* Abstract base class for {@link DataModel} tests.

*/ -public abstract class DataModelTestCaseBase extends TestCase { - - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public DataModelTestCaseBase(String name) { - - super(name); - - } +public abstract class DataModelTestCaseBase { // ------------------------------------------------------ Instance Variables // The array of beans we will be wrapping (must be initialized before setUp) @@ -66,28 +58,10 @@ protected void configure() { } } - // Set up instance variables required by this test case. - @Override - public void setUp() throws Exception { - // Subclasses must create "beans", call "configure()", create "model" - super.setUp(); - } - - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(DataModelTestCaseBase.class)); - } - - // Tear down instance variables required by ths test case - @Override - public void tearDown() throws Exception { - super.tearDown(); - beans = null; - model = null; - } - // ------------------------------------------------- Individual Test Methods + // Test invalid arguments to listener methods + @Test public void testInvalidListeners() throws Exception { try { model.addDataModelListener(null); @@ -105,6 +79,7 @@ public void testInvalidListeners() throws Exception { } // Test positioning to all rows in ascending order + @Test public void testPositionAscending() throws Exception { StringBuilder sb = new StringBuilder(); model.setRowIndex(-1); @@ -120,6 +95,7 @@ public void testPositionAscending() throws Exception { } // Test positioning to all rows in descending order + @Test public void testPositionDescending() throws Exception { StringBuilder sb = new StringBuilder(); model.setRowIndex(-1); @@ -135,24 +111,26 @@ public void testPositionDescending() throws Exception { } // Test a pristine DataModel instance + @Test public void testPristine() throws Exception { // Unopened instance - assertNotNull("beans exists", beans); - assertNotNull("model exists", model); + assertNotNull(beans); + assertNotNull(model); // Correct row count if (model instanceof ResultSetDataModel) { - assertEquals("correct row count", -1, model.getRowCount()); + assertEquals(-1, model.getRowCount()); } else { - assertEquals("correct row count", beans.length, + assertEquals(beans.length, model.getRowCount()); } // Correct row index - assertEquals("correct row index", 0, model.getRowIndex()); + assertEquals(0, model.getRowIndex()); } // Test removing listener + @Test public void testRemoveListener() throws Exception { ListenerTestImpl listener = new ListenerTestImpl(); ListenerTestImpl.trace(null); @@ -167,6 +145,7 @@ public void testRemoveListener() throws Exception { } // Test resetting the wrapped data (should trigger an event + @Test public void testReset() throws Exception { ListenerTestImpl listener = new ListenerTestImpl(); ListenerTestImpl.trace(null); @@ -178,6 +157,7 @@ public void testReset() throws Exception { } // Test row available manipulations + @Test public void testRowAvailable() throws Exception { // Position to the "no current row" position model.setRowIndex(-1); @@ -193,6 +173,7 @@ public void testRowAvailable() throws Exception { } // Test the ability to update through the Map returned by getRowData() + @Test @SuppressWarnings("unchecked") public void testRowData() throws Exception { // Retrieve the row data for row zero @@ -248,8 +229,9 @@ public void testRowData() throws Exception { } // Test row index manipulations + @Test public void testRowIndex() throws Exception { - assertEquals("correct row index", 0, model.getRowIndex()); + assertEquals(0, model.getRowIndex()); // Positive setRowIndex() tests model.setRowIndex(0); @@ -264,6 +246,7 @@ public void testRowIndex() throws Exception { } } + @Test public void testIterator() { Iterator iterator = model.iterator(); if (!(model instanceof ScalarDataModel)) { @@ -287,6 +270,7 @@ public void testIterator() { } // Test resetting the wrapped data to null + @Test public void testWrapped() throws Exception { model.setWrappedData(null); assertTrue(!model.isRowAvailable()); @@ -308,42 +292,42 @@ protected void checkRow(int i) throws Exception { model.setRowIndex(i); String prompt = "Row " + i + " property "; BeanTestImpl bean = data(); - assertNotNull("Row " + i + " data", bean); - assertEquals(prompt + "booleanProperty", + assertNotNull(bean, "Row " + i + " data"); + assertEquals( beans[i].getBooleanProperty(), - bean.getBooleanProperty()); - assertEquals(prompt + "booleanSecond", + bean.getBooleanProperty(), prompt + "booleanProperty"); + assertEquals( beans[i].isBooleanSecond(), - bean.isBooleanSecond()); - assertEquals(prompt + "byteProperty", + bean.isBooleanSecond(), prompt + "booleanSecond"); + assertEquals( beans[i].getByteProperty(), - bean.getByteProperty()); - assertEquals(prompt + "doubleProperty", + bean.getByteProperty(), prompt + "byteProperty"); + assertEquals( "" + beans[i].getDoubleProperty(), - "" + bean.getDoubleProperty()); - assertEquals(prompt + "floatProperty", + "" + bean.getDoubleProperty(), prompt + "doubleProperty"); + assertEquals( "" + beans[i].getFloatProperty(), - "" + bean.getFloatProperty()); - assertEquals(prompt + "intProperty", + "" + bean.getFloatProperty(), prompt + "floatProperty"); + assertEquals( beans[i].getIntProperty(), - bean.getIntProperty()); - assertEquals(prompt + "longProperty", + bean.getIntProperty(), prompt + "intProperty"); + assertEquals( beans[i].getLongProperty(), - bean.getLongProperty()); - assertEquals(prompt + "nullProperty", + bean.getLongProperty(), prompt + "longProperty"); + assertEquals( beans[i].getNullProperty(), - bean.getNullProperty()); - assertEquals(prompt + "readOnlyProperty", + bean.getNullProperty(), prompt + "nullProperty"); + assertEquals( beans[i].getReadOnlyProperty(), - bean.getReadOnlyProperty()); - assertEquals(prompt + "shortProperty", + bean.getReadOnlyProperty(), prompt + "readOnlyProperty"); + assertEquals( beans[i].getShortProperty(), - bean.getShortProperty()); - assertEquals(prompt + "stringProperty", + bean.getShortProperty(), prompt + "shortProperty"); + assertEquals( beans[i].getStringProperty(), - bean.getStringProperty()); - assertEquals(prompt + "writeOnlyProperty", + bean.getStringProperty(), prompt + "stringProperty"); + assertEquals( beans[i].getWriteOnlyPropertyValue(), - bean.getWriteOnlyPropertyValue()); + bean.getWriteOnlyPropertyValue(), prompt + "writeOnlyProperty"); } } diff --git a/impl/src/test/java/jakarta/faces/model/ListDataModelTestCase.java b/impl/src/test/java/jakarta/faces/model/ListDataModelTestCase.java index 8da2e0b96e..552542f90e 100644 --- a/impl/src/test/java/jakarta/faces/model/ListDataModelTestCase.java +++ b/impl/src/test/java/jakarta/faces/model/ListDataModelTestCase.java @@ -19,8 +19,7 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeEach; /** *

@@ -28,22 +27,10 @@ */ public class ListDataModelTestCase extends DataModelTestCaseBase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public ListDataModelTestCase(String name) { - - super(name); - - } - // ------------------------------------------------------ Instance Variables // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. - @Override + @BeforeEach public void setUp() throws Exception { List list = new ArrayList(); for (int i = 0; i < 5; i++) { @@ -52,12 +39,6 @@ public void setUp() throws Exception { beans = list.toArray(new BeanTestImpl[5]); configure(); model = new ListDataModel(list); - super.setUp(); - } - - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(ListDataModelTestCase.class)); } // ------------------------------------------------- Individual Test Methods diff --git a/impl/src/test/java/jakarta/faces/model/ResultSetDataModelTestCase.java b/impl/src/test/java/jakarta/faces/model/ResultSetDataModelTestCase.java index 8bf5a92c0d..635edacba9 100644 --- a/impl/src/test/java/jakarta/faces/model/ResultSetDataModelTestCase.java +++ b/impl/src/test/java/jakarta/faces/model/ResultSetDataModelTestCase.java @@ -16,16 +16,23 @@ package jakarta.faces.model; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import com.sun.faces.mock.MockResultSet; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.sun.faces.mock.MockResultSet; /** *

@@ -33,23 +40,13 @@ */ public class ResultSetDataModelTestCase extends DataModelTestCaseBase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public ResultSetDataModelTestCase(String name) { - super(name); - } - // ------------------------------------------------------ Instance Variables // The ResultSet passed to our ResultSetDataModel protected MockResultSet result = null; // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. - @Override + @BeforeEach public void setUp() throws Exception { beans = new BeanTestImpl[5]; for (int i = 0; i < beans.length; i++) { @@ -58,16 +55,11 @@ public void setUp() throws Exception { configure(); result = new MockResultSet(beans); model = new ResultSetDataModel(result); - super.setUp(); - } - - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(ResultSetDataModelTestCase.class)); } // ------------------------------------------------- Individual Test Methods // Test ((Map) getRowData()).containsKey() + @Test public void testRowDataContainsKey() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); @@ -105,6 +97,7 @@ public void testRowDataContainsKey() throws Exception { } // Test ((Map) getRowData()).containsValue() + @Test public void testRowDataContainsValue() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); @@ -130,6 +123,7 @@ public void testRowDataContainsValue() throws Exception { } // Test ((Map) getRowData()).entrySet() + @Test public void testRowDataEntrySet() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); @@ -180,15 +174,16 @@ public void testRowDataEntrySet() throws Exception { assertEquals("This is string 1 modified", beans[1].getStringProperty()); assertEquals("This is string 1 modified", - (String) map.get("stringProperty")); + map.get("stringProperty")); assertEquals("This is string 1 modified", - (String) map.get("stringPROPERTY")); + map.get("stringPROPERTY")); result.absolute(2); // ResultSet indexing is one-relative assertEquals("This is string 1 modified", - (String) result.getObject("stringProperty")); + result.getObject("stringProperty")); } // Test ((Map) getRowData()).get() + @Test public void testRowDataGet() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); @@ -206,7 +201,7 @@ public void testRowDataGet() throws Exception { assertEquals(Float.valueOf((float) 10.0), map.get("floatProperty")); assertEquals(Integer.valueOf(1000), map.get("intProperty")); assertEquals(Long.valueOf(10000l), map.get("longProperty")); - assertEquals("This is string 1", (String) map.get("stringProperty")); + assertEquals("This is string 1", map.get("stringProperty")); // Test inexact match on column names assertEquals(Boolean.FALSE, map.get("booleanPROPERTY")); @@ -216,7 +211,7 @@ public void testRowDataGet() throws Exception { assertEquals(Float.valueOf((float) 10.0), map.get("floatPROPERTY")); assertEquals(Integer.valueOf(1000), map.get("intPROPERTY")); assertEquals(Long.valueOf(10000l), map.get("longPROPERTY")); - assertEquals("This is string 1", (String) map.get("stringPROPERTY")); + assertEquals("This is string 1", map.get("stringPROPERTY")); // Test null return on non-existent column names assertNull(map.get("foo")); @@ -226,6 +221,7 @@ public void testRowDataGet() throws Exception { } // Test ((Map) getRowData()).keySet() + @Test public void testRowDataKeySet() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); @@ -267,6 +263,7 @@ public void testRowDataKeySet() throws Exception { } // Test ((Map) getRowData()).put() + @Test public void testRowDataPut() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); @@ -278,6 +275,7 @@ public void testRowDataPut() throws Exception { } // Test unsupported operations on ((Map) getRowData()) + @Test public void testRowDataUnsupported() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); @@ -456,6 +454,7 @@ public void testRowDataUnsupported() throws Exception { } // Test ((Map) getRowData()).values() + @Test public void testRowDataValues() throws Exception { // Position to row 1 and retrieve the corresponding Map model.setRowIndex(1); diff --git a/impl/src/test/java/jakarta/faces/model/ScalarDataModelTestCase.java b/impl/src/test/java/jakarta/faces/model/ScalarDataModelTestCase.java index a99295c7d0..96d6cba224 100644 --- a/impl/src/test/java/jakarta/faces/model/ScalarDataModelTestCase.java +++ b/impl/src/test/java/jakarta/faces/model/ScalarDataModelTestCase.java @@ -16,8 +16,7 @@ package jakarta.faces.model; -import junit.framework.Test; -import junit.framework.TestSuite; +import org.junit.jupiter.api.BeforeEach; /** *

@@ -25,31 +24,15 @@ */ public class ScalarDataModelTestCase extends DataModelTestCaseBase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public ScalarDataModelTestCase(String name) { - super(name); - } - // ------------------------------------------------------ Instance Variables // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. - @Override + @BeforeEach public void setUp() throws Exception { beans = new BeanTestImpl[1]; beans[0] = new BeanTestImpl(); configure(); model = new ScalarDataModel(beans[0]); - super.setUp(); - } - - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(ScalarDataModelTestCase.class)); } // ------------------------------------------------- Individual Test Methods diff --git a/impl/src/test/java/jakarta/faces/validator/BeanValidatorTestCase.java b/impl/src/test/java/jakarta/faces/validator/BeanValidatorTestCase.java index 78be58d7ba..f711dc736a 100644 --- a/impl/src/test/java/jakarta/faces/validator/BeanValidatorTestCase.java +++ b/impl/src/test/java/jakarta/faces/validator/BeanValidatorTestCase.java @@ -16,13 +16,14 @@ package jakarta.faces.validator; +import java.util.Locale; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + import jakarta.faces.component.UIInput; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import java.util.Locale; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.junit.Assert; /** *

Unit tests for {@link BeanValidator}.

@@ -49,23 +50,8 @@ public void setMessage(String message) { } } - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public BeanValidatorTestCase(String name) { - super(name); - } - - // ---------------------------------------------------- Overall Test Methods - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(BeanValidatorTestCase.class)); - } - // ------------------------------------------------- Individual Test Methods + @Test public void testMessageOK() { BeanValidator validator = new BeanValidator(); Locale.setDefault(Locale.US); @@ -77,6 +63,7 @@ public void testMessageOK() { validator.validate(facesContext, component, "something"); } + @Test public void testMessageKO() { BeanValidator validator = new BeanValidator(); Locale.setDefault(Locale.US); @@ -87,12 +74,13 @@ public void testMessageKO() { try { validator.validate(facesContext, component, ""); - Assert.fail("ValidatorException expected"); + Assertions.fail("ValidatorException expected"); } catch (ValidatorException e) { - Assert.assertEquals("size must be between 1 and 64", e.getMessage()); + Assertions.assertEquals("size must be between 1 and 64", e.getMessage()); } } + @Test public void testNoBase() { BeanValidator validator = new BeanValidator(); Locale.setDefault(Locale.US); diff --git a/impl/src/test/java/jakarta/faces/validator/CastingValidatorTestCase.java b/impl/src/test/java/jakarta/faces/validator/CastingValidatorTestCase.java index a9e8c57d60..fa9f13042c 100644 --- a/impl/src/test/java/jakarta/faces/validator/CastingValidatorTestCase.java +++ b/impl/src/test/java/jakarta/faces/validator/CastingValidatorTestCase.java @@ -16,8 +16,9 @@ package jakarta.faces.validator; -import junit.framework.Test; -import junit.framework.TestSuite; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; /** *

@@ -25,27 +26,12 @@ */ public class CastingValidatorTestCase extends ValidatorTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public CastingValidatorTestCase(String name) { - super(name); - } - - // ---------------------------------------------------- Overall Test Methods - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(CastingValidatorTestCase.class)); - } - // ------------------------------------------------- Individual Test Methods + @Test + @SuppressWarnings("rawtypes") public void testWithGenericCanCastToRaw() { - Validator validatorWithGeneric = (context, component, value) -> { - }; - Validator validatorRaw = validatorWithGeneric; + Validator validatorWithGeneric = (context, component, value) -> {}; + Validator validatorRaw = validatorWithGeneric; assertNotNull(validatorRaw); } diff --git a/impl/src/test/java/jakarta/faces/validator/DoubleRangeValidatorTestCase.java b/impl/src/test/java/jakarta/faces/validator/DoubleRangeValidatorTestCase.java index ba0ac8f904..5daa37ed77 100644 --- a/impl/src/test/java/jakarta/faces/validator/DoubleRangeValidatorTestCase.java +++ b/impl/src/test/java/jakarta/faces/validator/DoubleRangeValidatorTestCase.java @@ -16,11 +16,14 @@ package jakarta.faces.validator; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.Locale; +import org.junit.jupiter.api.Test; + import jakarta.faces.component.UIInput; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -28,23 +31,8 @@ */ public class DoubleRangeValidatorTestCase extends ValidatorTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public DoubleRangeValidatorTestCase(String name) { - super(name); - } - - // ---------------------------------------------------- Overall Test Methods - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(DoubleRangeValidatorTestCase.class)); - } - // ------------------------------------------------- Individual Test Methods + @Test public void testLocaleHonored() { DoubleRangeValidator validator = new DoubleRangeValidator(); validator.setMinimum(10.1); @@ -61,10 +49,10 @@ public void testLocaleHonored() { } catch (ValidatorException e) { exceptionThrown = true; message = e.getMessage(); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("10.1")); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("20.1")); + assertTrue( + -1 != message.indexOf("10.1"), "message: \"" + message + "\" missing localized chars."); + assertTrue( + -1 != message.indexOf("20.1"), "message: \"" + message + "\" missing localized chars."); } assertTrue(exceptionThrown); @@ -78,14 +66,15 @@ public void testLocaleHonored() { } catch (ValidatorException e) { exceptionThrown = true; message = e.getMessage(); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("10,1")); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("20,1")); + assertTrue( + -1 != message.indexOf("10,1"), "message: \"" + message + "\" missing localized chars."); + assertTrue( + -1 != message.indexOf("20,1"), "message: \"" + message + "\" missing localized chars."); } assertTrue(exceptionThrown); } + @Test public void testHashCode() { DoubleRangeValidator validator1 = new DoubleRangeValidator(); DoubleRangeValidator validator2 = new DoubleRangeValidator(); diff --git a/impl/src/test/java/jakarta/faces/validator/LengthValidatorTestCase.java b/impl/src/test/java/jakarta/faces/validator/LengthValidatorTestCase.java index b86a29092d..97e4414b3f 100644 --- a/impl/src/test/java/jakarta/faces/validator/LengthValidatorTestCase.java +++ b/impl/src/test/java/jakarta/faces/validator/LengthValidatorTestCase.java @@ -16,12 +16,14 @@ package jakarta.faces.validator; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.Locale; -import jakarta.faces.component.UIInput; +import org.junit.jupiter.api.Test; -import junit.framework.Test; -import junit.framework.TestSuite; +import jakarta.faces.component.UIInput; /** *

@@ -29,23 +31,8 @@ */ public class LengthValidatorTestCase extends ValidatorTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public LengthValidatorTestCase(String name) { - super(name); - } - - // ---------------------------------------------------- Overall Test Methods - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(LengthValidatorTestCase.class)); - } - // ------------------------------------------------- Individual Test Methods + @Test public void testLocaleHonored() { LengthValidator validator = new LengthValidator(); validator.setMinimum(1000); @@ -63,8 +50,8 @@ public void testLocaleHonored() { } catch (ValidatorException e) { exceptionThrown = true; message = e.getMessage(); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("1,000")); + assertTrue( + -1 != message.indexOf("1,000"), "message: \"" + message + "\" missing localized chars."); } assertTrue(exceptionThrown); @@ -79,12 +66,13 @@ public void testLocaleHonored() { } catch (ValidatorException e) { exceptionThrown = true; message = e.getMessage(); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("1.000")); + assertTrue( + -1 != message.indexOf("1.000"), "message: \"" + message + "\" missing localized chars."); } assertTrue(exceptionThrown); } + @Test public void testHashCode() { LengthValidator validator1 = new LengthValidator(); LengthValidator validator2 = new LengthValidator(); diff --git a/impl/src/test/java/jakarta/faces/validator/LongRangeValidatorTestCase.java b/impl/src/test/java/jakarta/faces/validator/LongRangeValidatorTestCase.java index e81464d226..c59b18fdcc 100644 --- a/impl/src/test/java/jakarta/faces/validator/LongRangeValidatorTestCase.java +++ b/impl/src/test/java/jakarta/faces/validator/LongRangeValidatorTestCase.java @@ -16,12 +16,14 @@ package jakarta.faces.validator; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.Locale; -import jakarta.faces.component.UIInput; +import org.junit.jupiter.api.Test; -import junit.framework.Test; -import junit.framework.TestSuite; +import jakarta.faces.component.UIInput; /** *

@@ -29,23 +31,8 @@ */ public class LongRangeValidatorTestCase extends ValidatorTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public LongRangeValidatorTestCase(String name) { - super(name); - } - - // ---------------------------------------------------- Overall Test Methods - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(LongRangeValidatorTestCase.class)); - } - // ------------------------------------------------- Individual Test Methods + @Test public void testLocaleHonored() { LongRangeValidator validator = new LongRangeValidator(); validator.setMinimum(10100); @@ -62,10 +49,10 @@ public void testLocaleHonored() { } catch (ValidatorException e) { exceptionThrown = true; message = e.getMessage(); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("10,100")); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("20,100")); + assertTrue( + -1 != message.indexOf("10,100"), "message: \"" + message + "\" missing localized chars."); + assertTrue( + -1 != message.indexOf("20,100"), "message: \"" + message + "\" missing localized chars."); } assertTrue(exceptionThrown); @@ -79,14 +66,15 @@ public void testLocaleHonored() { } catch (ValidatorException e) { exceptionThrown = true; message = e.getMessage(); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("10.100")); - assertTrue("message: \"" + message + "\" missing localized chars.", - -1 != message.indexOf("20.100")); + assertTrue( + -1 != message.indexOf("10.100"), "message: \"" + message + "\" missing localized chars."); + assertTrue( + -1 != message.indexOf("20.100"), "message: \"" + message + "\" missing localized chars."); } assertTrue(exceptionThrown); } + @Test public void testHashCode() { LongRangeValidator validator1 = new LongRangeValidator(); LongRangeValidator validator2 = new LongRangeValidator(); diff --git a/impl/src/test/java/jakarta/faces/validator/RegexValidatorTestCase.java b/impl/src/test/java/jakarta/faces/validator/RegexValidatorTestCase.java index 5ec275a53a..189ae63241 100644 --- a/impl/src/test/java/jakarta/faces/validator/RegexValidatorTestCase.java +++ b/impl/src/test/java/jakarta/faces/validator/RegexValidatorTestCase.java @@ -16,11 +16,14 @@ package jakarta.faces.validator; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.Locale; +import org.junit.jupiter.api.Test; + import jakarta.faces.component.UIInput; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -28,23 +31,8 @@ */ public class RegexValidatorTestCase extends ValidatorTestCase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public RegexValidatorTestCase(String name) { - super(name); - } - - // ---------------------------------------------------- Overall Test Methods - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(RegexValidatorTestCase.class)); - } - // ------------------------------------------------- Individual Test Methods + @Test public void testPatternMatch() { String patternStr = "t.*"; RegexValidator validator = new RegexValidator(); @@ -59,6 +47,7 @@ public void testPatternMatch() { } } + @Test public void testPatterMismatch() { String patternStr = "t.*"; facesContext.getViewRoot().setLocale(Locale.US); diff --git a/impl/src/test/java/jakarta/faces/validator/RequiredValidatorTest.java b/impl/src/test/java/jakarta/faces/validator/RequiredValidatorTest.java index 9f9c50754b..4ed683411c 100644 --- a/impl/src/test/java/jakarta/faces/validator/RequiredValidatorTest.java +++ b/impl/src/test/java/jakarta/faces/validator/RequiredValidatorTest.java @@ -16,7 +16,7 @@ package jakarta.faces.validator; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * The JUnit tests for the RequiredValidator class. diff --git a/impl/src/test/java/jakarta/faces/validator/ValidatorTestCase.java b/impl/src/test/java/jakarta/faces/validator/ValidatorTestCase.java index ab884dc313..740b917d76 100644 --- a/impl/src/test/java/jakarta/faces/validator/ValidatorTestCase.java +++ b/impl/src/test/java/jakarta/faces/validator/ValidatorTestCase.java @@ -16,6 +16,9 @@ package jakarta.faces.validator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.junit.JUnitFacesTestCaseBase; import com.sun.faces.mock.MockRenderKit; @@ -23,8 +26,6 @@ import jakarta.faces.component.UIViewRoot; import jakarta.faces.render.RenderKit; import jakarta.faces.render.RenderKitFactory; -import junit.framework.Test; -import junit.framework.TestSuite; /** *

@@ -32,19 +33,10 @@ */ public class ValidatorTestCase extends JUnitFacesTestCaseBase { - // ------------------------------------------------------------ Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public ValidatorTestCase(String name) { - super(name); - } - // ---------------------------------------------------- Overall Test Methods // Set up instance variables required by this test case. @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); @@ -60,11 +52,7 @@ public void setUp() throws Exception { } - // Return the tests included in this test case. - public static Test suite() { - return (new TestSuite(ValidatorTestCase.class)); - } - + @Test public void testNoOp() { } } diff --git a/impl/src/test/java/jakarta/faces/webapp/ComponentTestImpl.java b/impl/src/test/java/jakarta/faces/webapp/ComponentTestImpl.java index 396ee61862..869fb33325 100644 --- a/impl/src/test/java/jakarta/faces/webapp/ComponentTestImpl.java +++ b/impl/src/test/java/jakarta/faces/webapp/ComponentTestImpl.java @@ -27,11 +27,9 @@ public class ComponentTestImpl extends UIComponentBase { public ComponentTestImpl() { - super(); } public ComponentTestImpl(String id) { - super(); setId(id); } diff --git a/impl/src/test/java/jakarta/faces/webapp/ConfigFileTestCase.java b/impl/src/test/java/jakarta/faces/webapp/ConfigFileTestCase.java index 53c022bb43..18b6e4594d 100644 --- a/impl/src/test/java/jakarta/faces/webapp/ConfigFileTestCase.java +++ b/impl/src/test/java/jakarta/faces/webapp/ConfigFileTestCase.java @@ -16,26 +16,28 @@ package jakarta.faces.webapp; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Map; import org.apache.commons.digester.Digester; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; import com.sun.faces.config.DigesterFactory; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - /** *

* Unit tests for Configuration File processing. *

*/ -public class ConfigFileTestCase extends TestCase { +public class ConfigFileTestCase { // The public identifier of our DTD protected String CONFIG_DTD_PUBLIC_ID = "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"; @@ -46,43 +48,28 @@ public class ConfigFileTestCase extends TestCase { */ protected Digester digester = null; - // ----------------------------------------------------------- Constructors - /** - * Construct a new instance of this test case. - * - * @param name Name of the test case - */ - public ConfigFileTestCase(String name) { - super(name); - } - // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. * * @throws java.lang.Exception */ - @Override + @BeforeEach public void setUp() throws Exception { digester = createDigester(); configureRules(digester); } - /** - * Return the tests included in this test suite. - */ - public static Test suite() { - return (new TestSuite(ConfigFileTestCase.class)); - } - // ------------------------------------------------ Individual Test Methods // Test parsing an empty configuration file + @Test public void testEmpty() throws Exception { ConfigBase base = parseConfig(relativeURL("src/test/java/jakarta/faces/webapp/config-file-0.xml")); assertNotNull(base); } // Test parsing a full configuration file + @Test public void testFull() throws Exception { // Retrieve entire configuration metadata instance ConfigBase base = parseConfig(relativeURL("src/test/java/jakarta/faces/webapp/config-file-1.xml")); @@ -187,10 +174,6 @@ public void testFull() throws Exception { assertEquals("java.lang.String", cv2p1.getPropertyClass()); } - // Test a pristine Digester instance - public void testPristine() { - } - // ------------------------------------------------------ Protected Methods // Create a Digester instance with no rules yet protected Digester createDigester() throws Exception { diff --git a/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java b/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java index 84623ca640..7e9fa7ea6d 100644 --- a/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java +++ b/impl/src/test/java/jakarta/faces/webapp/FacesServletTestCase.java @@ -16,6 +16,11 @@ package jakarta.faces.webapp; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import com.sun.faces.junit.JUnitFacesTestCaseBase; import com.sun.faces.mock.MockRenderKit; @@ -24,8 +29,6 @@ import jakarta.faces.render.RenderKit; import jakarta.faces.render.RenderKitFactory; import jakarta.servlet.http.HttpServletResponse; -import junit.framework.Test; -import junit.framework.TestSuite; public class FacesServletTestCase extends JUnitFacesTestCaseBase { @@ -33,15 +36,8 @@ public class FacesServletTestCase extends JUnitFacesTestCaseBase { private static final String ALLOWED_HTTP_METHODS_ATTR_COPY = "com.sun.faces.allowedHttpMethods"; - public FacesServletTestCase(String name) { - super(name); - } - - public static Test suite() { - return (new TestSuite(FacesServletTestCase.class)); - } - @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); // Set up Servlet API Objects @@ -62,6 +58,7 @@ public void setUp() throws Exception { } } + @Test public void testPositiveInitWithNoContextParams() throws Exception { FacesServlet me = new FacesServlet(); me.init(config); @@ -83,6 +80,7 @@ public void testPositiveInitWithNoContextParams() throws Exception { assertEquals(HttpServletResponse.SC_OK, response.getStatus()); } + @Test public void testPositiveInitWithContextParamsOfKnownHttpMethods() throws Exception { FacesServlet me = new FacesServlet(); servletContext.addInitParameter(ALLOWED_HTTP_METHODS_ATTR_COPY, "GET POST"); @@ -105,6 +103,7 @@ public void testPositiveInitWithContextParamsOfKnownHttpMethods() throws Excepti assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus()); } + @Test public void testNegativeInitWithContextParamsOfKnownHttpMethods() throws Exception { FacesServlet me = new FacesServlet(); servletContext.addInitParameter(ALLOWED_HTTP_METHODS_ATTR_COPY, "GET POST GET POST"); @@ -127,6 +126,7 @@ public void testNegativeInitWithContextParamsOfKnownHttpMethods() throws Excepti assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus()); } + @Test public void testPositiveInitWithContextParamsOfWildcardHttpMethods() throws Exception { FacesServlet me = new FacesServlet(); servletContext.addInitParameter(ALLOWED_HTTP_METHODS_ATTR_COPY, "*"); @@ -151,6 +151,7 @@ public void testPositiveInitWithContextParamsOfWildcardHttpMethods() throws Exce assertEquals(HttpServletResponse.SC_OK, response.getStatus()); } + @Test public void testNegativeInitWithContextParamsOfWildcardHttpMethods() throws Exception { FacesServlet me = new FacesServlet(); servletContext.addInitParameter(ALLOWED_HTTP_METHODS_ATTR_COPY, "* * * *"); @@ -175,6 +176,7 @@ public void testNegativeInitWithContextParamsOfWildcardHttpMethods() throws Exce assertEquals(HttpServletResponse.SC_OK, response.getStatus()); } + @Test public void testPositiveInitWithContextParamsOfUnknownAndKnownHttpMethods() throws Exception { FacesServlet me = new FacesServlet(); servletContext.addInitParameter(ALLOWED_HTTP_METHODS_ATTR_COPY, "GET\tPOST\tGETAAAAA");