Package org.internna.iwebmvc.spring.i18n

Source Code of org.internna.iwebmvc.spring.i18n.TranslatorImplTest

/*
* Copyright 2002-2007 the original author or authors.
*
* 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.internna.iwebmvc.spring.i18n;

import java.util.Locale;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.StaticMessageSource;
import static org.junit.Assert.*;

/**
*
* @author Jose Noheda
*/
public class TranslatorImplTest {

    private static TranslatorImpl translator;
    private static String message = "test.first";
    private static Locale en = new Locale("en");
    private static Locale es = new Locale("es");

    @BeforeClass
    public static void setUpClass() throws Exception {
        translator = new TranslatorImpl();
        StaticMessageSource messageSource = new StaticMessageSource();
        messageSource.addMessage(message, en, "First test");
        messageSource.addMessage(message, es, "Primer test");
        messageSource.addMessage("test.other", es, "Otro test");
        translator.setMessageSource(messageSource);
    }

    @Test
    public void testTranslate() {
        assertEquals("No locale", "First test", translator.translate(message, null));
        assertEquals("English locale", "First test", translator.translate(message, en));
        assertEquals("Spanish locale", "Primer test", translator.translate(message, es));
        assertEquals("No message", "test.other", translator.translate("test.other", en));
        assertEquals("Message in Spanish", "Otro test", translator.translate("test.other", es));
    }

}
TOP

Related Classes of org.internna.iwebmvc.spring.i18n.TranslatorImplTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.