1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.localization.jar.internal

File RootClassLoaderTranslationBundleTest.java

 

Code metrics

2
9
3
1
80
49
4
0.44
3
3
1.33

Classes

Class Line # Actions
RootClassLoaderTranslationBundleTest 43 9 0% 4 2
0.8571428785.7%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.localization.jar.internal;
21   
22    import java.util.Locale;
23   
24    import org.junit.Assert;
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.component.internal.ContextComponentManagerProvider;
29    import org.xwiki.context.internal.DefaultExecution;
30    import org.xwiki.localization.LocalizationManager;
31    import org.xwiki.localization.Translation;
32    import org.xwiki.localization.internal.DefaultLocalizationManager;
33    import org.xwiki.localization.internal.DefaultTranslationBundleContext;
34    import org.xwiki.localization.messagetool.internal.MessageToolTranslationMessageParser;
35    import org.xwiki.model.internal.DefaultModelContext;
36    import org.xwiki.rendering.internal.parser.plain.PlainTextBlockParser;
37    import org.xwiki.test.annotation.ComponentList;
38    import org.xwiki.test.mockito.MockitoComponentManagerRule;
39   
40    @ComponentList({MessageToolTranslationMessageParser.class, PlainTextBlockParser.class,
41    ContextComponentManagerProvider.class, DefaultLocalizationManager.class, DefaultTranslationBundleContext.class,
42    DefaultExecution.class, DefaultModelContext.class, RootClassLoaderTranslationBundle.class})
 
43    public class RootClassLoaderTranslationBundleTest
44    {
45    @Rule
46    public final MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule();
47   
48    private LocalizationManager localizationManager;
49   
 
50  1 toggle @Before
51    public void setUp() throws Exception
52    {
53    // Components
54   
55  1 this.localizationManager = this.componentManager.getInstance(LocalizationManager.class);
56    }
57   
 
58  3 toggle private void assertTranslation(String key, String message, Locale locale)
59    {
60  3 Translation translation = this.localizationManager.getTranslation(key, locale);
61   
62  3 if (message != null) {
63  3 Assert.assertNotNull("Could not find translation for key [" + key + "] and locale [" + locale + "]",
64    translation);
65  3 Assert.assertEquals(message, translation.getRawSource());
66    } else {
67  0 Assert.assertNull("Found translation for key [" + key + "] and locale [" + locale + "]", translation);
68    }
69    }
70   
71    // tests
72   
 
73  1 toggle @Test
74    public void getTranslations()
75    {
76  1 assertTranslation("test.key", "default translation", Locale.ROOT);
77  1 assertTranslation("test.key", "en translation", Locale.ENGLISH);
78  1 assertTranslation("test.key", "en_US translation", Locale.US);
79    }
80    }