From 88a83e95f6a2e818f594c18dec1590b051364b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pekka=20Hyv=C3=B6nen?= Date: Wed, 23 Dec 2020 11:19:43 +0200 Subject: [PATCH] refactor: fix unit tests after app-config changes Adds necessary mocking for application configuration for CdiServlet in unit tests. Related to vaadin/flow#9642 --- .../java/com/vaadin/cdi/CdiVaadinServletTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vaadin-cdi/src/test/java/com/vaadin/cdi/CdiVaadinServletTest.java b/vaadin-cdi/src/test/java/com/vaadin/cdi/CdiVaadinServletTest.java index 31d894a7..c59285ec 100644 --- a/vaadin-cdi/src/test/java/com/vaadin/cdi/CdiVaadinServletTest.java +++ b/vaadin-cdi/src/test/java/com/vaadin/cdi/CdiVaadinServletTest.java @@ -23,13 +23,18 @@ import javax.servlet.ServletException; import java.util.Collections; +import java.util.Enumeration; +import com.vaadin.flow.server.startup.ApplicationConfiguration; +import com.vaadin.flow.server.startup.ApplicationConfigurationFactory; +import com.vaadin.flow.server.startup.DefaultApplicationConfigurationFactory; import org.apache.deltaspike.core.api.provider.BeanProvider; import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.mockito.Mockito; import com.vaadin.cdi.context.ServiceUnderTestContext; @@ -61,6 +66,14 @@ public void setUp() throws ServletException { Mockito.when(servletContext.getAttribute(Lookup.class.getName())) .thenReturn(lookup); + final DefaultApplicationConfigurationFactory applicationConfigurationFactory + = Mockito.mock(DefaultApplicationConfigurationFactory.class); + final ApplicationConfiguration applicationConfiguration = Mockito.mock(ApplicationConfiguration.class); + Mockito.when(applicationConfiguration.getPropertyNames()).thenReturn(Collections.emptyEnumeration()); + + Mockito.when(lookup.lookup(ApplicationConfigurationFactory.class)).thenReturn(applicationConfigurationFactory); + Mockito.when(applicationConfigurationFactory.create(Mockito.any())).thenReturn(applicationConfiguration); + Mockito.when(servletConfig.getInitParameterNames()) .thenReturn(Collections.emptyEnumeration()); Mockito.when(servletConfig.getServletContext())