Created
July 10, 2016 23:54
-
-
Save broccolinisoup/191b08e247971a8227121fc8ec638489 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2016, Red Hat, Inc. and individual contributors as indicated by the | |
* @author tags. See the copyright.txt file in the distribution for a full | |
* listing of individual contributors. | |
* | |
* This is free software; you can redistribute it and/or modify it under the | |
* terms of the GNU Lesser General Public License as published by the Free | |
* Software Foundation; either version 2.1 of the License, or (at your option) | |
* any later version. | |
* | |
* This software is distributed in the hope that it will be useful, but WITHOUT | |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
* details. | |
* | |
* You should have received a copy of the GNU Lesser General Public License | |
* along with this software; if not, write to the Free Software Foundation, | |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | |
* site: http://www.fsf.org. | |
*/ | |
package org.zanata.cache; | |
import com.google.common.cache.CacheLoader; | |
import com.google.common.html.HtmlEscapers; | |
import org.infinispan.manager.DefaultCacheManager; | |
import org.infinispan.manager.EmbeddedCacheManager; | |
import org.infinispan.stats.Stats; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mock; | |
import org.mockito.Spy; | |
import org.zanata.action.CacheAction; | |
import org.zanata.common.LocaleId; | |
import org.zanata.events.DocumentLocaleKey; | |
import org.zanata.i18n.Messages; | |
import org.zanata.test.CdiUnitRunner; | |
import org.zanata.ui.model.statistic.WordStatistic; | |
import org.zanata.util.Zanata; | |
import org.zanata.webtrans.shared.model.DocumentId; | |
import org.zanata.webtrans.shared.model.DocumentStatus; | |
import org.zanata.webtrans.shared.model.ValidationId; | |
import static org.hamcrest.Matchers.contains; | |
import static org.hamcrest.core.Is.is; | |
import static org.junit.Assert.*; | |
import javax.enterprise.inject.Produces; | |
import javax.inject.Inject; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collection; | |
import java.util.Collections; | |
import java.util.Date; | |
import java.util.LinkedHashSet; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Set; | |
import static org.mockito.Mockito.atLeastOnce; | |
import static org.mockito.Mockito.doReturn; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.verify; | |
import static org.hamcrest.MatcherAssert.assertThat; | |
import static org.hamcrest.Matchers.equalTo; | |
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.when; | |
/** | |
* Created by aersoz on 7/6/16. | |
*/ | |
@RunWith(CdiUnitRunner.class) | |
public class CacheActionTest { | |
@Inject CacheAction cacheAction; | |
private static final String EMPTY_STRING = "empty string"; | |
private static final String I18N_EMPTY_STRING = "jsf.cacheStats.emptyString"; | |
private List<String> expectedCacheList; | |
private Set<String> cacheNamesSet = new LinkedHashSet<>(); | |
private static final String CACHE_NAME = "org.zanata.service.impl.TranslationStateCacheImpl.docStatusCache"; | |
// @Produces @Spy @Zanata private DefaultCacheManager cacheManager; | |
@Produces @Mock @Zanata private EmbeddedCacheManager cacheManager; | |
@Produces @Mock private Messages msgs; | |
@Before | |
public void setUp() throws Exception { | |
cacheNamesSet.add(CACHE_NAME); | |
assertNotNull(cacheManager); | |
} | |
@Test | |
public void returnCacheList() throws Exception { | |
expectedCacheList = new ArrayList<>(cacheNamesSet); | |
// I am not testing how the cache manager is working I am testing if getCacheNames | |
//function is working properly | |
when(cacheManager.getCacheNames()).thenReturn(cacheNamesSet); | |
cacheAction.getCacheList(); | |
verify(cacheManager, atLeastOnce()).getCacheNames(); | |
assertNotNull(cacheAction.getCacheList()); | |
assertThat(cacheAction.getCacheList(), is(expectedCacheList)); | |
} | |
@Test | |
public void whenCacheNameisEmptyReturnItalicString() throws Exception { | |
when(msgs.get(I18N_EMPTY_STRING)).thenReturn(EMPTY_STRING); | |
String actualResult = cacheAction.getDisplayName(""); | |
verify(msgs,atLeastOnce()).get(I18N_EMPTY_STRING); | |
String expectedResult ="<em>(" + EMPTY_STRING + ")</em>"; | |
assertThat(actualResult,is(expectedResult)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment