1 23 24 package com.sun.enterprise.cli.framework; 25 26 import java.util.Iterator ; 27 import java.util.Locale ; 28 import junit.framework.TestCase; 29 import junit.framework.TestSuite; 30 import java.util.NoSuchElementException ; 31 36 37 public class CLIManFileFinderTest extends TestCase { 38 public void testEndOfIterator() { 39 CLIManFileFinder c = new CLIManFileFinder(); 40 Locale l = new Locale ("en", "UK", "v1"); 41 Iterator it = c.getPossibleLocations("command", l); 42 for (int i = 0; i < 71; i++){ 43 it.next(); 44 } 45 assertEquals("help/command.9m", (String ) it.next()); 46 assertTrue(!it.hasNext()); 47 try { 48 it.next(); 49 fail("Expected NoSuchElementException indicating we'd read beyond the end of the interator"); 50 } 51 catch (NoSuchElementException nse){ 52 } 53 54 } 55 56 public void testEndOfThirdSearch() { 57 CLIManFileFinder c = new CLIManFileFinder(); 58 Locale l = new Locale ("en", "UK", "v1"); 59 Iterator it = c.getPossibleLocations("command", l); 60 for (int i = 0; i < 53; i++){ 61 it.next(); 62 } 63 assertEquals("help/en/command.9m", (String ) it.next()); 64 assertEquals("help/command.1", (String ) it.next()); 65 } 66 public void testEndOfSecondSearch() { 67 CLIManFileFinder c = new CLIManFileFinder(); 68 Locale l = new Locale ("en", "UK", "v1"); 69 Iterator it = c.getPossibleLocations("command", l); 70 for (int i = 0; i < 35; i++){ 71 it.next(); 72 } 73 assertEquals("help/en/UK/command.9m", (String ) it.next()); 74 assertEquals("help/en/command.1", (String ) it.next()); 75 } 76 public void testEndOfFirstSearch() { 77 CLIManFileFinder c = new CLIManFileFinder(); 78 Locale l = new Locale ("en", "UK", "v1"); 79 Iterator it = c.getPossibleLocations("command", l); 80 for (int i = 0; i < 17; i++){ 81 it.next(); 82 } 83 assertEquals("help/en/UK/v1/command.9m", (String ) it.next()); 84 assertEquals("help/en/UK/command.1", (String ) it.next()); 85 } 86 87 public void testLocations() { 88 CLIManFileFinder c = new CLIManFileFinder(); 89 Locale l = new Locale ("en", "UK", "v1"); 90 Iterator it = c.getPossibleLocations("command", l); 91 assertEquals("help/en/UK/v1/command.1", (String ) it.next()); 92 assertEquals("help/en/UK/v1/command.1m",(String ) it.next()); 93 assertEquals("help/en/UK/v1/command.2", (String ) it.next()); 94 for (int i = 0; i < 5; i++){ 95 it.next(); 96 } 97 assertEquals("help/en/UK/v1/command.5", (String ) it.next()); 98 } 99 100 101 public void testNoLanguage() { 102 CLIManFileFinder c = new CLIManFileFinder(); 103 Locale l = new Locale ("", "UK", "v1"); 104 assertEquals(1,c.getLocaleLocations(l).length); 105 assertEquals("", c.getLocaleLocations(l)[0]); 106 } 107 108 public void testNoCountry() { 109 CLIManFileFinder c = new CLIManFileFinder(); 110 Locale l = new Locale ("en", "", "v1"); 111 assertEquals(2,c.getLocaleLocations(l).length); 112 assertEquals("/en", c.getLocaleLocations(l)[0]); 113 assertEquals("", c.getLocaleLocations(l)[1]); 114 } 115 116 public void testEmptyVariant(){ 117 CLIManFileFinder c = new CLIManFileFinder(); 118 Locale l = new Locale ("en", "uk", ""); 119 assertEquals(3,c.getLocaleLocations(l).length); 120 assertEquals("/en/UK", c.getLocaleLocations(l)[0]); 121 assertEquals("/en", c.getLocaleLocations(l)[1]); 122 assertEquals("", c.getLocaleLocations(l)[2]); 123 } 124 public void testNoVariant(){ 125 CLIManFileFinder c = new CLIManFileFinder(); 126 Locale l = new Locale ("en", "uk"); 127 assertEquals(3,c.getLocaleLocations(l).length); 128 assertEquals("/en/UK", c.getLocaleLocations(l)[0]); 129 assertEquals("/en", c.getLocaleLocations(l)[1]); 130 assertEquals("", c.getLocaleLocations(l)[2]); 131 } 132 133 public void testSimpleLocation() { 134 CLIManFileFinder c = new CLIManFileFinder(); 135 Locale l = new Locale ("en", "uk", "v1"); 136 assertEquals(4,c.getLocaleLocations(l).length); 137 assertEquals("/en/UK/v1", c.getLocaleLocations(l)[0]); 138 assertEquals("/en/UK", c.getLocaleLocations(l)[1]); 139 assertEquals("/en", c.getLocaleLocations(l)[2]); 140 assertEquals("", c.getLocaleLocations(l)[3]); 141 142 } 143 144 public CLIManFileFinderTest(String name){ 145 super(name); 146 } 147 148 protected void setUp() { 149 } 150 151 protected void tearDown() { 152 } 153 154 private void nyi(){ 155 fail("Not Yet Implemented"); 156 } 157 158 public static void main(String args[]){ 159 if (args.length == 0){ 160 junit.textui.TestRunner.run(CLIManFileFinderTest.class); 161 } else { 162 junit.textui.TestRunner.run(makeSuite(args)); 163 } 164 } 165 private static TestSuite makeSuite(String args[]){ 166 final TestSuite ts = new TestSuite(); 167 for (int i = 0; i < args.length; i++){ 168 ts.addTest(new CLIManFileFinderTest(args[i])); 169 } 170 return ts; 171 } 172 } 173 | Popular Tags |