Skip to content

Commit

Permalink
refactor: fix unit tests after app-config changes
Browse files Browse the repository at this point in the history
Adds necessary mocking for application configuration for CdiServlet
in unit tests.

Related to vaadin/flow#9642
  • Loading branch information
pleku committed Dec 23, 2020
1 parent 055653b commit 88a83e9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions vaadin-cdi/src/test/java/com/vaadin/cdi/CdiVaadinServletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 88a83e9

Please sign in to comment.