ByteTest.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.apache.harmony.luni.tests.java.lang;
18
19import dalvik.annotation.TestInfo;
20import dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTarget;
22import dalvik.annotation.TestTargetClass;
23
24import junit.framework.TestCase;
25
26@TestTargetClass(Byte.class)
27public class ByteTest extends TestCase {
28
29    /**
30     * @tests java.lang.Byte#valueOf(byte)
31     */
32    @TestInfo(
33      level = TestLevel.COMPLETE,
34      purpose = "",
35      targets = {
36        @TestTarget(
37          methodName = "valueOf",
38          methodArgs = {byte.class}
39        )
40    })
41    public void test_valueOfB() {
42        assertEquals(new Byte(Byte.MIN_VALUE), Byte.valueOf(Byte.MIN_VALUE));
43        assertEquals(new Byte(Byte.MAX_VALUE), Byte.valueOf(Byte.MAX_VALUE));
44        assertEquals(new Byte((byte) 0), Byte.valueOf((byte) 0));
45
46        byte b = Byte.MIN_VALUE + 1;
47        while (b < Byte.MAX_VALUE) {
48            assertEquals(new Byte(b), Byte.valueOf(b));
49            assertSame(Byte.valueOf(b), Byte.valueOf(b));
50            b++;
51        }
52    }
53
54    /**
55     * @tests java.lang.Byte#hashCode()
56     */
57    @TestInfo(
58      level = TestLevel.COMPLETE,
59      purpose = "",
60      targets = {
61        @TestTarget(
62          methodName = "hashCode",
63          methodArgs = {}
64        )
65    })
66    public void test_hashCode() {
67        assertEquals(1, new Byte((byte) 1).hashCode());
68        assertEquals(2, new Byte((byte) 2).hashCode());
69        assertEquals(0, new Byte((byte) 0).hashCode());
70        assertEquals(-1, new Byte((byte) -1).hashCode());
71    }
72
73    /**
74     * @tests java.lang.Byte#Byte(String)
75     */
76    @TestInfo(
77      level = TestLevel.COMPLETE,
78      purpose = "",
79      targets = {
80        @TestTarget(
81          methodName = "Byte",
82          methodArgs = {java.lang.String.class}
83        )
84    })
85    public void test_ConstructorLjava_lang_String() {
86        assertEquals(new Byte((byte) 0), new Byte("0"));
87        assertEquals(new Byte((byte) 1), new Byte("1"));
88        assertEquals(new Byte((byte) -1), new Byte("-1"));
89
90        try {
91            new Byte("0x1");
92            fail("Expected NumberFormatException with hex string.");
93        } catch (NumberFormatException e) {
94        }
95
96        try {
97            new Byte("9.2");
98            fail("Expected NumberFormatException with floating point string.");
99        } catch (NumberFormatException e) {
100        }
101
102        try {
103            new Byte("");
104            fail("Expected NumberFormatException with empty string.");
105        } catch (NumberFormatException e) {
106        }
107
108        try {
109            new Byte(null);
110            fail("Expected NumberFormatException with null string.");
111        } catch (NumberFormatException e) {
112        }
113    }
114
115    /**
116     * @tests java.lang.Byte#Byte(byte)
117     */
118    @TestInfo(
119      level = TestLevel.COMPLETE,
120      purpose = "",
121      targets = {
122        @TestTarget(
123          methodName = "Byte",
124          methodArgs = {byte.class}
125        )
126    })
127    public void test_ConstructorB() {
128        assertEquals(1, new Byte((byte) 1).byteValue());
129        assertEquals(2, new Byte((byte) 2).byteValue());
130        assertEquals(0, new Byte((byte) 0).byteValue());
131        assertEquals(-1, new Byte((byte) -1).byteValue());
132    }
133
134    /**
135     * @tests java.lang.Byte#byteValue()
136     */
137    @TestInfo(
138      level = TestLevel.PARTIAL_OK,
139      purpose = "",
140      targets = {
141        @TestTarget(
142          methodName = "byteValue",
143          methodArgs = {}
144        )
145    })
146    public void test_byteValue1() {
147        assertEquals(1, new Byte((byte) 1).byteValue());
148        assertEquals(2, new Byte((byte) 2).byteValue());
149        assertEquals(0, new Byte((byte) 0).byteValue());
150        assertEquals(-1, new Byte((byte) -1).byteValue());
151    }
152
153    /**
154     * @tests java.lang.Byte#equals(Object)
155     */
156    @TestInfo(
157      level = TestLevel.COMPLETE,
158      purpose = "",
159      targets = {
160        @TestTarget(
161          methodName = "equals",
162          methodArgs = {java.lang.Object.class}
163        )
164    })
165    public void test_equalsLjava_lang_Object() {
166        assertEquals(new Byte((byte) 0), Byte.valueOf((byte) 0));
167        assertEquals(new Byte((byte) 1), Byte.valueOf((byte) 1));
168        assertEquals(new Byte((byte) -1), Byte.valueOf((byte) -1));
169
170        Byte fixture = new Byte((byte) 25);
171        assertEquals(fixture, fixture);
172        assertFalse(fixture.equals(null));
173        assertFalse(fixture.equals("Not a Byte"));
174    }
175
176    /**
177     * @tests java.lang.Byte#toString()
178     */
179    @TestInfo(
180      level = TestLevel.COMPLETE,
181      purpose = "",
182      targets = {
183        @TestTarget(
184          methodName = "toString",
185          methodArgs = {}
186        )
187    })
188    public void test_toString() {
189        assertEquals("-1", new Byte((byte) -1).toString());
190        assertEquals("0", new Byte((byte) 0).toString());
191        assertEquals("1", new Byte((byte) 1).toString());
192        assertEquals("-1", new Byte((byte) 0xFF).toString());
193    }
194
195    /**
196     * @tests java.lang.Byte#toString(byte)
197     */
198    @TestInfo(
199      level = TestLevel.COMPLETE,
200      purpose = "",
201      targets = {
202        @TestTarget(
203          methodName = "toString",
204          methodArgs = {byte.class}
205        )
206    })
207    public void test_toStringB() {
208        assertEquals("-1", Byte.toString((byte) -1));
209        assertEquals("0", Byte.toString((byte) 0));
210        assertEquals("1", Byte.toString((byte) 1));
211        assertEquals("-1", Byte.toString((byte) 0xFF));
212    }
213
214    /**
215     * @tests java.lang.Byte#valueOf(String)
216     */
217    @TestInfo(
218      level = TestLevel.COMPLETE,
219      purpose = "Checks only positive functionality.",
220      targets = {
221        @TestTarget(
222          methodName = "valueOf",
223          methodArgs = {java.lang.String.class}
224        )
225    })
226    public void test_valueOfLjava_lang_String() {
227        assertEquals(new Byte((byte) 0), Byte.valueOf("0"));
228        assertEquals(new Byte((byte) 1), Byte.valueOf("1"));
229        assertEquals(new Byte((byte) -1), Byte.valueOf("-1"));
230
231        try {
232            Byte.valueOf("0x1");
233            fail("Expected NumberFormatException with hex string.");
234        } catch (NumberFormatException e) {
235        }
236
237        try {
238            Byte.valueOf("9.2");
239            fail("Expected NumberFormatException with floating point string.");
240        } catch (NumberFormatException e) {
241        }
242
243        try {
244            Byte.valueOf("");
245            fail("Expected NumberFormatException with empty string.");
246        } catch (NumberFormatException e) {
247        }
248
249        try {
250            Byte.valueOf(null);
251            fail("Expected NumberFormatException with null string.");
252        } catch (NumberFormatException e) {
253        }
254    }
255
256    /**
257     * @tests java.lang.Byte#valueOf(String,int)
258     */
259    @TestInfo(
260      level = TestLevel.PARTIAL_OK,
261      purpose = "Doesn't check boundary values.",
262      targets = {
263        @TestTarget(
264          methodName = "valueOf",
265          methodArgs = {java.lang.String.class, int.class}
266        )
267    })
268    public void test_valueOfLjava_lang_StringI() {
269        assertEquals(new Byte((byte) 0), Byte.valueOf("0", 10));
270        assertEquals(new Byte((byte) 1), Byte.valueOf("1", 10));
271        assertEquals(new Byte((byte) -1), Byte.valueOf("-1", 10));
272
273        //must be consistent with Character.digit()
274        assertEquals(Character.digit('1', 2), Byte.valueOf("1", 2).byteValue());
275        assertEquals(Character.digit('F', 16), Byte.valueOf("F", 16).byteValue());
276
277        try {
278            Byte.valueOf("0x1", 10);
279            fail("Expected NumberFormatException with hex string.");
280        } catch (NumberFormatException e) {
281        }
282
283        try {
284            Byte.valueOf("9.2", 10);
285            fail("Expected NumberFormatException with floating point string.");
286        } catch (NumberFormatException e) {
287        }
288
289        try {
290            Byte.valueOf("", 10);
291            fail("Expected NumberFormatException with empty string.");
292        } catch (NumberFormatException e) {
293        }
294
295        try {
296            Byte.valueOf(null, 10);
297            fail("Expected NumberFormatException with null string.");
298        } catch (NumberFormatException e) {
299        }
300    }
301
302    /**
303     * @tests java.lang.Byte#parseByte(String)
304     */
305    @TestInfo(
306      level = TestLevel.COMPLETE,
307      purpose = "",
308      targets = {
309        @TestTarget(
310          methodName = "parseByte",
311          methodArgs = {java.lang.String.class}
312        )
313    })
314    public void test_parseByteLjava_lang_String() {
315        assertEquals(0, Byte.parseByte("0"));
316        assertEquals(1, Byte.parseByte("1"));
317        assertEquals(-1, Byte.parseByte("-1"));
318
319        try {
320            Byte.parseByte("0x1");
321            fail("Expected NumberFormatException with hex string.");
322        } catch (NumberFormatException e) {
323        }
324
325        try {
326            Byte.parseByte("9.2");
327            fail("Expected NumberFormatException with floating point string.");
328        } catch (NumberFormatException e) {
329        }
330
331        try {
332            Byte.parseByte("");
333            fail("Expected NumberFormatException with empty string.");
334        } catch (NumberFormatException e) {
335        }
336
337        try {
338            Byte.parseByte(null);
339            fail("Expected NumberFormatException with null string.");
340        } catch (NumberFormatException e) {
341        }
342    }
343
344    /**
345     * @tests java.lang.Byte#parseByte(String,int)
346     */
347    @TestInfo(
348      level = TestLevel.PARTIAL_OK,
349      purpose = "Doesn't check boundary values.",
350      targets = {
351        @TestTarget(
352          methodName = "parseByte",
353          methodArgs = {java.lang.String.class, int.class}
354        )
355    })
356    public void test_parseByteLjava_lang_StringI() {
357        assertEquals(0, Byte.parseByte("0", 10));
358        assertEquals(1, Byte.parseByte("1", 10));
359        assertEquals(-1, Byte.parseByte("-1", 10));
360
361        //must be consistent with Character.digit()
362        assertEquals(Character.digit('1', 2), Byte.parseByte("1", 2));
363        assertEquals(Character.digit('F', 16), Byte.parseByte("F", 16));
364
365        try {
366            Byte.parseByte("0x1", 10);
367            fail("Expected NumberFormatException with hex string.");
368        } catch (NumberFormatException e) {
369        }
370
371        try {
372            Byte.parseByte("9.2", 10);
373            fail("Expected NumberFormatException with floating point string.");
374        } catch (NumberFormatException e) {
375        }
376
377        try {
378            Byte.parseByte("", 10);
379            fail("Expected NumberFormatException with empty string.");
380        } catch (NumberFormatException e) {
381        }
382
383        try {
384            Byte.parseByte(null, 10);
385            fail("Expected NumberFormatException with null string.");
386        } catch (NumberFormatException e) {
387        }
388    }
389
390    /**
391     * @tests java.lang.Byte#decode(String)
392     */
393    @TestInfo(
394      level = TestLevel.COMPLETE,
395      purpose = "",
396      targets = {
397        @TestTarget(
398          methodName = "decode",
399          methodArgs = {java.lang.String.class}
400        )
401    })
402    public void test_decodeLjava_lang_String() {
403        assertEquals(new Byte((byte) 0), Byte.decode("0"));
404        assertEquals(new Byte((byte) 1), Byte.decode("1"));
405        assertEquals(new Byte((byte) -1), Byte.decode("-1"));
406        assertEquals(new Byte((byte) 0xF), Byte.decode("0xF"));
407        assertEquals(new Byte((byte) 0xF), Byte.decode("#F"));
408        assertEquals(new Byte((byte) 0xF), Byte.decode("0XF"));
409        assertEquals(new Byte((byte) 07), Byte.decode("07"));
410
411        try {
412            Byte.decode("9.2");
413            fail("Expected NumberFormatException with floating point string.");
414        } catch (NumberFormatException e) {
415        }
416
417        try {
418            Byte.decode("");
419            fail("Expected NumberFormatException with empty string.");
420        } catch (NumberFormatException e) {
421        }
422
423        try {
424            Byte.decode(null);
425            //undocumented NPE, but seems consistent across JREs
426            fail("Expected NullPointerException with null string.");
427        } catch (NullPointerException e) {
428        }
429    }
430
431    /**
432     * @tests java.lang.Byte#doubleValue()
433     */
434    @TestInfo(
435      level = TestLevel.PARTIAL_OK,
436      purpose = "No boundary verification.",
437      targets = {
438        @TestTarget(
439          methodName = "doubleValue",
440          methodArgs = {}
441        )
442    })
443    public void test_doubleValue() {
444        assertEquals(-1D, new Byte((byte) -1).doubleValue(), 0D);
445        assertEquals(0D, new Byte((byte) 0).doubleValue(), 0D);
446        assertEquals(1D, new Byte((byte) 1).doubleValue(), 0D);
447    }
448
449    /**
450     * @tests java.lang.Byte#floatValue()
451     */
452    @TestInfo(
453      level = TestLevel.PARTIAL_OK,
454      purpose = "Doesn't verify boundary values.",
455      targets = {
456        @TestTarget(
457          methodName = "floatValue",
458          methodArgs = {}
459        )
460    })
461    public void test_floatValue() {
462        assertEquals(-1F, new Byte((byte) -1).floatValue(), 0F);
463        assertEquals(0F, new Byte((byte) 0).floatValue(), 0F);
464        assertEquals(1F, new Byte((byte) 1).floatValue(), 0F);
465    }
466
467    /**
468     * @tests java.lang.Byte#intValue()
469     */
470    @TestInfo(
471      level = TestLevel.PARTIAL_OK,
472      purpose = "No boundary verification.",
473      targets = {
474        @TestTarget(
475          methodName = "intValue",
476          methodArgs = {}
477        )
478    })
479    public void test_intValue() {
480        assertEquals(-1, new Byte((byte) -1).intValue());
481        assertEquals(0, new Byte((byte) 0).intValue());
482        assertEquals(1, new Byte((byte) 1).intValue());
483    }
484
485    /**
486     * @tests java.lang.Byte#longValue()
487     */
488    @TestInfo(
489      level = TestLevel.PARTIAL_OK,
490      purpose = "No boundary verification.",
491      targets = {
492        @TestTarget(
493          methodName = "longValue",
494          methodArgs = {}
495        )
496    })
497    public void test_longValue() {
498        assertEquals(-1L, new Byte((byte) -1).longValue());
499        assertEquals(0L, new Byte((byte) 0).longValue());
500        assertEquals(1L, new Byte((byte) 1).longValue());
501    }
502
503    /**
504     * @tests java.lang.Byte#shortValue()
505     */
506    @TestInfo(
507      level = TestLevel.PARTIAL_OK,
508      purpose = "Doesn't check boundary values.",
509      targets = {
510        @TestTarget(
511          methodName = "shortValue",
512          methodArgs = {}
513        )
514    })
515    public void test_shortValue() {
516        assertEquals(-1, new Byte((byte) -1).shortValue());
517        assertEquals(0, new Byte((byte) 0).shortValue());
518        assertEquals(1, new Byte((byte) 1).shortValue());
519    }
520
521    /**
522     * @tests java.lang.Byte#compareTo(Byte)
523     */
524    @TestInfo(
525      level = TestLevel.COMPLETE,
526      purpose = "",
527      targets = {
528        @TestTarget(
529          methodName = "compareTo",
530          methodArgs = {java.lang.Byte.class}
531        )
532    })
533    public void test_compareToLjava_lang_Byte() {
534        final Byte min = new Byte(Byte.MIN_VALUE);
535        final Byte zero = new Byte((byte) 0);
536        final Byte max = new Byte(Byte.MAX_VALUE);
537
538        assertTrue(max.compareTo(max) == 0);
539        assertTrue(min.compareTo(min) == 0);
540        assertTrue(zero.compareTo(zero) == 0);
541
542        assertTrue(max.compareTo(zero) > 0);
543        assertTrue(max.compareTo(min) > 0);
544
545        assertTrue(zero.compareTo(max) < 0);
546        assertTrue(zero.compareTo(min) > 0);
547
548        assertTrue(min.compareTo(zero) < 0);
549        assertTrue(min.compareTo(max) < 0);
550
551        try {
552            min.compareTo(null);
553            fail("No NPE");
554        } catch (NullPointerException e) {
555        }
556    }
557
558    /**
559     * @tests java.lang.Byte#Byte(byte)
560     */
561    @TestInfo(
562      level = TestLevel.PARTIAL,
563      purpose = "Boundary test.",
564      targets = {
565        @TestTarget(
566          methodName = "Byte",
567          methodArgs = {byte.class}
568        )
569    })
570    public void test_ConstructorB2() {
571        // Test for method java.lang.Byte(byte)
572
573        Byte b = new Byte((byte) 127);
574        assertTrue("Byte creation failed", b.byteValue() == (byte) 127);
575    }
576
577    /**
578     * @tests java.lang.Byte#Byte(java.lang.String)
579     */
580    @TestInfo(
581      level = TestLevel.PARTIAL,
582      purpose = "Doesn't check empty string or null.",
583      targets = {
584        @TestTarget(
585          methodName = "Byte",
586          methodArgs = {java.lang.String.class}
587        )
588    })
589    public void test_ConstructorLjava_lang_String2() {
590        // Test for method java.lang.Byte(java.lang.String)
591
592        Byte b = new Byte("127");
593        Byte nb = new Byte("-128");
594        assertTrue("Incorrect Byte Object created", b.byteValue() == (byte) 127
595                && (nb.byteValue() == (byte) -128));
596
597    }
598
599    /**
600     * @tests java.lang.Byte#byteValue()
601     */
602    @TestInfo(
603      level = TestLevel.PARTIAL_OK,
604      purpose = "Boundary test.",
605      targets = {
606        @TestTarget(
607          methodName = "byteValue",
608          methodArgs = {}
609        )
610    })
611    public void test_byteValue() {
612        // Test for method byte java.lang.Byte.byteValue()
613        assertTrue("Returned incorrect byte value",
614                new Byte((byte) 127).byteValue() == (byte) (127));
615    }
616
617    /**
618     * @tests java.lang.Byte#compareTo(java.lang.Byte)
619     */
620    @TestInfo(
621      level = TestLevel.COMPLETE,
622      purpose = "",
623      targets = {
624        @TestTarget(
625          methodName = "compareTo",
626          methodArgs = {java.lang.Byte.class}
627        )
628    })
629    public void test_compareToLjava_lang_Byte2() {
630        // Test for method int java.lang.Byte.compareTo(java.lang.Byte)
631        assertTrue("Comparison failed", new Byte((byte) 1).compareTo(new Byte((byte) 2)) < 0);
632        assertTrue("Comparison failed", new Byte((byte) 1).compareTo(new Byte((byte) -2)) > 0);
633        assertEquals("Comparison failed", 0, new Byte((byte) 1).compareTo(new Byte((byte) 1)));
634    }
635
636    /**
637     * @tests java.lang.Byte#decode(java.lang.String)
638     */
639    @TestInfo(
640      level = TestLevel.COMPLETE,
641      purpose = "",
642      targets = {
643        @TestTarget(
644          methodName = "decode",
645          methodArgs = {java.lang.String.class}
646        )
647    })
648    public void test_decodeLjava_lang_String2() {
649        // Test for method java.lang.Byte
650        // java.lang.Byte.decode(java.lang.String)
651        assertTrue("String decoded incorrectly, wanted: 1 got: " + Byte.decode("1").toString(),
652                Byte.decode("1").equals(new Byte((byte) 1)));
653        assertTrue("String decoded incorrectly, wanted: -1 got: "
654                + Byte.decode("-1").toString(), Byte.decode("-1").equals(new Byte((byte) -1)));
655        assertTrue("String decoded incorrectly, wanted: 127 got: "
656                + Byte.decode("127").toString(), Byte.decode("127")
657                .equals(new Byte((byte) 127)));
658        assertTrue("String decoded incorrectly, wanted: -128 got: "
659                + Byte.decode("-128").toString(), Byte.decode("-128").equals(
660                new Byte((byte) -128)));
661        assertTrue("String decoded incorrectly, wanted: 127 got: "
662                + Byte.decode("0x7f").toString(), Byte.decode("0x7f").equals(
663                new Byte((byte) 127)));
664        assertTrue("String decoded incorrectly, wanted: -128 got: "
665                + Byte.decode("-0x80").toString(), Byte.decode("-0x80").equals(
666                new Byte((byte) -128)));
667
668        boolean exception = false;
669        try {
670            Byte.decode("128");
671        } catch (NumberFormatException e) {
672            // Correct
673            exception = true;
674        }
675        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
676
677        exception = false;
678        try {
679            Byte.decode("-129");
680        } catch (NumberFormatException e) {
681            // Correct
682            exception = true;
683        }
684        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
685
686        exception = false;
687        try {
688            Byte.decode("0x80");
689        } catch (NumberFormatException e) {
690            // Correct
691            exception = true;
692        }
693        assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
694
695        exception = false;
696        try {
697            Byte.decode("-0x81");
698        } catch (NumberFormatException e) {
699            // Correct
700            exception = true;
701        }
702        assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
703    }
704
705    /**
706     * @tests java.lang.Byte#doubleValue()
707     */
708    @TestInfo(
709      level = TestLevel.PARTIAL_OK,
710      purpose = "Checks boundary value.",
711      targets = {
712        @TestTarget(
713          methodName = "doubleValue",
714          methodArgs = {}
715        )
716    })
717    public void test_doubleValue2() {
718        assertEquals(127D, new Byte((byte) 127).doubleValue(), 0.0);
719    }
720
721    /**
722     * @tests java.lang.Byte#equals(java.lang.Object)
723     */
724    @TestInfo(
725      level = TestLevel.PARTIAL,
726      purpose = "Checks that negative value doesn't equal to positive.",
727      targets = {
728        @TestTarget(
729          methodName = "equals",
730          methodArgs = {java.lang.Object.class}
731        )
732    })
733    public void test_equalsLjava_lang_Object2() {
734        // Test for method boolean java.lang.Byte.equals(java.lang.Object)
735        Byte b1 = new Byte((byte) 90);
736        Byte b2 = new Byte((byte) 90);
737        Byte b3 = new Byte((byte) -90);
738        assertTrue("Equality test failed", b1.equals(b2));
739        assertTrue("Equality test failed", !b1.equals(b3));
740    }
741
742    /**
743     * @tests java.lang.Byte#floatValue()
744     */
745    @TestInfo(
746      level = TestLevel.PARTIAL_OK,
747      purpose = "Boundary test.",
748      targets = {
749        @TestTarget(
750          methodName = "floatValue",
751          methodArgs = {}
752        )
753    })
754    public void test_floatValue2() {
755        assertEquals(127F, new Byte((byte) 127).floatValue(), 0.0);
756    }
757
758    /**
759     * @tests java.lang.Byte#hashCode()
760     */
761    @TestInfo(
762      level = TestLevel.PARTIAL,
763      purpose = "Boundary test.",
764      targets = {
765        @TestTarget(
766          methodName = "hashCode",
767          methodArgs = {}
768        )
769    })
770    public void test_hashCode2() {
771        // Test for method int java.lang.Byte.hashCode()
772        assertEquals("Incorrect hash returned", 127, new Byte((byte) 127).hashCode());
773    }
774
775    /**
776     * @tests java.lang.Byte#intValue()
777     */
778    @TestInfo(
779      level = TestLevel.PARTIAL_OK,
780      purpose = "Boundary test.",
781      targets = {
782        @TestTarget(
783          methodName = "intValue",
784          methodArgs = {}
785        )
786    })
787    public void test_intValue2() {
788        // Test for method int java.lang.Byte.intValue()
789        assertEquals("Returned incorrect int value", 127, new Byte((byte) 127).intValue());
790    }
791
792    /**
793     * @tests java.lang.Byte#longValue()
794     */
795    @TestInfo(
796      level = TestLevel.PARTIAL_OK,
797      purpose = "Verifies boundary values.",
798      targets = {
799        @TestTarget(
800          methodName = "longValue",
801          methodArgs = {}
802        )
803    })
804    public void test_longValue2() {
805        // Test for method long java.lang.Byte.longValue()
806        assertEquals("Returned incorrect long value", 127L, new Byte((byte) 127).longValue());
807    }
808
809    /**
810     * @tests java.lang.Byte#parseByte(java.lang.String)
811     */
812    @TestInfo(
813      level = TestLevel.PARTIAL,
814      purpose = "Boundary verification.",
815      targets = {
816        @TestTarget(
817          methodName = "parseByte",
818          methodArgs = {java.lang.String.class}
819        )
820    })
821    public void test_parseByteLjava_lang_String2() {
822        assertEquals((byte)127, Byte.parseByte("127"));
823        assertEquals((byte)-128, Byte.parseByte("-128"));
824        assertEquals((byte)0, Byte.parseByte("0"));
825        assertEquals((byte)0x80, Byte.parseByte("-128"));
826        assertEquals((byte)0x7F, Byte.parseByte("127"));
827
828        try {
829            Byte.parseByte("-1000");
830            fail("No NumberFormatException");
831        } catch (NumberFormatException e) {
832        }
833
834        try {
835            Byte.parseByte("128");
836            fail("No NumberFormatException");
837        } catch (NumberFormatException e) {
838        }
839
840        try {
841            Byte.parseByte("-129");
842            fail("No NumberFormatException");
843        } catch (NumberFormatException e) {
844        }
845    }
846
847    /**
848     * @tests java.lang.Byte#parseByte(java.lang.String, int)
849     */
850    @TestInfo(
851      level = TestLevel.PARTIAL_OK,
852      purpose = "Boundary test.",
853      targets = {
854        @TestTarget(
855          methodName = "parseByte",
856          methodArgs = {java.lang.String.class, int.class}
857        )
858    })
859    public void test_parseByteLjava_lang_StringI2() {
860        // Test for method byte java.lang.Byte.parseByte(java.lang.String, int)
861        byte b = Byte.parseByte("127", 10);
862        byte bn = Byte.parseByte("-128", 10);
863        assertTrue("Invalid parse of dec byte", b == (byte) 127 && (bn == (byte) -128));
864        assertEquals("Failed to parse hex value", 10, Byte.parseByte("A", 16));
865        assertEquals("Returned incorrect value for 0 hex", 0, Byte.parseByte("0", 16));
866        assertTrue("Returned incorrect value for most negative value hex", Byte.parseByte(
867                "-80", 16) == (byte) 0x80);
868        assertTrue("Returned incorrect value for most positive value hex", Byte.parseByte("7f",
869                16) == 0x7f);
870        assertEquals("Returned incorrect value for 0 decimal", 0, Byte.parseByte("0", 10));
871        assertTrue("Returned incorrect value for most negative value decimal", Byte.parseByte(
872                "-128", 10) == (byte) 0x80);
873        assertTrue("Returned incorrect value for most positive value decimal", Byte.parseByte(
874                "127", 10) == 0x7f);
875
876        try {
877            Byte.parseByte("-1000", 10);
878            fail("Failed to throw exception");
879        } catch (NumberFormatException e) {
880        }
881
882        try {
883            Byte.parseByte("128", 10);
884            fail("Failed to throw exception for MAX_VALUE + 1");
885        } catch (NumberFormatException e) {
886        }
887
888        try {
889            Byte.parseByte("-129", 10);
890            fail("Failed to throw exception for MIN_VALUE - 1");
891        } catch (NumberFormatException e) {
892        }
893
894        try {
895            Byte.parseByte("80", 16);
896            fail("Failed to throw exception for hex MAX_VALUE + 1");
897        } catch (NumberFormatException e) {
898        }
899
900        try {
901            Byte.parseByte("-81", 16);
902            fail("Failed to throw exception for hex MIN_VALUE + 1");
903        } catch (NumberFormatException e) {
904        }
905    }
906
907    /**
908     * @tests java.lang.Byte#shortValue()
909     */
910    @TestInfo(
911      level = TestLevel.PARTIAL_OK,
912      purpose = "Boundary test.",
913      targets = {
914        @TestTarget(
915          methodName = "shortValue",
916          methodArgs = {}
917        )
918    })
919    public void test_shortValue2() {
920        assertEquals((short)127, new Byte((byte)127).shortValue());
921    }
922
923    /**
924     * @tests java.lang.Byte#toString()
925     */
926    @TestInfo(
927      level = TestLevel.PARTIAL,
928      purpose = "Boundary test.",
929      targets = {
930        @TestTarget(
931          methodName = "toString",
932          methodArgs = {}
933        )
934    })
935    public void test_toString2() {
936        assertEquals("Returned incorrect String", "127", new Byte((byte) 127).toString());
937        assertEquals("Returned incorrect String", "-127", new Byte((byte) -127).toString());
938        assertEquals("Returned incorrect String", "-128", new Byte((byte) -128).toString());
939    }
940
941    /**
942     * @tests java.lang.Byte#toString(byte)
943     */
944    @TestInfo(
945      level = TestLevel.PARTIAL,
946      purpose = "Boundary test.",
947      targets = {
948        @TestTarget(
949          methodName = "toString",
950          methodArgs = {byte.class}
951        )
952    })
953    public void test_toStringB2() {
954        assertEquals("Returned incorrect String", "127", Byte.toString((byte) 127));
955        assertEquals("Returned incorrect String", "-127", Byte.toString((byte) -127));
956        assertEquals("Returned incorrect String", "-128", Byte.toString((byte) -128));
957    }
958
959    /**
960     * @tests java.lang.Byte#valueOf(java.lang.String)
961     */
962    @TestInfo(
963      level = TestLevel.PARTIAL,
964      purpose = "Boundary test.",
965      targets = {
966        @TestTarget(
967          methodName = "valueOf",
968          methodArgs = {java.lang.String.class}
969        )
970    })
971    public void test_valueOfLjava_lang_String2() {
972        assertEquals("Returned incorrect byte", 0, Byte.valueOf("0").byteValue());
973        assertEquals("Returned incorrect byte", 127, Byte.valueOf("127").byteValue());
974        assertEquals("Returned incorrect byte", -127, Byte.valueOf("-127").byteValue());
975        assertEquals("Returned incorrect byte", -128, Byte.valueOf("-128").byteValue());
976
977        try {
978            Byte.valueOf("128");
979            fail("Failed to throw exception when passes value > byte");
980        } catch (NumberFormatException e) {
981        }
982    }
983
984    /**
985     * @tests java.lang.Byte#valueOf(java.lang.String, int)
986     */
987    @TestInfo(
988      level = TestLevel.PARTIAL_OK,
989      purpose = "Boundary test.",
990      targets = {
991        @TestTarget(
992          methodName = "valueOf",
993          methodArgs = {java.lang.String.class, int.class}
994        )
995    })
996    public void test_valueOfLjava_lang_StringI2() {
997        assertEquals("Returned incorrect byte", 10, Byte.valueOf("A", 16).byteValue());
998        assertEquals("Returned incorrect byte", 127, Byte.valueOf("127", 10).byteValue());
999        assertEquals("Returned incorrect byte", -127, Byte.valueOf("-127", 10).byteValue());
1000        assertEquals("Returned incorrect byte", -128, Byte.valueOf("-128", 10).byteValue());
1001        assertEquals("Returned incorrect byte", 127, Byte.valueOf("7f", 16).byteValue());
1002        assertEquals("Returned incorrect byte", -127, Byte.valueOf("-7f", 16).byteValue());
1003        assertEquals("Returned incorrect byte", -128, Byte.valueOf("-80", 16).byteValue());
1004
1005        try {
1006            Byte.valueOf("128", 10);
1007            fail("Failed to throw exception when passes value > byte");
1008        } catch (NumberFormatException e) {
1009        }
1010    }
1011}
1012