⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i18nbundleimpltest.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.components.xmlbundle.tests;
import java.util.Locale;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
import org.rapla.components.xmlbundle.I18nBundle;
import org.rapla.components.xmlbundle.LocaleSelector;
import org.rapla.components.xmlbundle.impl.I18nBundleImpl;
import org.rapla.components.xmlbundle.impl.LocaleSelectorImpl;
import org.rapla.framework.RaplaDefaultContext;


public class I18nBundleImplTest extends AbstractI18nTest {
    I18nBundleImpl i18n;
    boolean useFile;
    LocaleSelector localeSelector;
    Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);

    public I18nBundleImplTest(String name) {
        this(name, true);
    }

    public I18nBundleImplTest(String name,boolean useFile) {
        super(name);
        this.useFile = useFile;
    }

    protected void setUp() throws Exception {
        DefaultConfiguration config = new DefaultConfiguration("i18n",this.toString());
        if (this.useFile) {
            DefaultConfiguration child = new DefaultConfiguration("file",this.toString());
            child.setValue("src/org/rapla/RaplaResources.xml");
            config.addChild(child);
        } else {
            config.setAttribute("id","org.rapla.RaplaResources");
        }
        i18n = create(config);
    }

    private I18nBundleImpl create(Configuration config) throws Exception {
        I18nBundleImpl i18n;
        RaplaDefaultContext context = new RaplaDefaultContext();
        localeSelector = new LocaleSelectorImpl();
        context.put(LocaleSelector.ROLE,localeSelector);
        i18n = new I18nBundleImpl(context,config,new ConsoleLogger());
        return i18n;
    }

    protected void tearDown() {
        i18n.dispose();
    }
    public I18nBundle getI18n() {
        return i18n;
    }

    public static Test suite() {
        TestSuite suite = new TestSuite();
        // The first four test only succeed if the Resource Bundles are build.
        suite.addTest(new I18nBundleImplTest("testLocaleChanged",false));
        suite.addTest(new I18nBundleImplTest("testGetIcon",false));
        suite.addTest(new I18nBundleImplTest("testGetString",false));
        suite.addTest(new I18nBundleImplTest("testLocale",false));
        /*
       */
        suite.addTest(new I18nBundleImplTest("testInvalidConfig",true));
        suite.addTest(new I18nBundleImplTest("testLocaleChanged",true));
        suite.addTest(new I18nBundleImplTest("testGetIcon",true));
        suite.addTest(new I18nBundleImplTest("testGetString",true));
        suite.addTest(new I18nBundleImplTest("testLocale",true));

        return suite;
    }

    public void testLocaleChanged() {
        localeSelector.setLocale(new Locale("de","DE"));
        assertEquals(getI18n().getString("cancel"),"Abbrechen");
        localeSelector.setLocale(new Locale("en","DE"));
        assertEquals(getI18n().getString("cancel"),"cancel");
    }

    public void testInvalidConfig() throws Exception {
        if (!this.useFile)
            return;
        DefaultConfiguration config = new DefaultConfiguration("i18n",this.toString());
        try {
            create(config);
            assertTrue("id is missing should be reported", true);
        } catch (Exception ex) {
        }
        config.setAttribute("id","org.rapla.RaplaResources");
        DefaultConfiguration child = new DefaultConfiguration("file",this.toString());
        child.setValue("./src/org/rapla/RaplaResou");
        config.addChild( child );
        try {
            create(config);
            assertTrue("file ./src/org/rapla/RaplaResou should fail", true);
        } catch (Exception ex) {
        }
    }
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -