1   /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   *
19   * For further informations on the SmartWeb Framework please visit
20   *
21   *                        http://smartweb.sourceforge.net
22   */
23  package net.smartlab.web;
24  
25  import junit.framework.TestCase;
26  
27  /**
28   * @TODO documentation
29   * @author rlogiacco
30   */
31  public class EnumerationTest extends TestCase {
32  
33  	private Mock mock = new Mock();
34  
35  
36  	/**
37  	 * Test method for {@link net.smartlab.web.Enumeration#getId()}.
38  	 */
39  	public void testGetCode() {
40  		super.assertEquals(1, Mock.FIRST.getId());
41  		super.assertEquals(2, Mock.SECOND.getId());
42  		super.assertEquals(3, Mock.THIRD.getId());
43  	}
44  
45  	/**
46  	 * Test method for {@link net.smartlab.web.Enumeration#getDisplay()}.
47  	 */
48  	public void testGetDisplay() {
49  		super.assertEquals("First", Mock.FIRST.getDisplay());
50  		super.assertEquals("Second", Mock.SECOND.getDisplay());
51  		super.assertEquals("Third", Mock.THIRD.getDisplay());
52  	}
53  
54  	/**
55  	 * Test method for {@link net.smartlab.web.Enumeration#decode(int)}.
56  	 */
57  	public void testDecode() {
58  		super.assertEquals(Mock.FIRST, mock.decode(1));
59  		super.assertEquals(Mock.SECOND, mock.decode(2));
60  		super.assertEquals(Mock.THIRD, mock.decode(3));
61  		super.assertNull(mock.decode(4));
62  	}
63  
64  
65  	protected static class Mock extends Enumeration {
66  
67  		private static final long serialVersionUID = 1L;
68  
69  		public static Mock FIRST = new Mock(1, "First");
70  
71  		public static Mock SECOND = new Mock(2, "Second");
72  
73  		public static Mock THIRD = new Mock(3, "Third");
74  
75  
76  		public Mock(int code, String display) {
77  			super(code, display);
78  		}
79  
80  		public Mock() {
81  			super();
82  		}
83  
84  		/**
85  		 * @see net.smartlab.web.StringEnumeration#decode(java.lang.String)
86  		 */
87  		public Enumeration decode(int code) {
88  			switch (code) {
89  				case 1:
90  					return FIRST;
91  				case 2:
92  					return SECOND;
93  				case 3:
94  					return THIRD;
95  				default:
96  					return null;
97  			}
98  		}
99  	}
100 }