View Javadoc
1   package org.itracker.core.resources;
2   
3   import org.itracker.AbstractDependencyInjectionTest;
4   import org.junit.Test;
5   
6   import java.util.Enumeration;
7   import java.util.Locale;
8   import java.util.ResourceBundle;
9   
10  import static org.junit.Assert.assertEquals;
11  import static org.junit.Assert.assertNotNull;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: masta
16   * Date: 23.11.12
17   * Time: 09:58
18   * To change this template use File | Settings | File Templates.
19   */
20  public class ItrackerResourcesIT extends AbstractDependencyInjectionTest {
21  
22      @Test
23      public void testInitialized() {
24          assertTrue(ITrackerResources.isInitialized());
25      }
26  
27      @Test
28      public void testGetBundleEmptyString() {
29          ResourceBundle resourceBundle = ITrackerResources.getBundle("");
30          assertNotNull(resourceBundle);
31          assertEquals(ITrackerResources.getBundle(), resourceBundle);
32      }
33  
34      @Test
35      public void testGetBundleStringParameter() {
36          ResourceBundle resourceBundle = ITrackerResources.getBundle(ITrackerResources.getLocale());
37          assertNotNull(resourceBundle);
38          assertEquals(ITrackerResources.getBundle(), resourceBundle);
39      }
40  
41      @Test
42      public void testGetBundleNullLocale() {
43          ResourceBundle resourceBundle = ITrackerResources.getBundle((Locale) null);
44          assertNotNull(resourceBundle);
45          assertEquals(ITrackerResources.getBundle(), resourceBundle);
46      }
47  
48      @Test
49      public void testGetStringWithLocaleWithDirtyKey() {
50          ResourceBundle b = ITrackerResources.getBundle();
51  
52          ((ITrackerResourceBundle)b).removeValue("itracker.web.attr.admin", true);
53          String value = ITrackerResources.getString("itracker.web.attr.admin", ITrackerResources.getLocale());
54  
55  
56          // When a language items is removed, the default is loaded from properties.
57          assertEquals("Admin", value);
58      }
59  
60  
61      @Test
62      public void testGetEditBundleNullLocale() {
63          //TODO: set languageDAO of ConfigurationService
64          ResourceBundle resourceBundle = ITrackerResources.getEditBundle(null);
65          assertNotNull(resourceBundle);
66          assertEquals(ITrackerResources.getLocale(), resourceBundle.getLocale());
67          Enumeration<String> keys = resourceBundle.getKeys(); // keys of copy bundle
68          while (keys.hasMoreElements()) {
69              String key = keys.nextElement();
70              assertEquals(ITrackerResources.getString(key), resourceBundle.getString(key));
71          }
72          keys = ITrackerResources.getBundle().getKeys(); // keys of original bundle
73          while (keys.hasMoreElements()) {
74              String key = keys.nextElement();
75              assertEquals(ITrackerResources.getString(key), resourceBundle.getString(key));
76          }
77      }
78      @Override
79      protected String[] getDataSetFiles() {
80          return new String[0];
81      }
82  
83      @Override
84      protected String[] getConfigLocations() {
85          return new String[]{"application-context.xml"};
86      }
87  
88  }