1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  GNU General Public License for more details.
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  package org.xnap.gui.component;
22  
23  import junit.framework.TestCase;
24  
25  /***
26   * @author Steffen Pingel
27   */
28  public class DefaultCompletionModelTest extends TestCase {
29  
30  	private DefaultCompletionModel model;
31  
32  	public DefaultCompletionModelTest(String name)
33  	{
34  		super(name);
35  	}
36  
37  	public void setUp()
38  	{
39  		model = new DefaultCompletionModel();
40  		model.insert("aaaa");
41  		model.insert("aaab");
42  		model.insert("aaac");
43  		model.insert("abaa");
44  	}
45  
46  	public void tearDown()
47  	{
48  		model = null;
49  	}
50  
51  	public void testCompletion()
52  	{
53  		model.complete("aa");
54  		assertEquals(3, model.getSize());
55  
56  		model.complete("ab");
57  		assertEquals(1, model.getSize());
58  	}
59  
60  	public void testEmptyCompletion()
61  	{
62  		model.complete("b");
63  		assertEquals(0, model.getSize());
64  	}
65  
66  	public void testSingleCompletion()
67  	{
68  		model.complete("aaaa");
69  		assertEquals(1, model.getSize());
70  
71  		model.complete("aaac");
72  		assertEquals(1, model.getSize());
73  	}
74  
75  	public void testEmptyStringCompletion()
76  	{
77  		model.complete("");
78  		assertEquals(0, model.getSize());
79  	}
80  
81  	public void testUniquePrefix()
82  	{
83  		assertEquals("aaa", model.completeUniquePrefix("aa"));
84  	}
85  
86  	public void testSingleUniquePrefix()
87  	{
88  		assertEquals("aaaa", model.completeUniquePrefix("aaaa"));
89  		assertEquals("aaac", model.completeUniquePrefix("aaac"));
90  	}
91  
92  	public void testEmptyUniquePrefix()
93  	{
94  		assertEquals("b", model.completeUniquePrefix("b"));
95  	}
96  
97  }