01: package net.sf.clirr.core;
02:
03: import java.util.Locale;
04: import junit.framework.TestCase;
05: import net.sf.clirr.core.MessageManager;
06: import net.sf.clirr.core.MessageTranslator;
07:
08: /**
09: * Tests for the Message and MessageManager classes.
10: * <p>
11: * It is assumed here that the other unit tests have forced every Check
12: * class to be loaded into memory, hence all the static Message objects
13: * have been created and registered with the MessageManager.
14: */
15: public class MessageTest extends TestCase {
16: /**
17: * This test verifies that none of the check classes has used
18: * a message-id which is already in use elsewhere.
19: * <p>
20: * It is assumed that instantiating the Checker class causes every
21: * check class to be loaded, which in turn causes every Message
22: * object (which are expected to be static members of checks) to be created.
23: */
24: public void testUnique() {
25: Checker checker = CheckerFactory.createChecker();
26: MessageManager.getInstance().checkUnique();
27: }
28:
29: /**
30: * This test verifies that the default resource bundle contains an
31: * entry for every known message.
32: * <p>
33: * Unfortunately, it is not possible to check whether, for example,
34: * the "de" locale has a complete set of translations. This is because
35: * the ResourceBundle implementation simply returns a string from an
36: * inherited "parent" resource bundle if the key is not found in a
37: * locale-specific bundle, and there is no way of telling which
38: * bundle the message was retrieved from.
39: */
40: public void testComplete() {
41: Checker checker = CheckerFactory.createChecker();
42: java.util.Collection messages = MessageManager.getInstance()
43: .getMessages();
44:
45: // there are at least 10 messages in the system
46: assertTrue(messages.size() > 10);
47:
48: // check the english locale
49: MessageTranslator translator = new MessageTranslator();
50: translator.setLocale(Locale.ENGLISH);
51: translator.checkComplete(messages);
52: }
53: }
|