KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > spell > WebSpellCheckerTest


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

12
13 package com.openedit.modules.spell;
14
15 import java.util.List JavaDoc;
16
17 import com.openedit.BaseTestCase;
18 import com.swabunga.spell.event.SpellCheckEvent;
19
20
21 /**
22  * DOCUMENT ME!
23  *
24  * @author cburkey
25  */

26 public class WebSpellCheckerTest extends BaseTestCase
27 {
28     WebSpellChecker checker;
29
30     public WebSpellCheckerTest(String JavaDoc inName)
31     {
32         super(inName);
33     }
34
35     /**
36      * DOCUMENT ME!
37      *
38      * @throws Exception
39      */

40     public void testBadLetter() throws Exception JavaDoc
41     {
42         assertFalse("Bad ending", getChecker().areAllLetters("put\u00A0"));
43
44         //assertEquals( "This error one and two",error1.getFailedElement().getText("child2").getText() );
45
}
46
47     /**
48      * DOCUMENT ME!
49      *
50      * @throws Exception
51      */

52     public void testFix() throws Exception JavaDoc
53     {
54         StringBuffer JavaDoc b = new StringBuffer JavaDoc("This eror one and twoe");
55
56
57         List JavaDoc errors = getChecker().checkAllWords(b.toString());
58
59         SpellCheckEvent error1 = (SpellCheckEvent)errors.get(0);
60         assertNotNull(error1);
61         assertEquals("eror", error1.getInvalidWord());
62         assertTrue(error1.getSuggestions().size() > 0);
63         
64         SpellCheckEvent error2 = (SpellCheckEvent)errors.get(1);
65         assertNotNull(error2);
66         assertEquals("twoe", error2.getInvalidWord());
67         assertTrue(error2.getSuggestions().size() > 0);
68         error2.replaceWord("two", false);
69     }
70
71     protected WebSpellChecker getChecker() throws Exception JavaDoc
72     {
73         if (checker == null)
74         {
75             checker = new WebSpellChecker( getRoot().getAbsolutePath() +
76                     "/openedit/editors/spell/dictionary/all.dic");
77         }
78
79         return checker;
80     }
81 }
82
Popular Tags