1 15 package org.apache.hivemind.util; 16 17 import hivemind.test.FrameworkTestCase; 18 19 import java.util.Locale ; 20 import java.util.NoSuchElementException ; 21 22 import junit.framework.AssertionFailedError; 23 24 import org.apache.hivemind.util.LocalizedNameGenerator; 25 26 27 32 public class TestLocalizedNameGenerator extends FrameworkTestCase 33 { 34 35 public void testBasic() 36 { 37 LocalizedNameGenerator g = new LocalizedNameGenerator("basic", Locale.US, ".test"); 38 39 assertTrue(g.more()); 40 assertEquals("basic_en_US.test", g.next()); 41 42 assertTrue(g.more()); 43 assertEquals("basic_en.test", g.next()); 44 45 assertTrue(g.more()); 46 assertEquals("basic.test", g.next()); 47 48 assertTrue(!g.more()); 49 } 50 51 public void testNoCountry() 52 { 53 LocalizedNameGenerator g = new LocalizedNameGenerator("noCountry", Locale.FRENCH, ".zap"); 54 55 assertTrue(g.more()); 56 assertEquals("noCountry_fr.zap", g.next()); 57 58 assertTrue(g.more()); 59 assertEquals("noCountry.zap", g.next()); 60 61 assertTrue(!g.more()); 62 } 63 64 public void testVariantWithoutCountry() 65 { 66 LocalizedNameGenerator g = 67 new LocalizedNameGenerator("fred", new Locale ("en", "", "GEEK"), ".foo"); 68 69 assertTrue(g.more()); 70 71 77 assertEquals("fred_en__GEEK.foo", g.next()); 78 79 assertTrue(g.more()); 80 assertEquals("fred_en.foo", g.next()); 81 82 assertTrue(g.more()); 83 assertEquals("fred.foo", g.next()); 84 85 assertTrue(!g.more()); 86 } 87 88 public void testNullLocale() 89 { 90 LocalizedNameGenerator g = new LocalizedNameGenerator("nullLocale", null, ".bar"); 91 92 assertTrue(g.more()); 93 assertEquals("nullLocale.bar", g.next()); 94 95 assertTrue(!g.more()); 96 } 97 98 public void testNullSuffix() 99 { 100 LocalizedNameGenerator g = new LocalizedNameGenerator("nullSuffix", null, null); 101 102 assertTrue(g.more()); 103 assertEquals("nullSuffix", g.next()); 104 105 assertTrue(!g.more()); 106 } 107 108 public void testForException() 109 { 110 LocalizedNameGenerator g = new LocalizedNameGenerator("bob", null, ".foo"); 111 112 assertTrue(g.more()); 113 assertEquals("bob.foo", g.next()); 114 115 assertTrue(!g.more()); 116 117 try 118 { 119 g.next(); 120 121 throw new AssertionFailedError("Unreachable."); 122 } 123 catch (NoSuchElementException ex) 124 { 125 } 126 } 127 } 128 | Popular Tags |