1 package net.sf.clirr.core;
2
3 import java.util.Locale;
4 import junit.framework.TestCase;
5 import net.sf.clirr.core.MessageManager;
6 import net.sf.clirr.core.MessageTranslator;
7
8 /***
9 * 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 /***
18 * This test verifies that none of the check classes has used
19 * a message-id which is already in use elsewhere.
20 * <p>
21 * It is assumed that instantiating the Checker class causes every
22 * check class to be loaded, which in turn causes every Message
23 * object (which are expected to be static members of checks) to be created.
24 */
25 public void testUnique()
26 {
27 Checker checker = CheckerFactory.createChecker();
28 MessageManager.getInstance().checkUnique();
29 }
30
31 /***
32 * This test verifies that the default resource bundle contains an
33 * entry for every known message.
34 * <p>
35 * Unfortunately, it is not possible to check whether, for example,
36 * the "de" locale has a complete set of translations. This is because
37 * the ResourceBundle implementation simply returns a string from an
38 * inherited "parent" resource bundle if the key is not found in a
39 * locale-specific bundle, and there is no way of telling which
40 * bundle the message was retrieved from.
41 */
42 public void testComplete()
43 {
44 Checker checker = CheckerFactory.createChecker();
45 java.util.Collection messages = MessageManager.getInstance().getMessages();
46
47
48 assertTrue(messages.size() > 10);
49
50
51 MessageTranslator translator = new MessageTranslator();
52 translator.setLocale(Locale.ENGLISH);
53 translator.checkComplete(messages);
54 }
55 }