001: /*
002: * @(#) $Header: /cvs/jai-operators/src/tests/ca/forklabs/media/jai/opimage/ResourcesTest.java,v 1.1 2007/05/03 18:32:28 forklabs Exp $
003: *
004: * Copyright (C) 2007 Forklabs Daniel Léonard
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020:
021: package ca.forklabs.media.jai.opimage;
022:
023: import java.lang.reflect.Field;
024: import java.lang.reflect.Modifier;
025: import java.util.Enumeration;
026: import java.util.LinkedList;
027: import java.util.List;
028: import java.util.Locale;
029: import java.util.ResourceBundle;
030: import junit.framework.TestCase;
031: import ca.forklabs.media.jai.opimage.Resources;
032:
033: /**
034: * Class {@code ResourcesTest} tests class {@link Resources}.
035: *
036: * @author <a href="mailto:daniel.leonard at umontreal.ca?subject=ca.forklabs.media.jai.opimage.ResourcesTest">Daniel Léonard</a>
037: * @version $Revision: 1.1 $
038: */
039: @SuppressWarnings("nls")
040: public class ResourcesTest extends TestCase {
041:
042: //---------------------------
043: // Constructor
044: //---------------------------
045:
046: /**
047: * Constructor.
048: * @param name the name of this test.
049: */
050: public ResourcesTest(String name) {
051: super (name);
052: }
053:
054: //---------------------------
055: // Test methods
056: //---------------------------
057:
058: /**
059: * Gets the value of all {@code public static final String} variables from
060: * class {@link Resources}.
061: * @return the values.
062: * @throws Exception if anything goes wrong.
063: */
064: private List<String> getKeys() throws Exception {
065: Class<?> clazz = Resources.class;
066:
067: Field[] fields = clazz.getDeclaredFields();
068:
069: List<String> keys = new LinkedList<String>();
070: for (Field field : fields) {
071: Class<?> type = field.getType();
072: boolean is_string = type.equals(String.class);
073:
074: int modifiers = field.getModifiers();
075: boolean is_static = Modifier.isStatic(modifiers);
076: boolean is_public = Modifier.isPublic(modifiers);
077: boolean is_final = Modifier.isFinal(modifiers);
078:
079: if (is_string && is_static && is_public && is_final) {
080: String value = (String) field.get(null);
081: keys.add(value);
082: }
083: }
084:
085: return keys;
086: }
087:
088: /**
089: * Tests that all the keys are present.
090: * @throws Exception if anything goes wrong.
091: */
092: public void testAreAllKeysPresent() throws Exception {
093: Locale default_locale = Locale.getDefault();
094:
095: try {
096: Locale[] locales = new Locale[] { Locale.ENGLISH,
097: Locale.FRENCH, };
098:
099: List<String> keys = this .getKeys();
100:
101: for (Locale locale : locales) {
102: Locale.setDefault(Locale.FRENCH);
103: ResourceBundle bundle = Resources.getResourceBundle();
104:
105: int i = 0;
106: for (Enumeration<String> enumeration = bundle.getKeys(); enumeration
107: .hasMoreElements(); i++) {
108: String key = enumeration.nextElement();
109: assertTrue(locale.toString() + " - " + key, keys
110: .contains(key));
111: }
112: assertEquals(locale.toString(), keys.size(), i);
113: }
114: } finally {
115: Locale.setDefault(default_locale);
116: }
117: }
118:
119: //---------------------------
120: // Class methods
121: //---------------------------
122:
123: /**
124: * Runs only this test.
125: * @param args ignored.
126: */
127: public static void main(String... args) {
128: junit.swingui.TestRunner.run(ResourcesTest.class);
129: }
130:
131: }
132:
133: /*
134: * $Log: ResourcesTest.java,v $
135: * Revision 1.1 2007/05/03 18:32:28 forklabs
136: * Initial commit for the unaryfunction operator.
137: *
138: */
|