Skip to content

Commit

Permalink
test: fix MenuAccessControl mocking (#2863)
Browse files Browse the repository at this point in the history
* test: fix MenuAccessControl mocking

Mock object should call MenuAccessControl.canAccessView default method,
that also requires VaadinRequest thread local to be set.

* format
  • Loading branch information
mcollovati authored and ZheSun88 committed Oct 24, 2024
1 parent 917c31e commit 581d82d
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.internal.CurrentInstance;
import com.vaadin.flow.server.VaadinContext;
import com.vaadin.flow.server.VaadinRequest;

Expand All @@ -23,6 +24,7 @@
import org.jsoup.nodes.DataNode;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -124,13 +126,22 @@ public void setUp() throws IOException {
.thenReturn(menuAccessControl);
Mockito.when(menuAccessControl.getPopulateClientSideMenu())
.thenReturn(MenuAccessControl.PopulateClientMenu.ALWAYS);
Mockito.doCallRealMethod().when(menuAccessControl)
.canAccessView(any(AvailableViewInfo.class));

// Add test data for production mode
projectRoot.newFolder("META-INF", "VAADIN");
productionRouteFile = new File(projectRoot.getRoot(),
FILE_ROUTES_JSON_PROD_PATH);

copyClientRoutes("clientRoutes.json", productionRouteFile);

CurrentInstance.set(VaadinRequest.class, vaadinRequest);
}

@After
public void tearDown() {
CurrentInstance.set(VaadinRequest.class, null);
}

private static List<RouteData> prepareServerRoutes() {
Expand Down

0 comments on commit 581d82d

Please sign in to comment.