/* * Copyright 2016 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.kie.workbench.common.workbench.client.configuration.popups; import java.util.List; import com.google.gwtmockito.GwtMockitoTestRunner; import com.google.gwtmockito.WithClassesToStub; import org.jboss.errai.common.client.api.Caller; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.kie.workbench.common.workbench.client.configuration.ContextualView; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.uberfire.client.mvp.PerspectiveManager; import org.uberfire.client.mvp.PlaceManager; import org.uberfire.commons.data.Pair; import org.uberfire.ext.services.shared.preferences.UserPreferencesService; import org.uberfire.mocks.CallerMock; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @RunWith(GwtMockitoTestRunner.class) @WithClassesToStub(org.gwtbootstrap3.client.ui.ModalHeader.class) public class WorkbenchConfigurationPopupTest { private WorkbenchConfigurationPopup popup; //This is the list of locales supported by BxMS private final String[] locales = new String[]{ "default", "zh_CN", "de", "es", "fr", "ja", "pt_BR", "zh_TW", "ru" }; @Mock private PlaceManager placeManager; @Mock private PerspectiveManager perspectiveManager; @Mock private ContextualView contextualView; @Mock private UserPreferencesService preferencesService; private Caller<UserPreferencesService> preferencesServiceCaller; @Before public void setup() { this.preferencesServiceCaller = new CallerMock<UserPreferencesService>( preferencesService ); popup = new WorkbenchConfigurationPopup( placeManager, perspectiveManager, contextualView, preferencesServiceCaller ) { @Override protected String[] getAvailableLocaleNames() { return locales; } }; } @Test public void testSetupLanguageSelector() { final ArgumentCaptor<Pair> localesCaptor = ArgumentCaptor.forClass( Pair.class ); popup.setup(); verify( popup.languageListItems, times( locales.length ) ).addItem( localesCaptor.capture() ); final List<Pair> capturedLocales = localesCaptor.getAllValues(); assertEquals( locales.length, capturedLocales.size() ); for ( String locale : locales ) { assertTrue( "Locale '" + locale + "' was not setup.", isLocaleCaptured( locale, capturedLocales ) ); } } private boolean isLocaleCaptured( final String locale, final List<Pair> capturedLocales ) { for ( Pair p : capturedLocales ) { if ( p.getK2().equals( locale ) ) { return true; } } return false; } }