Source Code Cross Referenced for MutableByteTest.java in  » Library » Apache-common-lang » org » apache » commons » lang » mutable » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache common lang » org.apache.commons.lang.mutable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.lang.mutable;
018:
019:        import junit.framework.Test;
020:        import junit.framework.TestCase;
021:        import junit.framework.TestSuite;
022:        import junit.textui.TestRunner;
023:
024:        /**
025:         * JUnit tests.
026:         * 
027:         * @version $Id: MutableByteTest.java 437554 2006-08-28 06:21:41Z bayard $
028:         * @see MutableByte
029:         */
030:        public class MutableByteTest extends TestCase {
031:
032:            public MutableByteTest(String testName) {
033:                super (testName);
034:            }
035:
036:            public static void main(String[] args) {
037:                TestRunner.run(suite());
038:            }
039:
040:            public static Test suite() {
041:                return new TestSuite(MutableByteTest.class);
042:            }
043:
044:            // ----------------------------------------------------------------
045:            public void testConstructors() {
046:                assertEquals((byte) 0, new MutableByte().byteValue());
047:
048:                assertEquals((byte) 1, new MutableByte((byte) 1).byteValue());
049:
050:                assertEquals((byte) 2, new MutableByte(new Byte((byte) 2))
051:                        .byteValue());
052:                assertEquals((byte) 3, new MutableByte(
053:                        new MutableByte((byte) 3)).byteValue());
054:                try {
055:                    new MutableByte(null);
056:                    fail();
057:                } catch (NullPointerException ex) {
058:                }
059:            }
060:
061:            public void testGetSet() {
062:                final MutableByte mutNum = new MutableByte((byte) 0);
063:                assertEquals((byte) 0, new MutableByte().byteValue());
064:                assertEquals(new Byte((byte) 0), new MutableByte().getValue());
065:
066:                mutNum.setValue((byte) 1);
067:                assertEquals((byte) 1, mutNum.byteValue());
068:                assertEquals(new Byte((byte) 1), mutNum.getValue());
069:
070:                mutNum.setValue(new Byte((byte) 2));
071:                assertEquals((byte) 2, mutNum.byteValue());
072:                assertEquals(new Byte((byte) 2), mutNum.getValue());
073:
074:                mutNum.setValue(new MutableByte((byte) 3));
075:                assertEquals((byte) 3, mutNum.byteValue());
076:                assertEquals(new Byte((byte) 3), mutNum.getValue());
077:                try {
078:                    mutNum.setValue(null);
079:                    fail();
080:                } catch (NullPointerException ex) {
081:                }
082:                try {
083:                    mutNum.setValue("0");
084:                    fail();
085:                } catch (ClassCastException ex) {
086:                }
087:            }
088:
089:            public void testEquals() {
090:                final MutableByte mutNumA = new MutableByte((byte) 0);
091:                final MutableByte mutNumB = new MutableByte((byte) 0);
092:                final MutableByte mutNumC = new MutableByte((byte) 1);
093:
094:                assertEquals(true, mutNumA.equals(mutNumA));
095:                assertEquals(true, mutNumA.equals(mutNumB));
096:                assertEquals(true, mutNumB.equals(mutNumA));
097:                assertEquals(true, mutNumB.equals(mutNumB));
098:                assertEquals(false, mutNumA.equals(mutNumC));
099:                assertEquals(false, mutNumB.equals(mutNumC));
100:                assertEquals(true, mutNumC.equals(mutNumC));
101:                assertEquals(false, mutNumA.equals(null));
102:                assertEquals(false, mutNumA.equals(new Byte((byte) 0)));
103:                assertEquals(false, mutNumA.equals("0"));
104:            }
105:
106:            public void testHashCode() {
107:                final MutableByte mutNumA = new MutableByte((byte) 0);
108:                final MutableByte mutNumB = new MutableByte((byte) 0);
109:                final MutableByte mutNumC = new MutableByte((byte) 1);
110:
111:                assertEquals(true, mutNumA.hashCode() == mutNumA.hashCode());
112:                assertEquals(true, mutNumA.hashCode() == mutNumB.hashCode());
113:                assertEquals(false, mutNumA.hashCode() == mutNumC.hashCode());
114:                assertEquals(true, mutNumA.hashCode() == new Byte((byte) 0)
115:                        .hashCode());
116:            }
117:
118:            public void testCompareTo() {
119:                final MutableByte mutNum = new MutableByte((byte) 0);
120:
121:                assertEquals((byte) 0, mutNum.compareTo(new MutableByte(
122:                        (byte) 0)));
123:                assertEquals((byte) +1, mutNum.compareTo(new MutableByte(
124:                        (byte) -1)));
125:                assertEquals((byte) -1, mutNum.compareTo(new MutableByte(
126:                        (byte) 1)));
127:                try {
128:                    mutNum.compareTo(null);
129:                    fail();
130:                } catch (NullPointerException ex) {
131:                }
132:                try {
133:                    mutNum.compareTo(new Byte((byte) 0));
134:                    fail();
135:                } catch (ClassCastException ex) {
136:                }
137:                try {
138:                    mutNum.compareTo("0");
139:                    fail();
140:                } catch (ClassCastException ex) {
141:                }
142:            }
143:
144:            public void testPrimitiveValues() {
145:                MutableByte mutNum = new MutableByte((byte) 1);
146:
147:                assertEquals(1.0F, mutNum.floatValue(), 0);
148:                assertEquals(1.0, mutNum.doubleValue(), 0);
149:                assertEquals((byte) 1, mutNum.byteValue());
150:                assertEquals((short) 1, mutNum.shortValue());
151:                assertEquals(1, mutNum.intValue());
152:                assertEquals(1L, mutNum.longValue());
153:            }
154:
155:            public void testToByte() {
156:                assertEquals(new Byte((byte) 0), new MutableByte((byte) 0)
157:                        .toByte());
158:                assertEquals(new Byte((byte) 123), new MutableByte((byte) 123)
159:                        .toByte());
160:            }
161:
162:            public void testIncrement() {
163:                MutableByte mutNum = new MutableByte((byte) 1);
164:                mutNum.increment();
165:
166:                assertEquals(2, mutNum.intValue());
167:                assertEquals(2L, mutNum.longValue());
168:            }
169:
170:            public void testDecrement() {
171:                MutableByte mutNum = new MutableByte((byte) 1);
172:                mutNum.decrement();
173:
174:                assertEquals(0, mutNum.intValue());
175:                assertEquals(0L, mutNum.longValue());
176:            }
177:
178:            public void testAddValuePrimitive() {
179:                MutableByte mutNum = new MutableByte((byte) 1);
180:                mutNum.add((byte) 1);
181:
182:                assertEquals((byte) 2, mutNum.byteValue());
183:            }
184:
185:            public void testAddValueObject() {
186:                MutableByte mutNum = new MutableByte((byte) 1);
187:                mutNum.add(new Integer(1));
188:
189:                assertEquals((byte) 2, mutNum.byteValue());
190:            }
191:
192:            public void testSubtractValuePrimitive() {
193:                MutableByte mutNum = new MutableByte((byte) 1);
194:                mutNum.subtract((byte) 1);
195:
196:                assertEquals((byte) 0, mutNum.byteValue());
197:            }
198:
199:            public void testSubtractValueObject() {
200:                MutableByte mutNum = new MutableByte((byte) 1);
201:                mutNum.subtract(new Integer(1));
202:
203:                assertEquals((byte) 0, mutNum.byteValue());
204:            }
205:
206:            public void testToString() {
207:                assertEquals("0", new MutableByte((byte) 0).toString());
208:                assertEquals("10", new MutableByte((byte) 10).toString());
209:                assertEquals("-123", new MutableByte((byte) -123).toString());
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.