1   /*
2    *  XNap
3    *
4    *  A pure java file sharing client.
5    *
6    *  See AUTHORS for copyright information.
7    *
8    *  This program is free software; you can redistribute it and/or modify
9    *  it under the terms of the GNU General Public License as published by
10   *  the Free Software Foundation; either version 2 of the License, or
11   *  (at your option) any later version.
12   *
13   *  This program is distributed in the hope that it will be useful,
14   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   *  GNU General Public License for more details.
17   *
18   *  You should have received a copy of the GNU General Public License
19   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   *
22   */
23  package org.xnap.util.prefs;
24  
25  import junit.framework.TestCase;
26  
27  /***
28   * @author Steffen Pingel
29   */
30  public class IntValidatorTest extends TestCase {
31      
32      public IntValidatorTest(String name) 
33      {
34  		super(name);
35      }
36  
37      protected void setUp()
38      {
39      }
40  
41      protected void tearDown()
42      {
43      }
44  
45  	public void testEmptyConstructor()
46  	{
47  		// should validate anything
48  		IntValidator v = new IntValidator();
49  		v.validate(Integer.MIN_VALUE + "");
50  		v.validate("0");
51  		v.validate(Integer.MAX_VALUE + "");
52  		invalidate(v, "a");
53  	}
54  
55  	public void testMinConstructor()
56  	{
57  		IntValidator v = new IntValidator(0);
58  		v.validate("0");
59  		v.validate(Integer.MAX_VALUE + "");
60  		invalidate(v, "-1");
61  		invalidate(v, Integer.MIN_VALUE + "");
62  	}
63  
64  	public void testRangeConstructor()
65  	{
66  		IntValidator v = new IntValidator(0, 0);
67  		v.validate("0");
68  		invalidate(v, "-1");
69  		invalidate(v, "1");
70  
71  		v = new IntValidator(-1, 1);
72  		v.validate("0");
73  		v.validate("-1");
74  		v.validate("1");
75  		invalidate(v, "-2");
76  		invalidate(v, "2");
77  	}
78  
79  	public void testNull()
80  	{
81  		IntValidator v = new IntValidator();
82  		invalidate(v, null);
83  	}
84  
85  	public void testString()
86  	{
87  		IntValidator v = new IntValidator();
88  		invalidate(v, "a");
89  		invalidate(v, "");
90  	}
91  
92      public void invalidate(IntValidator validator, String s) 
93      {
94  		try {
95  			validator.validate(s);
96  			assertTrue(false);
97  		}
98  		catch (IllegalArgumentException e) {
99  		}
100 	}
101 
102 }
103