Struts example source code file (DefaultTextProviderTest.java)
This example Struts source code file (DefaultTextProviderTest.java) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Struts DefaultTextProviderTest.java source code
/*
* Copyright 2002-2006,2009 The Apache Software Foundation.
*
* 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 com.opensymphony.xwork2;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import junit.framework.TestCase;
import java.util.*;
/**
* Unit test for {@link DefaultTextProvider}.
*
* @author Claus Ibsen
*/
public class DefaultTextProviderTest extends TestCase {
private DefaultTextProvider tp;
public void testSimpleGetTexts() throws Exception {
assertEquals("Hello World", tp.getText("hello"));
assertEquals(null, tp.getText("not.in.bundle"));
assertEquals("Hello World", tp.getText("hello", "this is default"));
assertEquals("this is default", tp.getText("not.in.bundle", "this is default"));
List<Object> nullList = null;
assertEquals("Hello World", tp.getText("hello", nullList));
String[] nullStrings = null;
assertEquals("Hello World", tp.getText("hello", nullStrings));
}
public void testGetTextsWithArgs() throws Exception {
assertEquals("Hello World", tp.getText("hello", "this is default", "from me")); // no args in bundle
assertEquals("Hello World from me", tp.getText("hello.0", "this is default", "from me"));
assertEquals("this is default", tp.getText("not.in.bundle", "this is default", "from me"));
assertEquals("this is default from me", tp.getText("not.in.bundle", "this is default {0}", "from me"));
assertEquals(null, tp.getText("not.in.bundle"));
}
public void testGetTextsWithListArgs() throws Exception {
List<Object> args = new ArrayList