View Javadoc
1 /* 2 * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TestDefaultPluralStemmer.java,v 1.3 2002/12/30 18:16:48 mvdb Exp $ 3 * $Revision: 1.3 $ 4 * $Date: 2002/12/30 18:16:48 $ 5 * 6 * ==================================================================== 7 * 8 * The Apache Software License, Version 1.1 9 * 10 * Copyright (c) 1999-2002 The Apache Software Foundation. All rights 11 * reserved. 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in 22 * the documentation and/or other materials provided with the 23 * distribution. 24 * 25 * 3. The end-user documentation included with the redistribution, if 26 * any, must include the following acknowlegement: 27 * "This product includes software developed by the 28 * Apache Software Foundation (http://www.apache.org/)." 29 * Alternately, this acknowlegement may appear in the software itself, 30 * if and wherever such third-party acknowlegements normally appear. 31 * 32 * 4. The names "The Jakarta Project", "Commons", and "Apache Software 33 * Foundation" must not be used to endorse or promote products derived 34 * from this software without prior written permission. For written 35 * permission, please contact apache@apache.org. 36 * 37 * 5. Products derived from this software may not be called "Apache" 38 * nor may "Apache" appear in their names without prior written 39 * permission of the Apache Group. 40 * 41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 * SUCH DAMAGE. 53 * ==================================================================== 54 * 55 * This software consists of voluntary contributions made by many 56 * individuals on behalf of the Apache Software Foundation. For more 57 * information on the Apache Software Foundation, please see 58 * <http://www.apache.org/>;. 59 * 60 * $Id: TestDefaultPluralStemmer.java,v 1.3 2002/12/30 18:16:48 mvdb Exp $ 61 */ 62 package org.apache.commons.betwixt.strategy; 63 64 import java.util.HashMap; 65 66 import junit.framework.Test; 67 import junit.framework.TestCase; 68 import junit.framework.TestSuite; 69 70 import org.apache.commons.betwixt.ElementDescriptor; 71 72 /*** 73 * Tests the defaultPluralStemmer 74 * 75 * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a> 76 * @version $Id: TestDefaultPluralStemmer.java,v 1.3 2002/12/30 18:16:48 mvdb Exp $ 77 */ 78 public class TestDefaultPluralStemmer extends TestCase 79 { 80 81 public static Test suite() { 82 return new TestSuite(TestDefaultPluralStemmer.class); 83 } 84 85 public TestDefaultPluralStemmer(String testName) { 86 super(testName); 87 } 88 89 public void testNullMap() { 90 DefaultPluralStemmer stemmer = new DefaultPluralStemmer(); 91 try { 92 stemmer.findPluralDescriptor("test", null); 93 fail("Should throw a nullpointer exception, since the map in the stemmer cannot be null"); 94 }catch(NullPointerException npe) { 95 } 96 } 97 98 /*** 99 * This is the first match when calling the defaultStemmer. 100 * It just adds an s to the the property and it should find it.. 101 */ 102 public void testFirstMatch() { 103 104 ElementDescriptor des = new ElementDescriptor(); 105 des.setQualifiedName("FooBars"); 106 des.setPropertyType(java.util.List.class); 107 HashMap map = new HashMap(); 108 map.put("FooBars", des); 109 DefaultPluralStemmer dps = new DefaultPluralStemmer(); 110 ElementDescriptor result = dps.findPluralDescriptor("FooBar", map); 111 assertEquals(des, result); 112 } 113 /*** 114 * Tests if the y is nicely replaces with ies and the correct 115 * ElementDescriptor is returned 116 */ 117 public void testSecondMatch() { 118 ElementDescriptor des = new ElementDescriptor(); 119 des.setQualifiedName("FooBary"); 120 des.setPropertyType(java.util.List.class); 121 HashMap map = new HashMap(); 122 map.put("FooBaries", des); 123 DefaultPluralStemmer dps = new DefaultPluralStemmer(); 124 ElementDescriptor result = dps.findPluralDescriptor("FooBary", map); 125 assertEquals(des, result); 126 } 127 128 /*** 129 * Tests if it actually skips the y if the length not greater than 1. 130 */ 131 public void testSecondNonMatch() { 132 ElementDescriptor des = new ElementDescriptor(); 133 des.setQualifiedName("y"); 134 des.setPropertyType(java.util.List.class); 135 HashMap map = new HashMap(); 136 map.put("yies", des); 137 DefaultPluralStemmer dps = new DefaultPluralStemmer(); 138 ElementDescriptor result = dps.findPluralDescriptor("y", map); 139 assertNotNull(result); 140 } 141 142 /*** 143 * Uses the third if in pluralstemmer. 144 * It should return the specified y, without any changing. 145 */ 146 public void testThirdMatch() { 147 ElementDescriptor des = new ElementDescriptor(); 148 des.setQualifiedName("y"); 149 des.setPropertyType(java.util.List.class); 150 HashMap map = new HashMap(); 151 map.put("y", des); 152 DefaultPluralStemmer dps = new DefaultPluralStemmer(); 153 ElementDescriptor result = dps.findPluralDescriptor("y", map); 154 assertEquals(des, result); 155 } 156 157 /*** 158 * Tests to see if you get warned when there are multiple matches 159 * found 160 */ 161 public void testMultipleMatches() { 162 ElementDescriptor des = new ElementDescriptor(); 163 des.setQualifiedName("y"); 164 des.setPropertyType(java.util.List.class); 165 ElementDescriptor desyes = new ElementDescriptor(); 166 desyes.setQualifiedName("yes"); 167 desyes.setPropertyType(java.util.List.class); 168 ElementDescriptor desyesno = new ElementDescriptor(); 169 desyesno.setQualifiedName("yesno"); 170 desyesno.setPropertyType(java.util.List.class); 171 HashMap map = new HashMap(); 172 map.put("y", des); 173 map.put("yes", desyes); 174 map.put("yesno", desyesno); 175 DefaultPluralStemmer dps = new DefaultPluralStemmer(); 176 ElementDescriptor result = dps.findPluralDescriptor("y", map); 177 assertEquals(des, result); 178 result = dps.findPluralDescriptor("yes", map); 179 assertEquals(desyes, result); 180 result = dps.findPluralDescriptor("yesno", map); 181 assertEquals(desyesno, result); 182 } 183 184 /*** 185 * Test to find matched where plural ending is "es" 186 */ 187 public void testESPluralEndingMatch() { 188 HashMap map = new HashMap(); 189 190 ElementDescriptor index = new ElementDescriptor("index", "index",""); 191 map.put("index", index); 192 ElementDescriptor indexes = new ElementDescriptor("indexes", "indexes",""); 193 map.put("indexes", indexes); 194 195 ElementDescriptor patch = new ElementDescriptor("patch", "patch",""); 196 map.put("patch", patch); 197 ElementDescriptor patches = new ElementDescriptor("patches", "patches",""); 198 map.put("patches", patches); 199 200 DefaultPluralStemmer stemmer = new DefaultPluralStemmer(); 201 ElementDescriptor result = stemmer.findPluralDescriptor("index", map); 202 assertEquals(indexes, result); 203 204 result = stemmer.findPluralDescriptor("patches", map); 205 assertEquals(patches, result); 206 } 207 208 /*** 209 * Test if the closest match mechanisme is working 210 */ 211 public void testClosestMatch() { 212 HashMap map = new HashMap(); 213 ElementDescriptor yes1 = new ElementDescriptor("yes1", "yes1",""); 214 map.put("yes1", yes1); 215 ElementDescriptor yes12 = new ElementDescriptor("yes12", "yes12",""); 216 map.put("yes12", yes12); 217 ElementDescriptor yes123 = new ElementDescriptor("yes123", "yes123",""); 218 map.put("yes123", yes123); 219 DefaultPluralStemmer stemmer = new DefaultPluralStemmer(); 220 ElementDescriptor result = stemmer.findPluralDescriptor("yes", map); 221 assertEquals(yes1, result); 222 } 223 224 } 225

This page was automatically generated by Maven