Source Code Cross Referenced for ByteTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » lang » 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 » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  You may obtain a copy of the License at
007:         * 
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.harmony.luni.tests.java.lang;
018:
019:        import junit.framework.TestCase;
020:
021:        public class ByteTest extends TestCase {
022:
023:            /**
024:             * @tests java.lang.Byte#valueOf(byte)
025:             */
026:            public void test_valueOfB() {
027:                assertEquals(new Byte(Byte.MIN_VALUE), Byte
028:                        .valueOf(Byte.MIN_VALUE));
029:                assertEquals(new Byte(Byte.MAX_VALUE), Byte
030:                        .valueOf(Byte.MAX_VALUE));
031:                assertEquals(new Byte((byte) 0), Byte.valueOf((byte) 0));
032:
033:                byte b = Byte.MIN_VALUE + 1;
034:                while (b < Byte.MAX_VALUE) {
035:                    assertEquals(new Byte(b), Byte.valueOf(b));
036:                    assertSame(Byte.valueOf(b), Byte.valueOf(b));
037:                    b++;
038:                }
039:            }
040:
041:            /**
042:             * @tests java.lang.Byte#hashCode()
043:             */
044:            public void test_hashCode() {
045:                assertEquals(1, new Byte((byte) 1).hashCode());
046:                assertEquals(2, new Byte((byte) 2).hashCode());
047:                assertEquals(0, new Byte((byte) 0).hashCode());
048:                assertEquals(-1, new Byte((byte) -1).hashCode());
049:            }
050:
051:            /**
052:             * @tests java.lang.Byte#Byte(String)
053:             */
054:            public void test_ConstructorLjava_lang_String() {
055:                assertEquals(new Byte((byte) 0), new Byte("0"));
056:                assertEquals(new Byte((byte) 1), new Byte("1"));
057:                assertEquals(new Byte((byte) -1), new Byte("-1"));
058:
059:                try {
060:                    new Byte("0x1");
061:                    fail("Expected NumberFormatException with hex string.");
062:                } catch (NumberFormatException e) {
063:                }
064:
065:                try {
066:                    new Byte("9.2");
067:                    fail("Expected NumberFormatException with floating point string.");
068:                } catch (NumberFormatException e) {
069:                }
070:
071:                try {
072:                    new Byte("");
073:                    fail("Expected NumberFormatException with empty string.");
074:                } catch (NumberFormatException e) {
075:                }
076:
077:                try {
078:                    new Byte(null);
079:                    fail("Expected NumberFormatException with null string.");
080:                } catch (NumberFormatException e) {
081:                }
082:            }
083:
084:            /**
085:             * @tests java.lang.Byte#Byte(byte)
086:             */
087:            public void test_ConstructorB() {
088:                assertEquals(1, new Byte((byte) 1).byteValue());
089:                assertEquals(2, new Byte((byte) 2).byteValue());
090:                assertEquals(0, new Byte((byte) 0).byteValue());
091:                assertEquals(-1, new Byte((byte) -1).byteValue());
092:            }
093:
094:            /**
095:             * @tests java.lang.Byte#byteValue()
096:             */
097:            public void test_booleanValue() {
098:                assertEquals(1, new Byte((byte) 1).byteValue());
099:                assertEquals(2, new Byte((byte) 2).byteValue());
100:                assertEquals(0, new Byte((byte) 0).byteValue());
101:                assertEquals(-1, new Byte((byte) -1).byteValue());
102:            }
103:
104:            /**
105:             * @tests java.lang.Byte#equals(Object)
106:             */
107:            public void test_equalsLjava_lang_Object() {
108:                assertEquals(new Byte((byte) 0), Byte.valueOf((byte) 0));
109:                assertEquals(new Byte((byte) 1), Byte.valueOf((byte) 1));
110:                assertEquals(new Byte((byte) -1), Byte.valueOf((byte) -1));
111:
112:                Byte fixture = new Byte((byte) 25);
113:                assertEquals(fixture, fixture);
114:                assertFalse(fixture.equals(null));
115:                assertFalse(fixture.equals("Not a Byte"));
116:            }
117:
118:            /**
119:             * @tests java.lang.Byte#toString()
120:             */
121:            public void test_toString() {
122:                assertEquals("-1", new Byte((byte) -1).toString());
123:                assertEquals("0", new Byte((byte) 0).toString());
124:                assertEquals("1", new Byte((byte) 1).toString());
125:                assertEquals("-1", new Byte((byte) 0xFF).toString());
126:            }
127:
128:            /**
129:             * @tests java.lang.Byte#toString(byte)
130:             */
131:            public void test_toStringB() {
132:                assertEquals("-1", Byte.toString((byte) -1));
133:                assertEquals("0", Byte.toString((byte) 0));
134:                assertEquals("1", Byte.toString((byte) 1));
135:                assertEquals("-1", Byte.toString((byte) 0xFF));
136:            }
137:
138:            /**
139:             * @tests java.lang.Byte#valueOf(String)
140:             */
141:            public void test_valueOfLjava_lang_String() {
142:                assertEquals(new Byte((byte) 0), Byte.valueOf("0"));
143:                assertEquals(new Byte((byte) 1), Byte.valueOf("1"));
144:                assertEquals(new Byte((byte) -1), Byte.valueOf("-1"));
145:
146:                try {
147:                    Byte.valueOf("0x1");
148:                    fail("Expected NumberFormatException with hex string.");
149:                } catch (NumberFormatException e) {
150:                }
151:
152:                try {
153:                    Byte.valueOf("9.2");
154:                    fail("Expected NumberFormatException with floating point string.");
155:                } catch (NumberFormatException e) {
156:                }
157:
158:                try {
159:                    Byte.valueOf("");
160:                    fail("Expected NumberFormatException with empty string.");
161:                } catch (NumberFormatException e) {
162:                }
163:
164:                try {
165:                    Byte.valueOf(null);
166:                    fail("Expected NumberFormatException with null string.");
167:                } catch (NumberFormatException e) {
168:                }
169:            }
170:
171:            /**
172:             * @tests java.lang.Byte#valueOf(String,int)
173:             */
174:            public void test_valueOfLjava_lang_StringI() {
175:                assertEquals(new Byte((byte) 0), Byte.valueOf("0", 10));
176:                assertEquals(new Byte((byte) 1), Byte.valueOf("1", 10));
177:                assertEquals(new Byte((byte) -1), Byte.valueOf("-1", 10));
178:
179:                //must be consistent with Character.digit()
180:                assertEquals(Character.digit('1', 2), Byte.valueOf("1", 2)
181:                        .byteValue());
182:                assertEquals(Character.digit('F', 16), Byte.valueOf("F", 16)
183:                        .byteValue());
184:
185:                try {
186:                    Byte.valueOf("0x1", 10);
187:                    fail("Expected NumberFormatException with hex string.");
188:                } catch (NumberFormatException e) {
189:                }
190:
191:                try {
192:                    Byte.valueOf("9.2", 10);
193:                    fail("Expected NumberFormatException with floating point string.");
194:                } catch (NumberFormatException e) {
195:                }
196:
197:                try {
198:                    Byte.valueOf("", 10);
199:                    fail("Expected NumberFormatException with empty string.");
200:                } catch (NumberFormatException e) {
201:                }
202:
203:                try {
204:                    Byte.valueOf(null, 10);
205:                    fail("Expected NumberFormatException with null string.");
206:                } catch (NumberFormatException e) {
207:                }
208:            }
209:
210:            /**
211:             * @tests java.lang.Byte#parseByte(String)
212:             */
213:            public void test_parseByteLjava_lang_String() {
214:                assertEquals(0, Byte.parseByte("0"));
215:                assertEquals(1, Byte.parseByte("1"));
216:                assertEquals(-1, Byte.parseByte("-1"));
217:
218:                try {
219:                    Byte.parseByte("0x1");
220:                    fail("Expected NumberFormatException with hex string.");
221:                } catch (NumberFormatException e) {
222:                }
223:
224:                try {
225:                    Byte.parseByte("9.2");
226:                    fail("Expected NumberFormatException with floating point string.");
227:                } catch (NumberFormatException e) {
228:                }
229:
230:                try {
231:                    Byte.parseByte("");
232:                    fail("Expected NumberFormatException with empty string.");
233:                } catch (NumberFormatException e) {
234:                }
235:
236:                try {
237:                    Byte.parseByte(null);
238:                    fail("Expected NumberFormatException with null string.");
239:                } catch (NumberFormatException e) {
240:                }
241:            }
242:
243:            /**
244:             * @tests java.lang.Byte#parseByte(String,int)
245:             */
246:            public void test_parseByteLjava_lang_StringI() {
247:                assertEquals(0, Byte.parseByte("0", 10));
248:                assertEquals(1, Byte.parseByte("1", 10));
249:                assertEquals(-1, Byte.parseByte("-1", 10));
250:
251:                //must be consistent with Character.digit()
252:                assertEquals(Character.digit('1', 2), Byte.parseByte("1", 2));
253:                assertEquals(Character.digit('F', 16), Byte.parseByte("F", 16));
254:
255:                try {
256:                    Byte.parseByte("0x1", 10);
257:                    fail("Expected NumberFormatException with hex string.");
258:                } catch (NumberFormatException e) {
259:                }
260:
261:                try {
262:                    Byte.parseByte("9.2", 10);
263:                    fail("Expected NumberFormatException with floating point string.");
264:                } catch (NumberFormatException e) {
265:                }
266:
267:                try {
268:                    Byte.parseByte("", 10);
269:                    fail("Expected NumberFormatException with empty string.");
270:                } catch (NumberFormatException e) {
271:                }
272:
273:                try {
274:                    Byte.parseByte(null, 10);
275:                    fail("Expected NumberFormatException with null string.");
276:                } catch (NumberFormatException e) {
277:                }
278:            }
279:
280:            /**
281:             * @tests java.lang.Byte#decode(String)
282:             */
283:            public void test_decodeLjava_lang_String() {
284:                assertEquals(new Byte((byte) 0), Byte.decode("0"));
285:                assertEquals(new Byte((byte) 1), Byte.decode("1"));
286:                assertEquals(new Byte((byte) -1), Byte.decode("-1"));
287:                assertEquals(new Byte((byte) 0xF), Byte.decode("0xF"));
288:                assertEquals(new Byte((byte) 0xF), Byte.decode("#F"));
289:                assertEquals(new Byte((byte) 0xF), Byte.decode("0XF"));
290:                assertEquals(new Byte((byte) 07), Byte.decode("07"));
291:
292:                try {
293:                    Byte.decode("9.2");
294:                    fail("Expected NumberFormatException with floating point string.");
295:                } catch (NumberFormatException e) {
296:                }
297:
298:                try {
299:                    Byte.decode("");
300:                    fail("Expected NumberFormatException with empty string.");
301:                } catch (NumberFormatException e) {
302:                }
303:
304:                try {
305:                    Byte.decode(null);
306:                    //undocumented NPE, but seems consistent across JREs
307:                    fail("Expected NullPointerException with null string.");
308:                } catch (NullPointerException e) {
309:                }
310:            }
311:
312:            /**
313:             * @tests java.lang.Byte#doubleValue()
314:             */
315:            public void test_doubleValue() {
316:                assertEquals(-1D, new Byte((byte) -1).doubleValue(), 0D);
317:                assertEquals(0D, new Byte((byte) 0).doubleValue(), 0D);
318:                assertEquals(1D, new Byte((byte) 1).doubleValue(), 0D);
319:            }
320:
321:            /**
322:             * @tests java.lang.Byte#floatValue()
323:             */
324:            public void test_floatValue() {
325:                assertEquals(-1F, new Byte((byte) -1).floatValue(), 0F);
326:                assertEquals(0F, new Byte((byte) 0).floatValue(), 0F);
327:                assertEquals(1F, new Byte((byte) 1).floatValue(), 0F);
328:            }
329:
330:            /**
331:             * @tests java.lang.Byte#intValue()
332:             */
333:            public void test_intValue() {
334:                assertEquals(-1, new Byte((byte) -1).intValue());
335:                assertEquals(0, new Byte((byte) 0).intValue());
336:                assertEquals(1, new Byte((byte) 1).intValue());
337:            }
338:
339:            /**
340:             * @tests java.lang.Byte#longValue()
341:             */
342:            public void test_longValue() {
343:                assertEquals(-1L, new Byte((byte) -1).longValue());
344:                assertEquals(0L, new Byte((byte) 0).longValue());
345:                assertEquals(1L, new Byte((byte) 1).longValue());
346:            }
347:
348:            /**
349:             * @tests java.lang.Byte#shortValue()
350:             */
351:            public void test_shortValue() {
352:                assertEquals(-1, new Byte((byte) -1).shortValue());
353:                assertEquals(0, new Byte((byte) 0).shortValue());
354:                assertEquals(1, new Byte((byte) 1).shortValue());
355:            }
356:
357:            /**
358:             * @tests java.lang.Byte#compareTo(Byte)
359:             */
360:            public void test_compareToLjava_lang_Byte() {
361:                final Byte min = new Byte(Byte.MIN_VALUE);
362:                final Byte zero = new Byte((byte) 0);
363:                final Byte max = new Byte(Byte.MAX_VALUE);
364:
365:                assertTrue(max.compareTo(max) == 0);
366:                assertTrue(min.compareTo(min) == 0);
367:                assertTrue(zero.compareTo(zero) == 0);
368:
369:                assertTrue(max.compareTo(zero) > 0);
370:                assertTrue(max.compareTo(min) > 0);
371:
372:                assertTrue(zero.compareTo(max) < 0);
373:                assertTrue(zero.compareTo(min) > 0);
374:
375:                assertTrue(min.compareTo(zero) < 0);
376:                assertTrue(min.compareTo(max) < 0);
377:
378:                try {
379:                    min.compareTo(null);
380:                    fail("No NPE");
381:                } catch (NullPointerException e) {
382:                }
383:            }
384:
385:            /**
386:             * @tests java.lang.Byte#Byte(byte)
387:             */
388:            public void test_ConstructorB2() {
389:                // Test for method java.lang.Byte(byte)
390:
391:                Byte b = new Byte((byte) 127);
392:                assertTrue("Byte creation failed", b.byteValue() == (byte) 127);
393:            }
394:
395:            /**
396:             * @tests java.lang.Byte#Byte(java.lang.String)
397:             */
398:            public void test_ConstructorLjava_lang_String2() {
399:                // Test for method java.lang.Byte(java.lang.String)
400:
401:                Byte b = new Byte("127");
402:                Byte nb = new Byte("-128");
403:                assertTrue("Incorrect Byte Object created",
404:                        b.byteValue() == (byte) 127
405:                                && (nb.byteValue() == (byte) -128));
406:
407:            }
408:
409:            /**
410:             * @tests java.lang.Byte#byteValue()
411:             */
412:            public void test_byteValue() {
413:                // Test for method byte java.lang.Byte.byteValue()
414:                assertTrue("Returned incorrect byte value",
415:                        new Byte((byte) 127).byteValue() == (byte) (127));
416:            }
417:
418:            /**
419:             * @tests java.lang.Byte#compareTo(java.lang.Byte)
420:             */
421:            public void test_compareToLjava_lang_Byte2() {
422:                // Test for method int java.lang.Byte.compareTo(java.lang.Byte)
423:                assertTrue("Comparison failed", new Byte((byte) 1)
424:                        .compareTo(new Byte((byte) 2)) < 0);
425:                assertTrue("Comparison failed", new Byte((byte) 1)
426:                        .compareTo(new Byte((byte) -2)) > 0);
427:                assertEquals("Comparison failed", 0, new Byte((byte) 1)
428:                        .compareTo(new Byte((byte) 1)));
429:            }
430:
431:            /**
432:             * @tests java.lang.Byte#decode(java.lang.String)
433:             */
434:            public void test_decodeLjava_lang_String2() {
435:                // Test for method java.lang.Byte
436:                // java.lang.Byte.decode(java.lang.String)
437:                assertTrue("String decoded incorrectly, wanted: 1 got: "
438:                        + Byte.decode("1").toString(), Byte.decode("1").equals(
439:                        new Byte((byte) 1)));
440:                assertTrue("String decoded incorrectly, wanted: -1 got: "
441:                        + Byte.decode("-1").toString(), Byte.decode("-1")
442:                        .equals(new Byte((byte) -1)));
443:                assertTrue("String decoded incorrectly, wanted: 127 got: "
444:                        + Byte.decode("127").toString(), Byte.decode("127")
445:                        .equals(new Byte((byte) 127)));
446:                assertTrue("String decoded incorrectly, wanted: -128 got: "
447:                        + Byte.decode("-128").toString(), Byte.decode("-128")
448:                        .equals(new Byte((byte) -128)));
449:                assertTrue("String decoded incorrectly, wanted: 127 got: "
450:                        + Byte.decode("0x7f").toString(), Byte.decode("0x7f")
451:                        .equals(new Byte((byte) 127)));
452:                assertTrue("String decoded incorrectly, wanted: -128 got: "
453:                        + Byte.decode("-0x80").toString(), Byte.decode("-0x80")
454:                        .equals(new Byte((byte) -128)));
455:
456:                boolean exception = false;
457:                try {
458:                    Byte.decode("128");
459:                } catch (NumberFormatException e) {
460:                    // Correct
461:                    exception = true;
462:                }
463:                assertTrue("Failed to throw exception for MAX_VALUE + 1",
464:                        exception);
465:
466:                exception = false;
467:                try {
468:                    Byte.decode("-129");
469:                } catch (NumberFormatException e) {
470:                    // Correct
471:                    exception = true;
472:                }
473:                assertTrue("Failed to throw exception for MIN_VALUE - 1",
474:                        exception);
475:
476:                exception = false;
477:                try {
478:                    Byte.decode("0x80");
479:                } catch (NumberFormatException e) {
480:                    // Correct
481:                    exception = true;
482:                }
483:                assertTrue("Failed to throw exception for hex MAX_VALUE + 1",
484:                        exception);
485:
486:                exception = false;
487:                try {
488:                    Byte.decode("-0x81");
489:                } catch (NumberFormatException e) {
490:                    // Correct
491:                    exception = true;
492:                }
493:                assertTrue("Failed to throw exception for hex MIN_VALUE - 1",
494:                        exception);
495:            }
496:
497:            /**
498:             * @tests java.lang.Byte#doubleValue()
499:             */
500:            public void test_doubleValue2() {
501:                assertEquals(127D, new Byte((byte) 127).doubleValue(), 0.0);
502:            }
503:
504:            /**
505:             * @tests java.lang.Byte#equals(java.lang.Object)
506:             */
507:            public void test_equalsLjava_lang_Object2() {
508:                // Test for method boolean java.lang.Byte.equals(java.lang.Object)
509:                Byte b1 = new Byte((byte) 90);
510:                Byte b2 = new Byte((byte) 90);
511:                Byte b3 = new Byte((byte) -90);
512:                assertTrue("Equality test failed", b1.equals(b2));
513:                assertTrue("Equality test failed", !b1.equals(b3));
514:            }
515:
516:            /**
517:             * @tests java.lang.Byte#floatValue()
518:             */
519:            public void test_floatValue2() {
520:                assertEquals(127F, new Byte((byte) 127).floatValue(), 0.0);
521:            }
522:
523:            /**
524:             * @tests java.lang.Byte#hashCode()
525:             */
526:            public void test_hashCode2() {
527:                // Test for method int java.lang.Byte.hashCode()
528:                assertEquals("Incorrect hash returned", 127, new Byte(
529:                        (byte) 127).hashCode());
530:            }
531:
532:            /**
533:             * @tests java.lang.Byte#intValue()
534:             */
535:            public void test_intValue2() {
536:                // Test for method int java.lang.Byte.intValue()
537:                assertEquals("Returned incorrect int value", 127, new Byte(
538:                        (byte) 127).intValue());
539:            }
540:
541:            /**
542:             * @tests java.lang.Byte#longValue()
543:             */
544:            public void test_longValue2() {
545:                // Test for method long java.lang.Byte.longValue()
546:                assertEquals("Returned incorrect long value", 127L, new Byte(
547:                        (byte) 127).longValue());
548:            }
549:
550:            /**
551:             * @tests java.lang.Byte#parseByte(java.lang.String)
552:             */
553:            public void test_parseByteLjava_lang_String2() {
554:                assertEquals((byte) 127, Byte.parseByte("127"));
555:                assertEquals((byte) -128, Byte.parseByte("-128"));
556:                assertEquals((byte) 0, Byte.parseByte("0"));
557:                assertEquals((byte) 0x80, Byte.parseByte("-128"));
558:                assertEquals((byte) 0x7F, Byte.parseByte("127"));
559:
560:                try {
561:                    Byte.parseByte("-1000");
562:                    fail("No NumberFormatException");
563:                } catch (NumberFormatException e) {
564:                }
565:
566:                try {
567:                    Byte.parseByte("128");
568:                    fail("No NumberFormatException");
569:                } catch (NumberFormatException e) {
570:                }
571:
572:                try {
573:                    Byte.parseByte("-129");
574:                    fail("No NumberFormatException");
575:                } catch (NumberFormatException e) {
576:                }
577:            }
578:
579:            /**
580:             * @tests java.lang.Byte#parseByte(java.lang.String, int)
581:             */
582:            public void test_parseByteLjava_lang_StringI2() {
583:                // Test for method byte java.lang.Byte.parseByte(java.lang.String, int)
584:                byte b = Byte.parseByte("127", 10);
585:                byte bn = Byte.parseByte("-128", 10);
586:                assertTrue("Invalid parse of dec byte", b == (byte) 127
587:                        && (bn == (byte) -128));
588:                assertEquals("Failed to parse hex value", 10, Byte.parseByte(
589:                        "A", 16));
590:                assertEquals("Returned incorrect value for 0 hex", 0, Byte
591:                        .parseByte("0", 16));
592:                assertTrue(
593:                        "Returned incorrect value for most negative value hex",
594:                        Byte.parseByte("-80", 16) == (byte) 0x80);
595:                assertTrue(
596:                        "Returned incorrect value for most positive value hex",
597:                        Byte.parseByte("7f", 16) == 0x7f);
598:                assertEquals("Returned incorrect value for 0 decimal", 0, Byte
599:                        .parseByte("0", 10));
600:                assertTrue(
601:                        "Returned incorrect value for most negative value decimal",
602:                        Byte.parseByte("-128", 10) == (byte) 0x80);
603:                assertTrue(
604:                        "Returned incorrect value for most positive value decimal",
605:                        Byte.parseByte("127", 10) == 0x7f);
606:
607:                try {
608:                    Byte.parseByte("-1000", 10);
609:                    fail("Failed to throw exception");
610:                } catch (NumberFormatException e) {
611:                }
612:
613:                try {
614:                    Byte.parseByte("128", 10);
615:                    fail("Failed to throw exception for MAX_VALUE + 1");
616:                } catch (NumberFormatException e) {
617:                }
618:
619:                try {
620:                    Byte.parseByte("-129", 10);
621:                    fail("Failed to throw exception for MIN_VALUE - 1");
622:                } catch (NumberFormatException e) {
623:                }
624:
625:                try {
626:                    Byte.parseByte("80", 16);
627:                    fail("Failed to throw exception for hex MAX_VALUE + 1");
628:                } catch (NumberFormatException e) {
629:                }
630:
631:                try {
632:                    Byte.parseByte("-81", 16);
633:                    fail("Failed to throw exception for hex MIN_VALUE + 1");
634:                } catch (NumberFormatException e) {
635:                }
636:            }
637:
638:            /**
639:             * @tests java.lang.Byte#shortValue()
640:             */
641:            public void test_shortValue2() {
642:                assertEquals((short) 127, new Byte((byte) 127).shortValue());
643:            }
644:
645:            /**
646:             * @tests java.lang.Byte#toString()
647:             */
648:            public void test_toString2() {
649:                assertEquals("Returned incorrect String", "127", new Byte(
650:                        (byte) 127).toString());
651:                assertEquals("Returned incorrect String", "-127", new Byte(
652:                        (byte) -127).toString());
653:                assertEquals("Returned incorrect String", "-128", new Byte(
654:                        (byte) -128).toString());
655:            }
656:
657:            /**
658:             * @tests java.lang.Byte#toString(byte)
659:             */
660:            public void test_toStringB2() {
661:                assertEquals("Returned incorrect String", "127", Byte
662:                        .toString((byte) 127));
663:                assertEquals("Returned incorrect String", "-127", Byte
664:                        .toString((byte) -127));
665:                assertEquals("Returned incorrect String", "-128", Byte
666:                        .toString((byte) -128));
667:            }
668:
669:            /**
670:             * @tests java.lang.Byte#valueOf(java.lang.String)
671:             */
672:            public void test_valueOfLjava_lang_String2() {
673:                assertEquals("Returned incorrect byte", 0, Byte.valueOf("0")
674:                        .byteValue());
675:                assertEquals("Returned incorrect byte", 127, Byte
676:                        .valueOf("127").byteValue());
677:                assertEquals("Returned incorrect byte", -127, Byte.valueOf(
678:                        "-127").byteValue());
679:                assertEquals("Returned incorrect byte", -128, Byte.valueOf(
680:                        "-128").byteValue());
681:
682:                try {
683:                    Byte.valueOf("128");
684:                    fail("Failed to throw exception when passes value > byte");
685:                } catch (NumberFormatException e) {
686:                }
687:            }
688:
689:            /**
690:             * @tests java.lang.Byte#valueOf(java.lang.String, int)
691:             */
692:            public void test_valueOfLjava_lang_StringI2() {
693:                assertEquals("Returned incorrect byte", 10, Byte.valueOf("A",
694:                        16).byteValue());
695:                assertEquals("Returned incorrect byte", 127, Byte.valueOf(
696:                        "127", 10).byteValue());
697:                assertEquals("Returned incorrect byte", -127, Byte.valueOf(
698:                        "-127", 10).byteValue());
699:                assertEquals("Returned incorrect byte", -128, Byte.valueOf(
700:                        "-128", 10).byteValue());
701:                assertEquals("Returned incorrect byte", 127, Byte.valueOf("7f",
702:                        16).byteValue());
703:                assertEquals("Returned incorrect byte", -127, Byte.valueOf(
704:                        "-7f", 16).byteValue());
705:                assertEquals("Returned incorrect byte", -128, Byte.valueOf(
706:                        "-80", 16).byteValue());
707:
708:                try {
709:                    Byte.valueOf("128", 10);
710:                    fail("Failed to throw exception when passes value > byte");
711:                } catch (NumberFormatException e) {
712:                }
713:            }
714:        }
w_ww_._j_a__v_a2__s._c_o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.