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   * @author rlogiacco
29   */
30  public class StringEnumerationTest extends TestCase {
31  
32  	private Mock mock = new Mock();
33  
34  	/**
35  	 * Test method for {@link net.smartlab.web.StringEnumeration#getCode()}.
36  	 */
37  	public void testGetCode() {
38  		super.assertEquals("first", Mock.FIRST.getCode());
39  		super.assertEquals("second", Mock.SECOND.getCode());
40  		super.assertEquals("third", Mock.THIRD.getCode());
41  	}
42  
43  	/**
44  	 * Test method for {@link net.smartlab.web.StringEnumeration#getDisplay()}.
45  	 */
46  	public void testGetDisplay() {
47  		super.assertEquals("First", Mock.FIRST.getDisplay());
48  		super.assertEquals("Second", Mock.SECOND.getDisplay());
49  		super.assertEquals("Third", Mock.THIRD.getDisplay());
50  	}
51  
52  	/**
53  	 * Test method for
54  	 * {@link net.smartlab.web.StringEnumeration#decode(java.lang.String)}.
55  	 */
56  	public void testDecode() {
57  		super.assertEquals(Mock.FIRST, mock.decode("first"));
58  		super.assertEquals(Mock.SECOND, mock.decode("second"));
59  		super.assertEquals(Mock.THIRD, mock.decode("third"));
60  		super.assertNull(mock.decode("fourth"));
61  	}
62  
63  
64  	private static class Mock extends StringEnumeration {
65  
66  		private static final long serialVersionUID = 1L;
67  
68  		public static Mock FIRST = new Mock("first", "First");
69  
70  		public static Mock SECOND = new Mock("second", "Second");
71  
72  		public static Mock THIRD = new Mock("third", "Third");
73  
74  
75  		public Mock(String code, String display) {
76  			super(code, display);
77  		}
78  
79  		private Mock() {
80  			super();
81  		}
82  
83  		/**
84  		 * @see net.smartlab.web.StringEnumeration#decode(java.lang.String)
85  		 */
86  		public StringEnumeration decode(String code) {
87  			if (code.equals("first")) {
88  				return FIRST;
89  			} else if (code.equals("second")) {
90  				return SECOND;
91  			} else if (code.equals("third")) {
92  				return THIRD;
93  			} else {
94  				return null;
95  			}
96  		}
97  	}
98  }